PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.7.2
GenerateBlocks v1.7.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 3 years ago ButtonContentRenderer.js 3 years ago ComponentCSS.js 4 years ago ConditionalColors.js 3 years ago InspectorAdvancedControls.js 3 years ago
ConditionalColors.js
73 lines
1 import { __ } from '@wordpress/i18n';
2 import { addFilter, applyFilters } 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 = applyFilters(
20 'generateblocks.editor.addButtonCurrentColors',
21 useDynamicData && 'pagination-numbers' === dynamicContentType,
22 props
23 );
24
25 if ( addCurrentColors ) {
26 const newItems = [
27 {
28 group: 'background',
29 attribute: 'backgroundColorCurrent',
30 tooltip: __( 'Current', 'generateblocks' ),
31 alpha: true,
32 },
33 {
34 group: 'text',
35 attribute: 'textColorCurrent',
36 tooltip: __( 'Current', 'generateblocks' ),
37 alpha: false,
38 },
39 {
40 group: 'border',
41 attribute: 'borderColorCurrent',
42 tooltip: __( 'Current', 'generateblocks' ),
43 alpha: true,
44 },
45 ];
46
47 items.forEach( ( colorItem, index ) => {
48 newItems.forEach( ( newColorItem ) => {
49 if (
50 newColorItem.group === colorItem.group &&
51 ! colorItem.items.some( ( item ) => item.attribute === newColorItem.attribute )
52 ) {
53 items[ index ].items.push(
54 {
55 tooltip: newColorItem.tooltip,
56 attribute: newColorItem.attribute,
57 alpha: newColorItem.alpha,
58 }
59 );
60 }
61 } );
62 } );
63 }
64
65 return items;
66 }
67
68 addFilter(
69 'generateblocks.editor.colorGroupItems',
70 'generateblocks/button-colors/add-conditional-color-items',
71 AddColorItems
72 );
73