Text Editor React Component
Text Editor React component represents Text Editor component.
Text Editor Components
There are following components included:
TextEditor
/F7TextEditor
Text Editor Properties
Prop | Type | Default | Description |
---|---|---|---|
<TextEditor> properties | |||
value | string | Text editor initial html content value. | |
placeholder | string | Editor placeholder content displayed when it is empty. By default it is not specified | |
resizable | boolean | false | Makes editor resizable (when its height will fit to its content) |
mode | string | toolbar | Text editor buttons mode. Can be:
|
buttons | array | Array with editor buttons, or array of arrays (groups) with editor buttons. By default all buttons enabled and its default value is:
| |
dividers | boolean | true | Adds visual divider between buttons group |
imageUrlText | string | Insert image URL | Prompt text that appears on image url request |
linkUrlText | string | Insert link URL | Prompt text that appears on link url request |
clearFormattingOnPaste | boolean | true | When enabled it will clear any formatting on paste from clipboard |
customButtons | object | Object with custom buttons. Object property key is the button id that should be used in For example to specify custom button that will add
` |
Text Editor Events
Event | Arguments | Description |
---|---|---|
<TextEditor> events | ||
textEditorChange | (value) | Event will be triggered when editor value has been changed |
textEditorInput | Event will be triggered on editor’s content “input” event | |
textEditorFocus | Event will be triggered on editor’s content focus | |
textEditorBlur | Event will be triggered on editor’s content blur | |
textEditorButtonClick | (buttonId) | Event will be triggered on editor button click |
textEditorKeyboardOpen | Event will be triggered when editor keyboard toolbar appears | |
textEditorKeyboardClose | Event will be triggered when editor keyboard toolbar disappears | |
textEditorPopoverOpen | Event will be triggered on editor popover open | |
textEditorPopoverClose | Event will be triggered on editor popover close | |
textEditorBeforeDestroy | Event will be triggered right before Text Editor instance will be destroyed |
Access To Text Editor Instance
If you need to use Text Editor API you can access its initialized instance by accessing .f7TextEditor
component’s property.
Examples
export default class extends React.Component {
constructor() {
super();
this.state = {
customButtons: {
hr: {
content: '<hr>',
onClick(editor, buttonEl) {
document.execCommand('insertHorizontalRule', false);
},
},
},
customValue: '<p>Lorem, ipsum dolor sit amet consectetur adipisicing...</p>',
listEditorValue: '',
};
}
render() {
return (
<Page>
<Navbar title="Text Editor"></Navbar>
<BlockTitle>Default Setup</BlockTitle>
<TextEditor />
<BlockTitle>With Placeholder</BlockTitle>
<TextEditor
placeholder="Enter text..."
/>
<BlockTitle>With Default Value</BlockTitle>
<TextEditor
placeholder="Enter text..."
value={this.state.customValue}
onTextEditorChange={(value) => this.setState({ customValue: value })}
/>
<BlockTitle>Specific Buttons</BlockTitle>
<BlockHeader>It is possible to customize which buttons (commands) to show.</BlockHeader>
<TextEditor
placeholder="Enter text..."
buttons={[
['bold', 'italic', 'underline', 'strikeThrough'],
['orderedList', 'unorderedList']
]}
/>
<BlockTitle>Custom Button</BlockTitle>
<BlockHeader>It is possible to create custom editor buttons. Here is the custom "hr" button that adds horizontal rule:</BlockHeader>
<TextEditor
placeholder="Enter text..."
customButtons={this.state.customButtons}
buttons={[
['bold', 'italic', 'underline', 'strikeThrough'],
'hr'
]}
/>
<BlockTitle>Resizable</BlockTitle>
<BlockHeader>Editor will be resized based on its content.</BlockHeader>
<TextEditor
placeholder="Enter text..."
resizable
buttons={['bold', 'italic', 'underline', 'strikeThrough']}
/>
<BlockTitle>Popover Mode</BlockTitle>
<BlockHeader>In this mode, there is no toolbar with buttons, but they appear as popover when you select any text in editor.</BlockHeader>
<TextEditor
placeholder="Enter text..."
mode="popover"
buttons={['bold', 'italic', 'underline', 'strikeThrough']}
style={{'--f7-text-editor-height': '150px'}}
/>
<BlockTitle>Keyboard Toolbar Mode</BlockTitle>
<BlockHeader>In this mode, toolbar with buttons will appear on top of virtual keyboard when editor is in the focus. It is supported only in iOS, Android cordova apps and in Android Chrome. When not supported it will fallback to "popover" mode.</BlockHeader>
<TextEditor
placeholder="Enter text..."
mode="keyboard-toolbar"
style={{'--f7-text-editor-height': '150px'}}
/>
<BlockTitle>As List Input</BlockTitle>
<BlockHeader>Text editor can be used in list with other inputs. In this example it is enabled with "keyboard-toolbar"/"popover" type for "About" field.</BlockHeader>
<List>
<ListInput
type="text"
label="Name"
placeholder="Your name"
/>
<ListInput
type="texteditor"
label="About"
placeholder="About"
resizable
textEditorParams={{
mode: 'popover',
buttons: ['bold', 'italic', 'underline', 'strikeThrough']
}}
value={this.state.listEditorValue}
onTextEditorChange={(value) => this.setState({listEditorValue: value})}
/>
</List>
</Page>
);
}
}
当前内容版权归 Framework7 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Framework7 .