@wordpress/block-editor
Version:
113 lines (111 loc) • 4.69 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/block-alignment-control/ui.js
var ui_exports = {};
__export(ui_exports, {
default: () => ui_default
});
module.exports = __toCommonJS(ui_exports);
var import_clsx = __toESM(require("clsx"));
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_use_available_alignments = __toESM(require("./use-available-alignments"));
var import_constants = require("./constants");
var import_jsx_runtime = require("react/jsx-runtime");
function BlockAlignmentUI({
value,
onChange,
controls,
isToolbar,
isCollapsed = true
}) {
const enabledControls = (0, import_use_available_alignments.default)(controls);
const hasEnabledControls = !!enabledControls.length;
if (!hasEnabledControls) {
return null;
}
function onChangeAlignment(align) {
onChange([value, "none"].includes(align) ? void 0 : align);
}
const activeAlignmentControl = import_constants.BLOCK_ALIGNMENTS_CONTROLS[value];
const defaultAlignmentControl = import_constants.BLOCK_ALIGNMENTS_CONTROLS[import_constants.DEFAULT_CONTROL];
const UIComponent = isToolbar ? import_components.ToolbarGroup : import_components.ToolbarDropdownMenu;
const commonProps = {
icon: activeAlignmentControl ? activeAlignmentControl.icon : defaultAlignmentControl.icon,
label: (0, import_i18n.__)("Align")
};
const extraProps = isToolbar ? {
isCollapsed,
controls: enabledControls.map(({ name: controlName }) => {
return {
...import_constants.BLOCK_ALIGNMENTS_CONTROLS[controlName],
isActive: value === controlName || !value && controlName === "none",
role: isCollapsed ? "menuitemradio" : void 0,
onClick: () => onChangeAlignment(controlName)
};
})
} : {
toggleProps: { description: (0, import_i18n.__)("Change alignment") },
children: ({ onClose }) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { className: "block-editor-block-alignment-control__menu-group", children: enabledControls.map(
({ name: controlName, info }) => {
const { icon, title } = import_constants.BLOCK_ALIGNMENTS_CONTROLS[controlName];
const isSelected = controlName === value || !value && controlName === "none";
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.MenuItem,
{
icon,
iconPosition: "left",
className: (0, import_clsx.default)(
"components-dropdown-menu__menu-item",
{
"is-active": isSelected
}
),
isSelected,
onClick: () => {
onChangeAlignment(
controlName
);
onClose();
},
role: "menuitemradio",
info,
children: title
},
controlName
);
}
) }) });
}
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UIComponent, { ...commonProps, ...extraProps });
}
var ui_default = BlockAlignmentUI;
//# sourceMappingURL=ui.js.map