import { useEffect, useState, type ReactNode } from "react" import type { Meta, StoryObj } from "@storybook/react-vite" import { AspectRatio, Card, CardContent, Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, type CarouselApi } from "@hm-design/ui" import { StateBoard } from "@/components/story-board" import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page" // The representative Story shows real, draggable carousels; the same specimens also exist as Stories tagged `verification` // (hidden from the sidebar). Slide widths (`basis-*`) are the consumer's `className` on CarouselItem; Card and AspectRatio are // Story composition (Carousel imports neither). `setApi` feeds the "slide n / total" readout. const frame = (node: ReactNode) =>
{node}
const svg = (n: number) => "data:image/svg+xml;utf8," + encodeURIComponent( `Slide ${n + 1}` ) function SlideCard({ n }: { n: number }) { return ( {n + 1} ) } function useReadout() { const [api, setApi] = useState() const [current, setCurrent] = useState(0) const [count, setCount] = useState(0) useEffect(() => { if (!api) return setCount(api.scrollSnapList().length) setCurrent(api.selectedScrollSnap() + 1) api.on("select", () => setCurrent(api.selectedScrollSnap() + 1)) }, [api]) return { setApi, current, count } } // `showValue={false}` hides the value readout on the representative page; the verification Stories keep it. function Basic({ showValue = true }: { showValue?: boolean }) { const { setApi, current, count } = useReadout() return frame(
{Array.from({ length: 5 }, (_, i) => ( ))} {showValue ? {`slide ${current} / ${count}`} : null}
) } function Multiple() { return frame( {Array.from({ length: 8 }, (_, i) => ( ))} ) } function Loop({ showValue = true }: { showValue?: boolean }) { const { setApi, current, count } = useReadout() return frame(
{Array.from({ length: 3 }, (_, i) => ( ))} {showValue ? {`slide ${current} / ${count}`} : null}
) } function Vertical() { return (
{Array.from({ length: 4 }, (_, i) => ( ))}
) } function Media() { return frame( {Array.from({ length: 4 }, (_, i) => ( {`슬라이드 ))} ) } const sections = [ { id: "basic", label: "Basic", node: }, { id: "multiple", label: "Multiple items", node: }, { id: "loop", label: "Loop", node: }, { id: "vertical", label: "Vertical", node: }, { id: "media", label: "Media", node: }, ] const meta = { title: "Components/Data & Display/Carousel", component: Carousel, parameters: { layout: "padded" } } satisfies Meta export default meta type Story = StoryObj // Representative-page layout (Storybook presentation only): equal columns on PC (iframe width 1000px and up), fewer below that // (200px 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. // The Media example spans two columns; carousels fill their column by design. 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 }) { return (
{ids.map((id) => { const s = sections.find((section) => section.id === id)! return (
) })}
) } // Representative Story: the common Story page; the sections group the same specimens. // Representative Story: Overview (Basic) is merged into Variants (Basic, Multiple items, Loop, Vertical), 4 columns on PC; Media stays under Usage. export const All: Story = { name: "Carousel", parameters: { layout: "fullscreen", controls: { disable: true } }, render: () => ( ), } export const BasicCarousel: Story = { tags: ["verification"], name: "Basic", render: () => } export const MultipleItems: Story = { tags: ["verification"], name: "Multiple Items", render: () => } export const LoopCarousel: Story = { tags: ["verification"], name: "Loop", render: () => } export const VerticalCarousel: Story = { tags: ["verification"], name: "Vertical", render: () => }