From e4fae234542cd3dbb9cb6639533d02fc3ea8e5d7 Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Wed, 15 May 2019 14:50:11 -0700 Subject: [PATCH] Separate out EditorValue component for examples (#2785) * Separate out EditorValue component for examples * Made it prettier --- examples/components.js | 46 ++++++++++++++++++++++++++++++++ examples/composition/index.js | 50 +++-------------------------------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/examples/components.js b/examples/components.js index d0dcbce80..ef8427e3a 100644 --- a/examples/components.js +++ b/examples/components.js @@ -19,6 +19,52 @@ export const Button = React.forwardRef( ) ) +export const EditorValue = React.forwardRef( + ({ className, value, ...props }, ref) => { + const textLines = value.document.nodes + .map(node => node.text) + .toArray() + .join('\n') + return ( +
+
+ Slate's value as text +
+
+ {textLines} +
+
+ ) + } +) + export const Icon = React.forwardRef(({ className, ...props }, ref) => ( ( /> ) -const EditorText = props => ( -
-) - -const EditorTextCaption = props => ( -
-) - -/** - * Extract lines of text from `Value` - * - * @return {String[]} - */ - -function getTextLines(value) { - return value.document.nodes.map(node => node.text).toArray() -} - /** * Subpages which are each a smoke test. * @@ -210,7 +171,7 @@ class RichTextExample extends React.Component { render() { const { text } = this.state if (text == null) return - const textLines = getTextLines(this.state.value) + // const textLines = getTextLines(this.state.value) return (
@@ -257,12 +218,7 @@ class RichTextExample extends React.Component { renderBlock={this.renderBlock} renderMark={this.renderMark} /> - - Text in Slate's `Value` - {textLines.map((line, index) => ( -
{line.length > 0 ? line : ' '}
- ))} -
+
) }