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 |