@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
35 lines (34 loc) • 1.56 kB
JavaScript
import { useRuntimeActions } from "../../hooks/use-runtime-actions.mjs";
import { splitWidgetActions } from "../../utils/split-widget-actions.mjs";
import { WidgetActions } from "../widget-actions/index.mjs";
import { WidgetAttributes } from "../widget-attributes/index.mjs";
import { WidgetHeader } from "../widget-header/index.mjs";
import { WidgetToolbar } from "../widget-toolbar/index.mjs";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/widget-dashboard/src/components/widgets/widget-tile-controls.tsx
/**
* One tile's normal-mode toolbar: the attribute controls and the menu
* actions. Subscribes to the instance's runtime actions here, so a
* declaration re-renders this toolbar alone.
*
* @param {WidgetTileControlsProps} props Component props.
*/
function WidgetTileControls({ widget, widgetType, editable, overlay }) {
const runtimeActions = useRuntimeActions(widget.uuid);
const hasSettings = editable && !!widgetType.attributes?.length;
const { menu: menuActions } = splitWidgetActions(widgetType, runtimeActions);
if (!hasSettings && menuActions.length === 0) return null;
const toolbar = /* @__PURE__ */ jsxs(WidgetToolbar, { children: [hasSettings && /* @__PURE__ */ jsx(WidgetAttributes, {
widget,
widgetType
}), menuActions.length > 0 && /* @__PURE__ */ jsx(WidgetActions, {
uuid: widget.uuid,
actions: menuActions
})] });
return overlay ? /* @__PURE__ */ jsx(WidgetHeader, {
overlay: true,
children: toolbar
}) : toolbar;
}
export { WidgetTileControls };
//# sourceMappingURL=widget-tile-controls.mjs.map