PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.5.2
GenerateBlocks v1.5.2
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / button / components / ConditionalColors.js
generateblocks / src / blocks / button / components Last commit date
BlockControls.js 4 years ago ButtonContentRenderer.js 4 years ago ComponentCSS.js 4 years ago ConditionalColors.js 4 years ago InspectorAdvancedControls.js 4 years ago InspectorControls.js 4 years ago
ConditionalColors.js
69 lines
1 import { __ } from '@wordpress/i18n';
2 import { addFilter } from '@wordpress/hooks';
3
4 function AddColorItems( items, props ) {
5 const {
6 name,
7 attributes,
8 } = props;
9
10 const {
11 useDynamicData,
12 dynamicContentType,
13 } = attributes;
14
15 if ( 'generateblocks/button' !== name ) {
16 return items;
17 }
18
19 const addCurrentColors = useDynamicData && 'pagination-numbers' === dynamicContentType;
20
21 if ( addCurrentColors ) {
22 const newItems = [
23 {
24 group: 'background',
25 attribute: 'backgroundColorCurrent',
26 tooltip: __( 'Current', 'generateblocks' ),
27 alpha: true,
28 },
29 {
30 group: 'text',
31 attribute: 'textColorCurrent',
32 tooltip: __( 'Current', 'generateblocks' ),
33 alpha: false,
34 },
35 {
36 group: 'border',
37 attribute: 'borderColorCurrent',
38 tooltip: __( 'Current', 'generateblocks' ),
39 alpha: true,
40 },
41 ];
42
43 items.forEach( ( colorItem, index ) => {
44 newItems.forEach( ( newColorItem ) => {
45 if (
46 newColorItem.group === colorItem.group &&
47 ! colorItem.items.some( ( item ) => item.attribute === newColorItem.attribute )
48 ) {
49 items[ index ].items.push(
50 {
51 tooltip: newColorItem.tooltip,
52 attribute: newColorItem.attribute,
53 alpha: newColorItem.alpha,
54 }
55 );
56 }
57 } );
58 } );
59 }
60
61 return items;
62 }
63
64 addFilter(
65 'generateblocks.editor.colorGroupItems',
66 'generateblocks/button-colors/add-conditional-color-items',
67 AddColorItems
68 );
69