Skip to content

Commit

Permalink
feat(tokens): add radius (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamKelley authored May 10, 2024
1 parent 9e12e61 commit 3e382c3
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 4 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"babel-jest": "^29.4.1",
"chromatic": "^9.1.0",
"concurrently": "^8.2.2",
"csstype": "^3.1.3",
"eslint": "8.57.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "2.27.5",
Expand Down
16 changes: 16 additions & 0 deletions packages/tokens/.storybook/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ export const Palette = function Palette(
/>
);
};

export const RadiusSwatch = function RadiusSwatch(
props: React.ComponentProps<typeof Swatch>
) {
return (
<div style={{ padding: 4 }}>
<Swatch
{...props}
style={{
border: '1px solid black',
...props.style,
}}
/>
</div>
);
};
4 changes: 3 additions & 1 deletion packages/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
}
},
"type": "module",
"dependencies": {}
"dependencies": {
"csstype": "^3.1.3"
}
}
3 changes: 3 additions & 0 deletions packages/tokens/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export { color } from './color';
export type { ColorToken, ColorPalette, ColorNestedPalettes } from './color';

export { radius } from './radius';
export type { RadiusToken, RadiusPalette } from './radius';

export { skinTone } from './skin-tone';
export type {
SkinToneToken,
Expand Down
60 changes: 60 additions & 0 deletions packages/tokens/src/radius.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Meta, StoryObj } from '@storybook/react';
import * as radius from './radius';
import { Palette, RadiusSwatch as Swatch } from '../.storybook/components';

const meta: Meta = {
title: 'Radius',
};

export default meta;

type Story = StoryObj;

export const Zero: Story = {
render: () => <Swatch style={{ borderRadius: radius.zero }} />,
name: 'zero',
};

export const Xs: Story = {
render: () => <Swatch style={{ borderRadius: radius.xs }} />,
name: 'xs',
};

export const Sm: Story = {
render: () => <Swatch style={{ borderRadius: radius.sm }} />,
name: 'sm',
};

export const Md: Story = {
render: () => <Swatch style={{ borderRadius: radius.md }} />,
name: 'md',
};

export const Lg: Story = {
render: () => <Swatch style={{ borderRadius: radius.lg }} />,
name: 'lg',
};

export const Xl: Story = {
render: () => <Swatch style={{ borderRadius: radius.xl }} />,
name: 'xl',
};

export const Full: Story = {
render: () => <Swatch style={{ borderRadius: radius.full }} />,
name: 'full',
};

export const Radius: Story = {
render: () => (
<Palette>
{Object.entries(radius.radius).map(([name, value]) => (
<div key={name}>
<div>{name}</div>
<Swatch style={{ borderRadius: value }} />
</div>
))}
</Palette>
),
name: 'radius (palette)',
};
25 changes: 25 additions & 0 deletions packages/tokens/src/radius.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Property } from 'csstype';

/** A global token for a CSS border radius property value. */
export type RadiusToken = Property.BorderRadius;

export const zero = '0px' as const satisfies RadiusToken;
export const xs = '2px' as const satisfies RadiusToken;
export const sm = '4px' as const satisfies RadiusToken;
export const md = '8px' as const satisfies RadiusToken;
export const lg = '16px' as const satisfies RadiusToken;
export const xl = '32px' as const satisfies RadiusToken;
export const full = '9999px' as const satisfies RadiusToken;

/** A palette of radius tokens. */
export type RadiusPalette = Record<string, RadiusToken>;

export const radius = {
zero,
xs,
sm,
md,
lg,
xl,
full,
} as const satisfies RadiusPalette;

0 comments on commit 3e382c3

Please sign in to comment.