@wordpress/components
Version:
UI components for WordPress.
109 lines (107 loc) • 4.41 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/components/src/alignment-matrix-control/index.tsx
var alignment_matrix_control_exports = {};
__export(alignment_matrix_control_exports, {
AlignmentMatrixControl: () => AlignmentMatrixControl,
default: () => alignment_matrix_control_default
});
module.exports = __toCommonJS(alignment_matrix_control_exports);
var import_clsx = __toESM(require("clsx"));
var import_i18n = require("@wordpress/i18n");
var import_compose = require("@wordpress/compose");
var import_element = require("@wordpress/element");
var import_cell = __toESM(require("./cell"));
var import_composite = require("../composite");
var import_styles = require("./styles");
var import_icon = __toESM(require("./icon"));
var import_utils = require("./utils");
var import_jsx_runtime = require("react/jsx-runtime");
function UnforwardedAlignmentMatrixControl({
className,
id,
label = (0, import_i18n.__)("Alignment Matrix Control"),
defaultValue = "center center",
value,
onChange,
width = 92,
...props
}) {
const baseId = (0, import_compose.useInstanceId)(UnforwardedAlignmentMatrixControl, "alignment-matrix-control", id);
const setActiveId = (0, import_element.useCallback)((nextActiveId) => {
const nextValue = (0, import_utils.getItemValue)(baseId, nextActiveId);
if (nextValue) {
onChange?.(nextValue);
}
}, [baseId, onChange]);
const classes = (0, import_clsx.default)("component-alignment-matrix-control", className);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_composite.Composite, {
defaultActiveId: (0, import_utils.getItemId)(baseId, defaultValue),
activeId: (0, import_utils.getItemId)(baseId, value),
setActiveId,
rtl: (0, import_i18n.isRTL)(),
render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.GridContainer, {
...props,
"aria-label": label,
className: classes,
id: baseId,
role: "grid",
size: width
}),
children: import_utils.GRID.map((cells, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_composite.Composite.Row, {
render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styles.GridRow, {
role: "row"
}),
children: cells.map((cell) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_cell.default, {
id: (0, import_utils.getItemId)(baseId, cell),
value: cell
}, cell))
}, index))
});
}
var AlignmentMatrixControl = Object.assign(UnforwardedAlignmentMatrixControl, {
/**
* Render an alignment matrix as an icon.
*
* ```jsx
* import { AlignmentMatrixControl } from '@wordpress/components';
*
* <Icon icon={<AlignmentMatrixControl.Icon value="top left" />} />
* ```
*/
Icon: Object.assign(import_icon.default, {
displayName: "AlignmentMatrixControl.Icon"
})
});
var alignment_matrix_control_default = AlignmentMatrixControl;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AlignmentMatrixControl
});
//# sourceMappingURL=index.js.map