From 86450881192a95ce22d463b7163107e00d0b7bd3 Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 14 Aug 2020 11:43:04 +0100 Subject: [PATCH] add toggle control for inline --- src/index.js | 76 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/src/index.js b/src/index.js index bb3e4ea..aede38f 100644 --- a/src/index.js +++ b/src/index.js @@ -3,9 +3,15 @@ import './editor.scss'; import { registerBlockType } from '@wordpress/blocks'; -import { Fragment } from '@wordpress/element'; +import { RawHTML, Fragment } from '@wordpress/element'; import { InspectorControls } from '@wordpress/editor'; -import { TextControl, Panel, PanelRow } from '@wordpress/components'; +import { + Button, + TextControl, + ToggleControl, + Panel, + PanelRow, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; registerBlockType('room-vw/iconify', { @@ -21,15 +27,25 @@ registerBlockType('room-vw/iconify', { attributes: { prefix: { type: 'string', + source: 'attribute', + selector: 'data-prefix', default: 'noto-v1', }, name: { type: 'string', + source: 'attribute', + selector: 'data-name', default: 'unicorn', }, inline: { type: 'boolean', - default: true, + default: false, + }, + svg: { + type: 'string', + source: 'html', + selector: '.icon', + default: 'Select an icon', }, }, @@ -54,27 +70,53 @@ registerBlockType('room-vw/iconify', { }} /> + + { + setAttributes({ inline: state }); + }} + /> + + -
- - {attributes.prefix + ':' + attributes.name} -
+ + {attributes.svg} + ); }, - save({ className, attributes }) { + save({ attributes }) { return ( - + + {attributes.svg} + ); }, });