* feat: add editor icon * refactor: remove 'any' type and format * refactor: move NotesOptions and add ChangeEditorOption * refactor: fix type for using regular RefObject<T> * feat: add hide-if-last-child util class * feat: add Change Editor option * feat: make radio btn gray if not checked * fix: accordion menu header and item sizing/spacing * feat: add Escape key to KeyboardKey enum * refactor: Remove Editor Menu * feat: add editor select functionality * refactor: move plain editor name to constant * feat: add premium editors with modal if no subscription refactor: simplify menu group creation * feat: show alert when switching to non-interchangeable editor * fix: change editor menu going out of bounds * feat: increase group header & editor item size * fix: change editor menu close on blur * refactor: Use KeyboardKey enum & remove else statement * feat: add keyboard navigation to change editor menu * fix: editor menu separators * feat: improve change editor menu sizing & spacing * feat: show alert only if editor is not interchangeable * feat: don't show alert when switching to/from plain editor * chore: bump snjs version * feat: temporarily remove change editor alert * feat: dynamically get footer height * refactor: move magic number to const * refactor: move constants to constants file * feat: use const instead of magic number
102 lines
3.1 KiB
TypeScript
102 lines
3.1 KiB
TypeScript
import { AppState } from '@/ui_models/app_state';
|
|
import { Icon } from './Icon';
|
|
import VisuallyHidden from '@reach/visually-hidden';
|
|
import { toDirective, useCloseOnBlur } from './utils';
|
|
import {
|
|
Disclosure,
|
|
DisclosureButton,
|
|
DisclosurePanel,
|
|
} from '@reach/disclosure';
|
|
import { useRef, useState } from 'preact/hooks';
|
|
import { observer } from 'mobx-react-lite';
|
|
import { NotesOptions } from './NotesOptions/NotesOptions';
|
|
import { WebApplication } from '@/ui_models/application';
|
|
|
|
type Props = {
|
|
application: WebApplication;
|
|
appState: AppState;
|
|
};
|
|
|
|
export const NotesOptionsPanel = observer(
|
|
({ application, appState }: Props) => {
|
|
const [open, setOpen] = useState(false);
|
|
const [position, setPosition] = useState({
|
|
top: 0,
|
|
right: 0,
|
|
});
|
|
const [maxHeight, setMaxHeight] = useState<number | 'auto'>('auto');
|
|
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
const panelRef = useRef<HTMLDivElement>(null);
|
|
const [closeOnBlur] = useCloseOnBlur(panelRef, setOpen);
|
|
const [submenuOpen, setSubmenuOpen] = useState(false);
|
|
|
|
const onSubmenuChange = (open: boolean) => {
|
|
setSubmenuOpen(open);
|
|
};
|
|
|
|
return (
|
|
<Disclosure
|
|
open={open}
|
|
onChange={() => {
|
|
const rect = buttonRef.current?.getBoundingClientRect();
|
|
if (rect) {
|
|
const { clientHeight } = document.documentElement;
|
|
const footerElementRect = document
|
|
.getElementById('footer-bar')
|
|
?.getBoundingClientRect();
|
|
const footerHeightInPx = footerElementRect?.height;
|
|
if (footerHeightInPx) {
|
|
setMaxHeight(clientHeight - rect.bottom - footerHeightInPx - 2);
|
|
}
|
|
setPosition({
|
|
top: rect.bottom,
|
|
right: document.body.clientWidth - rect.right,
|
|
});
|
|
setOpen(!open);
|
|
}
|
|
}}
|
|
>
|
|
<DisclosureButton
|
|
onKeyDown={(event) => {
|
|
if (event.key === 'Escape' && !submenuOpen) {
|
|
setOpen(false);
|
|
}
|
|
}}
|
|
onBlur={closeOnBlur}
|
|
ref={buttonRef}
|
|
className="sn-icon-button"
|
|
>
|
|
<VisuallyHidden>Actions</VisuallyHidden>
|
|
<Icon type="more" className="block" />
|
|
</DisclosureButton>
|
|
<DisclosurePanel
|
|
onKeyDown={(event) => {
|
|
if (event.key === 'Escape' && !submenuOpen) {
|
|
setOpen(false);
|
|
buttonRef.current?.focus();
|
|
}
|
|
}}
|
|
ref={panelRef}
|
|
style={{
|
|
...position,
|
|
maxHeight,
|
|
}}
|
|
className="sn-dropdown sn-dropdown--animated min-w-80 max-h-120 max-w-xs flex flex-col py-2 overflow-y-auto fixed"
|
|
onBlur={closeOnBlur}
|
|
>
|
|
{open && (
|
|
<NotesOptions
|
|
application={application}
|
|
appState={appState}
|
|
closeOnBlur={closeOnBlur}
|
|
onSubmenuChange={onSubmenuChange}
|
|
/>
|
|
)}
|
|
</DisclosurePanel>
|
|
</Disclosure>
|
|
);
|
|
}
|
|
);
|
|
|
|
export const NotesOptionsPanelDirective = toDirective<Props>(NotesOptionsPanel);
|