@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
1 lines • 2.55 kB
Source Map (JSON)
{"version":3,"file":"widget-tile-controls.mjs","names":[],"sources":["../../../src/components/widgets/widget-tile-controls.tsx"],"sourcesContent":["import type { WidgetType } from '@wordpress/widget-primitives';\nimport { useRuntimeActions } from '../../hooks/use-runtime-actions';\nimport { splitWidgetActions } from '../../utils/split-widget-actions';\nimport { WidgetActions } from '../widget-actions';\nimport { WidgetAttributes } from '../widget-attributes';\nimport { WidgetHeader } from '../widget-header';\nimport { WidgetToolbar } from '../widget-toolbar';\nimport type { DashboardWidget } from '../../types';\n\ninterface WidgetTileControlsProps {\n\twidget: DashboardWidget;\n\twidgetType: WidgetType;\n\n\t/**\n\t * Whether the policy lets the user edit the instance's attributes.\n\t */\n\teditable: boolean;\n\n\t/**\n\t * Lift the toolbar into the grid's actionable-area slot, for full-bleed\n\t * widgets without an in-card header.\n\t */\n\toverlay: boolean;\n}\n\n/**\n * One tile's normal-mode toolbar: the attribute controls and the menu\n * actions. Subscribes to the instance's runtime actions here, so a\n * declaration re-renders this toolbar alone.\n *\n * @param {WidgetTileControlsProps} props Component props.\n */\nexport function WidgetTileControls( {\n\twidget,\n\twidgetType,\n\teditable,\n\toverlay,\n}: WidgetTileControlsProps ): React.ReactNode {\n\tconst runtimeActions = useRuntimeActions( widget.uuid );\n\tconst hasSettings = editable && !! widgetType.attributes?.length;\n\tconst { menu: menuActions } = splitWidgetActions(\n\t\twidgetType,\n\t\truntimeActions\n\t);\n\n\tif ( ! hasSettings && menuActions.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst toolbar = (\n\t\t<WidgetToolbar>\n\t\t\t{ hasSettings && (\n\t\t\t\t<WidgetAttributes widget={ widget } widgetType={ widgetType } />\n\t\t\t) }\n\n\t\t\t{ menuActions.length > 0 && (\n\t\t\t\t<WidgetActions uuid={ widget.uuid } actions={ menuActions } />\n\t\t\t) }\n\t\t</WidgetToolbar>\n\t);\n\n\treturn overlay ? <WidgetHeader overlay>{ toolbar }</WidgetHeader> : toolbar;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,SAAgB,mBAAoB,EACnC,QACA,YACA,UACA,WAC6C;CAC7C,MAAM,iBAAiB,kBAAmB,OAAO,IAAK;CACtD,MAAM,cAAc,YAAY,CAAC,CAAE,WAAW,YAAY;CAC1D,MAAM,EAAE,MAAM,gBAAgB,mBAC7B,YACA,cACD;CAEA,IAAK,CAAE,eAAe,YAAY,WAAW,GAC5C,OAAO;CAGR,MAAM,UACL,qBAAC,eAAD,EAAA,UAAA,CACG,eACD,oBAAC,kBAAD;EAA2B;EAAsB;CAAc,CAAA,GAG9D,YAAY,SAAS,KACtB,oBAAC,eAAD;EAAe,MAAO,OAAO;EAAO,SAAU;CAAe,CAAA,CAEhD,EAAA,CAAA;CAGhB,OAAO,UAAU,oBAAC,cAAD;EAAc,SAAA;EAAU,UAAA;CAAuB,CAAA,IAAI;AACrE"}