switch
ora-ui/switchFreeComponent
ora-ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by ora-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ora-ui.com/r/switch.jsonSource
1'use client';23import * as React from 'react';4import { Switch as SwitchPrimitive } from '@base-ui/react/switch';56import { cn } from '@/registry/lib/utils';78type Theme = 'gray' | 'accent' | (string & {});910function Switch({11 className,12 size = 'default',13 theme = 'gray',14 checked,15 defaultChecked,16 onCheckedChange,17 ...props18}: SwitchPrimitive.Root.Props & {19 size?: 'sm' | 'default';20 theme?: Theme;21}) {22 const [internalChecked, setInternalChecked] = React.useState(checked ?? defaultChecked ?? false);23 const isChecked = checked !== undefined ? checked : internalChecked;2425 return (26 <SwitchPrimitive.Root27 data-slot="switch"28 data-size={size}29 data-theme={theme !== 'gray' && isChecked ? theme : undefined}30 checked={checked}31 defaultChecked={defaultChecked}32 onCheckedChange={(value, event) => {33 setInternalChecked(value);34 onCheckedChange?.(value, event);35 }}36 className={cn(37 'peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent outline-none transition-all after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus data-checked:focus-visible:outline-focus-fill aria-invalid:border-destructive aria-invalid:ring-[3px] aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-fill data-unchecked:bg-line data-disabled:cursor-not-allowed data-disabled:opacity-50',38 className39 )}40 {...props}41 >42 <SwitchPrimitive.Thumb43 data-slot="switch-thumb"44 className="pointer-events-none block rounded-full ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] data-checked:bg-on-fill group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 data-unchecked:bg-background dark:data-unchecked:bg-primary"45 />46 </SwitchPrimitive.Root>47 );48}4950export { Switch };
What it pulls in
npm packages
Other registry items
Files it writes
More from ora-ui
All 31 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | ora-ui | Components | Free | 2 deps | |
| alert-dialogalert-dialog | ora-ui | Components | Free | 1 dep | |
| avataravatar | ora-ui | Components | Free | 1 dep | |
| avatar-groupavatar-group | ora-ui | Components | Free | no deps | |
| badgebadge | ora-ui | Components | Free | 2 deps | |
| buttonbutton | ora-ui | Components | Free | 2 deps | |
| button-groupbutton-group | ora-ui | Components | Free | 2 deps | |
| checkboxcheckbox | ora-ui | Components | Free | 3 deps |
