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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@custmaz/switch-toggle-buttons

v0.1.0

Published

Accessible React switch and single-select toggle button components with CSS-variable theming

Readme

A streamlined UI component library for switches and multi-option toggle groups in React.

React Switch & Toggle Buttons

Two focused UI controls:

Switch (Binary Toggle)

  • iOS-style binary toggle
  • Supports text or icons in track and thumb
  • widthMode="auto" prevents label clipping
  • Horizontal and vertical layouts
  • No layout shift during animation

Toggle Button Group

  • Single-select (radio-group behavior)
  • Supports text and/or icons
  • Horizontal and vertical layouts
  • Unlimited items

Shared Features

  • Fully controlled (no hidden state)
  • Accessible (ARIA compliant)
  • CSS-variable theming (no CSS-in-JS)
  • No runtime styling
  • SSR safe

Designed for dashboards and settings-heavy UIs where predictability matters.


Why This Library?

  • Content-aware sizing (widthMode="auto") prevents label clipping
  • Fully controlled, predictable state
  • CSS-variable theming (no runtime styles)
  • Layout-safe animations (no shift)
  • SSR safe

Installation

npm install @custmaz/switch-toggle-buttons

Import default styles:

import '@custmaz/switch-toggle-buttons/styles.css';

Basic Usage

Switch (Two-way)

import { useState } from 'react';
import { Switch } from '@custmaz/switch-toggle-buttons';

export default function Example() {
  const [enabled, setEnabled] = useState(false);

  return (
    <Switch
      checked={enabled}
      onCheckedChange={setEnabled}
      aria-label="Enable notifications"
    />
  );
}

With track & thumb content


<Switch
  checked={enabled}
  onCheckedChange={setEnabled}
  widthMode="auto"
  trackContent={{
    off: 'Disabled',
    on: 'Enabled',
  }}
  thumbContent="✓"
/>

ToggleButtons (Multi-option)


import { useState } from 'react';
import { ToggleButtons, ToggleButtonItem } from '@custmaz/switch-toggle-buttons';

export default function LayoutToggle() {
  const [layout, setLayout] = useState('grid');

  return (
    <ToggleButtons value={layout} onValueChange={setLayout}>
      <ToggleButtonItem value="grid">Grid</ToggleButtonItem>
      <ToggleButtonItem value="list">List</ToggleButtonItem>
    </ToggleButtons>
  );
}

Vertical layout


<ToggleButtons value={mode} onValueChange={setMode} orientation="vertical">
  <ToggleButtonItem value="write">Write</ToggleButtonItem>
  <ToggleButtonItem value="preview">Preview</ToggleButtonItem>
  <ToggleButtonItem value="split">Split</ToggleButtonItem>
</ToggleButtons>

Customisation & Theming

This library is CSS-first, fully controlled via CSS variables:

  • No CSS-in-JS
  • No runtime style injection
  • No global resets
  • Easy dark mode integration

All styling is controlled through CSS variables.

Example: global theme

:root {
  --tb-bg-track: #e5e7eb;
  --tb-bg-track-active: #6366f1;
  --tb-bg-thumb: #ffffff;
  --tb-bg-thumb-active: #111827;

  --tb-text-inactive: #4b5563;
  --tb-text-active: #111827;

  --tb-radius-pill: 9999px;
  --tb-transition-medium: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

Per-component overrides


.my-switch {
  --tb-bg-track-active: #ff6b6b;
  --tb-bg-thumb: #ffffff;
}

.my-toggle-group {
  --tb-bg-track: #f0f0f0;
  --tb-text-active: #ff3b30;
}

Dark mode example

<body data-theme="dark">
[data-theme="dark"] {
  --tb-bg-track: #2a2a2a;
  --tb-bg-track-active: #818cf8;
  --tb-bg-thumb: #1f1f1f;
  --tb-text-active: #ffffff;
}

Render Props

ToggleButtonItem supports render props for more control over icons or content:

<ToggleButtonItem value="grid">
  {(isActive) => (
    <>
      <GridIcon color={isActive ? 'var(--tb-text-active)' : 'var(--tb-text-inactive)'} />
      <p>Grid</p>
    </>
  )}
</ToggleButtonItem>

This is optional. If you just pass children, the component will compute the active state internally.


Accessibility

Accessibility is built-in and follows standard ARIA patterns.

Switch

  • role="switch"
  • aria-checked reflects state
  • Keyboard support (Enter/Space)
  • aria-orientation supported (horizontal/vertical)
  • aria-label required if no visible label

Toggle Button Group

  • role="radiogroup" on container
  • role="radio" per item
  • Full keyboard navigation:
    • Arrow keys navigate
    • Space/Enter selects
    • Home/End jump bounds

Follows WAI-ARIA radio group behavior. No custom or non-standard key bindings.


Maintainer

Maintained solely by the author. External contributions may be considered.

See the Changelog for details on versions and updates.


Issues

Report bugs or request features on GitHub:

https://github.com/custmaz/switch-toggle-buttons/issues


License

MIT