Files
HMDesign/src/components/skeleton.stories.tsx
T

97 lines
3.5 KiB
TypeScript

import type { Meta, StoryObj } from "@storybook/react-vite"
import { Card, CardContent, CardHeader, Skeleton } from "@hm-design/ui"
import { StateBoard } from "@/components/story-board"
import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
// Skeleton is a visual placeholder; size and shape come from `className` (layout classes here are Story composition).
// There is no data fetching. The representative Story shows text lines, an avatar, and a card / list loading composition.
function TextLines() {
return (
<div className="grid gap-2">
<Skeleton className="h-4 w-3/4" />
<Skeleton className="h-4 w-full" />
<Skeleton className="h-4 w-1/2" />
</div>
)
}
function AvatarRow() {
return (
<div className="flex items-center gap-3">
<Skeleton className="size-10 rounded-full" />
<div className="grid flex-1 gap-2">
<Skeleton className="h-4 w-1/3" />
<Skeleton className="h-3 w-2/3" />
</div>
</div>
)
}
function CardLoading() {
return (
<Card>
<CardHeader>
<Skeleton className="h-5 w-1/2" />
</CardHeader>
<CardContent className="grid gap-3">
<Skeleton className="h-24 w-full" />
<AvatarRow />
<AvatarRow />
</CardContent>
</Card>
)
}
const sections = [
{ id: "text", label: "Text", node: <TextLines /> },
{ id: "avatar", label: "Avatar + text", node: <AvatarRow /> },
{ id: "card", label: "Card / list loading", node: <CardLoading /> },
]
const meta = { title: "Components/Data & Display/Skeleton", component: Skeleton, parameters: { layout: "padded" } } satisfies Meta<typeof Skeleton>
export default meta
type Story = StoryObj<typeof meta>
// Representative-page layout (Storybook presentation only): equal columns on PC (iframe width 1000px and up), fewer below that
// (240px minimum). Each specimen sits in its own single-column StateBoard (min larger than any column), so every subtitle and divider
// has the width of its column; a section with fewer specimens than columns leaves the remaining columns empty.
const specimenColumns = {
2: "min-[1000px]:grid-cols-2",
3: "min-[1000px]:grid-cols-3",
4: "min-[1000px]:grid-cols-4",
} as const
function SpecimenGrid({ ids, columns, spans = {} }: { ids: string[]; columns: 2 | 3 | 4; spans?: Record<string, 2> }) {
return (
<div className={`grid items-start gap-6 [grid-template-columns:repeat(auto-fill,minmax(min(100%,240px),1fr))] ${specimenColumns[columns]}`}>
{ids.map((id) => {
const s = sections.find((section) => section.id === id)!
return (
<div key={id} className={spans[id] ? "min-[1000px]:col-span-2" : undefined}>
<StateBoard min={10000} states={[{ id: s.id, label: s.label, children: s.node }]} />
</div>
)
})}
</div>
)
}
// Representative Story: the common Story page; the sections group the same specimens.
// Representative Story: Overview / Usage are merged into one Variants section (Text, Avatar + text, Card / list loading). 3 columns on PC.
export const All: Story = {
name: "Skeleton",
parameters: { layout: "fullscreen", controls: { disable: true } },
render: () => (
<StoryPage>
<StoryPageHeader title="Skeleton" />
<StorySection title="Variants">
<SpecimenGrid ids={["text", "avatar", "card"]} columns={3} />
</StorySection>
</StoryPage>
),
}
export const Text: Story = { tags: ["verification"], render: () => <TextLines /> }
export const CardList: Story = { tags: ["verification"], name: "Card List", render: () => <CardLoading /> }