"use client" import { useState } from "react" import { Switch } from "@/components/ui/switch" import { Label } from "@/components/ui/label" import { ComponentContainer } from "@/components/ui/component-container" import { SectionHeading } from "@/components/ui/section-heading" import { PageBreadcrumb } from "@/components/page-breadcrumb" export function ToggleSection() { const [basicToggle, setBasicToggle] = useState(false) const [labelToggle, setLabelToggle] = useState(true) const [formToggle, setFormToggle] = useState(false) // Properties for the interactive switch const [switchChecked, setSwitchChecked] = useState(false) const [switchDisabled, setSwitchDisabled] = useState(false) const [switchSize, setSwitchSize] = useState<"default" | "sm" | "lg">("default") const [showLabel, setShowLabel] = useState(true) const [labelText, setLabelText] = useState("Enable notifications") const [labelPosition, setLabelPosition] = useState<"left" | "right">("right") const getSwitchSizeClasses = (size: string) => { switch (size) { case "sm": return "h-4 w-7" case "lg": return "h-7 w-12" default: return "h-6 w-11" } } const generateCode = (props: Record) => { const { checked, disabled, size, showLabel, labelText, labelPosition } = props const sizeClasses = size !== "default" ? ` className="${getSwitchSizeClasses(size)}"` : "" const disabledProp = disabled ? " disabled" : "" const checkedProp = checked ? " checked" : "" if (!showLabel) { return `import { Switch } from "@/components/ui/switch" export function SwitchDemo() { return }` } const labelComponent = `` const switchComponent = `` if (labelPosition === "left") { return `import { Switch } from "@/components/ui/switch" import { Label } from "@/components/ui/label" export function SwitchDemo() { return (
${labelComponent} ${switchComponent}
) }` } return `import { Switch } from "@/components/ui/switch" import { Label } from "@/components/ui/label" export function SwitchDemo() { return (
${switchComponent} ${labelComponent}
) }` } const renderInteractiveSwitch = (props: Record) => { const { checked, disabled, size, showLabel, labelText, labelPosition } = props return (
{showLabel && labelPosition === "left" && } {showLabel && labelPosition === "right" && }
) } const switchProperties = [ { name: "checked", type: "boolean" as const, defaultValue: false, label: "Checked", description: "Whether the switch is checked", }, { name: "disabled", type: "boolean" as const, defaultValue: false, label: "Disabled", description: "Whether the switch is disabled", }, { name: "size", type: "select" as const, defaultValue: "default", label: "Size", options: ["sm", "default", "lg"], description: "Size of the switch", }, { name: "showLabel", type: "boolean" as const, defaultValue: true, label: "Show Label", description: "Whether to show a label", }, { name: "labelText", type: "text" as const, defaultValue: "Enable notifications", label: "Label Text", description: "Text for the label", }, { name: "labelPosition", type: "select" as const, defaultValue: "right", label: "Label Position", options: ["left", "right"], description: "Position of the label relative to switch", }, ] return (
}`} >
) }`} >
) }`} >
Receive emails about new products, features, and more.
) }`} >
Receive emails about new products, features, and more.
}`} >
) }