Switch 10

PreviousNext

A switch with icon label that toggles between sun and moon icons for theme switching

Docs
shadcn-studiocomponent

Preview

Loading preview…
registry/new-york/components/switch/switch-10.tsx
'use client'

import { useState } from 'react'

import { MoonIcon, SunIcon } from 'lucide-react'

import { Label } from '@/registry/new-york/ui/label'
import { Switch } from '@/registry/new-york/ui/switch'

const SwitchIconLabelDemo = () => {
  const [checked, setChecked] = useState<boolean>(true)

  return (
    <div className='inline-flex items-center gap-2'>
      <Switch id='icon-label' checked={checked} onCheckedChange={setChecked} aria-label='Toggle switch' />
      <Label htmlFor='icon-label'>
        <span className='sr-only'>Toggle switch</span>
        {checked ? (
          <MoonIcon className='size-4' aria-hidden='true' />
        ) : (
          <SunIcon className='size-4' aria-hidden='true' />
        )}
      </Label>
    </div>
  )
}

export default SwitchIconLabelDemo

Installation

npx shadcn@latest add @shadcn-studio/switch-10

Usage

import { Switch10 } from "@/components/switch-10"
<Switch10 />