Skip to content
5 changes: 5 additions & 0 deletions .changeset/poor-kiwis-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Added `AlphaStack` component
42 changes: 42 additions & 0 deletions polaris-react/src/components/AlphaStack/AlphaStack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import type {spacing} from '@shopify/polaris-tokens';

import {classNames} from '../../utilities/css';

import styles from './Stack.scss';

type SpacingTokenGroup = typeof spacing;
type SpacingTokenName = keyof SpacingTokenGroup;

// TODO: Bring this logic into tokens
type Spacing = SpacingTokenName extends `space-${infer Scale}` ? Scale : never;

type Align = 'start' | 'end' | 'center';

export interface AlphaStackProps {
/** Elements to display inside stack */
children?: React.ReactNode;
/** Adjust spacing between elements */
spacing?: Spacing;
/** Adjust vertical alignment of elements */
align?: Align;
}

export const AlphaStack = ({
children,
spacing,
align = 'start',
}: AlphaStackProps) => {
const className = classNames(styles.Stack);

const style = {
...(spacing ? {'--pc-stack-spacing': `var(--p-space-${spacing})`} : {}),
'align-items': align ? `${align}` : '',
} as React.CSSProperties;

return (
<div className={className} style={style}>
{children}
</div>
);
};
14 changes: 14 additions & 0 deletions polaris-react/src/components/AlphaStack/Stack.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.Stack {
--pc-stack-spacing: var(--p-space-4);
display: flex;
flex-direction: column;
gap: var(--pc-stack-spacing);
}

.alignEnd {
align-items: end;
}

.alignCenter {
align-items: center;
}
1 change: 1 addition & 0 deletions polaris-react/src/components/AlphaStack/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AlphaStack';
3 changes: 3 additions & 0 deletions polaris-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export type {
export {ActionMenu} from './components/ActionMenu';
export type {ActionMenuProps} from './components/ActionMenu';

export {AlphaStack} from './components/AlphaStack';
export type {AlphaStackProps} from './components/AlphaStack';

export {Autocomplete} from './components/Autocomplete';
export type {AutocompleteProps} from './components/Autocomplete';

Expand Down