Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(layout): standardize sizing props (Tiers 1–2 of #3223) (#3232)

Cindy Zhang22ccb6964396
diff --git a/.changeset/standard-layout-props.md b/.changeset/standard-layout-props.md
new file mode 100644
index 0000000000..6bbb221b63
--- /dev/null
+++ b/.changeset/standard-layout-props.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Standardize layout component sizing props. Add `maxWidth`/`minHeight` to `Stack`, `Grid`, and `Center` (matching `Section`/`Card`), migrate `Layout`/`LayoutHeader`/`LayoutFooter`/`LayoutPanel` sizing to the shared `SizeValue` type, and drop redundant `xstyle`/`className`/`style` re-declarations on `Stack`, `StackItem`, and `Layout`. No runtime behavior change.
+@cixzhang
diff --git a/packages/core/src/Center/Center.doc.mjs b/packages/core/src/Center/Center.doc.mjs
index 60b50923e5..7b13e3a394 100644
--- a/packages/core/src/Center/Center.doc.mjs
+++ b/packages/core/src/Center/Center.doc.mjs
@@ -18,14 +18,24 @@ export const docs = {
},
{
name: 'width',
- type: 'number | string',
+ type: 'SizeValue',
description: 'Container width (px or CSS value).',
},
{
name: 'height',
- type: 'number | string',
+ type: 'SizeValue',
description: 'Container height (px or CSS value).',
},
+ {
+ name: 'maxWidth',
+ type: 'SizeValue',
+ description: 'Maximum container width (px or CSS value).',
+ },
+ {
+ name: 'minHeight',
+ type: 'SizeValue',
+ description: 'Minimum container height (px or CSS value).',
+ },
{
name: 'isInline',
type: 'boolean',
diff --git a/packages/core/src/Center/Center.tsx b/packages/core/src/Center/Center.tsx
index 14a71cceb9..626419470b 100644
--- a/packages/core/src/Center/Center.tsx
+++ b/packages/core/src/Center/Center.tsx
@@ -39,15 +39,21 @@ const styles = stylex.create({
// Dynamic styles for sizing props
const dynamicStyles = stylex.create({
- sizing: (width: SizeValue | null, height: SizeValue | null) => ({
+ sizing: (
+ width: SizeValue | null,
+ height: SizeValue | null,
+ maxWidth: SizeValue | null,
+ minHeight: SizeValue | null,
+ ) => ({
width,
height,
+ maxWidth,
+ minHeight,
}),
});
export type CenterAxis = 'both' | 'horizontal' | 'vertical';
-
export interface CenterProps extends BaseProps<HTMLDivElement> {
/** Ref forwarded to the root element */
ref?: React.Ref<HTMLDivElement>;
@@ -72,6 +78,18 @@ export interface CenterProps extends BaseProps<HTMLDivElement> {
*/
height?: SizeValue;
+ /**
+ * Maximum width of the container.
+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').
+ */
+ maxWidth?: SizeValue;
+
+ /**
+ * Minimum height of the container.
+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').
+ */
+ minHeight?: SizeValue;
+
/**
* Whether to make the container inline-flex (useful for text/icons).
* @default false
@@ -101,6 +119,8 @@ export function Center({
axis = 'both',
width,
height,
+ maxWidth,
+ minHeight,
isInline = false,
children,
xstyle,
@@ -115,7 +135,12 @@ export function Center({
isInline ? styles.inline : styles.base,
(axis === 'both' || axis === 'vertical') && styles.alignItemsCenter,
(axis === 'both' || axis === 'horizontal') && styles.justifyContentCenter,
- dynamicStyles.sizing(width ?? null, height ?? null),
+ dynamicStyles.sizing(
+ width ?? null,
+ height ?? null,
+ maxWidth ?? null,
+ minHeight ?? null,
+ ),
xstyle,
),
className,
diff --git a/packages/core/src/Grid/Grid.doc.mjs b/packages/core/src/Grid/Grid.doc.mjs
index 2d7bdb5106..b43275552a 100644
--- a/packages/core/src/Grid/Grid.doc.mjs
+++ b/packages/core/src/Grid/Grid.doc.mjs
@@ -39,13 +39,23 @@ export const docs = {
},
{
name: 'width',
- type: 'number | string',
- description: 'Container width.',
+ type: 'SizeValue',
+ description: 'Container width. Numbers are treated as pixels, strings are used as-is.',
},
{
name: 'height',
- type: 'number | string',
- description: 'Container height.',
+ type: 'SizeValue',
+ description: 'Container height. Numbers are treated as pixels, strings are used as-is.',
+ },
+ {
+ name: 'maxWidth',
+ type: 'SizeValue',
+ description: 'Maximum container width. Numbers are treated as pixels, strings are used as-is.',
+ },
+ {
+ name: 'minHeight',
+ type: 'SizeValue',
+ description: 'Minimum container height. Numbers are treated as pixels, strings are used as-is.',
},
{
name: 'gap',
diff --git a/packages/core/src/Grid/Grid.tsx b/packages/core/src/Grid/Grid.tsx
index 2a787d549c..b68ef0acdd 100644
--- a/packages/core/src/Grid/Grid.tsx
+++ b/packages/core/src/Grid/Grid.tsx
@@ -83,6 +83,18 @@ export interface GridProps extends BaseProps<HTMLDivElement> {
*/
height?: SizeValue;
+ /**
+ * Maximum width of the grid container.
+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').
+ */
+ maxWidth?: SizeValue;
+
+ /**
+ * Minimum height of the grid container.
+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').
+ */
+ minHeight?: SizeValue;
+
/**
* Spacing between all grid items (both row and column).
* Accepts numeric spacing steps: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.
@@ -346,6 +358,8 @@ export function Grid({
rowHeight,
width,
height,
+ maxWidth,
+ minHeight,
gap,
rowGap,
columnGap,
@@ -409,6 +423,12 @@ export function Grid({
...(height != null && {
height: typeof height === 'number' ? `${height}px` : height,
}),
+ ...(maxWidth != null && {
+ maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,
+ }),
+ ...(minHeight != null && {
+ minHeight: typeof minHeight === 'number' ? `${minHeight}px` : minHeight,
+ }),
};
// For themeProps, extract numeric columns value for variant tracking
diff --git a/packages/core/src/Layout/Layout.tsx b/packages/core/src/Layout/Layout.tsx
index cf6f7ded2f..8b6b6a5607 100644
--- a/packages/core/src/Layout/Layout.tsx
+++ b/packages/core/src/Layout/Layout.tsx
@@ -26,7 +26,7 @@ import {stack} from '../Stack/stack.stylex';
import {stackItem} from '../Stack/stackItem.stylex';
import {mergeProps} from '../utils';
import type {BaseProps} from '../BaseProps';
-import type {SpacingStep} from '../utils/types';
+import type {SizeValue, SpacingStep} from '../utils/types';
import {themeProps} from '../utils/themeProps';
import {
layoutPaddingOuterXVarStyles,
@@ -76,12 +76,12 @@ const styles = stylex.create({
});
const dynamicStyles = stylex.create({
- contentWidthVar: (width: number) => ({
- '--layout-content-width': `${width}px`,
+ contentWidthVar: (width: SizeValue) => ({
+ '--layout-content-width': typeof width === 'number' ? `${width}px` : width,
}),
- contentWidth: (width: number) => ({
+ contentWidth: (width: SizeValue) => ({
width: '100%',
- maxWidth: width,
+ maxWidth: typeof width === 'number' ? `${width}px` : width,
marginInline: 'auto',
}),
});
@@ -102,11 +102,12 @@ export interface LayoutProps extends Omit<BaseProps, 'content'> {
* panels). Dividers remain full-bleed. Content is centered with
* `margin-inline: auto` when narrower than the available space.
*
- * Accepts any pixel value. Common page widths from internal patterns:
+ * Numbers are treated as pixels, strings are used as-is (e.g., '60ch').
+ * Common page widths:
* - `640` — forms, settings, text-focused pages
* - `960` — content pages, component demos, wider layouts
*/
- contentWidth?: number;
+ contentWidth?: SizeValue;
/**
* End panel slot (right in LTR, left in RTL).
@@ -149,15 +150,6 @@ export interface LayoutProps extends Omit<BaseProps, 'content'> {
*/
defaultHasDividers?: boolean;
- /**
- * CSS class name(s) appended to the root element.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element.
- */
- style?: React.CSSProperties;
-
/**
* Children are a shorthand for the `content` slot:
* `<Layout>{main}</Layout>` is equivalent to `<Layout content={main} />`.
diff --git a/packages/core/src/Layout/LayoutFooter.doc.mjs b/packages/core/src/Layout/LayoutFooter.doc.mjs
index 67e147a3a1..b5472e4555 100644
--- a/packages/core/src/Layout/LayoutFooter.doc.mjs
+++ b/packages/core/src/Layout/LayoutFooter.doc.mjs
@@ -22,8 +22,8 @@ export const docs = {
},
{
name: 'height',
- type: 'number | string',
- description: 'Footer height.',
+ type: 'SizeValue',
+ description: 'Footer height. Numbers are treated as pixels, strings are used as-is.',
},
{
name: 'label',
@@ -57,8 +57,8 @@ export const docsZh = {
},
{
name: 'height',
- type: 'number | string',
- description: '页脚高度。',
+ type: 'SizeValue',
+ description: '页脚高度。数字类型会被解释为像素值,字符串类型按原样使用。',
},
{
name: 'label',
diff --git a/packages/core/src/Layout/LayoutFooter.tsx b/packages/core/src/Layout/LayoutFooter.tsx
index 227db72523..ae7a7bced8 100644
--- a/packages/core/src/Layout/LayoutFooter.tsx
+++ b/packages/core/src/Layout/LayoutFooter.tsx
@@ -22,7 +22,7 @@ import * as stylex from '@stylexjs/stylex';
import {LayoutDividerContext} from './LayoutDividerContext';
import {colorVars, spacingVars} from '../theme/tokens.stylex';
import {mergeProps} from '../utils';
-import type {SpacingStep} from '../utils/types';
+import type {SizeValue, SpacingStep} from '../utils/types';
import {themeProps} from '../utils/themeProps';
import {
paddingStyles,
@@ -71,7 +71,7 @@ const styles = stylex.create({
// Dynamic styles for sizing props
const dynamicStyles = stylex.create({
- sizing: (height: number | string | null) => ({
+ sizing: (height: SizeValue | null) => ({
height,
}),
});
@@ -95,7 +95,7 @@ export interface LayoutFooterProps extends BaseProps<HTMLDivElement> {
* Height of the footer.
* Numbers are treated as pixels, strings are used as-is.
*/
- height?: number | string;
+ height?: SizeValue;
/**
* Internal padding of the footer using the spacing scale.
diff --git a/packages/core/src/Layout/LayoutHeader.doc.mjs b/packages/core/src/Layout/LayoutHeader.doc.mjs
index 27694a5989..ec7d0b0ae2 100644
--- a/packages/core/src/Layout/LayoutHeader.doc.mjs
+++ b/packages/core/src/Layout/LayoutHeader.doc.mjs
@@ -22,8 +22,8 @@ export const docs = {
},
{
name: 'height',
- type: 'number | string',
- description: 'Header height.',
+ type: 'SizeValue',
+ description: 'Header height. Numbers are treated as pixels, strings are used as-is.',
},
{
name: 'label',
@@ -57,8 +57,8 @@ export const docsZh = {
},
{
name: 'height',
- type: 'number | string',
- description: '页眉高度。',
+ type: 'SizeValue',
+ description: '页眉高度。数字类型会被解释为像素值,字符串类型按原样使用。',
},
{
name: 'label',
diff --git a/packages/core/src/Layout/LayoutHeader.tsx b/packages/core/src/Layout/LayoutHeader.tsx
index 144d3f6316..68d6206d6c 100644
--- a/packages/core/src/Layout/LayoutHeader.tsx
+++ b/packages/core/src/Layout/LayoutHeader.tsx
@@ -22,7 +22,7 @@ import * as stylex from '@stylexjs/stylex';
import {LayoutDividerContext} from './LayoutDividerContext';
import {colorVars, spacingVars} from '../theme/tokens.stylex';
import {mergeProps} from '../utils';
-import type {SpacingStep} from '../utils/types';
+import type {SizeValue, SpacingStep} from '../utils/types';
import {themeProps} from '../utils/themeProps';
import {
paddingStyles,
@@ -71,7 +71,7 @@ const styles = stylex.create({
// Dynamic styles for sizing props
const dynamicStyles = stylex.create({
- sizing: (height: number | string | null) => ({
+ sizing: (height: SizeValue | null) => ({
height,
}),
});
@@ -95,7 +95,7 @@ export interface LayoutHeaderProps extends BaseProps<HTMLDivElement> {
* Height of the header.
* Numbers are treated as pixels, strings are used as-is.
*/
- height?: number | string;
+ height?: SizeValue;
/**
* Internal padding of the header using the spacing scale.
diff --git a/packages/core/src/Layout/LayoutPanel.tsx b/packages/core/src/Layout/LayoutPanel.tsx
index 70b920fb19..e65c9f71c3 100644
--- a/packages/core/src/Layout/LayoutPanel.tsx
+++ b/packages/core/src/Layout/LayoutPanel.tsx
@@ -23,7 +23,7 @@ import {colorVars, spacingVars} from '../theme/tokens.stylex';
import {LayoutAreaContext} from './LayoutAreaContext';
import {LayoutSlotsContext} from './LayoutSlotsContext';
import {mergeProps} from '../utils';
-import type {SpacingStep} from '../utils/types';
+import type {SizeValue, SpacingStep} from '../utils/types';
import type {ResizableProps} from '../Resizable/useResizable';
import {themeProps} from '../utils/themeProps';
import {
@@ -102,7 +102,7 @@ const styles = stylex.create({
// Dynamic styles for sizing props
const dynamicStyles = stylex.create({
- sizing: (width: number | string | null) => ({
+ sizing: (width: SizeValue | null) => ({
width,
}),
});
@@ -158,7 +158,7 @@ export interface LayoutPanelProps extends BaseProps<HTMLDivElement> {
* Numbers are treated as pixels, strings are used as-is.
* When `resizable` is provided, this is ignored — the hook controls width.
*/
- width?: number | string;
+ width?: SizeValue;
/**
* Resize props from `useResizable()`. When provided, the panel width
diff --git a/packages/core/src/Stack/Stack.doc.mjs b/packages/core/src/Stack/Stack.doc.mjs
index 7322e87211..14a9f7eb9a 100644
--- a/packages/core/src/Stack/Stack.doc.mjs
+++ b/packages/core/src/Stack/Stack.doc.mjs
@@ -63,6 +63,16 @@ export const docs = {
type: 'SizeValue',
description: "Height of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",
},
+ {
+ name: 'maxWidth',
+ type: 'SizeValue',
+ description: "Maximum width of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",
+ },
+ {
+ name: 'minHeight',
+ type: 'SizeValue',
+ description: "Minimum height of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",
+ },
{
name: 'hAlign',
type: "'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'",
@@ -156,6 +166,16 @@ export const docs = {
type: 'SizeValue',
description: "Height of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",
},
+ {
+ name: 'maxWidth',
+ type: 'SizeValue',
+ description: "Maximum width of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",
+ },
+ {
+ name: 'minHeight',
+ type: 'SizeValue',
+ description: "Minimum height of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",
+ },
{
name: 'hAlign',
type: "'start' | 'center' | 'end' | 'stretch'",
diff --git a/packages/core/src/Stack/Stack.tsx b/packages/core/src/Stack/Stack.tsx
index 7ecacf3892..44d201535b 100644
--- a/packages/core/src/Stack/Stack.tsx
+++ b/packages/core/src/Stack/Stack.tsx
@@ -15,7 +15,6 @@
import {createElement, type ElementType, type ReactNode, type Ref} from 'react';
import type {BaseProps} from '../BaseProps';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {
stack,
type StackCrossAlignment,
@@ -109,6 +108,18 @@ export interface StackProps extends BaseProps<HTMLElement> {
*/
height?: SizeValue;
+ /**
+ * Maximum width of the stack container.
+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').
+ */
+ maxWidth?: SizeValue;
+
+ /**
+ * Minimum height of the stack container.
+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').
+ */
+ minHeight?: SizeValue;
+
/**
* Spacing between items.
* Accepts numeric spacing steps: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.
@@ -161,28 +172,6 @@ export interface StackProps extends BaseProps<HTMLElement> {
*/
as?: ElementType;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { marginBottom: 8 } });
- * <Component xstyle={overrides.root} />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element. Spread after StyleX
- * inline styles, so these values take priority.
- */
- style?: React.CSSProperties;
-
/**
* Content to render inside the stack.
*/
@@ -226,6 +215,8 @@ export function Stack({
isScrollable,
width,
height,
+ maxWidth,
+ minHeight,
wrap,
as: element = 'div',
xstyle,
@@ -278,6 +269,12 @@ export function Stack({
...(height != null && {
height: typeof height === 'number' ? `${height}px` : height,
}),
+ ...(maxWidth != null && {
+ maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,
+ }),
+ ...(minHeight != null && {
+ minHeight: typeof minHeight === 'number' ? `${minHeight}px` : minHeight,
+ }),
};
return createElement(
diff --git a/packages/core/src/Stack/StackItem.tsx b/packages/core/src/Stack/StackItem.tsx
index 32c072f5f9..94ef9442b8 100644
--- a/packages/core/src/Stack/StackItem.tsx
+++ b/packages/core/src/Stack/StackItem.tsx
@@ -14,7 +14,6 @@
import {createElement, type ElementType, type ReactNode, type Ref} from 'react';
import type {BaseProps} from '../BaseProps';
import * as stylex from '@stylexjs/stylex';
-import type {StyleXStyles} from '@stylexjs/stylex';
import {
stackItem,
type StackItemCrossAlignSelf,
@@ -65,28 +64,6 @@ export interface StackItemProps extends BaseProps<HTMLElement> {
*/
as?: ElementType;
- /**
- * StyleX styles created via `stylex.create()`. Merged with the component's
- * base styles inside a single `stylex.props()` call for optimal deduplication.
- *
- * @example
- * ```
- * const overrides = stylex.create({ root: { marginBottom: 8 } });
- * <Component xstyle={overrides.root} />
- * ```
- */
- xstyle?: StyleXStyles;
- /**
- * CSS class name(s) appended to the root element.
- * If you're using StyleX, prefer `xstyle` for optimal style deduplication.
- */
- className?: string;
- /**
- * Inline styles to apply to the root element. Spread after StyleX
- * inline styles, so these values take priority.
- */
- style?: React.CSSProperties;
-
/**
* Content to render inside the stack item.
*/