diff --git a/src/components/Accordion/FormAccordion.tsx b/src/components/Accordion/FormAccordion.tsx index 8ca5403476..7af312beb5 100644 --- a/src/components/Accordion/FormAccordion.tsx +++ b/src/components/Accordion/FormAccordion.tsx @@ -50,6 +50,12 @@ const StyledAccordionItemTrigger = styled(AccordionItemTrigger, { const StyledAccordionItemContent = styled(AccordionItemContent, { base: { overflowX: "visible", + // We need to keep overflow unset for our sticky toolbar. + // Ark has a bug where data-state is removed when the accordion is open, so we have to check + // whether it doesn't exist to know if the accordion is open. + "&:not([data-state])": { + overflow: "unset", + }, }, variants: { invalid: { diff --git a/src/components/SlateEditor/RichTextEditor.tsx b/src/components/SlateEditor/RichTextEditor.tsx index 395ba3d76b..71811cc6b6 100644 --- a/src/components/SlateEditor/RichTextEditor.tsx +++ b/src/components/SlateEditor/RichTextEditor.tsx @@ -20,6 +20,7 @@ import { FormikStatus } from "../../interfaces"; import { nativeOnDragOver, nativeOnDragStart, nativeOnDrop } from "./plugins/DND/nativeDnd"; import { SlateDndContext } from "./plugins/DND/SlateDndContext"; import { SlateToolbar } from "./plugins/toolbar"; +import { NewSlateToolbar } from "./plugins/toolbar/NewSlateToolbar"; import { ArticleFormType } from "../../containers/FormikForm/articleFormHooks"; const StyledSlateWrapper = styled("div", { @@ -142,7 +143,8 @@ const RichTextEditor = ({ - + {/* */} + {blockPicker} { + // Do not render categories with only disabled and hidden options + const validChildren = Children.toArray(children).filter( + (child) => + isValidElement>(child) && + !child.props.options?.every((el) => el.hidden === true), + ); + + return validChildren; +}; + +export const NewSlateToolbar = () => { + const editor = useSlate(); + const selection = useSlateSelection(); + // const prevState = usePrevious(state); + const { userPermissions } = useSession(); + const options = useMemo(() => { + return editor.toolbarState?.({ + // TODO: This is not really scalable if we're going to introduce more constraints later-on. + options: userPermissions?.includes(AI_ACCESS_SCOPE) + ? undefined + : { inline: { rephrase: { hidden: true, disabled: true } } }, + }); + }, [editor, selection, userPermissions]); + + return ( + + + + + + + + + + + ); +};