import React from "react"; import Checkbox from "../app/components/Checkbox"; import { within, userEvent } from "@storybook/test"; import { expect } from "@storybook/test"; // Interaction functions for Storybook play functions const DefaultInteraction = { play: async ({ canvasElement }) => { const canvas = within(canvasElement); const checkbox = canvas.getByRole("checkbox"); expect(checkbox).toHaveAttribute("aria-checked", "false"); await userEvent.click(checkbox); expect(checkbox).toHaveAttribute("aria-checked", "true"); await userEvent.click(checkbox); expect(checkbox).toHaveAttribute("aria-checked", "false"); }, }; const CheckedInteraction = { play: async ({ canvasElement }) => { const canvas = within(canvasElement); const checkbox = canvas.getByRole("checkbox"); expect(checkbox).toHaveAttribute("aria-checked", "true"); await userEvent.click(checkbox); expect(checkbox).toHaveAttribute("aria-checked", "false"); }, }; export default { title: "Forms/Checkbox", component: Checkbox, parameters: { layout: "centered", backgrounds: { default: "dark", values: [ { name: "light", value: "#ffffff" }, { name: "dark", value: "#000000" }, ], }, }, argTypes: { checked: { control: "boolean", description: "Whether the checkbox is checked", }, mode: { control: "select", options: ["standard", "inverse", "Standard", "Inverse"], description: "Visual mode of the checkbox (case-insensitive: accepts both lowercase and PascalCase)", }, state: { control: "select", options: ["default", "hover", "focus", "Default", "Hover", "Focus"], description: "Interaction state for static display (case-insensitive: accepts both lowercase and PascalCase)", }, disabled: { control: "boolean", description: "Whether the checkbox is disabled", }, label: { control: "text", description: "Label text for the checkbox", }, }, }; export const Default = { args: { checked: false, mode: "standard", state: "default", disabled: false, label: "Default checkbox", }, play: DefaultInteraction.play, render: (args) => { const [checked, setChecked] = React.useState(args.checked); return ( setChecked(newChecked)} /> ); }, }; export const Checked = { args: { checked: true, mode: "standard", state: "default", disabled: false, label: "Checked checkbox", }, play: CheckedInteraction.play, render: (args) => { const [checked, setChecked] = React.useState(args.checked); return ( setChecked(newChecked)} /> ); }, }; export const Standard = { render: () => { const [checked, setChecked] = React.useState(false); return (

Standard Mode

setChecked(newChecked)} />
); }, }; export const Inverse = { render: () => { const [checked, setChecked] = React.useState(false); return (

Inverse Mode

setChecked(newChecked)} />
); }, }; export const Disabled = { args: { checked: false, mode: "standard", state: "default", disabled: true, label: "Disabled checkbox", }, render: (args) => , }; export const DisabledChecked = { args: { checked: true, mode: "standard", state: "default", disabled: true, label: "Disabled checked checkbox", }, render: (args) => , }; // All modes comparison export const AllModes = () => { const [standardChecked, setStandardChecked] = React.useState(false); const [inverseChecked, setInverseChecked] = React.useState(false); return (

Standard Mode

setStandardChecked(checked)} />

Inverse Mode

setInverseChecked(checked)} />
); }; // Test PascalCase props from Figma export const FigmaPascalCase = () => { const [standardChecked, setStandardChecked] = React.useState(false); const [inverseChecked, setInverseChecked] = React.useState(false); return (

Figma PascalCase Props (Standard/Inverse)

These components accept both PascalCase (from Figma) and lowercase (from codebase) prop values.

setStandardChecked(checked)} /> setInverseChecked(checked)} />

Mixed Case (backward compatibility)

); };