Skip to content

Commit 3606fae

Browse files
committed
Code refactor and testing with 5.9
1 parent 436dfea commit 3606fae

File tree

15 files changed

+6200
-2098
lines changed

15 files changed

+6200
-2098
lines changed

color-palette/build/color-palette.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

color-palette/readme.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ Give each color block a color using the selector in the Inspector Panel on the r
3434

3535
== Changelog ==
3636

37+
= 4.2 =
38+
* Tested for compatibility with WordPress 5.9.
39+
* Code refactor to use the latest version of block.json.
40+
* Added front-end search functionality within the palette block. Search is opt-in. You can turn it on via an option in the Inspector Panel.
41+
3742
= 4.1.1 =
3843
* Tested for compatibility with Wordpress 5.8.
3944
* Fixed minor "invalid color" bug when Color Palette block is added to a page.
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
2+
3+
"api_version": 2,
4+
25
"name": "tdg/color",
36
"title": "Color",
4-
"description": "A single color block.",
57
"category": "design",
8+
"description": "A single color block.",
69
"keywords": [ "colors", "styles", "visual identity" ],
710
"parent": [ "tdg/colors" ],
11+
812
"attributes": {
913
"hex": {
1014
"type": "string",
@@ -13,9 +17,22 @@
1317
"label": {
1418
"type": "string",
1519
"default": ""
20+
},
21+
"autoLabel": {
22+
"type": "string",
23+
"default": ""
24+
}
25+
},
26+
27+
"example": {
28+
"attributes": {
29+
"hex": "#604c8d",
30+
"label": "Cyber Grape"
1631
}
1732
},
33+
1834
"script": "file:../../../build/color-palette.min.js",
1935
"editorStyle": "file:../../../build/styles-editor.min.css",
2036
"style": "file:../../../build/styles-frontend.min.css"
37+
2138
}

