npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@darksnow-ui/switch

v1.0.0

Published

switch component for DarkSnow UI

Readme

Switch

A control that allows the user to toggle between checked and not checked. Built on top of Radix UI Switch primitive.

Installation

npm install @darksnow-ui/switch

Peer Dependencies

npm install react react-dom

Usage

import { Switch } from "@darksnow-ui/switch"
import { Label } from "@darksnow-ui/label"

export function SwitchExample() {
  return (
    <div className="flex items-center space-x-2">
      <Switch id="airplane-mode" />
      <Label htmlFor="airplane-mode">Airplane mode</Label>
    </div>
  )
}

Props

| Prop | Type | Default | Description | |---------------|-------------------|---------|--------------------------------| | checked | boolean | - | Controlled checked state | | defaultChecked| boolean | false | Default checked state | | onCheckedChange| function | - | Called when checked changes | | disabled | boolean | false | Disables the switch | | name | string | - | Form name attribute | | value | string | "on" | Form value when checked | | id | string | - | HTML id attribute | | className | string | - | Additional CSS classes |

Examples

Basic Switch

<div className="flex items-center space-x-2">
  <Switch id="s1" />
  <Label htmlFor="s1">Enable notifications</Label>
</div>

Controlled Switch

function ControlledSwitch() {
  const [checked, setChecked] = useState(false)

  return (
    <div className="flex items-center space-x-2">
      <Switch 
        id="controlled" 
        checked={checked} 
        onCheckedChange={setChecked} 
      />
      <Label htmlFor="controlled">
        {checked ? "Enabled" : "Disabled"}
      </Label>
    </div>
  )
}

Disabled Switch

<div className="space-y-4">
  <div className="flex items-center space-x-2">
    <Switch id="disabled-off" disabled />
    <Label htmlFor="disabled-off">Disabled (off)</Label>
  </div>
  <div className="flex items-center space-x-2">
    <Switch id="disabled-on" disabled defaultChecked />
    <Label htmlFor="disabled-on">Disabled (on)</Label>
  </div>
</div>

Form Integration

<form>
  <div className="space-y-4">
    <div className="flex items-center space-x-2">
      <Switch id="marketing" name="notifications" value="marketing" />
      <Label htmlFor="marketing">Marketing emails</Label>
    </div>
    <div className="flex items-center space-x-2">
      <Switch id="security" name="notifications" value="security" defaultChecked />
      <Label htmlFor="security">Security updates</Label>
    </div>
  </div>
</form>

Settings Panel

<div className="space-y-6">
  <div>
    <h3 className="text-lg font-medium">Privacy Settings</h3>
    <div className="mt-4 space-y-4">
      <div className="flex items-center justify-between">
        <div className="space-y-1">
          <Label htmlFor="analytics">Analytics</Label>
          <p className="text-sm text-theme-content-muted">
            Help us improve our product by sharing usage data.
          </p>
        </div>
        <Switch id="analytics" />
      </div>
      <div className="flex items-center justify-between">
        <div className="space-y-1">
          <Label htmlFor="marketing">Marketing</Label>
          <p className="text-sm text-theme-content-muted">
            Receive emails about new products and features.
          </p>
        </div>
        <Switch id="marketing" />
      </div>
    </div>
  </div>
</div>

Accessibility

  • Full keyboard support (Space and Enter keys)
  • Screen reader accessible with proper ARIA attributes
  • Focus management and focus indicators
  • Supports labeling and descriptions
  • Form integration support

Styling

The Switch component uses DarkSnow UI design tokens:

  • Track: Background changes between checked/unchecked states
  • Thumb: Circular indicator that slides between positions
  • Focus: Ring outline on focus
  • Disabled: Reduced opacity and disabled cursor
  • Transitions: Smooth animations for state changes

States

  • Unchecked: bg-theme-mark-light
  • Checked: bg-theme-accent
  • Disabled: opacity-50 cursor-not-allowed
  • Focus: ring-2 ring-theme-accent-sm

Best Practices

  1. Always use labels: Associate switches with descriptive labels
  2. Clear states: Make it obvious what the switch controls
  3. Immediate feedback: Provide immediate visual feedback on toggle
  4. Logical defaults: Choose sensible default states
  5. Group related switches: Organize related settings together

Related Components