| 1 |
import { BlockControls } from '@wordpress/block-editor'; |
| 2 |
import { |
| 3 |
ToolbarButton, |
| 4 |
ToolbarDropdownMenu, |
| 5 |
ToolbarGroup, |
| 6 |
} from '@wordpress/components'; |
| 7 |
import { __ } from '@wordpress/i18n'; |
| 8 |
|
| 9 |
import getIcon from '../../../utils/get-icon'; |
| 10 |
import UrlPicker from './url-picker'; |
| 11 |
|
| 12 |
export default function EditBlockControls({ |
| 13 |
attributes, |
| 14 |
setAttributes, |
| 15 |
isSelected, |
| 16 |
}) { |
| 17 |
const { justify, flipH, flipV } = attributes; |
| 18 |
|
| 19 |
const iconStart = getIcon('icon-horizontal-start'); |
| 20 |
const iconCenter = getIcon('icon-horizontal-center'); |
| 21 |
const iconEnd = getIcon('icon-horizontal-end'); |
| 22 |
|
| 23 |
const justifyControls = [ |
| 24 |
{ |
| 25 |
title: __('Justify Icon Start', 'ghostkit'), |
| 26 |
icon: iconStart, |
| 27 |
isActive: justify === 'start', |
| 28 |
onClick: () => setAttributes({ justify: 'start' }), |
| 29 |
}, |
| 30 |
{ |
| 31 |
title: __('Justify Icon Center', 'ghostkit'), |
| 32 |
icon: iconCenter, |
| 33 |
isActive: justify === 'center', |
| 34 |
onClick: () => setAttributes({ justify: 'center' }), |
| 35 |
}, |
| 36 |
{ |
| 37 |
title: __('Justify Icon End', 'ghostkit'), |
| 38 |
icon: iconEnd, |
| 39 |
isActive: justify === 'end', |
| 40 |
onClick: () => setAttributes({ justify: 'end' }), |
| 41 |
}, |
| 42 |
]; |
| 43 |
|
| 44 |
let currentJustifyIcon; |
| 45 |
if (justify === 'start') { |
| 46 |
currentJustifyIcon = iconStart; |
| 47 |
} else if (justify === 'center') { |
| 48 |
currentJustifyIcon = iconCenter; |
| 49 |
} else { |
| 50 |
currentJustifyIcon = iconEnd; |
| 51 |
} |
| 52 |
|
| 53 |
return ( |
| 54 |
<> |
| 55 |
<BlockControls group="block"> |
| 56 |
<ToolbarGroup> |
| 57 |
<ToolbarDropdownMenu |
| 58 |
icon={currentJustifyIcon} |
| 59 |
label={__('Justify Icon', 'ghostkit')} |
| 60 |
controls={justifyControls} |
| 61 |
/> |
| 62 |
</ToolbarGroup> |
| 63 |
</BlockControls> |
| 64 |
|
| 65 |
<UrlPicker |
| 66 |
attributes={attributes} |
| 67 |
setAttributes={setAttributes} |
| 68 |
isSelected={isSelected} |
| 69 |
/> |
| 70 |
|
| 71 |
<BlockControls> |
| 72 |
<ToolbarGroup> |
| 73 |
<ToolbarButton |
| 74 |
icon={getIcon('icon-flip-horizontal')} |
| 75 |
title={__('Flip Horizontal', 'ghostkit')} |
| 76 |
onClick={() => setAttributes({ flipH: !flipH })} |
| 77 |
isActive={flipH} |
| 78 |
/> |
| 79 |
<ToolbarButton |
| 80 |
icon={getIcon('icon-flip-vertical')} |
| 81 |
title={__('Flip Vertical', 'ghostkit')} |
| 82 |
onClick={() => setAttributes({ flipV: !flipV })} |
| 83 |
isActive={flipV} |
| 84 |
/> |
| 85 |
</ToolbarGroup> |
| 86 |
</BlockControls> |
| 87 |
</> |
| 88 |
); |
| 89 |
} |
| 90 |
|