Skip to content

Commit

Permalink
Fix Stack component
Browse files Browse the repository at this point in the history
Signed-off-by: Charles de Dreuille <[email protected]>
  • Loading branch information
cdedreuille committed Dec 19, 2024
1 parent 85d6754 commit bd74f76
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 69 deletions.
34 changes: 28 additions & 6 deletions packages/canon/src/components/Container/Docs.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Meta, Unstyled, Source } from '@storybook/blocks';
import * as ContainerStories from './Container.stories';
import { Title, Text, PropsTable, getProps } from '../../../docs/components';
import { spacingProperties } from '../../layout/sprinkles.css';
import { containerProperties } from './sprinkles.css';
import { spacePropsList } from '../../../docs/spaceProps';

<Meta of={ContainerStories} />

Expand All @@ -28,18 +27,41 @@ import { containerProperties } from './sprinkles.css';

<PropsTable
data={{
...getProps(containerProperties.styles),
children: {
type: 'ReactNode',
required: false,
responsive: false,
},
className: {
type: 'string',
required: false,
responsive: false,
},
marginY: {
type: spacePropsList.marginY.type,
responsive: spacePropsList.marginY.responsive,
},
marginBottom: {
type: spacePropsList.marginBottom.type,
responsive: spacePropsList.marginBottom.responsive,
},
marginTop: {
type: spacePropsList.marginTop.type,
responsive: spacePropsList.marginTop.responsive,
},
paddingY: {
type: spacePropsList.paddingY.type,
responsive: spacePropsList.paddingY.responsive,
},
paddingBottom: {
type: spacePropsList.paddingBottom.type,
responsive: spacePropsList.paddingBottom.responsive,
},
paddingTop: {
type: spacePropsList.paddingTop.type,
responsive: spacePropsList.paddingTop.responsive,
},
style: {
type: 'CSSProperties',
required: false,
responsive: false,
},
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/canon/src/components/Stack/Docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { spacingProperties } from '../../layout/sprinkles.css';
<PropsTable
data={{
align: {
type: ['left', 'center', 'right'],
type: ['start', 'center', 'end'],
responsive: true,
},
children: {
Expand Down
10 changes: 5 additions & 5 deletions packages/canon/src/components/Stack/Stack.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const meta = {
},
},
args: {
align: 'left',
align: 'start',
gap: 'xs',
},
} satisfies Meta<typeof Stack>;
Expand Down Expand Up @@ -75,7 +75,7 @@ export const Default: Story = {
export const AlignLeft: Story = {
args: {
...Default.args,
align: 'left',
align: 'start',
},
};

Expand All @@ -89,17 +89,17 @@ export const AlignCenter: Story = {
export const AlignRight: Story = {
args: {
...Default.args,
align: 'right',
align: 'end',
},
};

export const ResponsiveAlign: Story = {
args: {
...Default.args,
align: {
xs: 'left',
xs: 'start',
md: 'center',
lg: 'right',
lg: 'end',
},
},
};
Expand Down
24 changes: 7 additions & 17 deletions packages/canon/src/components/Stack/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,29 @@

import { createElement, forwardRef } from 'react';
import { StackProps } from './types';
import { stackSprinkles } from './sprinkles.css';

const alignToFlexAlign = (align: StackProps['align']) => {
if (align === 'left') return 'stretch';
if (align === 'center') return 'center';
if (align === 'right') return 'flex-end';
return undefined;
};
import { getClassNames } from '../../utils/getClassNames';

/** @public */
export const Stack = forwardRef<HTMLDivElement, StackProps>((props, ref) => {
const {
as = 'div',
children,
align = 'left',
align = 'start',
gap = 'xs',
className,
style,
...restProps
} = props;

// Transform the align prop
const flexAlign = alignToFlexAlign(align);

// Generate the list of class names
const sprinklesClassName = stackSprinkles({
...restProps,
// Generate utility class names
const utilityClassNames = getClassNames({
gap,
alignItems: flexAlign,
alignItems: align === 'start' ? 'stretch' : align,
...restProps,
});

// Combine the base class name, the sprinkles class name, and any additional class names
const classNames = ['stack', sprinklesClassName, className]
const classNames = ['canon-stack', utilityClassNames, className]
.filter(Boolean)
.join(' ');

Expand Down
33 changes: 0 additions & 33 deletions packages/canon/src/components/Stack/sprinkles.css.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/canon/src/components/Stack/styles.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.stack {
.canon-stack {
display: flex;
flex-direction: column;
}
8 changes: 2 additions & 6 deletions packages/canon/src/components/Stack/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
* limitations under the License.
*/
import { AsProps, ColorProps } from '../../layout/types';
import type { Breakpoint, SpaceProps, UtilityProps } from '../../types';
import type { SpaceProps, UtilityProps } from '../../types';

/** @public */
export interface StackProps extends SpaceProps, ColorProps {
children: React.ReactNode;
as?: AsProps;
gap?: UtilityProps['gap'];
align?:
| 'left'
| 'center'
| 'right'
| Partial<Record<Breakpoint, 'left' | 'center' | 'right'>>;
align?: UtilityProps['alignItems'];
className?: string;
style?: React.CSSProperties;
}

0 comments on commit bd74f76

Please sign in to comment.