1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 05:49:47 +01:00
Ian Storm Taylor f42a64ac8f refactor placeholder to use schema (#1253)
* refactor placeholder to use schema

* update placeholder, remove old export

* add maxWidth to prevent overflow

* update docs
2017-10-18 00:23:39 -07:00

59 lines
944 B
JavaScript

import Plain from 'slate-plain-serializer'
import { Editor } from 'slate-react'
import React from 'react'
/**
* The read-only example.
*
* @type {Component}
*/
class ReadOnly extends React.Component {
/**
* Deserialize the initial editor state.
*
* @type {Object}
*/
state = {
state: Plain.deserialize('This is read-only text. You should not be able to edit it, which is useful for scenarios where you want to render via Slate, without giving the user editing permissions.')
}
/**
* On change.
*
* @param {Change} change
*/
onChange = ({ state }) => {
this.setState({ state })
}
/**
* Render the editor.
*
* @return {Component} component
*/
render() {
return (
<Editor
readOnly
placeholder="Enter some text..."
state={this.state.state}
onChange={this.onChange}
/>
)
}
}
/**
* Export.
*/
export default ReadOnly