| 1 |
import { BlockControls } from '@wordpress/block-editor'; |
| 2 |
import { ToolbarDropdownMenu, ToolbarGroup } from '@wordpress/components'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
|
| 5 |
import getIcon from '../../../utils/get-icon'; |
| 6 |
|
| 7 |
export default function EditBlockControls({ attributes, setAttributes }) { |
| 8 |
const { buttonsAlign, buttonsVerticalAlign } = attributes; |
| 9 |
|
| 10 |
const alignConf = { |
| 11 |
start: { |
| 12 |
icon: getIcon('icon-horizontal-start'), |
| 13 |
label: __('Buttons Justify Start', 'ghostkit'), |
| 14 |
}, |
| 15 |
center: { |
| 16 |
icon: getIcon('icon-horizontal-center'), |
| 17 |
label: __('Buttons Justify Center', 'ghostkit'), |
| 18 |
}, |
| 19 |
end: { |
| 20 |
icon: getIcon('icon-horizontal-end'), |
| 21 |
label: __('Buttons Justify End', 'ghostkit'), |
| 22 |
}, |
| 23 |
stretch: { |
| 24 |
icon: getIcon('icon-horizontal-stretch'), |
| 25 |
label: __('Buttons Justify Stretch', 'ghostkit'), |
| 26 |
}, |
| 27 |
}; |
| 28 |
|
| 29 |
if (buttonsVerticalAlign) { |
| 30 |
alignConf.start.icon = getIcon('icon-vertical-top'); |
| 31 |
alignConf.start.label = __('Buttons Vertical Start', 'ghostkit'); |
| 32 |
alignConf.center.icon = getIcon('icon-vertical-center'); |
| 33 |
alignConf.center.label = __('Buttons Vertical Center', 'ghostkit'); |
| 34 |
alignConf.end.icon = getIcon('icon-vertical-bottom'); |
| 35 |
alignConf.end.label = __('Buttons Vertical End', 'ghostkit'); |
| 36 |
alignConf.stretch = undefined; |
| 37 |
} |
| 38 |
|
| 39 |
const alignControls = []; |
| 40 |
Object.entries(alignConf).forEach((item) => { |
| 41 |
if (!item[1]) { |
| 42 |
return; |
| 43 |
} |
| 44 |
alignControls.push({ |
| 45 |
title: item[1].label, |
| 46 |
icon: item[1].icon, |
| 47 |
isActive: buttonsAlign === item[0], |
| 48 |
onClick: () => setAttributes({ buttonsAlign: item[0] }), |
| 49 |
}); |
| 50 |
}); |
| 51 |
|
| 52 |
const alignLabel = buttonsVerticalAlign |
| 53 |
? __('Buttons Vertical Align', 'ghostkit') |
| 54 |
: __('Buttons Justify Align', 'ghostkit'); |
| 55 |
|
| 56 |
return ( |
| 57 |
<BlockControls group="block"> |
| 58 |
<ToolbarGroup> |
| 59 |
<ToolbarDropdownMenu |
| 60 |
icon={alignConf[buttonsAlign].icon} |
| 61 |
label={alignLabel} |
| 62 |
controls={alignControls} |
| 63 |
/> |
| 64 |
</ToolbarGroup> |
| 65 |
</BlockControls> |
| 66 |
); |
| 67 |
} |
| 68 |
|