import { useState, useEffect } from "react"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { AnimatedCounter } from "./animated-counter"; const meta = { title: "Components/AnimatedCounter", component: AnimatedCounter, parameters: { layout: "centered", }, tags: ["autodocs"], args: { size: "md", count: 0, }, } satisfies Meta; export default meta; type Story = StoryObj; export const Default: Story = { render(args) { const [count, setCount] = useState(0); return (
); }, }; export const Sizes: Story = { render() { const [count, setCount] = useState(42); return (
Small:
Medium:
Large:
); }, }; export const LargeNumbers: Story = { render() { const [count, setCount] = useState(1234567); return (
); }, }; export const Countdown: Story = { render() { const [count, setCount] = useState(10); const [isRunning, setIsRunning] = useState(false); useEffect(() => { if (isRunning && count > 0) { const timer = setTimeout(() => setCount((prev) => prev - 1), 1000); return () => clearTimeout(timer); } if (count === 0) { setIsRunning(false); } }, [count, isRunning]); const handleStart = () => { setCount(10); setIsRunning(true); }; return (
); }, }; export const LiveCounter: Story = { render() { const [count, setCount] = useState(0); const [isRunning, setIsRunning] = useState(false); useEffect(() => { if (isRunning) { const timer = setInterval(() => setCount((prev) => prev + 1), 500); return () => clearInterval(timer); } }, [isRunning]); return (
); }, }; export const MultipleCounters: Story = { render() { const [likes, setLikes] = useState(42); const [comments, setComments] = useState(15); const [shares, setShares] = useState(8); return (

Engagement Stats

Likes
Comments
Shares
); }, }; export const InBadge: Story = { render() { const [notifications, setNotifications] = useState(3); return (
); }, }; export const FastAnimation: Story = { render() { const [count, setCount] = useState(0); const incrementFast = () => { for (let i = 1; i <= 10; i++) { setTimeout(() => setCount((prev) => prev + 1), i * 50); } }; return (
); }, };