@wordpress/block-editor
Version:
99 lines (97 loc) • 2.99 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/alignment-control/ui.js
var ui_exports = {};
__export(ui_exports, {
default: () => ui_default
});
module.exports = __toCommonJS(ui_exports);
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_icons = require("@wordpress/icons");
var import_jsx_runtime = require("react/jsx-runtime");
var DEFAULT_ALIGNMENT_CONTROLS = [
{
icon: import_icons.alignLeft,
title: (0, import_i18n.__)("Align text left"),
align: "left"
},
{
icon: import_icons.alignCenter,
title: (0, import_i18n.__)("Align text center"),
align: "center"
},
{
icon: import_icons.alignRight,
title: (0, import_i18n.__)("Align text right"),
align: "right"
}
];
var POPOVER_PROPS = {
placement: "bottom-start"
};
function AlignmentUI({
value,
onChange,
alignmentControls = DEFAULT_ALIGNMENT_CONTROLS,
label = (0, import_i18n.__)("Align text"),
description = (0, import_i18n.__)("Change text alignment"),
isCollapsed = true,
isToolbar
}) {
function applyOrUnset(align) {
return () => onChange(value === align ? void 0 : align);
}
const activeAlignment = alignmentControls.find(
(control) => control.align === value
);
function setIcon() {
if (activeAlignment) {
return activeAlignment.icon;
}
return (0, import_i18n.isRTL)() ? import_icons.alignRight : import_icons.alignLeft;
}
const UIComponent = isToolbar ? import_components.ToolbarGroup : import_components.ToolbarDropdownMenu;
const extraProps = isToolbar ? { isCollapsed } : {
toggleProps: {
description
},
popoverProps: POPOVER_PROPS
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
UIComponent,
{
icon: setIcon(),
label,
controls: alignmentControls.map((control) => {
const { align } = control;
const isActive = value === align;
return {
...control,
isActive,
role: isCollapsed ? "menuitemradio" : void 0,
onClick: applyOrUnset(align)
};
}),
...extraProps
}
);
}
var ui_default = AlignmentUI;
//# sourceMappingURL=ui.js.map