Actionsduskmoonimplemented1 demos

Swap

Swap switches between two decorative indicators using one native checkbox.

Import@duskmoon-dev/components/swap
2API sections
12documented props
3behavior scenarios
Key API
checkeddefaultCheckedonChangeoffonrotate

Usage

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

StylesheetImport @duskmoon-dev/components/styles.css once in the app or docs shell.
StateStart with default props for static examples, then switch to controlled props when state must be shared.
ThemeThe preview inherits the active DuskMoon data-theme value from the docs layout.

Features

Controlled and uncontrolled usage

Documents default values, value props, and change callbacks for form integration.

Validation state

Surfaces status, size, disabled, and option data patterns where the component supports them.

Primary API surface

Swap is most often configured through `checked`, `defaultChecked`, `onChange`, `off`.

Covered behavior

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.

Preview

Appearance: Light

Interactive usage

authored

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.

Types: packages/components/src/components/swap/Swap.types.tsScenarios: packages/components/src/components/swap/Swap.test.tsx
SwapPropsinterface extends Omit< ComponentProps<"input">, | "checked" | "children" | "className" | "defaultChecked" | "onChange" | "size" | "type" >
PropTypeRequiredDescription
checkedbooleanNochecked configures Swap.
defaultCheckedbooleanNodefaultChecked configures Swap.
onChangeChangeEventHandler<HTMLInputElement>NoonChange configures Swap.
offReactNodeNoDecorative, noninteractive content shown while unchecked.
onReactNodeNoDecorative, noninteractive content shown while checked.
rotatebooleanNorotate configures Swap.
wrapperClassNamestringNoAdditional class names for the wrapping label.
classNamestringNoAdditional class names for the native checkbox.
SwapButtonPropsinterface extends Omit< ComponentProps<"button">, "children" | "aria-pressed" >
PropTypeRequiredDescription
onReactNodeYeson configures Swap.
offReactNodeYesoff configures Swap.
rotatebooleanNorotate configures Swap.
pressedbooleanYespressed configures Swap.