Switch
scificn/switchFreeComponent
Toggle switch with ASCII bracket style [OFF]/[ON] display.
Live preview
live · rendered by the registry
Rendered by scificn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.scificn.dev/r/switch.jsonSource
1import * as React from 'react'2import * as SwitchPrimitive from '@radix-ui/react-switch'3import { cn } from '@/lib/utils'45export interface SwitchProps6 extends React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root> {7 label?: string8}910const Switch = React.forwardRef<11 React.ElementRef<typeof SwitchPrimitive.Root>,12 SwitchProps13>(({ className, label, id, ...props }, ref) => {14 const switchId = id ?? label?.toLowerCase().replace(/\s+/g, '-')1516 return (17 <div style={{ display: 'inline-flex', alignItems: 'center', gap: '0.625rem' }}>18 <SwitchPrimitive.Root19 ref={ref}20 id={switchId}21 className={cn(22 'peer inline-flex items-center shrink-0',23 'h-6 w-14',24 'rounded-none',25 'border border-[var(--border)]',26 'bg-[var(--surface)]',27 'cursor-pointer',28 'focus-visible:outline-none',29 'focus-visible:border-[var(--border-active)]',30 'focus-visible:shadow-[var(--glow-green)]',31 'disabled:cursor-not-allowed disabled:opacity-40',32 'data-[state=checked]:border-[var(--color-green)]',33 'data-[state=checked]:shadow-[var(--glow-green)]',34 'transition-all duration-150',35 'font-mono text-[0.6rem] tracking-widest',36 'relative overflow-hidden',37 className38 )}39 {...props}40 >41 {/* OFF label */}42 <span43 className="absolute left-1.5 select-none"44 style={{45 color: 'var(--text-muted)',46 letterSpacing: '0.04em',47 fontSize: '0.6rem',48 transition: 'opacity 0.15s',49 }}50 aria-hidden="true"51 >52 [OFF]53 </span>5455 <SwitchPrimitive.Thumb asChild>56 {/* Invisible thumb — state is conveyed via root styles + text */}57 <span style={{ display: 'none' }} />58 </SwitchPrimitive.Thumb>5960 {/* ON label — shows when checked via CSS */}61 <span62 className="absolute right-1.5 select-none peer-data-[state=unchecked]:opacity-0"63 style={{64 color: 'var(--color-green)',65 textShadow: 'var(--text-glow-green)',66 letterSpacing: '0.04em',67 fontSize: '0.6rem',68 transition: 'opacity 0.15s',69 }}70 aria-hidden="true"71 >72 [ON]73 </span>74 </SwitchPrimitive.Root>7576 {label && (77 <label78// … truncated
What it pulls in
npm packages
More from scificn
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alertalert | scificn | Components | Free | 1 dep | |
| Badgebadge | scificn | Components | Free | 1 dep | |
| Bar Chartbar-chart | scificn | Components | Free | no deps | |
| Breadcrumbbreadcrumb | scificn | Components | Free | no deps | |
| Buttonbutton | scificn | Components | Free | 2 deps | |
| Cardcard | scificn | Components | Free | no deps | |
| Checkboxcheckbox | scificn | Components | Free | 1 dep | |
| Dialogdialog | scificn | Components | Free | 1 dep |
