import { AppState } from '@/ui_models/app_state'; import { Icon, IconType } from './Icon'; import { Switch } from './Switch'; import { observer } from 'mobx-react-lite'; import { useRef, useState } from 'preact/hooks'; import { Disclosure, DisclosureButton, DisclosurePanel, } from '@reach/disclosure'; type Props = { appState: AppState; closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void; setLockCloseOnBlur: (lock: boolean) => void; }; export const NotesOptions = observer( ({ appState, closeOnBlur, setLockCloseOnBlur }: Props) => { const [tagsMenuOpen, setTagsMenuOpen] = useState(false); const [tagsMenuPosition, setTagsMenuPosition] = useState({ top: 0, right: 0, }); const notes = Object.values(appState.notes.selectedNotes); const hidePreviews = !notes.some((note) => !note.hidePreview); const locked = !notes.some((note) => !note.locked); const archived = !notes.some((note) => !note.archived); const trashed = !notes.some((note) => !note.trashed); const pinned = !notes.some((note) => !note.pinned); const trashButtonRef = useRef(); const tagsButtonRef = useRef(); const iconClass = 'fill-current color-neutral mr-2'; const buttonClass = 'flex items-center border-0 focus:inner-ring-info ' + 'cursor-pointer hover:bg-contrast color-text bg-transparent h-10 px-3 ' + 'text-left'; return ( <> { appState.notes.setLockSelectedNotes(!locked); }} > Prevent editing { appState.notes.setHideSelectedNotePreviews(!hidePreviews); }} > Show preview
{ const buttonRect = tagsButtonRef.current.getBoundingClientRect(); const { offsetTop, offsetWidth } = tagsButtonRef.current; setTagsMenuPosition({ top: offsetTop, right: ((buttonRect.right + 265) > document.body.clientWidth) ? offsetWidth : -offsetWidth, }); setTagsMenuOpen(!tagsMenuOpen); }} > { if (event.key === 'Escape') { setTagsMenuOpen(false); } }} onBlur={closeOnBlur} ref={tagsButtonRef} className={`${buttonClass} justify-between`} >
{"Add tag"}
{ if (event.key === 'Escape') { setTagsMenuOpen(false); tagsButtonRef.current.focus(); } }} style={{ ...tagsMenuPosition }} className="sn-dropdown sn-dropdown-anchor-right flex flex-col py-2 max-w-265" > {appState.tags.tags.map(tag => ( ))}
); } );