/
positioner-extension.stories.tsx
69 lines (63 loc) 路 1.58 KB
/
positioner-extension.stories.tsx
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
57
58
59
60
61
62
63
64
65
66
67
68
69
import { FC } from 'react';
import {
BoldExtension,
BulletListExtension,
HeadingExtension,
ItalicExtension,
OrderedListExtension,
UnderlineExtension,
} from 'remirror/extensions';
import {
FloatingWrapper,
Remirror,
ThemeProvider,
useActive,
useCommands,
useRemirror,
} from '@remirror/react';
export default { title: 'Extensions / Positioner' };
const extensions = () => [
new HeadingExtension(),
new BoldExtension(),
new ItalicExtension(),
new UnderlineExtension(),
new BulletListExtension(),
new OrderedListExtension(),
];
const FloatingButtons = () => {
const commands = useCommands();
const active = useActive();
return (
<FloatingWrapper positioner='cursor' placement='top'>
<button
onClick={() => commands.toggleBold()}
style={{ fontWeight: active.bold() ? 'bold' : undefined }}
data-testid='bubble-menu-bold'
>
Bold
</button>
<button
onClick={() => commands.toggleItalic()}
style={{ fontWeight: active.italic() ? 'bold' : undefined }}
>
Italic
</button>
<button
onClick={() => commands.toggleUnderline()}
style={{ fontWeight: active.underline() ? 'bold' : undefined }}
>
Underline
</button>
</FloatingWrapper>
);
};
export const CursorPositioner: FC = () => {
const { manager, state, onChange } = useRemirror({ extensions });
return (
<ThemeProvider>
<Remirror manager={manager} state={state} onChange={onChange} autoRender>
<FloatingButtons />
</Remirror>
</ThemeProvider>
);
};