import { useEffect, useState } from 'react' import type { Meta, StoryObj } from '@storybook/react-vite' import { Button } from './Button' import { Skeleton, SkeletonGroup, SkeletonText } from './Skeleton' import { SKELETON_VARIANTS } from './skeleton.tokens' const meta = { title: 'Feedback/Skeleton', component: Skeleton, tags: ['autodocs'], parameters: { docs: { description: { component: 'Placeholder shapes shown while content loads, so the layout does not jump. `Skeleton` draws one block (`rectangle`, `circle` for avatars, `text` for a line); `SkeletonText` draws a paragraph. The shapes are `aria-hidden`; wrap a loading region in `SkeletonGroup`, which sets `aria-busy` and gives screen readers one "Loading" message. The pulse stops under reduced motion.', }, }, }, argTypes: { variant: { control: 'inline-radio', options: SKELETON_VARIANTS, table: { defaultValue: { summary: 'rectangle' } } }, width: { control: 'text' }, height: { control: 'text' }, }, args: { variant: 'rectangle', width: '16rem', height: '1rem' }, } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const Shapes: Story = { render: () => (
), } export const Text: Story = { render: () => (
), } function CardSkeleton() { return (
) } export const CardLoading: Story = { parameters: { docs: { description: { story: 'A card placeholder inside a `SkeletonGroup` that marks the region busy.' } } }, render: () => ( ), } export const LoadingThenContent: Story = { render: function Render() { const [loading, setLoading] = useState(true) useEffect(() => { if (!loading) return const id = setTimeout(() => setLoading(false), 2000) return () => clearTimeout(id) }, [loading]) return (
{loading ? (
) : (
JD

Jane Doe

name@example.com

)}
) }, }