@gechiui/block-editor
Version:
77 lines (72 loc) • 2.1 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@gechiui/element";
/**
* GeChiUI dependencies
*/
import { ToolbarDropdownMenu, ToolbarGroup } from '@gechiui/components';
import { justifyLeft, justifyCenter, justifyRight, justifySpaceBetween } from '@gechiui/icons';
import { __ } from '@gechiui/i18n';
const icons = {
left: justifyLeft,
center: justifyCenter,
right: justifyRight,
'space-between': justifySpaceBetween
};
function JustifyContentUI(_ref) {
let {
allowedControls = ['left', 'center', 'right', 'space-between'],
isCollapsed = true,
onChange,
value,
popoverProps,
isToolbar
} = _ref;
// If the control is already selected we want a click
// again on the control to deselect the item, so we
// call onChange( undefined )
const handleClick = next => {
if (next === value) {
onChange(undefined);
} else {
onChange(next);
}
};
const icon = value ? icons[value] : icons.left;
const allControls = [{
name: 'left',
icon: justifyLeft,
title: __('左对齐项'),
isActive: 'left' === value,
onClick: () => handleClick('left')
}, {
name: 'center',
icon: justifyCenter,
title: __('居中对齐项'),
isActive: 'center' === value,
onClick: () => handleClick('center')
}, {
name: 'right',
icon: justifyRight,
title: __('右对齐项'),
isActive: 'right' === value,
onClick: () => handleClick('right')
}, {
name: 'space-between',
icon: justifySpaceBetween,
title: __('项目间距'),
isActive: 'space-between' === value,
onClick: () => handleClick('space-between')
}];
const UIComponent = isToolbar ? ToolbarGroup : ToolbarDropdownMenu;
const extraProps = isToolbar ? {
isCollapsed
} : {};
return createElement(UIComponent, _extends({
icon: icon,
popoverProps: popoverProps,
label: __('更改项目对齐'),
controls: allControls.filter(elem => allowedControls.includes(elem.name))
}, extraProps));
}
export default JustifyContentUI;
//# sourceMappingURL=ui.js.map