Switch
The iOS 26 switch: a 63×28 pt track with a 37×24 oval knob that stretches while pressed; 54×24 on macOS 26. Green or tinted when on.
In a list row
- Airplane Mode
- Wi-Fi
- Low Power Mode
- Unavailable
"use client"
import { List, ListRow, ListSection } from "@applecn/ui/components/list"
import { Switch } from "@applecn/ui/components/switch"
export default function SwitchBasic() {
return (
<List aria-label="Connectivity">
<ListSection>
<ListRow
title="Airplane Mode"
trailing={<Switch aria-label="Airplane Mode" />}
/>
<ListRow
title="Wi-Fi"
trailing={<Switch aria-label="Wi-Fi" defaultChecked />}
/>
<ListRow
title="Low Power Mode"
trailing={
<Switch aria-label="Low Power Mode" color="tint" defaultChecked />
}
/>
<ListRow
title="Unavailable"
trailing={<Switch aria-label="Unavailable" disabled />}
/>
</ListSection>
</List>
)
}Install
From the registry this site publishes, with dependencies resolved by the CLI.
npx shadcn@latest add https://applecn.vercel.app/r/switch.jsonSource
packages/ui/src/components/switch.tsx
"use client"
import { Switch as SwitchPrimitive } from "@base-ui/react/switch"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
/**
* The switch (HIG › Toggles). iOS 26: a 63×28 track with a 37×24 oval Liquid Glass knob inset
* 2 pt that stretches while pressed; macOS 26: 54×24 with a 31×20 knob; Apple's web apps keep
* the 51×31 switch. All from the platform tokens. On is system green by default, `color="tint"`
* the accent colour; off is the tertiary label. Use it in list rows, where the row text is the
* label.
*/
const switchVariants = cva(
"peer group/switch relative inline-flex h-(--switch-height) w-(--switch-width) shrink-0 items-center rounded-full transition-[background-color] duration-(--duration-hover) ease-(--ease-standard) outline-none focus-visible:ring-4 focus-visible:ring-ring/60 data-unchecked:bg-label-3 data-disabled:cursor-not-allowed data-disabled:opacity-40",
{
variants: {
color: {
green: "data-checked:bg-system-green",
tint: "data-checked:bg-primary",
},
},
defaultVariants: {
color: "green",
},
}
)
type SwitchProps = SwitchPrimitive.Root.Props &
VariantProps<typeof switchVariants>
function Switch({ className, color = "green", ...props }: SwitchProps) {
return (
<SwitchPrimitive.Root
data-slot="switch"
data-color={color}
className={cn(switchVariants({ color }), className)}
{...props}
>
<SwitchPrimitive.Thumb
data-slot="switch-thumb"
className="pointer-events-none absolute start-(--switch-inset) block h-(--switch-thumb-height) w-(--switch-thumb-width) knob group-active/switch:w-[calc(var(--switch-thumb-width)+6px)] data-checked:translate-x-[calc(var(--switch-width)-var(--switch-thumb-width)-2*var(--switch-inset))] group-active/switch:data-checked:translate-x-[calc(var(--switch-width)-var(--switch-thumb-width)-2*var(--switch-inset)-6px)] rtl:data-checked:-translate-x-[calc(var(--switch-width)-var(--switch-thumb-width)-2*var(--switch-inset))] data-unchecked:translate-x-0"
/>
</SwitchPrimitive.Root>
)
}
export { Switch, switchVariants }
export type { SwitchProps }