sdxc

Type to search, or start from one of these:

Switch

A native checkbox styled and wired as an on/off switch.

Notifications

Choose what we email you about.

View code
<Card>
	<Card.Header>
		<Card.Title>Notifications</Card.Title>
		<Card.Description>Choose what we email you about.</Card.Description>
	</Card.Header>
	<Card.Content>
		{preferences.map((preference) => (
			<label
				key={preference.name}
				htmlFor={`preview-switch-${preference.name}`}
				mix={[hstack({ gap: 4, align: "start", justify: "between" })]}
			>
				<span mix={[vstack({ gap: 1, align: "start" })]}>
					{preference.label}
					<Text>{preference.description}</Text>
				</span>
				<Switch
					id={`preview-switch-${preference.name}`}
					name={preference.name}
					defaultChecked={preference.defaultChecked}
					mix={[ariaChecked()]}
				/>
			</label>
		))}
	</Card.Content>
</Card>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

npm add @sdxc/ui
import "@sdxc/ui/theme.css";

Usage

import { Switch } from "@sdxc/ui";

Renders a single <input type="checkbox" role="switch">. It carries no aria-checked because an authored value would go stale the instant the switch is flipped; the live control's own checkedness is what persists.

Examples

<Label>
	{t("settings.notifications.label")}
	<Switch name="notifications" defaultChecked />
</Label>
<Switch aria-label={t("settings.darkMode")} checked={isDark} disabled={isLocked} />
<Switch aria-label={t("settings.notifications")} mix={[ariaChecked()]} />

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDescription
children?RemixNodeVisible label text rendered after the track, inside the same native <label> wrapping both, so clicking either half toggles the switch with no separate htmlFor/id pairing required.

Also accepts everything in Omit<TagProps<"input">, "type" | "role" | "aria-checked">.