Swap
Swap switches between two decorative indicators using one native checkbox.
@duskmoon-dev/components/swapUsage
When to use
- Use it inside forms, filters, settings, and any workflow that captures user input.
- Prefer controlled props when the value must stay synchronized with application state.
Implementation notes
Features
Documents default values, value props, and change callbacks for form integration.
Surfaces status, size, disabled, and option data patterns where the component supports them.
Swap is most often configured through `checked`, `defaultChecked`, `onChange`, `off`.
Uses one native checkbox as the form state source
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Appearance: Light
Interactive usage
The native checkbox drives both the visual slot and a visible preference value.
Source
import { useState } from "react";
import "@duskmoon-dev/components/styles.css";
import { Swap } from "@duskmoon-dev/components/swap";
export function SwapDemo() {
const [dark, setDark] = useState(false);
return <div>
<Swap aria-label="Use dark appearance" checked={dark}
onChange={(event) => setDark(event.currentTarget.checked)}
off="☀️" on="🌙" rotate />
<p>Appearance: {dark ? "Dark" : "Light"}</p>
</div>;
}API
The API reference below lists every parsed exported type or interface for Swap. Start with `checked`, `defaultChecked`, `onChange`, `off` for common usage.
packages/components/src/components/swap/Swap.types.tsScenarios: packages/components/src/components/swap/Swap.test.tsx| Prop | Type | Required | Description |
|---|---|---|---|
checked | boolean | No | checked configures Swap. |
defaultChecked | boolean | No | defaultChecked configures Swap. |
onChange | ChangeEventHandler<HTMLInputElement> | No | onChange configures Swap. |
off | ReactNode | No | Decorative, noninteractive content shown while unchecked. |
on | ReactNode | No | Decorative, noninteractive content shown while checked. |
rotate | boolean | No | rotate configures Swap. |
wrapperClassName | string | No | Additional class names for the wrapping label. |
className | string | No | Additional class names for the native checkbox. |
| Prop | Type | Required | Description |
|---|---|---|---|
on | ReactNode | Yes | on configures Swap. |
off | ReactNode | Yes | off configures Swap. |
rotate | boolean | No | rotate configures Swap. |
pressed | boolean | Yes | pressed configures Swap. |