Actionsduskmoonimplemented11 demos

Button

Button triggers primary, secondary, destructive, or icon-only actions.

Import@duskmoon-dev/components/button
5API sections
9documented props
5behavior scenarios
Key API
colorappearanceshapesizeblockisLoading

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

Button is most often configured through `color`, `appearance`, `shape`, `size`.

Covered behavior

Renders children correctly

Feature Demos

Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.

Preview
primary
secondary
tertiary
accent
neutral
base
info
success
warning
error

Colors

authored

Button supports the full semantic color palette: primary, secondary, tertiary, accent, neutral, base, info, success, warning, error.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";

const colors = [
  "primary",
  "secondary",
  "tertiary",
  "accent",
  "neutral",
  "base",
  "info",
  "success",
  "warning",
  "error"
] as const;

export function ButtonColorsDemo() {
  return (<div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
  {colors.map((color) => (
    <Button key={color} color={color}>
      {color}
    </Button>
  ))}
</div>);
}
Preview

Basic usage

authored

Import the component stylesheet and Button from its package subpath, then render it with the core props.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";

export function Example() {
  return (<Button color="primary">Save changes</Button>);
}
Preview

Appearances

authored

Compare the five Button appearances, including outline and ghost treatments.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";

const appearances = ["filled", "outline", "tonal", "ghost", "text"] as const;

export function ButtonAppearancesDemo() {
  return (
    <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
      {appearances.map((appearance) => (
        <Button key={appearance} appearance={appearance}>
          {appearance}
        </Button>
      ))}
    </div>
  );
}
Preview
filled
outline
tonal
ghost
text

Loading states

authored

Loading adds a spinner and disables the button while preserving each appearance and size.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";

const appearances = ["filled", "outline", "tonal", "ghost", "text"] as const;

export function ButtonLoadingDemo() {
  return (
    <div style={{ display: "grid", gap: 12 }}>
      {appearances.map((appearance) => (
        <div key={appearance} style={{ display: "flex", gap: 8, alignItems: "center" }}>
          <span style={{ minWidth: 68 }}>{appearance}</span>
          <Button appearance={appearance} isLoading>Saving</Button>
          <Button appearance={appearance} size="sm" isLoading>Saving</Button>
          <Button appearance={appearance} size="lg" isLoading>Saving</Button>
        </div>
      ))}
    </div>
  );
}
Preview
Ready to save

Interactive loading

authored

Click Save to show the loading state briefly; the button is disabled until it finishes.

Source
import "@duskmoon-dev/components/styles.css";
import { useEffect, useRef, useState } from "react";
import { Button } from "@duskmoon-dev/components/button";

export function InteractiveLoadingDemo() {
  const [isLoading, setIsLoading] = useState(false);
  const timeoutRef = useRef<number | null>(null);

  useEffect(() => () => {
    if (timeoutRef.current !== null) window.clearTimeout(timeoutRef.current);
  }, []);

  function save() {
    setIsLoading(true);
    timeoutRef.current = window.setTimeout(() => {
      timeoutRef.current = null;
      setIsLoading(false);
    }, 900);
  }

  return (
    <div style={{ display: "grid", gap: 8, justifyItems: "start" }}>
      <Button isLoading={isLoading} onClick={save}>Save changes</Button>
      <span role="status">{isLoading ? "Saving changes…" : "Ready to save"}</span>
    </div>
  );
}
Preview

Disabled states

authored

Use the native disabled prop to prevent interaction across Button appearances.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";

const appearances = ["filled", "outline", "tonal", "ghost", "text"] as const;

export function DisabledButtonsDemo() {
  return (
    <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
      {appearances.map((appearance) => (
        <Button key={appearance} appearance={appearance} disabled>
          {appearance}
        </Button>
      ))}
    </div>
  );
}
Preview

Icon buttons

authored

Use leftIcon or rightIcon beside text, and give icon-only buttons an accessible label. Circular buttons use fixed icon sizes.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";

