← All proposals

Badge

An extension of the PDS Badge: one new prop, as ('span' | 'kbd', default 'span').

Extends a PDS componentOpen in Storybook

proposals/Badge/Badge.stories.tsx63 lines · View on GitHub
import { Meta, StoryObj } from '@storybook/react-vite';

import { Badge } from './Badge';

const meta: Meta<typeof Badge> = {
	tags: ['in-progress'],
	title: 'Component Proposals/Badge',
	component: Badge,
	parameters: {
		docs: {
			description: {
				component:
					'Extension of the PDS Badge: `as` lets the badge render as a `kbd` element, for a keyboard key such as the Esc hint on Global search. Everything else is the package Badge.',
			},
		},
	},
	argTypes: {
		as: {
			control: 'inline-radio',
			options: ['span', 'kbd'],
			table: { category: 'Component configuration' },
		},
		className: { table: { category: 'Base attributes' } },
		color: { control: 'select', table: { category: 'Appearance' } },
		iconName: { table: { category: 'Content' } },
		isWrappable: {
			control: 'boolean',
			table: { category: 'Component configuration' },
		},
		label: { table: { category: 'Content' } },
		size: { control: 'select', table: { category: 'Component configuration' } },
	},
	args: {
		as: 'span',
		color: 'brand-muted',
		label: 'Badge',
		size: 's',
	},
};

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {};

export const KeyboardKey: Story = {
	parameters: {
		docs: {
			description: {
				story:
					"`as='kbd'` makes the badge the key itself. Use a muted neutral color and the `xs` size next to a field. Pass the key name as `label`, from a translatable string.",
			},
		},
	},
	args: {
		as: 'kbd',
		color: 'silver-muted',
		label: 'esc',
		size: 'xs',
	},
};