From d71aa2146d52e894bacc8ba96afe17b06f6d2bc8 Mon Sep 17 00:00:00 2001 From: Rhys Clay Date: Mon, 21 May 2018 13:00:02 +1000 Subject: [PATCH] Changes to feature block for improved UI --- src/blocks/features-list/index.js | 70 +++++++++++++++++---------- src/blocks/features-list/inspector.js | 39 ++++++++++----- 2 files changed, 70 insertions(+), 39 deletions(-) diff --git a/src/blocks/features-list/index.js b/src/blocks/features-list/index.js index d7782ea..e5f2d34 100644 --- a/src/blocks/features-list/index.js +++ b/src/blocks/features-list/index.js @@ -73,6 +73,10 @@ registerBlockType('cgb/block-feature', { type: 'string', default: '/contact', }, + showButton: { + type: 'boolean', + default: true, + }, buttonText: { type: 'string', default: 'Find out more', @@ -99,51 +103,55 @@ registerBlockType('cgb/block-feature', { const { attributes: { blockAlignment, + imgID, imgURL, imgAlt, + showButton, buttonText, + title, + description, link, circularImg, }, className, + setAttributes, + isSelected, } = props; - const attributes = props.attributes; - - const onChangeTitle = value => { - props.setAttributes({ title: value }); + const onChangeTitle = title => { + setAttributes({ title }); }; - const onChangeDescription = value => { - props.setAttributes({ description: value }); + const onChangeDescription = description => { + setAttributes({ description }); }; const onSelectImage = img => { let thumb = img.url; - props.setAttributes({ + setAttributes({ imgID: img.id, imgAlt: img.alt, }); - if (props.attributes.circularImg) { + if (circularImg) { const image = new wp.api.models.Media({ id: img.id }) .fetch() .done(res => { thumb = res.media_details.sizes['thumbnail'].source_url; - props.setAttributes({ + setAttributes({ imgURL: thumb, }); }); } else { - props.setAttributes({ + setAttributes({ imgURL: img.url, }); } }; const onRemoveImage = () => { - props.setAttributes({ + setAttributes({ imgID: null, imgURL: null, imgAlt: null, @@ -151,21 +159,25 @@ registerBlockType('cgb/block-feature', { }; const onChangeLink = value => { - props.setAttributes({ link: value }); + setAttributes({ link: value }); }; const onChangeButtonText = value => { - props.setAttributes({ buttonText: value }); + setAttributes({ buttonText: value }); }; const updateAlignment = nextAlign => { - props.setAttributes({ + setAttributes({ blockAlignment: nextAlign, }); }; const onChangeImgType = value => { - props.setAttributes({ circularImg: value }); + setAttributes({ circularImg: value }); + }; + + const onToggleButton = () => { + setAttributes({ showButton: !showButton }); }; const imgClasses = classnames( @@ -180,6 +192,7 @@ registerBlockType('cgb/block-feature', { onChangeLink, onChangeButtonText, onChangeImgType, + onToggleButton, ...props, }} /> @@ -194,11 +207,11 @@ registerBlockType('cgb/block-feature', {
- {!attributes.imgID ? ( + {!imgID ? ( ( @@ -224,7 +237,7 @@ registerBlockType('cgb/block-feature', { tagName="h3" placeholder={__('Feature title')} onChange={onChangeTitle} - value={attributes.title} + value={title} />
@@ -233,12 +246,14 @@ registerBlockType('cgb/block-feature', { multiline="p" placeholder={__('Feature description')} onChange={onChangeDescription} - value={attributes.description} + value={description} /> - - {buttonText} - + {showButton ? ( + + {buttonText} + + ) : null}
@@ -257,6 +272,7 @@ registerBlockType('cgb/block-feature', { description, buttonText, link, + showButton, }, classNames, } = props; @@ -276,9 +292,11 @@ registerBlockType('cgb/block-feature', {

{title}

{description}
- - {buttonText} - + {showButton ? ( + + {buttonText} + + ) : null} ); diff --git a/src/blocks/features-list/inspector.js b/src/blocks/features-list/inspector.js index 36120b4..2ca825d 100644 --- a/src/blocks/features-list/inspector.js +++ b/src/blocks/features-list/inspector.js @@ -16,28 +16,41 @@ export default class Inspector extends Component { render() { const { - attributes: { link, buttonText, circularImg }, + attributes: { link, buttonText, circularImg, showButton }, onChangeLink, onChangeButtonText, onChangeImgType, + onToggleButton, } = this.props; return ( - + - - - - + + {showButton ? ( +
+ + + + + + +
+ ) : null}