import { useState } from "react"
import type { Meta, StoryObj } from "@storybook/react-vite"
import { Button, Progress } from "@hm-design/ui"
import { StateBoard } from "@/components/story-board"
import { STORY_KICKER, StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
// Progress follows `value` (0..max). The representative Story shows fixed values plus one interactive value; the same specimens
// also exist as Stories tagged `verification` (hidden from the sidebar). No status colors are defined, so there is one look.
function Interactive() {
const [value, setValue] = useState(30)
return (
{`value = ${value}`}
setValue((v) => Math.max(0, v - 25))}>
-25
setValue((v) => Math.min(100, v + 25))}>
+25
)
}
function CustomMaximum() {
return (
)
}
const sections = [
{ id: "zero", label: "0%", node: },
{ id: "middle", label: "50%", node: },
{ id: "full", label: "100%", node: },
{ id: "custom-maximum", label: "max = 200", note: "0 / 50 / 200과 값 없음: ARIA 범위와 실제 채움 비율 확인", node: },
{ id: "interactive", label: "Interactive value", note: "버튼으로 value를 바꾸면 indicator 폭과 aria-valuenow가 함께 변합니다", node: },
]
const meta = { title: "Components/Data & Display/Progress", component: Progress, 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, note: s.note, noteAfter: true, children: s.node }))} />
)
// Representative Story: the common Story page; the sections group the same specimens.
export const All: Story = {
name: "Progress",
parameters: { layout: "fullscreen", controls: { disable: true } },
render: () => (
{board("middle")}
{board("zero", "full")}
{board("custom-maximum", "interactive")}
),
}
export const Zero: Story = { tags: ["verification"], render: () => }
export const Middle: Story = { tags: ["verification"], render: () => }
export const Full: Story = { tags: ["verification"], render: () => }
export const NonDefaultMax: Story = {
tags: ["verification"],
render: () => ,
play: async ({ canvasElement }) => {
const bars = canvasElement.querySelectorAll('[role="progressbar"]')
const expected = ["translateX(-100%)", "translateX(-75%)", "translateX(0%)", "translateX(-100%)"]
bars.forEach((bar, index) => {
const indicator = bar.querySelector('[data-slot="progress-indicator"]')
if (bar.getAttribute("aria-valuemax") !== "200" || indicator?.style.transform !== expected[index]) {
throw new Error(`Progress max=200: ARIA/fill mismatch in specimen ${index}`)
}
})
if (bars.length !== 4 || bars[1]?.getAttribute("aria-valuenow") !== "50" || bars[3]?.hasAttribute("aria-valuenow")) {
throw new Error("Progress max=200: incorrect determinate/indeterminate ARIA state")
}
},
}