120 lines
4.1 KiB
TypeScript
120 lines
4.1 KiB
TypeScript
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
import { CheckIcon } from "lucide-react"
|
|
import { Badge } from "@hm-design/ui"
|
|
import { StateBoard, type BoardState } from "@/components/story-board"
|
|
import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
|
|
|
|
const variants = ["default", "secondary", "destructive", "outline"] as const
|
|
|
|
const meta = {
|
|
title: "Components/Data & Display/Badge",
|
|
component: Badge,
|
|
parameters: {
|
|
layout: "padded",
|
|
docs: {
|
|
description: {
|
|
component:
|
|
"현재 HM 규격: 12/18/500, padding 2/8, radius 4, border 1px. variant는 현재 HM Theme에 의미가 있는 default(primary), secondary(neutral), destructive, outline만 둡니다. success·warning·information은 상태 색이 정해지지 않아 만들지 않았습니다. Button variant를 재사용하지 않는 별도 컴포넌트입니다.",
|
|
},
|
|
},
|
|
},
|
|
argTypes: { variant: { control: "inline-radio", options: variants } },
|
|
} satisfies Meta<typeof Badge>
|
|
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
|
|
// (280px 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({ states, columns }: { states: BoardState[]; columns: 2 | 3 | 4 }) {
|
|
return (
|
|
<div className={`grid items-start gap-6 [grid-template-columns:repeat(auto-fill,minmax(min(100%,280px),1fr))] ${specimenColumns[columns]}`}>
|
|
{states.map((state) => (
|
|
<StateBoard key={state.id} min={10000} states={[state]} />
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// Representative Story: Overview (a plain Badge, already the default item of Variants / Text) is removed. 2 columns on PC.
|
|
export const All: Story = {
|
|
name: "Badge",
|
|
parameters: { layout: "fullscreen", controls: { disable: true } },
|
|
render: () => (
|
|
<StoryPage>
|
|
<StoryPageHeader title="Badge" />
|
|
<StorySection title="Variants">
|
|
<SpecimenGrid
|
|
columns={2}
|
|
states={[
|
|
{
|
|
id: "variants",
|
|
label: "Text",
|
|
children: (
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
{variants.map((v) => (
|
|
<Badge key={v} variant={v}>
|
|
{v}
|
|
</Badge>
|
|
))}
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
id: "icon",
|
|
label: "With icon",
|
|
children: (
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
{variants.map((v) => (
|
|
<Badge key={v} variant={v}>
|
|
<CheckIcon aria-hidden="true" />
|
|
{v}
|
|
</Badge>
|
|
))}
|
|
</div>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
</StorySection>
|
|
<StorySection title="Usage">
|
|
<SpecimenGrid
|
|
columns={2}
|
|
states={[
|
|
{ id: "long", label: "Long text", children: <div className="max-w-[160px]"><Badge>A very long badge label</Badge></div> },
|
|
{
|
|
id: "link",
|
|
label: "Link",
|
|
children: (
|
|
<Badge asChild variant="outline">
|
|
<a href="#badge">Link badge</a>
|
|
</Badge>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
</StorySection>
|
|
</StoryPage>
|
|
),
|
|
}
|
|
|
|
export const Variants: Story = {
|
|
tags: ["verification"],
|
|
render: () => (
|
|
<div className="flex flex-wrap items-center gap-3">
|
|
{variants.map((v) => (
|
|
<Badge key={v} variant={v}>
|
|
{v}
|
|
</Badge>
|
|
))}
|
|
</div>
|
|
),
|
|
}
|
|
export const Playground: Story = { tags: ["verification"], args: { variant: "default", children: "Badge" } }
|