2016-07-11 13:19:39 -07:00
2016-07-11 15:59:00 -07:00
# `<Editor>`
2016-07-11 13:19:39 -07:00
2016-07-11 15:53:26 -07:00
```js
2016-07-11 18:54:15 -07:00
import { Editor } from 'slate'
2016-07-11 15:53:26 -07:00
```
2016-07-11 13:19:39 -07:00
The top-level React component that renders the Slate editor itself.
2016-07-11 15:13:12 -07:00
- [Properties ](#properties )
2016-07-11 19:28:35 -07:00
- [`className` ](#classname-string )
2016-07-11 15:53:26 -07:00
- [`onChange` ](#onchange-function )
2016-07-11 19:28:35 -07:00
- [`plugins` ](#plugins-array )
- [`state` ](#state-state )
- [`style` ](#style-object )
- [Placeholder Properties ](#placeholder-properties )
2016-07-11 18:58:00 -07:00
- [`placeholder` ](#placeholder-text-or-element )
2016-07-11 19:24:10 -07:00
- [`placeholderClassName` ](#placeholderclassname-string )
- [`placeholderStyle` ](#placeholderstyle-string )
2016-07-11 18:54:15 -07:00
- [Plugin-like Properties ](#plugin-like-properties )
- [`onBeforeInput` ](#onbeforeinput-function )
- [`onKeyDown` ](#onkeydown-function )
- [`onPaste` ](#onpaste-function )
- [`renderDecorations` ](#renderdecorations-function )
- [`renderMark` ](#rendermark-function )
- [`renderNode` ](#rendernode-function )
2016-07-11 15:13:12 -07:00
- [Methods ](#methods )
2016-07-11 15:53:26 -07:00
- [`getState()` ](#getstate-state )
- [`onChange(state)` ](#onchange-state-void )
2016-07-11 15:28:20 -07:00
2016-07-11 15:59:00 -07:00
## Properties
2016-07-11 13:22:41 -07:00
```js
< Editor
2016-07-11 19:28:35 -07:00
className={string}
2016-07-11 13:19:39 -07:00
onChange={Function}
plugins={Array}
state={State}
2016-07-11 19:28:35 -07:00
style={Object}
2016-07-11 13:19:39 -07:00
/>
```
2016-07-11 19:28:35 -07:00
#### `className: String`
An optional class name to apply to the content editable element.
2016-07-11 13:42:36 -07:00
#### `onChange: Function`
2016-07-11 13:38:45 -07:00
2016-07-11 13:40:46 -07:00
A change handler that will be called with the newly-changed editor `state` . You should usually pass the newly changed `state` back into the editor through its `state` property. This hook allows you to add persistence logic to your editor.
2016-07-11 13:38:45 -07:00
2016-07-11 19:28:35 -07:00
#### `plugins: Array`
An array of [`Plugins` ](../plugins ) that define the editor's behavior.
#### `state: State`
A [`State` ](../models/state ) object representing the current state of the editor.
#### `style: Object`
An optional dictionary of styles to apply to the content editable element.
## Placeholder Properties
```js
< Editor
2016-07-11 19:29:21 -07:00
placeholder={String || Element}
placeholderClassName={String}
2016-07-11 19:28:35 -07:00
placeholderStyle={Object}
/>
```
2016-07-11 19:29:21 -07:00
#### `placeholder: String || Element`
2016-07-11 18:58:00 -07:00
A placeholder string (or React element) that will be rendered as the default block type's placeholder.
2016-07-11 19:24:10 -07:00
#### `placeholderClassName: String`
An optional class name to apply to the default block type's placeholder.
#### `placeholderStyle: Object`
An optional dictionary of styles to apply to the default block type's placeholder. If `placeholder` is a string, and no class name or style dictionary is passed, this property will default to `{ opacity: '0.333' }` .
2016-07-11 13:27:34 -07:00
2016-07-11 18:54:15 -07:00
## Plugin-like Properties
2016-07-11 13:47:28 -07:00
2016-07-11 18:54:15 -07:00
In addition to its own properties, the editor allows passing any of the properties that a [`Plugin` ](../plugins ) defines as well.
2016-07-11 13:47:28 -07:00
These properties are actually just a convenience—an implicit plugin defintion. Internally, they are grouped together and turned into a plugin that is given first priority in the plugin stack.
For example, these two snippets of code are equivalent:
2016-07-11 13:31:08 -07:00
```js
2016-07-11 13:49:02 -07:00
const plugins = [
somePlugin
]
2016-07-11 13:33:46 -07:00
2016-07-11 13:31:08 -07:00
< Editor
2016-07-11 13:38:45 -07:00
onKeyDown={myKeyHandler}
2016-07-11 13:33:46 -07:00
plugins={plugins}
2016-07-11 13:31:08 -07:00
state={state}
/>
```
```js
2016-07-11 13:35:34 -07:00
const editorPlugin = {
2016-07-11 13:38:45 -07:00
onKeyDown: myKeyHandler
2016-07-11 13:35:34 -07:00
}
2016-07-11 13:31:08 -07:00
const plugins = [
2016-07-11 13:35:34 -07:00
editorPlugin,
somePlugin
2016-07-11 13:31:08 -07:00
]
< Editor
plugins={plugins}
state={state}
/>
```
2016-07-11 13:19:39 -07:00
2016-07-11 15:59:00 -07:00
## Methods
2016-07-11 13:19:39 -07:00
2016-07-11 15:12:15 -07:00
#### `getState() => State`
2016-07-11 13:19:39 -07:00
Return the editor's current internal state.
2016-07-11 13:27:34 -07:00
2016-07-11 15:12:15 -07:00
#### `onChange(state: State) => Void`
2016-07-11 13:27:34 -07:00
2016-07-11 13:47:28 -07:00
Effectively the same as `setState` . Invoking this method will update the state of the editor, running it through all of it's plugins, and passing it the parent component, before it cycles back down as the new `state` property of the editor.