2017-09-11 18:11:45 -07:00
|
|
|
import Plain from 'slate-plain-serializer'
|
|
|
|
import { Editor } from 'slate-react'
|
|
|
|
|
2016-06-17 19:57:37 -07:00
|
|
|
import React from 'react'
|
|
|
|
|
2016-06-21 10:49:11 -07:00
|
|
|
/**
|
2016-06-24 10:22:48 -07:00
|
|
|
* The plain text example.
|
2016-06-21 10:49:11 -07:00
|
|
|
*
|
2016-07-06 14:42:59 -07:00
|
|
|
* @type {Component}
|
2016-06-17 19:57:37 -07:00
|
|
|
*/
|
|
|
|
|
2016-06-24 10:22:48 -07:00
|
|
|
class PlainText extends React.Component {
|
2016-06-21 14:49:08 -07:00
|
|
|
/**
|
2017-10-27 13:39:06 -07:00
|
|
|
* Deserialize the initial editor value.
|
2016-06-21 14:49:08 -07:00
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
|
2016-06-17 19:57:37 -07:00
|
|
|
state = {
|
2018-02-06 23:12:00 +00:00
|
|
|
value: Plain.deserialize(
|
|
|
|
'This is editable plain text, just like a <textarea>!'
|
|
|
|
),
|
2017-09-05 18:03:41 -07:00
|
|
|
}
|
2016-06-17 19:57:37 -07:00
|
|
|
|
2016-07-13 14:57:20 -07:00
|
|
|
/**
|
2018-07-01 15:13:29 -06:00
|
|
|
* Render the editor.
|
2016-07-13 14:57:20 -07:00
|
|
|
*
|
2018-07-01 15:13:29 -06:00
|
|
|
* @return {Component} component
|
2016-07-13 14:57:20 -07:00
|
|
|
*/
|
|
|
|
|
2018-07-01 15:13:29 -06:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Editor
|
|
|
|
placeholder="Enter some plain text..."
|
|
|
|
value={this.state.value}
|
|
|
|
onChange={this.onChange}
|
|
|
|
/>
|
|
|
|
)
|
2016-07-13 14:57:20 -07:00
|
|
|
}
|
|
|
|
|
2016-06-21 14:49:08 -07:00
|
|
|
/**
|
2018-07-01 15:13:29 -06:00
|
|
|
* On change.
|
2016-06-21 14:49:08 -07:00
|
|
|
*
|
2018-07-01 15:13:29 -06:00
|
|
|
* @param {Change} change
|
2016-06-21 14:49:08 -07:00
|
|
|
*/
|
|
|
|
|
2018-07-01 15:13:29 -06:00
|
|
|
onChange = ({ value }) => {
|
|
|
|
this.setState({ value })
|
2016-06-17 19:57:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-24 10:22:48 -07:00
|
|
|
* Export.
|
2016-06-17 19:57:37 -07:00
|
|
|
*/
|
|
|
|
|
2016-06-24 10:22:48 -07:00
|
|
|
export default PlainText
|