import React, { useState } from "react"; import { screen, userEvent } from "@storybook/testing-library"; import { expect } from "@storybook/jest"; import { RadioGroup as Component, RadioButton } from "./"; import { styled, css, theme } from "../theme"; import { Box } from "../box"; import type { Meta, StoryFn } from "@storybook/react"; export default { title: "RadioGroup", component: Component, subcomponents: { RadioButton }, } as Meta; const Template: StoryFn = (args) => ( ); export const RadioGroup = { render: Template, args: { legend: "Select an option", name: "my-value", }, argTypes: { errorMessage: { control: "text", }, }, parameters: { chromatic: { disableSnapshot: true }, }, }; const WrapTemplate: StoryFn = (args) => ( ); export const WrapOptions = { render: WrapTemplate, args: { legend: "Select an option", name: "my-value", orientation: "horizontal", }, parameters: { chromatic: { disableSnapshot: true }, }, }; const OverflowTemplate: StoryFn = () => ( ); export const Overflow = { render: OverflowTemplate, parameters: { chromatic: { disableSnapshot: true }, }, }; const ControlledTemplate: StoryFn = () => { const [value, setValue] = useState("opt1"); function handleValueChange(val) { setValue(val); } return ( ); }; export const Controlled = { render: ControlledTemplate, parameters: { chromatic: { disableSnapshot: true }, }, }; const Column = styled("div", { display: "flex", flexDirection: "column", gap: "$100", alignItems: "center", marginBlockStart: "$200", }); const HStack = styled("section", { display: "flex", flexDirection: "row", gap: "$100", borderRadius: "$075", }); const Heading = styled("h2", { color: theme.colors.primary, fontSize: theme.fontSizes["112"], marginBlock: 0, }); const ChromaticTemplate: StoryFn = () => ( Variants isOutline
Secondary } variant="secondary" name="o-sec" isOutline >
Disabled Error Overflow
); export const Chromatic = { render: ChromaticTemplate, args: {}, }; const InteractionsTemplate: StoryFn = () => ( ); export const Interactions = { render: InteractionsTemplate, parameters: { chromatic: { disableSnapshot: true }, }, play: async () => { const input1 = screen.getByLabelText("Option 1"); const input2 = screen.getByLabelText("Option 2"); await userEvent.click(input1); await expect(input1).toBeChecked(); await userEvent.keyboard("[ArrowDown]"); await sleep(0); await userEvent.keyboard(" "); await expect(input2).toBeChecked(); }, }; // Function to emulate pausing between interactions function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }