/** * Copyright (c) 2023-present Plane Software, Inc. and contributors * SPDX-License-Identifier: AGPL-3.0-only * See the LICENSE file for details. */ import { useState } from "react"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { useArgs } from "storybook/preview-api"; import { Switch } from "./root"; const meta = { title: "Components/Switch", component: Switch, parameters: { layout: "centered", }, tags: ["autodocs"], args: { value: false, onChange: () => {} }, render(args) { const [{ value }, updateArgs] = useArgs(); const setValue = (newValue: boolean) => updateArgs({ value: newValue }); return ; }, } satisfies Meta; export default meta; type Story = StoryObj; export const Default: Story = {}; export const Checked: Story = { args: { value: true }, }; export const WithLabel: Story = { render(args) { const [value, setValue] = useState(args.value); return (
); }, }; export const Small: Story = { args: { size: "sm" }, }; export const Medium: Story = { args: { size: "md" }, }; export const Large: Story = { args: { size: "lg" }, }; export const Disabled: Story = { args: { disabled: true }, }; export const DisabledChecked: Story = { args: { value: true, disabled: true }, }; export const AllSizes: Story = { render() { const [small, setSmall] = useState(false); const [medium, setMedium] = useState(false); const [large, setLarge] = useState(false); return (

Small

Medium

Large

); }, }; export const AllStates: Story = { render() { const [unchecked, setUnchecked] = useState(false); const [checked, setChecked] = useState(true); const [disabledUnchecked] = useState(false); const [disabledChecked] = useState(true); return (
Unchecked
Checked
{}} disabled /> Disabled Unchecked
{}} disabled /> Disabled Checked
); }, }; export const InForm: Story = { render() { const [notifications, setNotifications] = useState(true); const [marketing, setMarketing] = useState(false); const [updates, setUpdates] = useState(true); return (

Notification Settings

Push Notifications

Receive push notifications on your device

Marketing Emails

Receive emails about new features

Product Updates

Get notified about product updates

); }, }; export const WithDescription: Story = { render() { const [enabled, setEnabled] = useState(false); return (

Enable Two-Factor Authentication

Add an extra layer of security to your account by enabling two-factor authentication.

); }, }; export const Interactive: Story = { render() { const [enabled, setEnabled] = useState(false); return (
Feature Toggle

Status: {enabled ? "Enabled" : "Disabled"}

{enabled &&

Feature is now active and ready to use!

}
); }, }; export const CustomStyles: Story = { render() { const [value, setValue] = useState(false); return (
Custom styled switch
); }, }; export const MultipleControls: Story = { render() { const [settings, setSettings] = useState({ feature1: true, feature2: false, feature3: true, feature4: false, feature5: true, }); const toggleSetting = (key: keyof typeof settings) => { setSettings((prev) => ({ ...prev, [key]: !prev[key] })); }; return (

Feature Flags

{Object.entries(settings).map(([key, value]) => (
{key.replace(/([A-Z])/g, " $1").trim()} toggleSetting(key as keyof typeof settings)} size="sm" />
))}
); }, };