@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
70 lines (69 loc) • 3.17 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_icons = require("@wordpress/icons");
let _wordpress_ui = require("@wordpress/ui");
let ______context_dashboard_context_tsx = require("../../context/dashboard-context.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/widget-dashboard/src/components/widget-layout-controls/widget-layout-controls.tsx
/**
* Customize-mode controls: width menu and removal, each following the
* policy's answer for its operation.
*
* @param {WidgetLayoutControlsProps} props Component props.
*/
function WidgetLayoutControls({ widget, canRemove = true, canResize = true }) {
const { layout, onLayoutChange } = (0, ______context_dashboard_context_tsx.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, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [canResize && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Menu.Root, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.Trigger, { render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.IconButton, {
icon: _wordpress_icons.moreVertical,
label: (0, _wordpress_i18n.__)("Widget options"),
size: "compact",
variant: "minimal",
tone: "neutral"
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.Popup, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Menu.RadioGroup, {
value: width ?? null,
onValueChange: onNamedWidthChange,
children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.GroupLabel, { children: (0, _wordpress_i18n.__)("Width") }),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.RadioItem, {
value: "fill",
closeOnClick: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.ItemLabel, { children: (0, _wordpress_i18n.__)("Use available width") })
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.RadioItem, {
value: "full",
closeOnClick: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Menu.ItemLabel, { children: (0, _wordpress_i18n.__)("Make full width") })
})
]
}) })] }), canRemove && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.IconButton, {
icon: _wordpress_icons.trash,
label: (0, _wordpress_i18n.__)("Remove"),
size: "compact",
variant: "minimal",
tone: "neutral",
onClick: onRemove
})] });
}
exports.WidgetLayoutControls = WidgetLayoutControls;
//# sourceMappingURL=widget-layout-controls.cjs.map