import React from "react"; import { Switch } from "."; import type { ComponentMeta, ComponentStory } from "@storybook/react"; import { styled } from "../theme"; import { userEvent, within } from "@storybook/testing-library"; import { expect } from "@storybook/jest"; export default { title: "Switch", component: Switch.Root, subcomponents: { Root: Switch.Root, Thumb: Switch.Thumb, }, argTypes: { variant: { control: "select", options: ["primary", "cta"], }, }, } as ComponentMeta; const Template: ComponentStory = (args) => ( ); export const Default = Template.bind({}); Default.args = {}; export const Interactions = Template.bind({}); Interactions.args = {}; Interactions.play = async ({ canvasElement }) => { const canvas = within(canvasElement); const root = canvas.getByRole("switch"); await userEvent.click(root); await expect(root).toBeChecked(); await userEvent.click(root); await expect(root).not.toBeChecked(); }; export const CTA = Template.bind({}); CTA.args = { variant: "cta", }; export const Error = Template.bind({}); Error.args = { error: true, }; export const Disabled = Template.bind({}); Disabled.args = { disabled: true, name: "disabled-switch", }; export const Mobile = Template.bind({}); Mobile.args = {}; Mobile.parameters = { viewport: { defaultViewport: "iphonex", }, }; const Stack = styled("div", { display: "flex", flexDirection: "column", gap: "$100", }); const ManyTemplate: ComponentStory = (args) => ( ); export const Many = ManyTemplate.bind({}); Many.args = {};