Files
HMDesign/src/components/avatar.stories.tsx
T
shkim4 da0e647b49 docs(storybook): simplify sidebar Story pages around the UI
Drop the category kicker from the 83 sidebar Stories (kicker is now optional;
hidden verification Stories keep it) and shorten or remove repeated, obvious
or internal page/section descriptions. Required specs, limits, virtual-data
and undecided-value notices stay. Story IDs, exports, fixtures, shared state
notes and package code are unchanged. Record: docs/reports/storybook-ui-simplification-2026-10-22.md
2026-10-22 16:13:58 +09:00

101 lines
3.7 KiB
TypeScript

import type { Meta, StoryObj } from "@storybook/react-vite"
import { Avatar, AvatarFallback, AvatarImage } from "@hm-design/ui"
import { StateBoard } from "@/components/story-board"
import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
// Images are inline data URIs so the Story does not depend on the network. "Broken" uses an address that cannot load so the
// Radix fallback shows. Radix renders the image only after it loads.
const photo =
"data:image/svg+xml;utf8," +
encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><rect width="80" height="80" fill="#266651"/><circle cx="40" cy="31" r="14" fill="#bddfd4"/><rect x="14" y="50" width="52" height="40" rx="22" fill="#bddfd4"/></svg>'
)
function Sizes() {
return (
<div className="flex items-end gap-4">
{(["sm", "default", "lg"] as const).map((size) => (
<div key={size} className="grid justify-items-center gap-2">
<Avatar size={size}>
<AvatarImage src={photo} alt="" />
<AvatarFallback>한맥</AvatarFallback>
</Avatar>
<span className="text-xs text-muted-foreground">{size}</span>
</div>
))}
</div>
)
}
function Fallbacks() {
const items = [
{ label: "한글 두 글자", text: "김한" },
{ label: "영문 두 글자", text: "HM" },
{ label: "한 글자", text: "한" },
{ label: "긴 fallback", text: "ABCDEFGHIJ" },
]
return (
<div className="flex flex-wrap items-end gap-4">
{items.map((i) => (
<div key={i.label} className="grid justify-items-center gap-2">
<Avatar>
<AvatarImage src="/broken-avatar-image.png" alt="" />
<AvatarFallback>{i.text}</AvatarFallback>
</Avatar>
<span className="text-xs text-muted-foreground">{i.label}</span>
</div>
))}
</div>
)
}
function Group() {
return (
<div className="flex items-center gap-3">
<Avatar>
<AvatarImage src={photo} alt="김한맥" />
<AvatarFallback>김한</AvatarFallback>
</Avatar>
<div className="grid text-sm">
<span className="font-medium">김한맥</span>
<span className="text-muted-foreground">노선 설계팀</span>
</div>
</div>
)
}
const sections = [
{ id: "image", label: "Image", note: "이미지가 로드되면 fallback은 나타나지 않습니다", node: <Sizes /> },
{ id: "fallback", label: "Fallback (image error)", note: "이미지 로드 실패 시 initials", node: <Fallbacks /> },
{ id: "composition", label: "Composition", node: <Group /> },
]
const meta = { title: "Components/Data & Display/Avatar", component: Avatar, parameters: { layout: "padded" } } satisfies Meta<typeof Avatar>
export default meta
type Story = StoryObj<typeof meta>
const board = (...ids: string[]) => (
<StateBoard min={320} states={sections.filter((s) => ids.includes(s.id)).map((s) => ({ id: s.id, label: s.label, note: s.note, children: s.node }))} />
)
// Representative Story: the common Story page; the sections group the same specimens.
export const All: Story = {
name: "Avatar",
parameters: { layout: "fullscreen", controls: { disable: true } },
render: () => (
<StoryPage>
<StoryPageHeader
title="Avatar"
description="이미지 실패 시 fallback 글자"
/>
<StorySection title="Overview">{board("image")}</StorySection>
<StorySection title="States">{board("fallback")}</StorySection>
<StorySection title="Usage">{board("composition")}</StorySection>
</StoryPage>
),
}
export const Image: Story = { tags: ["verification"], render: () => <Sizes /> }
export const FallbackError: Story = { tags: ["verification"], name: "Fallback", render: () => <Fallbacks /> }