import { AppState } from '@/ui_models/app_state'; import { Icon } from './Icon'; import { toDirective, useCloseOnBlur } from './utils'; import { useRef, useState } from 'preact/hooks'; import { WebApplication } from '@/ui_models/application'; import VisuallyHidden from '@reach/visually-hidden'; import { Disclosure, DisclosureButton, DisclosurePanel, } from '@reach/disclosure'; import { Switch } from './Switch'; import { observer } from 'mobx-react-lite'; type Props = { appState: AppState; application: WebApplication; }; const SearchOptions = observer(({ appState }: Props) => { const { searchOptions } = appState; const { includeProtectedContents, includeArchived, includeTrashed, } = searchOptions; const [open, setOpen] = useState(false); const [position, setPosition] = useState({ top: 0, right: 0, }); const buttonRef = useRef(); const panelRef = useRef(); const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(panelRef, setOpen); async function toggleIncludeProtectedContents() { setLockCloseOnBlur(true); try { await searchOptions.toggleIncludeProtectedContents(); } finally { setLockCloseOnBlur(false); } } return ( { const rect = buttonRef.current.getBoundingClientRect(); setPosition({ top: rect.bottom, right: document.body.clientWidth - rect.right, }); setOpen(!open); }} > Search options

Include protected contents

Include archived notes

Include trashed notes

); }); export const SearchOptionsDirective = toDirective(SearchOptions);