Button
Button triggers primary, secondary, destructive, or icon-only actions.
@duskmoon-dev/components/buttonUsage
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.
Button is most often configured through `color`, `appearance`, `shape`, `size`.
Renders children correctly
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Colors
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>);
}Basic usage
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>);
}Appearances
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>
);
}Loading states
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>
);
}Interactive loading
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>
);
}Disabled states
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>
);
}Icon buttons
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>
);
}Tooltip composition
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>
);
}Confirmation popover form
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>
);
}Custom confirmation content
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>
);
}Theme aware
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.
packages/components/src/components/button/Button.types.tsScenarios: packages/components/src/components/button/Button.test.tsx| Prop | Type | Required | Description |
|---|---|---|---|
color | ButtonColor | No | color configures Button. |
appearance | ButtonAppearance | No | appearance configures Button. |
shape | ButtonShape | No | shape configures Button. |
size | ButtonSize | No | size configures Button. |
block | boolean | No | block configures Button. |
isLoading | boolean | No | isLoading configures Button. |
leftIcon | React.ReactNode | No | leftIcon configures Button. |
rightIcon | React.ReactNode | No | rightIcon configures Button. |
confirm | boolean | { title?: React.ReactNode; component?: React.ReactElement; message?: React.ReactNode; description?: React.ReactNode; confirmText?: React.ReactNode; cancelText?: React.ReactNode } | No | confirm configures Button. |
Type definition
| "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error"Type definition
"filled" | "outline" | "tonal" | "ghost" | "text"Type definition
"rect" | "circle" | "square"Type definition
"xs" | "sm" | "md" | "lg"