import { AppState } from '@/ui_models/app_state'; import { Icon } from './Icon'; import { toDirective, useCloseOnBlur } from './utils'; import { useEffect, 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 [maxWidth, setMaxWidth] = useState('auto'); const buttonRef = useRef(null); const panelRef = useRef(null); const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(panelRef as any, setOpen); async function toggleIncludeProtectedContents() { setLockCloseOnBlur(true); try { await searchOptions.toggleIncludeProtectedContents(); } finally { setLockCloseOnBlur(false); } } const updateWidthAndPosition = () => { const rect = buttonRef.current!.getBoundingClientRect(); setMaxWidth(rect.right - 16); setPosition({ top: rect.bottom, right: document.body.clientWidth - rect.right, }); }; useEffect(() => { window.addEventListener('resize', updateWidthAndPosition); return () => { window.removeEventListener('resize', updateWidthAndPosition); }; }, []); return ( { updateWidthAndPosition(); setOpen(!open); }} > Search options

Include protected contents

Include archived notes

Include trashed notes

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