-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstyle-controls-inline.js
40 lines (36 loc) · 1.17 KB
/
style-controls-inline.js
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
import React, { Component } from 'react';
import { EditorState, RichUtils } from 'draft-js';
import { StyleControls } from './style-controls-base';
export default class InlineStyleControls extends Component {
static propTypes = {
editorState: React.PropTypes.instanceOf(EditorState).isRequired,
onChange: React.PropTypes.func.isRequired,
};
toggleInlineStyle = (style) => {
this.props.onChange(
RichUtils.toggleInlineStyle(
this.props.editorState,
style
)
);
}
isInlineActive = (style) => {
const currentStyle = this.props.editorState.getCurrentInlineStyle();
return currentStyle.has(style);
}
render() {
return (
<StyleControls
buttons={[
{ icon: 'glyphicon glyphicon-bold', style: 'BOLD' },
{ icon: 'glyphicon glyphicon-italic', style: 'ITALIC' },
{ icon: 'glyphicon glyphicon-text-color', style: 'UNDERLINE' },
{ icon: 'glyphicon glyphicon-text-background', style: 'STRIKETHROUGH' },
{ icon: 'glyphicon glyphicon-console', style: 'CODE' },
]}
isActive={this.isInlineActive}
onToggle={this.toggleInlineStyle}
/>
);
}
}