@gechiui/block-editor
Version:
72 lines (65 loc) • 2.08 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@gechiui/element";
/**
* GeChiUI dependencies
*/
import { _x } from '@gechiui/i18n';
import { ToolbarGroup, ToolbarDropdownMenu } from '@gechiui/components';
/**
* Internal dependencies
*/
import { alignTop, alignCenter, alignBottom } from './icons';
const BLOCK_ALIGNMENTS_CONTROLS = {
top: {
icon: alignTop,
title: _x('Align top', 'Block vertical alignment setting')
},
center: {
icon: alignCenter,
title: _x('Align middle', 'Block vertical alignment setting')
},
bottom: {
icon: alignBottom,
title: _x('Align bottom', 'Block vertical alignment setting')
}
};
const DEFAULT_CONTROLS = ['top', 'center', 'bottom'];
const DEFAULT_CONTROL = 'top';
const POPOVER_PROPS = {
isAlternate: true
};
function BlockVerticalAlignmentUI(_ref) {
let {
value,
onChange,
controls = DEFAULT_CONTROLS,
isCollapsed = true,
isToolbar
} = _ref;
function applyOrUnset(align) {
return () => onChange(value === align ? undefined : align);
}
const activeAlignment = BLOCK_ALIGNMENTS_CONTROLS[value];
const defaultAlignmentControl = BLOCK_ALIGNMENTS_CONTROLS[DEFAULT_CONTROL];
const UIComponent = isToolbar ? ToolbarGroup : ToolbarDropdownMenu;
const extraProps = isToolbar ? {
isCollapsed
} : {};
return createElement(UIComponent, _extends({
popoverProps: POPOVER_PROPS,
icon: activeAlignment ? activeAlignment.icon : defaultAlignmentControl.icon,
label: _x('Change vertical alignment', 'Block vertical alignment setting label'),
controls: controls.map(control => {
return { ...BLOCK_ALIGNMENTS_CONTROLS[control],
isActive: value === control,
role: isCollapsed ? 'menuitemradio' : undefined,
onClick: applyOrUnset(control)
};
})
}, extraProps));
}
/**
* @see https://github.com/GeChiUI/gutenberg/blob/HEAD/packages/block-editor/src/components/block-vertical-alignment-toolbar/README.md
*/
export default BlockVerticalAlignmentUI;
//# sourceMappingURL=ui.js.map