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 } } function Basic() { const { setApi, current, count } = useReadout() return frame(
{Array.from({ length: 5 }, (_, i) => ( ))} {`slide ${current} / ${count}`}
) } function Multiple() { return frame( {Array.from({ length: 8 }, (_, i) => ( ))} ) } function Loop() { const { setApi, current, count } = useReadout() return frame(
{Array.from({ length: 3 }, (_, i) => ( ))} {`slide ${current} / ${count}`}
) } function Vertical() { return (
{Array.from({ length: 4 }, (_, i) => ( ))}
) } function Media() { return frame( {Array.from({ length: 4 }, (_, i) => ( {`슬라이드 ))} ) } const sections = [ { id: "basic", label: "Basic (single item) + setApi readout", node: }, { id: "multiple", label: "Multiple items (basis-1/2)", node: }, { id: "loop", label: "Loop (controls never disable)", node: }, { id: "vertical", label: "Vertical", node: }, { id: "media", label: "Media (AspectRatio composition)", node: }, ] const meta = { title: "Components/Data & Display/Carousel", component: Carousel, parameters: { layout: "padded" } } satisfies Meta export default meta type Story = StoryObj const board = (...ids: string[]) => ( ids.includes(s.id)).map((s) => ({ id: s.id, label: s.label, children: s.node }))} /> ) // Representative Story: the common Story page; the sections group the same specimens. export const All: Story = { name: "Carousel", parameters: { layout: "fullscreen", controls: { disable: true } }, render: () => ( {board("basic")} {board("multiple", "loop", "vertical")} {board("media")} ), } 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: () => }