1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 13:59:47 +01:00
Ian Storm Taylor 257b28aa84
Improve and refactor examples (#1930)
This just refactors the examples to make the styled defined inline with each example, to make it easier to follow for folks. And in the process fixes a few issues that people brought up.

Fixes https://github.com/ianstormtaylor/slate/issues/1920
Fixes https://github.com/ianstormtaylor/slate/issues/1925
2018-07-01 15:13:29 -06:00

58 lines
954 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 value.
*
* @type {Object}
*/
state = {
value: 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.'
),
}
/**
* Render the editor.
*
* @return {Component} component
*/
render() {
return (
<Editor
readOnly
placeholder="Enter some text..."
value={this.state.value}
onChange={this.onChange}
/>
)
}
/**
* On change.
*
* @param {Change} change
*/
onChange = ({ value }) => {
this.setState({ value })
}
}
/**
* Export.
*/
export default ReadOnly