@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
118 lines (116 loc) • 4.41 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/widget-dashboard/src/components/widget-layout-controls/widget-layout-controls.tsx
var widget_layout_controls_exports = {};
__export(widget_layout_controls_exports, {
WidgetLayoutControls: () => WidgetLayoutControls
});
module.exports = __toCommonJS(widget_layout_controls_exports);
var import_components = require("@wordpress/components");
var import_i18n = require("@wordpress/i18n");
var import_icons = require("@wordpress/icons");
var import_ui = require("@wordpress/ui");
var import_lock_unlock = require("../../lock-unlock.cjs");
var import_dashboard_context = require("../../context/dashboard-context.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var { Menu } = (0, import_lock_unlock.unlock)(import_components.privateApis);
function WidgetLayoutControls({
widget,
canRemove = true,
canResize = true
}) {
const { layout, onLayoutChange } = (0, import_dashboard_context.useDashboardInternalContext)();
const width = widget.placement?.width;
const updateWidth = (nextWidth) => {
const nextLayout = layout.map(
(currentWidget) => currentWidget.uuid === widget.uuid ? {
...currentWidget,
placement: {
...currentWidget.placement,
width: nextWidth
}
} : currentWidget
);
onLayoutChange(nextLayout);
};
const onNamedWidthChange = (nextWidth) => {
updateWidth(nextWidth);
};
const onRemove = () => {
onLayoutChange(
layout.filter(
(currentWidget) => currentWidget.uuid !== widget.uuid
)
);
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
canResize && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Menu, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
Menu.TriggerButton,
{
render: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_ui.IconButton,
{
icon: import_icons.moreVertical,
label: (0, import_i18n.__)("Widget options"),
size: "compact",
variant: "minimal",
tone: "neutral"
}
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.Popover, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Menu.Group, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.GroupLabel, { children: (0, import_i18n.__)("Width") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
Menu.Item,
{
disabled: width === "fill",
onClick: () => onNamedWidthChange("fill"),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.ItemLabel, { children: (0, import_i18n.__)("Use available width") })
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
Menu.Item,
{
disabled: width === "full",
onClick: () => onNamedWidthChange("full"),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu.ItemLabel, { children: (0, import_i18n.__)("Make full width") })
}
)
] }) })
] }),
canRemove && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_ui.IconButton,
{
icon: import_icons.trash,
label: (0, import_i18n.__)("Remove"),
size: "compact",
variant: "minimal",
tone: "neutral",
onClick: onRemove
}
)
] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
WidgetLayoutControls
});
//# sourceMappingURL=widget-layout-controls.cjs.map