UNPKG

@wordpress/block-editor

Version:
80 lines (77 loc) 2.58 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _i18n = require("@wordpress/i18n"); var _components = require("@wordpress/components"); var _useAvailableAlignments = _interopRequireDefault(require("./use-available-alignments")); var _constants = require("./constants"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ /** * Internal dependencies */ function BlockAlignmentUI({ value, onChange, controls, isToolbar, isCollapsed = true, isBottomSheetControl = false }) { const enabledControls = (0, _useAvailableAlignments.default)(controls); const hasEnabledControls = !!enabledControls.length; if (!hasEnabledControls) { return null; } function onChangeAlignment(align) { onChange([value, 'none'].includes(align) ? undefined : align); } const activeAlignmentControl = _constants.BLOCK_ALIGNMENTS_CONTROLS[value]; const defaultAlignmentControl = _constants.BLOCK_ALIGNMENTS_CONTROLS[_constants.DEFAULT_CONTROL]; const toolbarUIComponent = isToolbar ? _components.ToolbarGroup : _components.ToolbarDropdownMenu; const UIComponent = isBottomSheetControl ? _components.BottomSheetSelectControl : toolbarUIComponent; const commonProps = { label: (0, _i18n.__)('Align') }; const extraProps = isBottomSheetControl ? { options: enabledControls.map(({ name: controlName }) => { const control = _constants.BLOCK_ALIGNMENTS_CONTROLS[controlName]; return { value: controlName, label: control.title, icon: control.icon }; }), value: activeAlignmentControl ? value : 'none', onChange: align => onChangeAlignment(align) } : { icon: activeAlignmentControl ? activeAlignmentControl.icon : defaultAlignmentControl.icon, isCollapsed: isToolbar ? isCollapsed : undefined, controls: enabledControls.map(({ name: controlName }) => { return { ..._constants.BLOCK_ALIGNMENTS_CONTROLS[controlName], isActive: value === controlName || !value && controlName === 'none', onClick: () => onChangeAlignment(controlName) }; }), popoverProps: _constants.POPOVER_PROPS, toggleProps: { description: (0, _i18n.__)('Change alignment') } }; return /*#__PURE__*/(0, _jsxRuntime.jsx)(UIComponent, { ...commonProps, ...extraProps }); } var _default = exports.default = BlockAlignmentUI; //# sourceMappingURL=ui.native.js.map