An open source design system that's fully customizable and agent ready
TypeScript
docs(Grid): lead with the columns shape that reflows (#7340)
Cindy Zhang5f9be6c18deb
diff --git a/.changeset/grid-columns-docs-reflow.md b/.changeset/grid-columns-docs-reflow.mdnew file mode 100644index 0000000000..2e8672f6e7--- /dev/null+++ b/.changeset/grid-columns-docs-reflow.md@@ -0,0 +1,8 @@+---+'@astryxdesign/core': patch+'@astryxdesign/cli': patch+---++[docs] Grid's `columns` docs now lead with the shape that reflows: a numeric `columns` is exactly N columns at every width and never reflows, and `columns={{minWidth, max}}` is the form for columns that must survive a phone. The `astryx docs layout/responsive` topic gains a "Columns that reflow" section with a reflowing stat row beside a fixed week row. No behavior changes.++@cixzhangdiff --git a/packages/cli/assets/docs/tree/responsive.doc.mjs b/packages/cli/assets/docs/tree/responsive.doc.mjsindex 16eba48764..f660b5050f 100644--- a/packages/cli/assets/docs/tree/responsive.doc.mjs+++ b/packages/cli/assets/docs/tree/responsive.doc.mjs@@ -21,6 +21,9 @@ export const docs = {'Dialog','BottomSheet','contract',+ 'Grid',+ 'columns',+ 'minWidth',],sections: [@@ -94,5 +97,39 @@ const isNarrow = useMediaQuery('(max-width: 1024px)');},],},+ {+ id: 'columns-that-reflow',+ title: 'Columns that reflow',+ content: [+ {+ type: 'prose',+ text: 'For columns that reflow on small screens, use `Grid columns={{minWidth, max}}`. A numeric `columns` is exactly N columns at every width and never reflows: `columns={4}` on a 390px phone renders four tracks under 100px wide, and the row overflows the page as soon as their content cannot shrink to fit. `{minWidth: 240, max: 4}` renders at most four columns, each at least 240px, and drops to one full-width column when the container is narrow; `max` is what lets that last column shrink to the container, and `gap` counts toward the room the columns need.',+ },+ {+ type: 'code',+ lang: 'tsx',+ label: 'Reflowing stat row versus a fixed week row',+ code: `// Reflows: 4 columns on desktop, 3 in a 768px-wide grid, 1 on a phone.+<Grid columns={{minWidth: 240, max: 4}} gap={3}>+ {stats.map(stat => <StatCard key={stat.id} {...stat} />)}+</Grid>++// Fixed: exactly 7 columns at every width (a number never reflows).+<Grid columns={7} gap={1}>+ {days.map(day => <DayCell key={day} day={day} />)}+</Grid>`,+ },+ {+ type: 'list',+ style: 'unordered',+ items: [+ '`{minWidth}` alone: as many columns as fit at the floor, no cap; a container narrower than `minWidth` overflows, so add `max` for anything that reaches a phone',+ "`{minWidth, repeat: 'fit'}`: empty tracks collapse so present items stretch",+ "A numeric `GridSpan` wider than the grid's current columns adds implicit columns to the whole grid; items placed before and after the span flow into them, and `columns='full'` then covers only the explicit columns. In a reflowing grid keep spans within the smallest count it can reach, or use `'full'`, which adds none",+ 'Styling that changes the room columns have to fit changes the count a reflowing shape reaches: a `columnGap` or `gap` step, inline padding on the grid, or `grid-auto-flow: column` through `xstyle`, which places items into extra implicit columns. A `className` rule replaces the computed track list only when it wins the cascade against the generated styles; prefer `xstyle` for overrides',+ ],+ },+ ],+ },],};diff --git a/packages/core/src/Grid/Grid.doc.mjs b/packages/core/src/Grid/Grid.doc.mjsindex b9800950b8..5312a8a8a3 100644--- a/packages/core/src/Grid/Grid.doc.mjs+++ b/packages/core/src/Grid/Grid.doc.mjs@@ -27,10 +27,11 @@ export const docs = {usage: {anatomy,description:- 'A CSS grid layout container for arranging children in rows and columns. Use Grid for card galleries, dashboards, and any multi-column layout. Supports fixed column counts and responsive columns that reflow based on available width.',+ 'A CSS grid layout container for arranging children in rows and columns. Use Grid for card galleries, dashboards, and any multi-column layout. For columns that reflow on small screens, use `columns={{minWidth, max}}`; a numeric `columns` is exactly N columns at every width and never reflows.',bestPractices: [- { guidance: true, description: 'Use responsive columns for layouts that should adapt to screen size: `columns={{minWidth: 280}}`.' },- { guidance: true, description: 'Cap the column count with `max` to prevent rows from getting too wide on large screens.' },+ { guidance: true, description: 'Default to responsive columns for anything that must survive a phone: `columns={{minWidth: 240, max: 4}}` renders at most 4 columns, each at least 240px, and drops to one full-width column when narrow.' },+ { guidance: false, description: 'Use `columns={4}` for a row that must work on small screens; a number never reflows and renders four narrow tracks on a phone. Reserve numbers for rows that must stay fixed, such as a 7-day week.' },+ { guidance: true, description: 'Always pair `minWidth` with `max`: `max` caps the count on wide screens and lets the last column shrink to a narrow container; `{minWidth}` alone overflows a phone narrower than `minWidth`.' },{ guidance: true, description: 'Use `repeat: \'fill\'` (the default) for consistent item widths. Use `\'fit\'` when items should stretch to fill leftover space.' },{ guidance: false, description: 'Write manual CSS grid; Grid handles spacing and responsive behavior for you.' },{ guidance: false, description: 'Use `HStack` with wrapping for grids; use Grid instead.' },@@ -54,12 +55,12 @@ export const docs = {],},},- description: 'Grid container with fixed or responsive columns.',+ description: 'Grid container with fixed or responsive columns; `{minWidth, max}` reflows, a number never does.',props: [{name: 'columns',type: "number | {minWidth: number, max?: number, repeat?: 'fill' | 'fit'}",- description: 'Column configuration. Use a number for fixed columns (e.g. `columns={3}`). Use an object for responsive columns: `minWidth` sets the minimum column width in px, `repeat` controls track behavior (`"fill"` preserves empty tracks for consistent widths, `"fit"` collapses empty tracks so items stretch; defaults to `"fill"`), and `max` caps the maximum number of columns.',+ description: 'Column configuration. A number is exactly N equal columns at every width and never reflows (e.g. `columns={3}`); for columns that reflow on small screens, use `{minWidth, max}`. Use an object for responsive columns: `minWidth` sets the minimum column width in px, `repeat` controls track behavior (`"fill"` preserves empty tracks for consistent widths, `"fit"` collapses empty tracks so items stretch; defaults to `"fill"`), and `max` caps the maximum number of columns.',},{name: 'width',@@ -129,10 +130,11 @@ export const docsZh = {usage: {anatomy,description:- 'A CSS grid layout container for arranging children in rows and columns. Use Grid for card galleries, dashboards, and any multi-column layout. Supports fixed column counts and responsive columns that reflow based on available width.',+ 'A CSS grid layout container for arranging children in rows and columns. Use Grid for card galleries, dashboards, and any multi-column layout. For columns that reflow on small screens, use `columns={{minWidth, max}}`; a numeric `columns` is exactly N columns at every width and never reflows.',bestPractices: [- { guidance: true, description: 'Use responsive columns for layouts that should adapt to screen size: `columns={{minWidth: 280}}`.' },- { guidance: true, description: 'Cap the column count with `max` to prevent rows from getting too wide on large screens.' },+ { guidance: true, description: 'Default to responsive columns for anything that must survive a phone: `columns={{minWidth: 240, max: 4}}` renders at most 4 columns, each at least 240px, and drops to one full-width column when narrow.' },+ { guidance: false, description: 'Use `columns={4}` for a row that must work on small screens; a number never reflows and renders four narrow tracks on a phone. Reserve numbers for rows that must stay fixed, such as a 7-day week.' },+ { guidance: true, description: 'Always pair `minWidth` with `max`: `max` caps the count on wide screens and lets the last column shrink to a narrow container; `{minWidth}` alone overflows a phone narrower than `minWidth`.' },{ guidance: true, description: 'Use `repeat: \'fill\'` (the default) for consistent item widths. Use `\'fit\'` when items should stretch to fill leftover space.' },{ guidance: false, description: 'Write manual CSS grid; Grid handles spacing and responsive behavior for you.' },{ guidance: false, description: 'Use `HStack` with wrapping for grids; use Grid instead.' },@@ -146,10 +148,11 @@ export const docsDense = {description: 'CSS Grid-based layout w/ responsive column support.',usage: {anatomy,- description: 'A CSS grid layout container for arranging children in rows and columns. Use Grid for card galleries, dashboards, and any multi-column layout. Supports fixed column counts and responsive columns that reflow based on available width.',+ description: 'A CSS grid layout container for arranging children in rows and columns. Use Grid for card galleries, dashboards, and any multi-column layout. For columns that reflow on small screens, use `columns={{minWidth, max}}`; a numeric `columns` is exactly N columns at every width and never reflows.',bestPractices: [- { guidance: true, description: 'Use responsive columns for layouts that should adapt to screen size: columns={{minWidth: 280}}.' },- { guidance: true, description: 'Cap the column count with max to prevent rows from getting too wide on large screens.' },+ { guidance: true, description: 'Default to responsive columns for anything that must survive a phone: columns={{minWidth: 240, max: 4}} = at most 4 columns, each >= 240px, one full-width column when narrow.' },+ { guidance: false, description: 'Use columns={4} for rows that must work on small screens; a number never reflows (4 narrow tracks on a phone). Numbers only for rows that must stay fixed, e.g. a 7-day week.' },+ { guidance: true, description: 'Always pair minWidth with max: max caps the count on wide screens and lets the last column shrink to a narrow container; {minWidth} alone overflows a phone narrower than minWidth.' },{ guidance: true, description: 'Use repeat: \'fill\' (the default) for consistent item widths. Use \'fit\' when items should stretch to fill leftover space.' },{ guidance: false, description: 'Write manual CSS grid; Grid handles spacing and responsive behavior for you.' },{ guidance: false, description: 'Use HStack with wrapping for grids; use Grid instead.' },diff --git a/packages/core/src/Grid/Grid.tsx b/packages/core/src/Grid/Grid.tsxindex 30475cddac..be4597945c 100644--- a/packages/core/src/Grid/Grid.tsx+++ b/packages/core/src/Grid/Grid.tsx@@ -31,7 +31,13 @@ export type GridAlignment = 'start' | 'center' | 'end' | 'stretch';/*** Column configuration for Grid.*- * - `number` — fixed equal-width columns (e.g. `columns={3}`)+ * A number means exactly N equal columns at every width; it never reflows, so+ * `columns={4}` on a phone renders four narrow tracks. For columns that reflow+ * on small screens, use the object form: `{minWidth: 240, max: 4}` renders at+ * most four columns, each at least 240px, and fewer when the container is+ * narrower.+ *+ * - `number` — exactly N equal-width columns (e.g. `columns={3}`); never reflows* - `object` — responsive columns based on minimum child width:* - `minWidth` — minimum width (px) for each column track* - `repeat` — `'fill'` (default) preserves empty tracks for consistent widths;@@ -53,9 +59,12 @@ export interface GridProps extends BaseProps<HTMLDivElement> {/** Ref forwarded to the root element */ref?: React.Ref<HTMLDivElement>;/**- * Column configuration.- * - `number` — fixed equal-width columns- * - `{minWidth, max?, repeat?}` — responsive columns+ * Column configuration. A number is exactly N equal columns and never+ * reflows; for columns that reflow on small screens, use+ * `{minWidth, max}`.+ * - `number` — exactly N equal-width columns at every width+ * - `{minWidth, max?, repeat?}` — responsive columns with a px floor and an+ * optional cap** @see GridColumns*/