forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSideMenuController.tsx
More file actions
56 lines (50 loc) · 1.51 KB
/
SideMenuController.tsx
File metadata and controls
56 lines (50 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { SideMenuExtension } from "@blocknote/core/extensions";
import { FC, useMemo } from "react";
import { useExtensionState } from "../../hooks/useExtension.js";
import { BlockPopover } from "../Popovers/BlockPopover.js";
import { FloatingUIOptions } from "../Popovers/FloatingUIOptions.js";
import { SideMenu } from "./SideMenu.js";
import { SideMenuProps } from "./SideMenuProps.js";
export const SideMenuController = (props: {
sideMenu?: FC<SideMenuProps>;
floatingUIOptions?: Partial<FloatingUIOptions>;
}) => {
const state = useExtensionState(SideMenuExtension, {
selector: (state) => {
return state !== undefined
? {
show: state.show,
block: state.block,
}
: undefined;
},
});
const { show, block } = state || {};
const floatingUIOptions = useMemo<FloatingUIOptions>(
() => ({
...props.floatingUIOptions,
useFloatingOptions: {
open: show,
placement: "left-start",
...props.floatingUIOptions?.useFloatingOptions,
},
useDismissProps: {
enabled: false,
...props.floatingUIOptions?.useDismissProps,
},
elementProps: {
style: {
zIndex: 20,
},
...props.floatingUIOptions?.elementProps,
},
}),
[props.floatingUIOptions, show],
);
const Component = props.sideMenu || SideMenu;
return (
<BlockPopover blockId={show ? block?.id : undefined} {...floatingUIOptions}>
{block?.id && <Component />}
</BlockPopover>
);
};