1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-22 16:17:17 +01:00
slate/site/examples/read-only.tsx
Julian Krispel-Samsel 602f170156
Update readonly example and add test (#4212)
* fixes #4039, update readonly example

* add cypress test for readonly mode
2021-04-21 09:29:19 +01:00

28 lines
757 B
TypeScript

import React, { useState, useMemo } from 'react'
import { createEditor, Descendant, Element } from 'slate'
import { Slate, Editable, withReact } from 'slate-react'
const ReadOnlyExample = () => {
const [value, setValue] = useState<Descendant[]>(initialValue)
const editor = useMemo(() => withReact(createEditor()), [])
return (
<Slate editor={editor} value={value} onChange={value => setValue(value)}>
<Editable readOnly placeholder="Enter some plain text..." />
</Slate>
)
}
const initialValue: Descendant[] = [
{
type: 'paragraph',
children: [
{
text:
'This example shows what happens when the Editor is set to readOnly, it is not editable',
},
],
},
]
export default ReadOnlyExample