Reticle@etched/reticle 0.0.0

Switch

Turns one setting on or off at once. For a choice saved with a form, prefer a Checkbox.

Kumo source
import { Switch } from "@etched/reticle/switch";

export function Preview() {
  return <Switch label="Email alerts" defaultChecked />;
}

Installation

import { Switch, SwitchGroup, SwitchItem, SwitchLegend } from "@etched/reticle/switch";

Examples

States

import { Switch } from "@etched/reticle/switch";

export function States() {
  return (
    <div className="row">
      <Switch aria-label="Off" />
      <Switch aria-label="On" defaultChecked />
      <Switch aria-label="Disabled" disabled />
      <Switch aria-label="Disabled and on" disabled defaultChecked />
      <Switch aria-label="Neutral" variant="neutral" />
      <Switch aria-label="Neutral and on" variant="neutral" defaultChecked />
    </div>
  );
}

Sizes

import { Switch, type SwitchSize } from "@etched/reticle/switch";

const sizes: SwitchSize[] = ["sm", "base", "lg"];

export function Sizes() {
  return (
    <div className="row">
      {sizes.map((s) => (
        <Switch key={s} size={s} label={s} defaultChecked />
      ))}
    </div>
  );
}

Labels

transitioning marks a switch busy while its change saves.

import { Switch } from "@etched/reticle/switch";

export function Labels() {
  return (
    <div className="grid">
      <Switch label="Break down by full-time and internship" />
      <Switch label="Label first" controlFirst={false} defaultChecked />
      <Switch label="Send a weekly digest" required={false} />
      <Switch label="Saving" defaultChecked transitioning />
      <Switch label="LinkedIn sending (not configured)" disabled />
    </div>
  );
}

Groups

Notifications

Changes save at once.

Bench controls (locked)
import { SwitchGroup, SwitchItem } from "@etched/reticle/switch";

export function Groups() {
  return (
    <div className="grid">
      <SwitchGroup legend="Notifications" description="Changes save at once.">
        <SwitchItem label="Run finished" defaultChecked />
        <SwitchItem label="Run failed" defaultChecked />
        <SwitchItem label="Weekly digest" />
      </SwitchGroup>
      <SwitchGroup legend="Bench controls (locked)" disabled>
        <SwitchItem label="Auto-drain" defaultChecked />
        <SwitchItem label="Night mode" />
      </SwitchGroup>
    </div>
  );
}

In a field

Sent to the run owner when a run fails.

import { Field } from "@etched/reticle/field";
import { Switch } from "@etched/reticle/switch";

export function InAField() {
  return (
    <div className="grid">
      <Field label="Email alerts" description="Sent to the run owner when a run fails.">
        <Switch defaultChecked />
      </Field>
    </div>
  );
}

API reference

SwitchGroup

PropTypeDefaultDescription
legendReactNode–Title of the group. Without it, add a SwitchLegend child or an aria-label.
children *ReactNode–SwitchItem children, and optionally a SwitchLegend.
descriptionReactNode–Help text below the group. Hidden while an error shows.
errorFieldError–
disabledboolean–Turns off every switch in the group.
controlFirstbooleantrueDefault controlFirst of every item.
aria-labelstring–
classNamestring–Class on the outer element, for layout.

SwitchItem

PropTypeDefaultDescription
variant"default" | "neutral""default"
requiredboolean–false adds the optional marker after the label.
controlFirstbooleantrueSwitch before the label. false puts the label first. Inside a SwitchGroup, the group sets the default.
size"sm" | "base" | "lg""base"
transitioningboolean–Marks the switch busy (aria-busy) while a change is saved.
classNamestring–Class on the outer element, for layout.
label *ReactNode–

SwitchLegend

PropTypeDefaultDescription
children *ReactNode–
classNamestring–

Switch

PropTypeDefaultDescription
variant"default" | "neutral""default"
labelReactNode–Text beside the switch. Without it, give the switch an aria-label.
requiredboolean–false adds the optional marker after the label.
controlFirstbooleantrueSwitch before the label. false puts the label first. Inside a SwitchGroup, the group sets the default.
size"sm" | "base" | "lg""base"
transitioningboolean–Marks the switch busy (aria-busy) while a change is saved.
classNamestring–Class on the outer element, for layout.