import React from "react"; import {ComponentStory, ComponentMeta} from "@storybook/react"; import {toggle} from "@nextui-org/theme"; import {VisuallyHidden} from "@react-aria/visually-hidden"; import {SunFilledIcon, MoonFilledIcon} from "@nextui-org/shared-icons"; import {clsx} from "@nextui-org/shared-utils"; import {Switch, SwitchProps, SwitchThumbIconProps, useSwitch} from "../src"; export default { title: "Components/Switch", component: Switch, argTypes: { color: { control: { type: "select", options: ["neutral", "primary", "secondary", "success", "warning", "danger"], }, }, size: { control: { type: "select", options: ["xs", "sm", "md", "lg", "xl"], }, }, isDisabled: { control: { type: "boolean", }, }, disableAnimation: { control: { type: "boolean", }, }, }, } as ComponentMeta; const defaultProps = { ...toggle.defaultVariants, }; const Template: ComponentStory = (args: SwitchProps) => ; const WithIconsTemplate: ComponentStory = (args: SwitchProps) => { const [isSelected, setIsSelected] = React.useState(true); return (
} rightIcon={} styles={{ leftIcon: "text-white", }} onChange={setIsSelected} />

Selected: {isSelected ? "true" : "false"}

); }; const ControlledTemplate: ComponentStory = (args: SwitchProps) => { const [isSelected, setIsSelected] = React.useState(true); return (

Selected: {isSelected ? "true" : "false"}

); }; const CustomWithStylesTemplate: ComponentStory = (args: SwitchProps) => { const [isSelected, setIsSelected] = React.useState(true); return (

Enable early access

Get access to new features before they are released.

Selected: {isSelected ? "true" : "false"}

); }; const CustomWithHooksTemplate: ComponentStory = (args: SwitchProps) => { const {Component, slots, isSelected, getBaseProps, getInputProps, getWrapperProps} = useSwitch(args); return (
{isSelected ? : }

Lights: {isSelected ? "on" : "off"}

); }; export const Default = Template.bind({}); Default.args = { ...defaultProps, }; export const IsReadOnly = Template.bind({}); IsReadOnly.args = { ...defaultProps, isReadOnly: true, defaultSelected: true, }; export const WithLabel = Template.bind({}); WithLabel.args = { ...defaultProps, children: "Bluetooth", }; export const DisableAnimation = Template.bind({}); DisableAnimation.args = { ...defaultProps, disableAnimation: true, }; export const WithThumbIcon = Template.bind({}); WithThumbIcon.args = { ...defaultProps, thumbIcon: (props: SwitchThumbIconProps) => props.isSelected ? ( ) : ( ), }; export const WithIcons = WithIconsTemplate.bind({}); WithIcons.args = { ...defaultProps, }; export const Controlled = ControlledTemplate.bind({}); Controlled.args = { ...defaultProps, }; export const CustomWithStyles = CustomWithStylesTemplate.bind({}); CustomWithStyles.args = { ...defaultProps, }; export const CustomWithHooks = CustomWithHooksTemplate.bind({}); CustomWithHooks.args = { ...defaultProps, };