An open source design system that's fully customizable and agent ready
TypeScript
feat(Stack): add width and height props (#1778)
Cindy Zhang13746e7401f4
diff --git a/packages/core/src/Stack/Stack.doc.mjs b/packages/core/src/Stack/Stack.doc.mjsindex 18bbe4962b..db57e26192 100644--- a/packages/core/src/Stack/Stack.doc.mjs+++ b/packages/core/src/Stack/Stack.doc.mjs@@ -22,6 +22,16 @@ export const docs = {description:'Numeric spacing step controlling the gap between items: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.',},+ {+ name: 'width',+ type: 'SizeValue',+ description: "Width of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",+ },+ {+ name: 'height',+ type: 'SizeValue',+ description: "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'",@@ -78,6 +88,16 @@ export const docs = {description:'Numeric spacing step controlling the gap between items: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.',},+ {+ name: 'width',+ type: 'SizeValue',+ description: "Width of the stack container. Numbers are treated as pixels, strings are used as-is (e.g., '100%').",+ },+ {+ name: 'height',+ type: 'SizeValue',+ description: "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'",@@ -233,6 +253,16 @@ export const docsZh = {description:'控制元素间距的数值间距步进:0、0.5、1、1.5、2、3、4、5、6、8、10。',},+ {+ name: 'width',+ type: 'SizeValue',+ description: '堆叠容器的宽度。数字按像素处理,字符串原样使用(如 \'100%\')。',+ },+ {+ name: 'height',+ type: 'SizeValue',+ description: '堆叠容器的高度。数字按像素处理,字符串原样使用(如 \'100%\')。',+ },{name: 'hAlign',type: "'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'",@@ -290,6 +320,16 @@ export const docsZh = {description:'控制元素间距的数值间距步进:0、0.5、1、1.5、2、3、4、5、6、8、10。',},+ {+ name: 'width',+ type: 'SizeValue',+ description: '堆叠容器的宽度。数字按像素处理,字符串原样使用(如 \'100%\')。',+ },+ {+ name: 'height',+ type: 'SizeValue',+ description: '堆叠容器的高度。数字按像素处理,字符串原样使用(如 \'100%\')。',+ },{name: 'hAlign',type: "'start' | 'center' | 'end' | 'stretch'",@@ -441,6 +481,8 @@ export const docsDense = {description: 'Horizontal stack; left-to-right, polymorphic rendering.',propDescriptions: {gap: 'Numeric spacing step for gap: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.',+ width: "Width of container. Numbers=pixels, strings=as-is (e.g. '100%').",+ height: "Height of container. Numbers=pixels, strings=as-is (e.g. '100%').",hAlign: 'Horizontal (main-axis) alignment.',vAlign: 'Vertical (cross-axis) alignment.',justify: 'Main-axis alignment alias for hAlign. Mirrors CSS justify-content.',@@ -456,6 +498,8 @@ export const docsDense = {description: 'Vertical stack; top-to-bottom, polymorphic rendering.',propDescriptions: {gap: 'Numeric spacing step for gap: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.',+ width: "Width of container. Numbers=pixels, strings=as-is (e.g. '100%').",+ height: "Height of container. Numbers=pixels, strings=as-is (e.g. '100%').",hAlign: 'Horizontal (cross-axis) alignment.',vAlign: 'Vertical (main-axis) alignment.',justify: 'Main-axis alignment alias for vAlign. Mirrors CSS justify-content.',diff --git a/packages/core/src/Stack/XDSStack.test.tsx b/packages/core/src/Stack/XDSStack.test.tsxindex bdd7c9b5b8..cb4f7aec4a 100644--- a/packages/core/src/Stack/XDSStack.test.tsx+++ b/packages/core/src/Stack/XDSStack.test.tsx@@ -202,4 +202,54 @@ describe('XDSStack', () => {);expect(container.firstChild).toBeInTheDocument();});++ it('applies numeric width as pixels', () => {+ render(+ <XDSStack direction="vertical" width={300} data-testid="stack">+ <div>Item</div>+ </XDSStack>,+ );+ expect(screen.getByTestId('stack')).toHaveStyle({width: '300px'});+ });++ it('applies string width as-is', () => {+ render(+ <XDSStack direction="vertical" width="100%" data-testid="stack">+ <div>Item</div>+ </XDSStack>,+ );+ expect(screen.getByTestId('stack')).toHaveStyle({width: '100%'});+ });++ it('applies numeric height as pixels', () => {+ render(+ <XDSStack direction="horizontal" height={200} data-testid="stack">+ <div>Item</div>+ </XDSStack>,+ );+ expect(screen.getByTestId('stack')).toHaveStyle({height: '200px'});+ });++ it('applies string height as-is', () => {+ render(+ <XDSStack direction="horizontal" height="50vh" data-testid="stack">+ <div>Item</div>+ </XDSStack>,+ );+ expect(screen.getByTestId('stack')).toHaveStyle({height: '50vh'});+ });++ it('applies both width and height together', () => {+ render(+ <XDSStack+ direction="vertical"+ width={400}+ height="100%"+ data-testid="stack">+ <div>Item</div>+ </XDSStack>,+ );+ const el = screen.getByTestId('stack');+ expect(el).toHaveStyle({width: '400px', height: '100%'});+ });});diff --git a/packages/core/src/Stack/XDSStack.tsx b/packages/core/src/Stack/XDSStack.tsxindex c105cf2bd4..7e619966b9 100644--- a/packages/core/src/Stack/XDSStack.tsx+++ b/packages/core/src/Stack/XDSStack.tsx@@ -28,6 +28,7 @@ import {type StackWrap,type SpacingStep,} from './stack.stylex';+import type {SizeValue} from '../utils/types';import {xdsClassName, mergeProps} from '../utils';/**@@ -91,6 +92,18 @@ export interface XDSStackProps extends XDSBaseProps<HTMLDivElement> {*/align?: StackCrossAlignment;+ /**+ * Width of the stack container.+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').+ */+ width?: SizeValue;++ /**+ * Height of the stack container.+ * Numbers are treated as pixels, strings are used as-is (e.g., '100%').+ */+ height?: SizeValue;+/*** Spacing between items.* Accepts numeric spacing steps: 0, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 8, 10.@@ -170,6 +183,8 @@ export function XDSStack({justify,align,gap,+ width,+ height,wrap,element = 'div',xstyle,@@ -212,6 +227,16 @@ export function XDSStack({xstyle,);+ // Build inline style for dynamic sizing values+ const sizingStyle: React.CSSProperties = {+ ...(width != null && {+ width: typeof width === 'number' ? `${width}px` : width,+ }),+ ...(height != null && {+ height: typeof height === 'number' ? `${height}px` : height,+ }),+ };+return createElement(element,{@@ -220,7 +245,7 @@ export function XDSStack({xdsClassName('stack', {direction, gap, wrap}),stylexProps,className,- style,+ {...style, ...sizingStyle},),...props,},