index.js
64 lines
| 1 | /** |
| 2 | * External dependencies |
| 3 | */ |
| 4 | import { applyFilters } from '@wordpress/hooks'; |
| 5 | |
| 6 | /** |
| 7 | * Internal dependencies |
| 8 | */ |
| 9 | import ColorPicker from '../color-picker'; |
| 10 | import './editor.scss'; |
| 11 | |
| 12 | export default function ColorGroup( props ) { |
| 13 | const { |
| 14 | setAttributes, |
| 15 | attributes, |
| 16 | colors, |
| 17 | } = props; |
| 18 | |
| 19 | const colorItems = applyFilters( |
| 20 | 'generateblocks.editor.colorGroupItems', |
| 21 | colors, |
| 22 | props |
| 23 | ); |
| 24 | |
| 25 | return ( |
| 26 | <div className="gblocks-color-group"> |
| 27 | { |
| 28 | colorItems.map( ( colorItem, index ) => { |
| 29 | return ( |
| 30 | <div key={ index } className="gblocks-color-group__row"> |
| 31 | { !! colorItem.label && |
| 32 | <span className="gblocks-color-group__row-label">{ colorItem.label }</span> |
| 33 | } |
| 34 | |
| 35 | { colorItem.items.map( ( color, colorIndex ) => { |
| 36 | return ( |
| 37 | <ColorPicker |
| 38 | key={ colorIndex } |
| 39 | label={ color?.label } |
| 40 | tooltip={ color?.tooltip } |
| 41 | value={ attributes[ color.attribute ] } |
| 42 | alpha={ color.alpha || false } |
| 43 | valueOpacity={ attributes[ color.attribute + 'Opacity' ] } |
| 44 | onChange={ ( nextBackgroundColor ) => |
| 45 | setAttributes( { |
| 46 | [ color.attribute ]: nextBackgroundColor, |
| 47 | } ) |
| 48 | } |
| 49 | onOpacityChange={ ( value ) => |
| 50 | setAttributes( { |
| 51 | [ color.attribute + 'Opacity' ]: value, |
| 52 | } ) |
| 53 | } |
| 54 | /> |
| 55 | ); |
| 56 | } ) } |
| 57 | </div> |
| 58 | ); |
| 59 | } ) |
| 60 | } |
| 61 | </div> |
| 62 | ); |
| 63 | } |
| 64 |