export function ButtonIconsDemo() {
  const addIcon = <svg aria-hidden="true" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24"><path strokeLinecap="round" d="M12 5v14M5 12h14" /></svg>;
  const downloadIcon = <svg aria-hidden="true" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" d="M12 3v12m-4-4 4 4 4-4M4 17v3h16v-3" /></svg>;
  const closeIcon = <svg aria-hidden="true" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24"><path strokeLinecap="round" d="M6 6l12 12M18 6 6 18" /></svg>;

  return (
    <div style={{ display: "grid", gap: 12 }}>
      <div style={{ display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" }}>
        <Button leftIcon={addIcon}>Add item</Button>
        <Button appearance="outline" rightIcon={downloadIcon}>
          Download
        </Button>
      </div>
      <div style={{ display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" }}>
        <Button shape="circle" aria-label="Close">{closeIcon}</Button>
        <Button shape="circle" size="sm" appearance="outline" aria-label="Add">{addIcon}</Button>
        <Button shape="circle" size="lg" appearance="tonal" aria-label="Close">{closeIcon}</Button>
        <Button shape="square" appearance="outline" aria-label="Add">{addIcon}</Button>
      </div>
    </div>
  );
}
Preview
Save your changes

Tooltip composition

authored

Wrap a Button with Tooltip to show help on hover or focus.

Source
import "@duskmoon-dev/components/styles.css";
import { Button } from "@duskmoon-dev/components/button";
import { Tooltip } from "@duskmoon-dev/components";

export function TooltipButtonDemo() {
  return (
    <Tooltip id="save-help" title="Save your changes" defaultOpen>
      <Button>Save</Button>
    </Tooltip>
  );
}
Preview
Confirmed deletions: 0

Confirmation popover form

authored

The action callback runs only after confirmation; cancelling leaves the confirmed count unchanged.

Source
import "@duskmoon-dev/components/styles.css";
import { useState } from "react";
import { Button } from "@duskmoon-dev/components/button";

export function ConfirmButtonDemo() {
  const [deletedCount, setDeletedCount] = useState(0);

  return (
    <div style={{ display: "grid", gap: 8, justifyItems: "start" }}>
      <Button
        color="error"
        confirm={{
          title: "Delete this item?",
          message: "This action cannot be undone.",
          confirmText: "Delete",
          cancelText: "Cancel",
        }}
        onClick={() => setDeletedCount((count) => count + 1)}
      >
        Delete item
      </Button>
      <span role="status">Confirmed deletions: {deletedCount}</span>
    </div>
  );
}
Preview
Confirmed draft deletions: 0

Custom confirmation content

authored

Pass a component without its own form as confirmation body content; Button keeps the confirmation controls and runs the action only after approval.

Source
import "@duskmoon-dev/components/styles.css";
import { useState } from "react";
import { Button } from "@duskmoon-dev/components/button";

function DeleteConfirmContent() {
  return <p>Delete this draft and discard its unsaved changes?</p>;
}

export function CustomConfirmButtonDemo() {
  const [deletedCount, setDeletedCount] = useState(0);

  return (
    <div style={{ display: "grid", gap: 8, justifyItems: "start" }}>
      <Button
        color="error"
        confirm={{ component: <DeleteConfirmContent /> }}
        onClick={() => setDeletedCount((count) => count + 1)}
      >
        Delete draft
      </Button>
      <span role="status">Confirmed draft deletions: {deletedCount}</span>
    </div>
  );
}
Preview
Sunshine Theme
Moonlight Theme

Theme aware

authored

Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.

Source
<div data-theme="sunshine">
  <Button color="primary">Save changes</Button>
</div>

<div data-theme="moonlight">
  <Button color="primary">Save changes</Button>
</div>

API

The API reference below lists every parsed exported type or interface for Button. Start with `color`, `appearance`, `shape`, `size` for common usage.

Types: packages/components/src/components/button/Button.types.tsScenarios: packages/components/src/components/button/Button.test.tsx
ButtonPropsinterface extends ComponentProps<"button">
PropTypeRequiredDescription
colorButtonColorNocolor configures Button.
appearanceButtonAppearanceNoappearance configures Button.
shapeButtonShapeNoshape configures Button.
sizeButtonSizeNosize configures Button.
blockbooleanNoblock configures Button.
isLoadingbooleanNoisLoading configures Button.
leftIconReact.ReactNodeNoleftIcon configures Button.
rightIconReact.ReactNodeNorightIcon configures Button.
confirmboolean | { title?: React.ReactNode; component?: React.ReactElement; message?: React.ReactNode; description?: React.ReactNode; confirmText?: React.ReactNode; cancelText?: React.ReactNode }Noconfirm configures Button.
ButtonColortype
Type definition
| "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error"
ButtonAppearancetype
Type definition
"filled" | "outline" | "tonal" | "ghost" | "text"
ButtonShapetype
Type definition
"rect" | "circle" | "square"
ButtonSizetype
Type definition
"xs" | "sm" | "md" | "lg"