import type { Meta, StoryObj } from '@storybook/react-vite' import { SIZES } from '../lib/styles' import { Kbd } from './Kbd' const meta = { title: 'Display/Kbd', component: Kbd, tags: ['autodocs'], parameters: { docs: { description: { component: 'Shows a key or a shortcut. Pass one key as `children`, or a combination as `keys` (`[\'⌘\', \'K\']`), which renders nested `` elements with a `separator`. Symbols such as ⌘ and ⇧ are announced by name.', }, }, }, argTypes: { keys: { control: 'object' }, separator: { control: 'text', table: { defaultValue: { summary: '+' } } }, size: { control: 'inline-radio', options: SIZES, table: { defaultValue: { summary: 'md' } } }, children: { control: 'text' }, }, args: { keys: ['⌘', 'K'], separator: '+', size: 'md', }, } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const SingleKeys: Story = { args: { keys: undefined }, render: (args) => (
{['Esc', 'Tab', '⇧', '⌘', '⌥', '↵', '⌫', '↑', '↓', 'A', '/'].map((k) => ( {k} ))}
), } export const Combinations: Story = { render: (args) => (
), } export const Sizes: Story = { render: (args) => (
{SIZES.map((size) => ( ))}
), } export const InContext: Story = { parameters: { docs: { description: { story: 'Shortcut hints in a search field and a shortcut list.' } } }, render: () => (
Search components…
{[ ['Open command palette', ['⌘', 'K']], ['Toggle dark mode', ['⌘', '⇧', 'L']], ['Go to inbox', ['G', 'I']], ['Close dialog', ['Esc']], ].map(([action, keys]) => (
{action as string}
))}

Press / to focus search, or ? to see every shortcut.

), }