-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
71 lines (65 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* External dependencies
*/
import TextareaAutosize from 'react-autosize-textarea';
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import EditableText from '../editable-text';
/**
* Render an auto-growing textarea allow users to fill any textual content.
*
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/plain-text/README.md
*
* @example
* ```jsx
* import { registerBlockType } from '@wordpress/blocks';
* import { PlainText } from '@wordpress/block-editor';
*
* registerBlockType( 'my-plugin/example-block', {
* // ...
*
* attributes: {
* content: {
* type: 'string',
* },
* },
*
* edit( { className, attributes, setAttributes } ) {
* return (
* <PlainText
* className={ className }
* value={ attributes.content }
* onChange={ ( content ) => setAttributes( { content } ) }
* />
* );
* },
* } );
* ````
*
* @param {Object} props Component props.
* @param {string} props.value String value of the textarea.
* @param {Function} props.onChange Function called when the text value changes.
* @param {Object} [props.ref] The component forwards the `ref` property to the `TextareaAutosize` component.
* @return {Element} Plain text component
*/
const PlainText = forwardRef( ( { __experimentalVersion, ...props }, ref ) => {
if ( __experimentalVersion === 2 ) {
return <EditableText ref={ ref } { ...props } />;
}
const { className, onChange, ...remainingProps } = props;
return (
<TextareaAutosize
ref={ ref }
className={ clsx( 'block-editor-plain-text', className ) }
onChange={ ( event ) => onChange( event.target.value ) }
{ ...remainingProps }
/>
);
} );
export default PlainText;