UNPKG

@wordpress/widget-dashboard

Version:

Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.

1 lines • 2.4 kB
{"version":3,"file":"widget-settings-trigger.mjs","names":[],"sources":["../../../src/components/widget-settings/widget-settings-trigger.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { drawerRight } from '@wordpress/icons';\n// Dashboard is still experimental.\nimport {\n\t// eslint-disable-next-line @wordpress/use-recommended-components\n\tIconButton,\n} from '@wordpress/ui';\nimport type { WidgetType } from '@wordpress/widget-primitives';\nimport { useWidgetSettingsToggle } from './use-widget-settings-toggle';\nimport type { DashboardWidget } from '../../types';\n\nexport interface WidgetSettingsTriggerProps {\n\t/**\n\t * The instance whose settings surface this control opens.\n\t */\n\twidget: DashboardWidget< unknown >;\n\n\t/**\n\t * The instance's widget type, used for the accessible label and the\n\t * attributes guard.\n\t */\n\twidgetType: WidgetType;\n}\n\n/**\n * Per-instance control that toggles the shared settings surface; the single\n * `WidgetSettings` at the root reacts to it. Clicking the control of the\n * instance whose settings surface is already open closes it. Returns `null`\n * when no attribute needs that surface (none, or all already promoted to the\n * prominent one), so chrome can mount it unconditionally.\n *\n * @param {WidgetSettingsTriggerProps} props Component props.\n */\nexport function WidgetSettingsTrigger( {\n\twidget,\n\twidgetType,\n}: WidgetSettingsTriggerProps ): React.ReactNode {\n\tconst { toggle } = useWidgetSettingsToggle( widget );\n\n\t// Surface the settings UI only when there are attributes not already\n\t// promoted inline; if every attribute is high-relevance, a second\n\t// surface would just repeat the prominent one.\n\tconst hasNonPromotedAttributes = widgetType.attributes?.some(\n\t\t( attribute ) => attribute.relevance !== 'high'\n\t);\n\tif ( ! hasNonPromotedAttributes ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<IconButton\n\t\t\ticon={ drawerRight }\n\t\t\tlabel={ __( 'Widget settings' ) }\n\t\t\tvariant=\"minimal\"\n\t\t\ttone=\"neutral\"\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ toggle }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,SAAgB,sBAAuB,EACtC,QACA,cACgD;CAChD,MAAM,EAAE,WAAW,wBAAyB,MAAO;CAQnD,IAAK,CAH4B,WAAW,YAAY,MACrD,cAAe,UAAU,cAAc,MAC1C,GAEC,OAAO;CAGR,OACC,oBAAC,YAAD;EACC,MAAO;EACP,OAAQ,GAAI,iBAAkB;EAC9B,SAAQ;EACR,MAAK;EACL,MAAK;EACL,SAAU;CACV,CAAA;AAEH"}