PeakUIPro

CellSwitch

Toggle switch styled as a settings cell

Usage

import {CellSwitch} from "@peakui-pro/react";

Anatomy

The Trigger is the whole clickable row — the label and the control inside it toggle the switch.

import {CellSwitch} from "@peakui-pro/react";

// Rendered as: the Trigger (a <label>), the Label span, then the Control with its thumb.
export default () => (
  <CellSwitch>
    <CellSwitch.Trigger>
      <CellSwitch.Label>Autoplay</CellSwitch.Label>
      <CellSwitch.Control />
    </CellSwitch.Trigger>
  </CellSwitch>
);

Examples

Variants

variant restyles the row and the resting track together.

Controlled

Settings Group

The row's leading label names the switch; the cell fills the value column.

Secondary Group

Disabled

Feature Announcement

Customization

Tailwind CSS

<CellSwitch className="w-full border border-border rounded-xl">
  <CellSwitch.Trigger>…</CellSwitch.Trigger>
</CellSwitch>

Global CSS

@layer components {
  /* The secondary track's resting fill; hover and pressed derive from it. */
  .cell-switch__control--secondary {
    --switch-control-bg: color-mix(in oklab, var(--default-foreground) 20%, transparent);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The CellSwitch component uses these CSS classes (view source styles):

Base Classes

  • .cell-switch - The root; fills the row a settings table gives it
  • .cell-switch--secondary - The secondary variant on the root

Element Classes

  • .cell-switch__trigger - The clickable row; a surface 36px high with the label leading
  • .cell-switch__trigger--default - The default trigger variant
  • .cell-switch__trigger--secondary - A quieter row: bg-default-soft with no surface shadow
  • .cell-switch__label - The leading label; takes the room the control leaves and truncates
  • .cell-switch__control - The switch track; the core Switch's own with the cell's name
  • .cell-switch__control--secondary - A neutral resting track instead of the default token

Slots

  • [data-slot="cell-switch"] - The root element
  • [data-slot="cell-switch-trigger"] - The clickable row
  • [data-slot="cell-switch-label"] - The label
  • [data-slot="cell-switch-control"] - The track; the thumb inside is the core's [data-slot="switch-thumb"]

API Reference

CellSwitch

PropTypeDefaultDescription
variant'default' | 'secondary''default'The cell's own variant axis; the core Switch beneath it has none
childrenReactNode-The parts
classNamestring-Additional classes
renderDOMRenderFunction<'div', SwitchFieldRenderProps>-Replaces the rendered <div> with your own element
...restComponentProps<typeof SwitchRoot>-The core Switch root's props: isSelected, defaultSelected, onChange, isDisabled, aria-label and the rest of React Aria's SwitchField attributes

CellSwitch.Trigger

PropTypeDefaultDescription
childrenReactNode-The row's content — the Label and the Control
classNamestring-Additional classes
renderDOMRenderFunction<'label', SwitchButtonRenderProps>-Replaces the rendered <label> with your own element
...restComponentProps<typeof SwitchContent>-The core Switch.Content's props, React Aria's SwitchButton attributes among them

CellSwitch.Label

PropTypeDefaultDescription
childrenReactNode-The label text; names the switch
classNamestring-Additional classes
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span> with your own element
...restComponentProps<'span'>-Native <span> attributes

CellSwitch.Control

PropTypeDefaultDescription
childrenReactNode-Custom control content; the core's thumb renders without it
classNamestring-Additional classes
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span> with your own element; E defaults to 'span'
...restComponentProps<typeof SwitchControl<"span">>-The core Switch.Control's props, native <span> attributes among them

On this page