import { Meta, StoryObj } from '@storybook/react-webpack5'; import { ArrowLeft, Cross, Defrost, Edit, Menu, Plus, Settings, Star, Travel, Briefcase, Bank, Freeze, } from '@transferwise/icons'; import { fn } from 'storybook/test'; import IconButton, { Props } from './IconButton'; import SentimentSurface from '../sentimentSurface'; /** * **Design guidance**: wise.design/components/icon-button */ export default { title: 'Actions/IconButton', component: IconButton, args: { onClick: fn(), 'aria-label': 'Action', }, argTypes: { id: { table: { category: 'Common' } }, className: { table: { category: 'Common' } }, role: { table: { category: 'Common' } }, tabIndex: { table: { category: 'Common' } }, 'data-testid': { table: { category: 'Common' } }, onClick: { table: { category: 'Common' } }, }, parameters: { docs: { toc: true }, }, } satisfies Meta; type Story = StoryObj; const sizes: Props['size'][] = [16, 24, 32, 40, 48, 56, 72]; /** * Explore size, priority, type, and disabled state via the controls panel. * Use `aria-label` to provide an accessible name. */ export const Playground: Story = { args: { size: 48, priority: 'primary', type: 'default', disabled: false, }, render: (args) => ( ), }; /** * Priorities set a visual hierarchy amongst the buttons displayed on the * screen to help more important buttons to take precedence over others.
* Design documentation */ export const Priority: Story = { args: { type: 'default', }, argTypes: { type: { control: 'radio', options: ['default', 'negative'], }, priority: { table: { disable: true } }, size: { table: { disable: true } }, disabled: { table: { disable: true } }, href: { table: { disable: true } }, target: { table: { disable: true } }, onClick: { table: { disable: true } }, }, decorators: [ (Story) => (
), ], render: (args: Props) => ( <> ), }; /** * There are two different types of button – default and negative – designed to emphasise the nature of the action.
* Design documentation */ export const Type: Story = { args: { priority: 'primary', }, argTypes: { priority: { control: 'radio', options: ['primary', 'secondary', 'tertiary', 'minimal'], }, type: { table: { disable: true } }, size: { table: { disable: true } }, disabled: { table: { disable: true } }, href: { table: { disable: true } }, target: { table: { disable: true } }, onClick: { table: { disable: true } }, }, decorators: [ (Story) => (
), ], render: (args: Props) => ( <> ), }; /** * IconButton is available in 7 sizes: 16, 24, 32, 40, 48, 56, 72.
* Design documentation */ export const Size: Story = { args: { priority: 'primary', type: 'default', }, argTypes: { priority: { control: 'radio', options: ['primary', 'secondary', 'tertiary', 'minimal'], }, type: { control: 'radio', options: ['default', 'negative'], }, size: { table: { disable: true } }, disabled: { table: { disable: true } }, href: { table: { disable: true } }, target: { table: { disable: true } }, onClick: { table: { disable: true } }, }, decorators: [ (Story) => (
), ], render: (args: Props) => ( <> {sizes.map((size) => (
{size}px
))} ), parameters: { docs: { source: { code: `{[16, 24, 32, 40, 48, 56, 72].map((size) => (
{size}px
))}`, }, }, }, }; /** * Disabled buttons cannot be interacted with and are visually distinct. */ export const Disabled: Story = { args: { priority: 'primary', type: 'default', }, argTypes: { priority: { control: 'radio', options: ['primary', 'secondary', 'tertiary', 'minimal'], }, type: { control: 'radio', options: ['default', 'negative'], }, size: { table: { disable: true } }, disabled: { table: { disable: true } }, href: { table: { disable: true } }, target: { table: { disable: true } }, onClick: { table: { disable: true } }, }, render: (args: Props) => ( ), }; /** * IconButton can render as an anchor element when `href` is provided. */ export const AsAnchor: Story = { args: { priority: 'primary', type: 'default', href: 'https://wise.com', target: '_blank', }, argTypes: { priority: { control: 'radio', options: ['primary', 'secondary', 'tertiary', 'minimal'], }, type: { control: 'radio', options: ['default', 'negative'], }, size: { table: { disable: true } }, disabled: { table: { disable: true } }, onClick: { table: { disable: true } }, }, render: (args: Props) => ( ), }; /** * `IconButton` is sentiment-aware and will automatically adjust its colours if wrapped inside * the [SentimentSurface](?path=/docs/foundations-sentimentsurface--docs) component */ export const SentimentAwareness: Story = { args: { size: 48, }, argTypes: { size: { control: 'radio', options: [16, 24, 32, 40, 48, 56, 72], }, }, render: (args: Props) => { const priorities = [ { key: 'primary', label: 'primary' }, { key: 'secondary', label: 'secondary' }, { key: 'tertiary', label: 'tertiary' }, { key: 'minimal', label: 'minimal' }, { key: 'neg-primary', label: 'negative\nprimary' }, { key: 'neg-secondary', label: 'negative\nsecondary' }, { key: 'disabled', label: 'disabled' }, ] as const; const sentiments = ['success', 'warning', 'negative', 'neutral', 'proposition'] as const; return (
{/* Header row with priority labels */}
{priorities.map((priority) => (
{priority.label}
))}
{/* Rows for each sentiment with base and elevated emphasis */} {sentiments.flatMap((sentiment) => [
{sentiment} (base)
,
{sentiment} (elevated)
, ])}
); }, parameters: { docs: { canvas: { sourceState: 'hidden' }, }, }, };