Skip to content

Commit

Permalink
feat: add two pre-defined tools: ItalicInlineTool and StrongInlineTool
Browse files Browse the repository at this point in the history
  • Loading branch information
natterstefan committed Nov 29, 2019
1 parent e4fcf1e commit aa23db2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import EditorJs from '@natterstefan/react-editor-js'
import Header from '@editorjs/header'
import Paragraph from '@editorjs/paragraph'

import createGenericInlineTool, { ItalicInlineTool } from 'editorjs-inline-tool'

const TOOLS = {
header: Header,
paragraph: {
Expand All @@ -64,6 +66,8 @@ const TOOLS = {
'<svg class="icon icon--bold" width="12px" height="14px"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#bold"></use></svg>',
}),
},
// or use a pre-defined tool instead
italic: ItalicInlineTool,
}

const App = () => {
Expand All @@ -83,6 +87,9 @@ options are available:
| tagName | `true` | `string` | `undefined` | text [formatting tag](https://www.w3schools.com/html/html_formatting.asp) (eg. `bold`) |
| toolboxIcon | `true` | `string` | `undefined` | Icon for the tools [inline toolbar](https://editorjs.io/inline-tools-api-1#render) |

Additionally, there are two pre-defined inline tools available: `ItalicInlineTool`
and `StrongInlineTool` (they can be found [here](src/inline-tools.tsx)).

## Licence

[MIT](LICENCE)
Expand Down
27 changes: 13 additions & 14 deletions src/__stories__/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ import SimpleImage from '@editorjs/simple-image'
import Table from '@editorjs/table'
import Warning from '@editorjs/warning'

import createGenericInlineTool from '..'
import createGenericInlineTool, { ItalicInlineTool } from '..'

export const TOOLS = {
embed: Embed,
table: Table,
list: List,
table: {
class: Table,
// in some cases it is also required to explicitly define `inlineToolbar` _again_
inlineToolbar: ['bold', 'italic', 'link'],
},
list: {
class: List,
inlineToolbar: ['bold', 'italic', 'link'],
},
warning: Warning,
code: Code,
linkTool: LinkTool,
Expand All @@ -39,6 +46,7 @@ export const TOOLS = {
simpleImage: SimpleImage,
// overwrite default tools of editorjs by using the same name
bold: {
// use createGenericInlineTool
class: createGenericInlineTool({
sanitize: {
strong: {},
Expand All @@ -49,15 +57,6 @@ export const TOOLS = {
'<svg class="icon icon--bold" width="12px" height="14px"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#bold"></use></svg>',
}),
},
italic: {
class: createGenericInlineTool({
sanitize: {
em: {},
},
shortcut: 'CMD+I',
tagName: 'EM',
toolboxIcon:
'<svg class="icon icon--italic" width="34px" height="34px"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#italic"></use></svg>',
}),
},
// or use a pre-defined tool
italic: ItalicInlineTool,
}
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default } from './tool'
export { ItalicInlineTool, StrongInlineTool } from './inline-tools'
23 changes: 23 additions & 0 deletions src/inline-tools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import createGenericInlineTool from './tool'

export const ItalicInlineTool = createGenericInlineTool({
sanitize: {
em: {},
},
shortcut: 'CMD+I',
tagName: 'EM',
toolboxIcon:
// icon editor-js uses
'<svg class="icon icon--italic" width="34px" height="34px"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#italic"></use></svg>',
})

export const StrongInlineTool = createGenericInlineTool({
sanitize: {
strong: {},
},
shortcut: 'CMD+B',
tagName: 'STRONG',
toolboxIcon:
// icon editor-js uses
'<svg class="icon icon--bold" width="12px" height="14px"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#bold"></use></svg>',
})

0 comments on commit aa23db2

Please sign in to comment.