color-palette/source/blocks/color/edit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import ntc from '../../vendor/ntc.js';
77
const ColorEdit = ( props ) => {
88

99
const { ColorPicker, PanelBody, TextControl } = wp.components;
10-
const { InspectorControls } = wp.blockEditor;
11-
const { Fragment } = wp.element;
10+
const { InspectorControls, useBlockProps } = wp.blockEditor;
1211

1312
// Get the values needed from props.
1413
const { setAttributes } = props;
1514
const { hex, label, autoLabel } = props.attributes;
15+
const blockProps = useBlockProps();
1616

1717
// Declare change event handlers.
18-
const onChangeHex = ( value ) => { setAttributes( { hex: value.hex } ) };
19-
const onChangeLabel = ( value ) => { setAttributes( { label: value } ) };
18+
const onChangeHex = ( value ) => { setAttributes( { hex: value.hex } ) };
19+
const onChangeLabel = ( value ) => { setAttributes( { label: value } ) };
2020

2121
// Get the automatic name for this hex from the "Name That Color" API.
2222
// This will be used as the placeholder text for the Color Label attribute
@@ -31,7 +31,7 @@ const ColorEdit = ( props ) => {
3131

3232
// Return the edit UI.
3333
return (
34-
<Fragment>
34+
<div { ...blockProps }>
3535

3636
<InspectorControls>
3737

@@ -65,7 +65,7 @@ const ColorEdit = ( props ) => {
6565

6666
</div>
6767

68-
</Fragment>
68+
</div>
6969
);
7070

7171
};

color-palette/source/blocks/color/example.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

color-palette/source/blocks/color/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@
44
* This block is the child block to the color palette block.
55
*/
66

7-
import ColorEdit from './edit.js';
8-
import ColorExample from './example.js';
9-
import ColorIcons from './icons.js';
7+
import { default as Edit } from './edit.js';
8+
import { default as Icons } from './icons.js';
9+
import { default as Metadata } from './block.json';
1010

1111
const Color = ( () => {
1212

1313
const { registerBlockType } = wp.blocks;
1414

15-
registerBlockType( 'tdg/color', {
16-
title: 'Color',
17-
description: 'A single color block.',
18-
category: 'design',
19-
icon: ColorIcons.block,
20-
example: ColorExample,
15+
registerBlockType( Metadata, {
16+
icon: Icons.block,
2117
parent: [ 'tdg/color' ],
22-
edit: ( props ) => { return ( ColorEdit( props ) ); },
18+
edit: ( props ) => { return ( Edit( props ) ); },
2319
save: () => { return null; }
2420
} );
2521

color-palette/source/blocks/color/register.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ public function __construct() {
2424
* @return void
2525
*/
2626
public function register(): void {
27-
register_block_type( 'tdg/color', [
28-
'attributes' => [
29-
'hex' => [ 'type' => 'string', 'default' => '' ],
30-
'label' => [ 'type' => 'string', 'default' => '' ],
31-
'autoLabel' => [ 'type' => 'string', 'default' => '' ]
32-
],
33-
27+
register_block_type_from_metadata( __DIR__, [
3428
'render_callback' => [ $this, 'render' ]
3529
] );
3630
}

color-palette/source/blocks/colors/block.json

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
2+
3+
"api_version": 2,
4+
25
"name": "tdg/colors",
36
"title": "Color Palette",
4-
"description": "A group of related color swatches.",
57
"category": "design",
8+
"description": "A group of related color swatches.",
69
"keywords": [ "colors", "styles", "visual identity" ],
10+
711
"attributes": {
812
"hideHex": {
913
"type": "boolean"
@@ -15,7 +19,36 @@
1519
"type": "boolean"
1620
}
1721
},
22+
23+
"example": {
24+
"innerBlocks": [
25+
{
26+
"name": "tdg/color",
27+
"attributes": {
28+
"hex": "#604c8d",
29+
"label": "Cyber Grape"
30+
}
31+
},
32+
{
33+
"name": "tdg/color",
34+
"attributes": {
35+
"hex": "#559cad",
36+
"label": "Pacific Blue"
37+
}
38+
},
39+
{
40+
"name": "tdg/color",
41+
"attributes": {
42+
"hex": "#c1b2ab",
43+
"label": "Pale Silver"
44+
}
45+
}
46+
],
47+
48+
},
49+
1850
"script": "file:../../../build/color-palette.min.js",
1951
"editorStyle": "file:../../../build/styles-editor.min.css",
2052
"style": "file:../../../build/styles-frontend.min.css"
53+
2154
}

color-palette/source/blocks/colors/edit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
*/
44

55
import { memoize, times } from 'lodash';
6-
import ColorsGetClasses from './get-classes.js';
6+
import { default as GetClasses } from './get-classes.js';
77

88
const ColorsEdit = ( props ) => {
99

10-
const { InnerBlocks, InspectorControls } = wp.blockEditor;
10+
const { InnerBlocks, InspectorControls, useBlockProps } = wp.blockEditor;
1111
const { PanelBody, ToggleControl } = wp.components;
12-
const { Fragment } = wp.element;
1312

1413
// Get attributes from props.
1514
const { setAttributes } = props;
1615
const { hideHex, hideRGB, hideCMYK } = props.attributes;
16+
const blockProps = useBlockProps();
1717

1818
// Figure out what classes should be applied to the colors.
19-
const colorsClasses = ColorsGetClasses( props );
19+
const colorsClasses = GetClasses( props );
2020

2121
// Change event handlers.
2222
const onChangeHideHex = ( value ) => { setAttributes( { hideHex: value } ) };
@@ -33,7 +33,7 @@ const ColorsEdit = ( props ) => {
3333

3434
// Return the edit UI.
3535
return (
36-
<Fragment>
36+
<div { ...blockProps }>
3737

3838
<InspectorControls>
3939
<PanelBody title='Color code display options'>
@@ -71,7 +71,7 @@ const ColorsEdit = ( props ) => {
7171
</div>
7272
</div>
7373

74-
</Fragment>
74+
</div>
7575
);
7676

7777
};

color-palette/source/blocks/colors/example.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)