Skip to content

Commit 3186d89

Browse files
authored
Merge pull request blocks#43 from johno/bulleted-lists-toolbar
Spike out basic list handling (only bulleted for now)
2 parents facde62 + 6327e9f commit 3186d89

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

packages/editor/src/plugins/toolbar/Toolbar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import LinkIcon from '@material-ui/icons/InsertLink'
99
import ImageIcon from '@material-ui/icons/InsertPhoto'
1010
import QuoteIcon from '@material-ui/icons/FormatQuote'
1111
import CodeIcon from '@material-ui/icons/Code'
12+
import ListIcon from '@material-ui/icons/List'
1213
// import ListIcon from '@material-ui/icons/FormatListBulleted'
1314
// import StrikethroughIcon from '@material-ui/icons/StrikethroughS'
1415
// import HeadingIcon from '@material-ui/icons/Title'
@@ -145,6 +146,12 @@ const buttons = [
145146
isActive: isActive('image')
146147
},
147148
{ separator: true },
149+
{
150+
title: 'Insert Bulleted List',
151+
Icon: ListIcon,
152+
command: 'toggleBulletedList',
153+
isActive: isActive('list-item')
154+
},
148155
{
149156
title: 'Insert JSX Block',
150157
Icon: JSX,

packages/editor/src/plugins/toolbar/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ const hasBlock = (editor, type) => {
2020
return editor.value.blocks.some(node => node.type === type)
2121
}
2222

23+
const toggleBulletedList = editor => {
24+
const {
25+
value: { startBlock, document }
26+
} = editor
27+
const parent = document.getParent(startBlock.key)
28+
29+
const isList =
30+
parent && (parent.type === 'list-item-child' || parent.type === 'list-item')
31+
32+
return isList
33+
? editor.unwrapList()
34+
: editor.wrapList({ type: 'bulleted-list' })
35+
}
36+
2337
const toggleBlock = (editor, type) => {
2438
if (editor.hasBlock(type)) {
2539
editor.setBlocks(DEFAULT_BLOCK)
@@ -69,6 +83,7 @@ export default (opts = {}) => ({
6983
toggleBlockQuote,
7084
toggleHeadingOne,
7185
toggleHeadingTwo,
86+
toggleBulletedList,
7287
toggleJSX,
7388
togglePre
7489
},

0 commit comments

Comments
 (0)