From be27caa21ceabf4dffba09a180cde4ba1ec536f7 Mon Sep 17 00:00:00 2001 From: Copons Date: Fri, 1 Nov 2019 18:57:59 +0000 Subject: [PATCH] Add block attributes PHP definitions and UI --- lib/blocks.php | 1 + .../src/site-description/block.json | 33 +-------- .../src/site-description/edit.js | 67 ++++++++++++++++++- .../src/site-description/index.php | 59 ++++++++++++++++ 4 files changed, 125 insertions(+), 35 deletions(-) create mode 100644 packages/block-library/src/site-description/index.php diff --git a/lib/blocks.php b/lib/blocks.php index 1dc7277d85ee80..34070e99a64d8f 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -53,6 +53,7 @@ function gutenberg_reregister_core_block_types() { 'social-link.php' => gutenberg_get_registered_social_link_blocks(), 'tag-cloud.php' => 'core/tag-cloud', 'site-title.php' => 'core/site-title', + 'site-description.php'=> 'core/site-description', ); $registry = WP_Block_Type_Registry::get_instance(); diff --git a/packages/block-library/src/site-description/block.json b/packages/block-library/src/site-description/block.json index 1704920020177d..fa41286e8ab679 100644 --- a/packages/block-library/src/site-description/block.json +++ b/packages/block-library/src/site-description/block.json @@ -3,37 +3,6 @@ "category": "layout", "supports": { "align": [ "wide", "full" ], - "html": false, - "multiple": false, - "reusable": false - }, - "attributes": { - "align": { - "type": "string", - "default": "wide" - }, - "textAlign": { - "type": "string", - "default": "center" - }, - "textColor": { - "type": "string" - }, - "customTextColor": { - "type": "string" - }, - "backgroundColor": { - "type": "string" - }, - "customBackgroundColor": { - "type": "string" - }, - "fontSize": { - "type": "string", - "default": "small" - }, - "customFontSize": { - "type": "number" - } + "html": false } } diff --git a/packages/block-library/src/site-description/edit.js b/packages/block-library/src/site-description/edit.js index 04b941bbfab235..c041fb6d452460 100644 --- a/packages/block-library/src/site-description/edit.js +++ b/packages/block-library/src/site-description/edit.js @@ -5,14 +5,35 @@ import { useEntityProp, __experimentalUseEntitySaving, } from '@wordpress/core-data'; -import { Button } from '@wordpress/components'; +import { Button, PanelBody } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; -import { PlainText } from '@wordpress/block-editor'; +import { + AlignmentToolbar, + BlockControls, + ContrastChecker, + FontSizePicker, + InspectorControls, + PanelColorSettings, + PlainText, + withColors, + withFontSizes, +} from '@wordpress/block-editor'; import { compose } from '@wordpress/compose'; import { withSelect, withDispatch } from '@wordpress/data'; import { ENTER } from '@wordpress/keycodes'; -function SiteDescriptionEdit( { insertDefaultBlock } ) { +function SiteDescriptionEdit( { + attributes, + backgroundColor, + fontSize, + insertDefaultBlock, + setAttributes, + setBackgroundColor, + setFontSize, + setTextColor, + textColor, + +} ) { const [ description, setDescription ] = useEntityProp( 'root', 'site', 'description' ); const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving( 'root', @@ -20,6 +41,9 @@ function SiteDescriptionEdit( { insertDefaultBlock } ) { 'description' ); + const { customFontSize, textAlign } = attributes; + const actualFontSize = customFontSize || fontSize.size; + const preventNewlines = ( event ) => { if ( event.keyCode === ENTER ) { event.preventDefault(); @@ -29,6 +53,41 @@ function SiteDescriptionEdit( { insertDefaultBlock } ) { return ( <> + + setAttributes( { textAlign: nextAlign } ) } + /> + + + + + + + + +