-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathEditorControls.jsx
More file actions
144 lines (127 loc) · 3.32 KB
/
Copy pathEditorControls.jsx
File metadata and controls
144 lines (127 loc) · 3.32 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* eslint-disable jsx-a11y/no-static-element-interactions */
import React from 'react';
import PropTypes from 'prop-types';
import getMessage from '../../utils/getMessage';
const BLOCK_TYPES = [
{ label: 'Väliotsikko', style: 'header-three' },
{ label: 'Lista', style: 'unordered-list-item' },
{ label: 'Numeroitu lista', style: 'ordered-list-item' },
{ label: 'Korostettu kappale', style: 'LEAD' },
{ label: 'Kuvateksti', style: 'ImageCaption' },
];
const INLINE_STYLES = [{ label: 'Lihavointi', style: 'BOLD' }];
const STYLE_INLINE_BLOCK = 'inline-block';
class StyleButton extends React.Component {
constructor() {
super();
this.onToggle = (event) => {
event.preventDefault();
this.props.onToggle(this.props.style);
};
}
render() {
let className = 'RichEditor-styleButton';
if (this.props.active) {
className += ' RichEditor-activeButton';
}
return (
<span className={className} onMouseDown={this.onToggle}>
{this.props.label}
</span>
);
}
}
StyleButton.propTypes = {
active: PropTypes.bool,
label: PropTypes.string,
onToggle: PropTypes.func,
style: PropTypes.string,
};
export const BlockStyleControls = (props) => {
const { editorState } = props;
const selection = editorState.getSelection();
const blockType = editorState
.getCurrentContent()
.getBlockForKey(selection.getStartKey())
.getType();
return (
<div className='RichEditor-controls'>
{BLOCK_TYPES.map((type) => (
<StyleButton
key={type.label}
active={type.style === blockType}
label={type.label}
onToggle={props.onToggle}
style={type.style}
/>
))}
</div>
);
};
BlockStyleControls.propTypes = {
editorState: PropTypes.object,
onToggle: PropTypes.func,
};
export const InlineStyleControls = (props) => {
const currentStyle = props.editorState.getCurrentInlineStyle();
return (
<div
className='RichEditor-controls'
style={{ display: STYLE_INLINE_BLOCK }}
>
{INLINE_STYLES.map((type) => (
<StyleButton
key={type.label}
active={currentStyle.has(type.style)}
label={type.label}
onToggle={props.onToggle}
style={type.style}
/>
))}
</div>
);
};
InlineStyleControls.propTypes = {
editorState: PropTypes.object,
onToggle: PropTypes.func,
};
export const IframeControls = (props) => (
<div className='RichEditor-controls' style={{ display: STYLE_INLINE_BLOCK }}>
<button
type='button'
className='RichEditor-styleButton'
onClick={props.onClick}
>
{getMessage('iframeAddButton')}
</button>
</div>
);
IframeControls.propTypes = {
onClick: PropTypes.func,
};
export const SkipLinkControls = (props) => (
<button
type='button'
className='RichEditor-styleButton'
onClick={props.onClick}
>
{getMessage('skipLinkAddButton')}
</button>
);
SkipLinkControls.propTypes = {
onClick: PropTypes.func,
};
export const ImageControls = (props) => (
<div className='RichEditor-controls' style={{ display: STYLE_INLINE_BLOCK }}>
<button
type='button'
className='RichEditor-styleButton'
onClick={props.onClick}
>
{getMessage('imageAddButton')}
</button>
</div>
);
ImageControls.propTypes = {
onClick: PropTypes.func,
};