-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Adding a PlainText component for raw editable content
- Loading branch information
1 parent
9752828
commit 727da2c
Showing
13 changed files
with
132 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
.gutenberg textarea.wp-block-html { | ||
box-shadow: none; | ||
.wp-block-html.blocks-plain-text { | ||
font-family: $editor-html-font; | ||
font-size: $text-editor-font-size; | ||
color: $dark-gray-800; | ||
padding: .8em 1.6em; | ||
overflow-x: auto !important; | ||
border: 1px solid $light-gray-500; | ||
border-radius: 4px; | ||
padding: .8em 1.6em; | ||
margin: 0; | ||
overflow-x: auto; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# `PlainText` | ||
|
||
Render an auto-growing textarea allow users to fill any textual content. | ||
|
||
## Properties | ||
|
||
### `value: string` | ||
|
||
*Required.* String value of the textarea | ||
|
||
### `onChange( value: string ): Function` | ||
|
||
*Required.* Called when the value changes. | ||
|
||
You can also pass any extra prop to the textarea rendered by this component. | ||
|
||
## Example | ||
|
||
{% codetabs %} | ||
{% ES5 %} | ||
```js | ||
wp.blocks.registerBlockType( /* ... */, { | ||
// ... | ||
|
||
attributes: { | ||
content: { | ||
type: 'string', | ||
}, | ||
}, | ||
|
||
edit: function( props ) { | ||
return wp.element.createElement( wp.blocks.PlainText, { | ||
className: props.className, | ||
value: props.attributes.content, | ||
onChange: function( content ) { | ||
props.setAttributes( { content: content } ); | ||
}, | ||
} ); | ||
}, | ||
} ); | ||
``` | ||
{% ESNext %} | ||
```js | ||
const { registerBlockType, PlainText } = wp.blocks; | ||
|
||
registerBlockType( /* ... */, { | ||
// ... | ||
|
||
attributes: { | ||
content: { | ||
type: 'string', | ||
}, | ||
}, | ||
|
||
edit( { className, attributes, setAttributes } ) { | ||
return ( | ||
<PlainText | ||
className={ className } | ||
value={ attributes.content } | ||
onChange={ ( content ) => setAttributes( { content } ) } | ||
/> | ||
); | ||
}, | ||
} ); | ||
``` | ||
{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import TextareaAutosize from 'react-autosize-textarea'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
function PlainText( { onChange, className, ...props } ) { | ||
return ( | ||
<TextareaAutosize | ||
className={ classnames( 'blocks-plain-text', className ) } | ||
onChange={ ( event ) => onChange( event.target.value ) } | ||
{ ...props } | ||
/> | ||
); | ||
} | ||
|
||
export default PlainText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.gutenberg .blocks-plain-text { | ||
box-shadow: none; | ||
font-family: inherit; | ||
font-size: inherit; | ||
color: inherit; | ||
line-height: inherit; | ||
border: none; | ||
padding: 0; | ||
margin: 0; | ||
width: 100%; | ||
} |