diff --git a/frontend/stories/Button.stories.tsx b/frontend/stories/Button.stories.tsx new file mode 100644 index 000000000000..315fb3f0c34b --- /dev/null +++ b/frontend/stories/Button.stories.tsx @@ -0,0 +1,196 @@ +import React from 'react' +import type { Meta, StoryObj } from '@storybook/react-webpack5' +import Button, { + themeClassNames, + sizeClassNames, +} from 'components/base/forms/Button' + +const themes = Object.keys(themeClassNames) as Array< + keyof typeof themeClassNames +> +const sizes = Object.keys(sizeClassNames) as Array + +const meta: Meta = { + component: Button, + parameters: { + layout: 'padded', + }, + title: 'Components/Button', +} +export default meta + +type Story = StoryObj + +// --------------------------------------------------------------------------- +// All themes +// --------------------------------------------------------------------------- + +export const AllThemes: Story = { + name: 'All themes', + render: () => ( +
+ {themes.map((theme) => ( + + ))} +
+ ), +} + +// --------------------------------------------------------------------------- +// All sizes +// --------------------------------------------------------------------------- + +export const AllSizes: Story = { + name: 'All sizes', + render: () => ( +
+ {sizes.map((size) => ( + + ))} +
+ ), +} + +// --------------------------------------------------------------------------- +// Theme × Size matrix +// --------------------------------------------------------------------------- + +export const ThemeSizeMatrix: Story = { + name: 'Theme × Size matrix', + render: () => ( + + + + + {sizes.map((size) => ( + + ))} + + + + {themes.map((theme) => ( + + + {sizes.map((size) => ( + + ))} + + ))} + +
+ Theme / Size + + {size} +
+ {theme} + + +
+ ), +} + +// --------------------------------------------------------------------------- +// With icons +// --------------------------------------------------------------------------- + +export const WithIcons: Story = { + name: 'With icons', + render: () => ( +
+ + + + + +
+ ), +} + +// --------------------------------------------------------------------------- +// States +// --------------------------------------------------------------------------- + +export const States: Story = { + render: () => ( +
+ + + + + + +
+ ), +} + +// --------------------------------------------------------------------------- +// As link +// --------------------------------------------------------------------------- + +export const AsLink: Story = { + name: 'As link (href)', + render: () => ( +
+ + + +
+ ), +} diff --git a/frontend/web/components/base/forms/Button.tsx b/frontend/web/components/base/forms/Button.tsx index 7cf9e499fb5f..864f7ce8aed7 100644 --- a/frontend/web/components/base/forms/Button.tsx +++ b/frontend/web/components/base/forms/Button.tsx @@ -2,7 +2,13 @@ import React from 'react' import cn from 'classnames' import { ButtonHTMLAttributes, HTMLAttributeAnchorTarget } from 'react' import Icon, { IconName } from 'components/Icon' -import Constants from 'common/constants' + +const iconColours = { + primary: 'var(--color-brand-default, #6837fc)', + white: 'var(--color-text-on-fill, #ffffff)', +} as const + +export type IconColour = keyof typeof iconColours export const themeClassNames = { danger: 'btn btn-danger', @@ -26,8 +32,8 @@ export const sizeClassNames = { export type ButtonType = ButtonHTMLAttributes & { iconRight?: IconName - iconRightColour?: keyof typeof Constants.colours - iconLeftColour?: keyof typeof Constants.colours + iconRightColour?: IconColour + iconLeftColour?: IconColour iconLeft?: IconName href?: string target?: HTMLAttributeAnchorTarget @@ -71,9 +77,7 @@ export const Button = React.forwardRef<
{!!iconLeft && ( @@ -82,9 +86,7 @@ export const Button = React.forwardRef<
{!!iconRight && ( {!!iconLeft && (