import type { Meta, StoryObj } from "@storybook/nextjs-vite" import React, { useState } from "react" import { ShowMoreButton } from "./ShowMoreButton" const meta: Meta = { title: "Core Components/ShowMoreButton", component: ShowMoreButton, argTypes: { loadMoreData: { table: { type: { summary: "function" }, defaultValue: { summary: "undefined" }, }, description: "Callback function to handle button press events.", }, showLess: { control: "boolean", table: { type: { summary: "boolean" }, defaultValue: { summary: "false" }, }, description: "When true, shows 'Show less' text and up arrow icon.", }, textShowMore: { control: "text", table: { type: { summary: "string" }, defaultValue: { summary: "undefined (uses i18n)" }, }, description: "Custom text for 'Show more' state. If not provided, uses i18n message.", }, textShowLess: { control: "text", table: { type: { summary: "string" }, defaultValue: { summary: "undefined (uses i18n)" }, }, description: "Custom text for 'Show less' state. If not provided, uses i18n message.", }, variant: { control: "select", options: ["Primary", "Secondary", "Tertiary", "Text"], table: { type: { summary: "Primary | Secondary | Tertiary | Text" }, defaultValue: { summary: "Text" }, }, }, color: { control: "select", options: ["Primary", "Inverted"], table: { type: { summary: "Primary | Inverted" }, defaultValue: { summary: "Primary" }, }, }, size: { control: "select", options: ["sm", "md", "lg"], table: { type: { summary: "sm | md | lg" }, defaultValue: { summary: "md" }, }, }, }, } export default meta type Story = StoryObj // Wrapper component that manages state for interactive stories function InteractiveShowMoreButton( props: Omit< React.ComponentProps, "showLess" | "loadMoreData" > & { initialShowLess?: boolean } ) { const [showLess, setShowLess] = useState(props.initialShowLess ?? false) const handleLoadMore = () => { setShowLess((prev) => !prev) } return ( ) } export const Default: Story = { render: (args) => , args: {}, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) // Button should now show "Show less" await userEvent.click(button) // Button should now show "Show more" again }, } export const ShowLess: Story = { render: (args) => ( ), args: {}, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) // Button should now show "Show more" await userEvent.click(button) // Button should now show "Show less" again }, } export const CustomText: Story = { render: (args) => , args: { textShowMore: "Load more items", textShowLess: "Show fewer items", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) // Button should now show "Show fewer items" await userEvent.click(button) // Button should now show "Load more items" again }, } export const PrimaryVariant: Story = { render: (args) => , args: { variant: "Primary", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) await userEvent.click(button) }, } export const SecondaryVariant: Story = { render: (args) => , args: { variant: "Secondary", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) await userEvent.click(button) }, } export const SmallSize: Story = { render: (args) => , args: { size: "sm", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) await userEvent.click(button) }, } export const LargeSize: Story = { render: (args) => , args: { size: "lg", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) await userEvent.click(button) }, } export const InvertedColor: Story = { globals: { backgrounds: { value: "scandicPrimaryDark" }, }, render: (args) => , args: { color: "Inverted", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) await userEvent.click(button) }, } export const InvertedShowLess: Story = { globals: { backgrounds: { value: "scandicPrimaryDark" }, }, render: (args) => ( ), args: { color: "Inverted", }, play: async ({ canvas, userEvent }) => { const button = await canvas.findByRole("button") await userEvent.click(button) await userEvent.click(button) }, }