-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor rich text charater limit example block
- Loading branch information
1 parent
94956d0
commit 7205b6e
Showing
3 changed files
with
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "example/rich-text-character-limit", | ||
"apiVersion": 2, | ||
"title": "Rich Text Character Limit", | ||
"description": "Example Block to show the Rich Text Character Limit in usage", | ||
"icon": "smiley", | ||
"category": "common", | ||
"example": {}, | ||
"supports": { | ||
"html": false | ||
}, | ||
"attributes": { | ||
"title": { | ||
"type": "string", | ||
"default": "" | ||
} | ||
}, | ||
"editorScript": "file:./index.js" | ||
} |
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,29 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { RichTextCharacterLimit } from '@10up/block-components'; | ||
|
||
export const BlockEdit = (props) => { | ||
const { | ||
attributes: { title }, | ||
setAttributes | ||
} = props; | ||
|
||
const blockProps = useBlockProps(); | ||
|
||
return ( | ||
<div {...blockProps}> | ||
<RichTextCharacterLimit | ||
limit={30} | ||
enforce={true} | ||
tagName="h2" | ||
value={title} | ||
placeholder={__('Enter some text', 'example')} | ||
onChange={(title) => setAttributes({ title })} | ||
allowedFormats={[ | ||
'core/bold', | ||
'core/link' | ||
]} | ||
/> | ||
</div> | ||
) | ||
}; |
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,50 +1,9 @@ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { RichTextCharacterLimit } from '@10up/block-components'; | ||
|
||
const NAMESPACE = 'example'; | ||
import metadata from './block.json'; | ||
import { BlockEdit } from './edit'; | ||
|
||
registerBlockType( `${ NAMESPACE }/rich-text-character-limit`, { | ||
apiVersion: 2, | ||
title: __( 'Rich Text Character Limit', NAMESPACE ), | ||
description: __( 'Example Block to show the Rich Text Character Limit in usage', NAMESPACE ), | ||
icon: 'smiley', | ||
category: 'common', | ||
example: {}, | ||
supports: { | ||
html: false | ||
}, | ||
attributes: { | ||
title: { | ||
type: 'string', | ||
default: '' | ||
} | ||
}, | ||
edit: (props) => { | ||
const { | ||
attributes: { title }, | ||
setAttributes | ||
} = props; | ||
|
||
const blockProps = useBlockProps(); | ||
|
||
return ( | ||
<div {...blockProps}> | ||
<RichTextCharacterLimit | ||
limit={30} | ||
enforce={true} | ||
tagName="h2" | ||
value={title} | ||
placeholder={ __( 'Enter some text', NAMESPACE ) } | ||
onChange={(title) => setAttributes({title})} | ||
allowedFormats={[ | ||
'core/bold', | ||
'core/link' | ||
]} | ||
/> | ||
</div> | ||
) | ||
}, | ||
registerBlockType(metadata, { | ||
edit: BlockEdit, | ||
save: () => null | ||
} ); | ||
}); |