-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.tsx
44 lines (36 loc) · 1.13 KB
/
index.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
import React from 'react';
import AutoReplace from 'slate-auto-replace';
import { RenderBlockProps, Editor } from 'slate-react';
import BlockButton, { BlockButtonProps } from '../../ui/BlockButton';
import ListHandler from '../../../helpers/ListHandler';
import { TYPE as LIST_ITEM_TYPE } from '../list-item';
import Icon from './icon.svg';
export const TYPE = 'ordered-list';
const Button: React.FunctionComponent<BlockButtonProps> = (props) => {
const onToggle = (event: React.MouseEvent, type: string) => {
event.preventDefault();
ListHandler.onToggleButton(props.editor, type);
}
const isActive = ListHandler.isActive(props.editor, TYPE);
return (
<BlockButton {...props} blockType={TYPE} isActive={isActive} onToggleBlock={onToggle}>
<Icon />
</BlockButton>
)
}
const Block: React.FunctionComponent<RenderBlockProps> = ({ isSelected, isFocused, ...props }) => (
<ol {...props} />
)
const Plugin = [
AutoReplace({
trigger: 'space', before: /^(1.)$/, change: (editor: Editor) => {
editor.setBlocks(LIST_ITEM_TYPE).wrapBlock(TYPE);
},
})
]
export default {
TYPE,
Button,
Block,
Plugin
};