Compare commits
No commits in common. "2d4e04211be8d251f34c216bd79a889b8d4c4ee5" and "a2a7f4bebfb39b7686d4f71d084d2f4e532cadf9" have entirely different histories.
2d4e04211b
...
a2a7f4bebf
62
src/index.js
62
src/index.js
|
@ -1,18 +1,8 @@
|
|||
/*eslint-disable @wordpress/i18n-text-domain, @wordpress/i18n-no-variables */
|
||||
|
||||
import './style.scss';
|
||||
import './editor.scss';
|
||||
|
||||
import { registerBlockStyle, registerBlockType } from '@wordpress/blocks';
|
||||
import { BlockControls, InspectorControls } from '@wordpress/editor';
|
||||
import { InnerBlocks } from '@wordpress/block-editor';
|
||||
import {
|
||||
Button,
|
||||
ColorPicker,
|
||||
PanelBody,
|
||||
ToolbarGroup,
|
||||
__experimentalToolbarItem as ToolbarItem,
|
||||
} from '@wordpress/components';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
const NAMESPACE = 'namespace'; // TODO
|
||||
|
@ -25,7 +15,7 @@ const INNER_TEMPLATE = [
|
|||
];
|
||||
|
||||
registerBlockType(`${NAMESPACE}/${SLUG}`, {
|
||||
title: __(BLOCK_TITLE, NAMESPACE),
|
||||
title: __(BLOCK_TITLE, SLUG),
|
||||
|
||||
category: 'widgets',
|
||||
|
||||
|
@ -41,54 +31,16 @@ registerBlockType(`${NAMESPACE}/${SLUG}`, {
|
|||
selector: 'p',
|
||||
default: __('Some default text.', NAMESPACE),
|
||||
},
|
||||
color: {
|
||||
type: 'string',
|
||||
default: 'rgba(0, 0, 0, 1)',
|
||||
},
|
||||
},
|
||||
|
||||
edit({ attributes, setAttributes, className }) {
|
||||
edit({ attributes, className }) {
|
||||
return (
|
||||
<>
|
||||
<InspectorControls>
|
||||
<PanelBody title={__('Inspector Control', NAMESPACE)}>
|
||||
<ColorPicker
|
||||
color={attributes.color}
|
||||
onChangeComplete={(value) => {
|
||||
const rgb = value.rgb;
|
||||
const color =
|
||||
rgb.a !== 1
|
||||
? `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})`
|
||||
: value.hex;
|
||||
setAttributes({ color });
|
||||
}}
|
||||
/>
|
||||
</PanelBody>
|
||||
</InspectorControls>
|
||||
|
||||
<BlockControls>
|
||||
<ToolbarGroup>
|
||||
<ToolbarItem
|
||||
as={Button}
|
||||
onClick={() =>
|
||||
console.log('Toolbar Button go brrrr!')
|
||||
}
|
||||
>
|
||||
Toolbar Button
|
||||
</ToolbarItem>
|
||||
</ToolbarGroup>
|
||||
</BlockControls>
|
||||
|
||||
<div className={className}>
|
||||
<div>
|
||||
<InnerBlocks
|
||||
template={INNER_TEMPLATE}
|
||||
templateLock="all"
|
||||
/>
|
||||
</div>
|
||||
<p>{attributes.text}</p>
|
||||
<div className={className}>
|
||||
<div>
|
||||
<InnerBlocks template={INNER_TEMPLATE} templateLock="all" />
|
||||
</div>
|
||||
</>
|
||||
<p>{attributes.text}</p>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue