import React, { useState } from "react"; import { screen, userEvent } from "@storybook/testing-library"; import { expect } from "@storybook/jest"; import { Tabs } from "."; import { styled, theme } from "../theme"; import { Info } from "@washingtonpost/wpds-assets"; import { Icon } from "../icon"; import type { Meta, StoryFn } from "@storybook/react"; export default { title: "Tabs", component: Tabs.Root, subcomponents: { List: Tabs.List, Trigger: Tabs.Trigger, Content: Tabs.Content, }, argTypes: { align: { options: ["center", "left"], control: "select", }, density: { options: ["compact", "default", "loose"], control: "select", }, disabled: { options: [true, false], control: "boolean", }, }, } as Meta; const StyledTabs = styled("div", { backgroundColor: theme.colors.secondary, width: "500px", border: `1px dashed ${theme.colors.primary}`, padding: "10px", }); const StyledLabel = styled("div", { marginBottom: "10px", color: theme.colors.primary, }); const StyledStack = styled("div", { display: "flex", flexDirection: "column", gap: theme.space["100"], }); const StyledContent = styled(Tabs.Content, { minHeight: "50px", paddingTop: "20px", color: theme.colors.primary, }); // eslint-disable-next-line @typescript-eslint/no-explicit-any const Template: StoryFn = (args) => { const { density, align, ...rest } = args; return ( <> Outline for viewing alignment purposes only France Brazil The Democratic Republic of the Congo Vietnam Papua New Guinea Venezuela Kenya Austria France is here 🇫🇷 Brazil is here 🇧🇷 This is disabled and should not show The Democratic Republic of the Congo is here 🇨🇩 Vietnam is here 🇻🇳 Papua New Guinea is here 🇵🇬 Venezuela is here 🇻🇪 Kenya is here 🇰🇪 Austria is here 🇦🇹 ); }; export const Play = { render: Template, args: { density: "default", }, name: "Default", }; // eslint-disable-next-line @typescript-eslint/no-explicit-any const TemplateShort: StoryFn = (args) => { const { density, align, ...rest } = args; return ( <> Outline for viewing alignment purposes only France Kenya Austria France is here 🇫🇷 Kenya is here 🇰🇪 Austria is here 🇦🇹 ); }; export const Center = { render: TemplateShort, args: { align: "center", density: "compact", }, }; // eslint-disable-next-line @typescript-eslint/no-explicit-any const TemplateDensity: StoryFn = () => { return ( Outline for viewing alignment purposes only France Brazil Vietnam France Brazil Vietnam France Brazil Vietnam ); }; export const Density = { render: TemplateDensity, }; // eslint-disable-next-line @typescript-eslint/no-explicit-any const TemplateControlled: StoryFn = (args) => { const { density, align, ...rest } = args; const [value, setValue] = useState("tab3"); return ( <> Outline for viewing alignment purposes only { setValue(val); }} > France Kenya Austria France is here 🇫🇷 Kenya is here 🇰🇪 Austria is here 🇦🇹
); }; export const ControlledExample = { render: TemplateControlled, }; // eslint-disable-next-line @typescript-eslint/no-explicit-any const InteractionsTemplate: StoryFn = (args) => ( France Brazil The Democratic Republic of the Congo Vietnam Papua New Guinea Venezuela Kenya Austria France is here 🇫🇷 Brazil is here 🇧🇷 This is disabled and should not show The Democratic Republic of the Congo is here 🇨🇩 Vietnam is here 🇻🇳 Papua New Guinea is here 🇵🇬 Venezuela is here 🇻🇪 Kenya is here 🇰🇪 Austria is here 🇦🇹 ); export const Interactions = { render: InteractionsTemplate, args: { align: "center", density: "compact", }, parameters: { chromatic: { disableSnapshot: true }, }, play: async () => { const trigger = screen.getAllByRole("tab"); // eslint-disable-next-line testing-library/no-node-access const icon = trigger[0].getElementsByTagName("svg")[0]; await expect(icon).toBeVisible(); await expect(trigger[0]).toHaveAttribute("aria-selected", "true"); await expect(trigger[4]).not.toHaveAttribute("aria-selected", "true"); await expect(trigger).toHaveLength(8); await expect(trigger[1]).toBeDisabled(); await expect(trigger[4]).toBeDefined(); await userEvent.click(trigger[4]); await expect(trigger[0]).not.toHaveAttribute("aria-selected", "true"); await expect(trigger[4]).toHaveAttribute("aria-selected", "true"); //Test that trigger shows up for truncated item const tooltipTrigger = screen.getAllByTestId("tabs-tooltip-trigger"); await userEvent.hover(tooltipTrigger[0]); await sleep(300); const tooltipContent = await screen.findAllByTestId("tabs-tooltip-content"); await sleep(300); await expect(tooltipContent[0]).toBeInTheDocument(); }, }; // Function to emulate pausing between interactions function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }