Files
HMDesign/src/components/scroll-area.stories.tsx
T

124 lines
4.8 KiB
TypeScript

import type { ReactNode } from "react"
import type { Meta, StoryObj } from "@storybook/react-vite"
import { ScrollArea, ScrollBar } from "@hm-design/ui"
import { StateBoard } from "@/components/story-board"
import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
// Scroll Area is Radix scrolling with a styled scrollbar (type "hover": the bar shows while hovering or scrolling). Sizes below
// are Story layout. The representative Story shows vertical, horizontal, both axes and a table-like content.
const items = Array.from({ length: 30 }, (_, i) => `항목 ${i + 1}`)
function Vertical() {
return (
<ScrollArea style={{ height: 200, width: 280 }} className="rounded-md border">
<div className="p-3 text-sm">
{items.map((t) => (
<div key={t} className="py-1.5">
{t}
</div>
))}
</div>
</ScrollArea>
)
}
function Horizontal() {
return (
<ScrollArea style={{ width: 280 }} className="rounded-md border whitespace-nowrap">
<div className="flex w-max gap-3 p-3">
{Array.from({ length: 12 }, (_, i) => (
<div key={i} className="grid h-16 w-24 place-items-center rounded-md bg-muted text-sm">{`카드 ${i + 1}`}</div>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
)
}
function Both() {
return (
<ScrollArea style={{ height: 200, width: 280 }} className="rounded-md border">
<div className="p-3 text-sm" style={{ width: 600 }}>
{items.map((t) => (
<div key={t} className="py-1.5">{`${t} — 가로로도 길어지는 내용입니다. 가로 scroll로 끝까지 볼 수 있습니다.`}</div>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
)
}
function TableLike() {
return (
<ScrollArea style={{ height: 180, width: 300 }} className="rounded-md border">
<div className="grid text-sm" style={{ width: 520 }}>
{Array.from({ length: 12 }, (_, r) => (
<div key={r} className="grid grid-cols-4 border-b p-2">
{["번호", "이름", "상태", "금액"].map((c) => (
<span key={c}>{`${c} ${r + 1}`}</span>
))}
</div>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
)
}
const sections: { id: string; label: string; node: ReactNode }[] = [
{ id: "vertical", label: "Vertical", node: <Vertical /> },
{ id: "horizontal", label: "Horizontal", node: <Horizontal /> },
{ id: "both", label: "Both axes", node: <Both /> },
{ id: "table-like", label: "Table-like content", node: <TableLike /> },
]
const meta = { title: "Components/Data & Display/Scroll Area", component: ScrollArea, parameters: { layout: "padded" } } satisfies Meta<typeof ScrollArea>
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
// (300px 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%,300px),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 (Vertical) is merged into Variants (Vertical, Horizontal, Both axes); Table-like stays under Usage. 3 columns on PC.
export const All: Story = {
name: "Scroll Area",
parameters: { layout: "fullscreen", controls: { disable: true } },
render: () => (
<StoryPage>
<StoryPageHeader title="Scroll Area" />
<StorySection title="Variants">
<SpecimenGrid ids={["vertical", "horizontal", "both"]} columns={3} />
</StorySection>
<StorySection title="Usage">
<SpecimenGrid ids={["table-like"]} columns={3} />
</StorySection>
</StoryPage>
),
}
export const VerticalScroll: Story = { tags: ["verification"], name: "Vertical", render: () => <Vertical /> }
export const HorizontalScroll: Story = { tags: ["verification"], name: "Horizontal", render: () => <Horizontal /> }