-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from niuware/development
Implement key bindings feature
- Loading branch information
Showing
5 changed files
with
105 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react' | ||
import { EditorState, RichUtils } from 'draft-js' | ||
import MUIRichTextEditor from '../../' | ||
|
||
const save = (data: string) => { | ||
console.log(data) | ||
} | ||
|
||
const KeyBindings = () => { | ||
return ( | ||
<MUIRichTextEditor | ||
label="Press CMD + C to clear the editor or CMD + K to add 'italic' style to the selection..." | ||
onSave={save} | ||
controls={["title", "italic", "save"]} | ||
keyCommands={[ | ||
{ | ||
key: 67, // C | ||
name: "clear-all", | ||
callback: (_) => { | ||
return EditorState.createEmpty() | ||
} | ||
}, | ||
{ | ||
key: 75, // K | ||
name: "toggle-italic", | ||
callback: (editorState: EditorState) => { | ||
const newState = RichUtils.toggleInlineStyle(editorState, "ITALIC") | ||
return newState | ||
} | ||
} | ||
]} | ||
/> | ||
) | ||
} | ||
|
||
export default KeyBindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters