@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
8 lines (7 loc) • 2.73 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/utils/resolve-dashboard-column-count/resolve-dashboard-column-count.ts"],
"sourcesContent": ["import { WIDGET_DASHBOARD_COLUMN_COUNT } from '../../types';\n\n/**\n * Container width (px) below which the dashboard uses a single column.\n * Matches `@container widget-dashboard (max-width: …)` in widgets CSS.\n */\nexport const WIDGET_DASHBOARD_CONTAINER_BREAKPOINT_ONE_COLUMN = 600;\n\n/**\n * Container width (px) below which the dashboard drops from the column\n * cap to two. Above this threshold the grid uses the cap itself.\n */\nexport const WIDGET_DASHBOARD_CONTAINER_BREAKPOINT_TWO_COLUMNS = 960;\n\n/**\n * Resolves the wide-container column count a host asked for. A finite value\n * is floored, with a floor of one and no ceiling: how many columns a surface\n * can carry is the host's decision, not the package's. An absent or\n * non-finite value resolves to {@link WIDGET_DASHBOARD_COLUMN_COUNT}.\n *\n * @param columns Host-provided `gridSettings.columns`, if any.\n * @return Column count for wide containers.\n */\nexport function resolveDashboardColumnCap( columns?: number ): number {\n\tif ( typeof columns !== 'number' || ! Number.isFinite( columns ) ) {\n\t\treturn WIDGET_DASHBOARD_COLUMN_COUNT;\n\t}\n\n\treturn Math.max( 1, Math.floor( columns ) );\n}\n\n/**\n * Resolves the dashboard grid column count from the widget surface\n * container width. Uses discrete steps (cap → 2 → 1), not viewport\n * media queries.\n *\n * @param containerWidth Measured inline size of the dashboard grid container.\n * @param maxColumns Column cap for wide containers; see\n * {@link resolveDashboardColumnCap}.\n * @return Column count for {@link @wordpress/grid} surfaces.\n */\nexport function resolveDashboardColumnCount(\n\tcontainerWidth: number,\n\tmaxColumns: number = WIDGET_DASHBOARD_COLUMN_COUNT\n): number {\n\tif ( containerWidth <= 0 ) {\n\t\treturn maxColumns;\n\t}\n\n\tif ( containerWidth < WIDGET_DASHBOARD_CONTAINER_BREAKPOINT_ONE_COLUMN ) {\n\t\treturn 1;\n\t}\n\n\tif ( containerWidth < WIDGET_DASHBOARD_CONTAINER_BREAKPOINT_TWO_COLUMNS ) {\n\t\t// A cap of one must not step up to two in the middle band.\n\t\treturn Math.min( 2, maxColumns );\n\t}\n\n\treturn maxColumns;\n}\n"],
"mappings": ";AAAA,SAAS,qCAAqC;AAMvC,IAAM,mDAAmD;AAMzD,IAAM,oDAAoD;AAW1D,SAAS,0BAA2B,SAA2B;AACrE,MAAK,OAAO,YAAY,YAAY,CAAE,OAAO,SAAU,OAAQ,GAAI;AAClE,WAAO;AAAA,EACR;AAEA,SAAO,KAAK,IAAK,GAAG,KAAK,MAAO,OAAQ,CAAE;AAC3C;AAYO,SAAS,4BACf,gBACA,aAAqB,+BACZ;AACT,MAAK,kBAAkB,GAAI;AAC1B,WAAO;AAAA,EACR;AAEA,MAAK,iBAAiB,kDAAmD;AACxE,WAAO;AAAA,EACR;AAEA,MAAK,iBAAiB,mDAAoD;AAEzE,WAAO,KAAK,IAAK,GAAG,UAAW;AAAA,EAChC;AAEA,SAAO;AACR;",
"names": []
}