Button
A button that triggers user actions. Supports five variants (filled, light, outline, ghost, reverse), three sizes (sm, md, lg), and icons before or after the label.
View in Storybook (opens in a new tab)
Installation
import { Button } from "@ginga-ui/core";Basic usage
The simplest button example.
button.tsx
button.module.css
import { Button, Dialog, DialogTitle, DialogTrigger, Modal } from "@ginga-ui/core";
import styles from "./button.module.css";
export function BasicExample() {
return (
<DialogTrigger>
<Button variant="filled">Click</Button>
<Modal>
<Dialog>
<DialogTitle>Clicked</DialogTitle>
<p>
Wrapping the button in DialogTrigger opens the dialog when it is
pressed.
</p>
<div className={styles.actions}>
<Button slot="close" variant="outline">
Close
</Button>
</div>
</Dialog>
</Modal>
</DialogTrigger>
);
}Variants
Shows the five variants (filled, light, outline, ghost, reverse).
button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import styles from "./button.module.css";
export function VariantsExample() {
return (
<div className={styles.variantRow}>
<Button variant="filled">Filled</Button>
<Button variant="light">Light</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="reverse">Reverse</Button>
</div>
);
}Sizes
Use the size prop to choose from three sizes: sm, md, and lg.
button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import styles from "./button.module.css";
export function SizesExample() {
return (
<div className={styles.sizeRow}>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
</div>
);
}With icons
Use startIcon and endIcon to show icons before and after the label.
button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import { ArrowRight, ChevronDown, Download, Plus } from "lucide-react";
import styles from "./button.module.css";
export function WithIconExample() {
return (
<div className={styles.variantRow}>
<Button startIcon={<Download />}>Download</Button>
<Button variant="light" endIcon={<ArrowRight />}>
Next
</Button>
<Button variant="outline" startIcon={<Plus />} endIcon={<ChevronDown />}>
Add
</Button>
</div>
);
}Disabled
Use the disabled prop to disable the button.
button.tsx
button.module.css
import { Button } from "@ginga-ui/core";
import styles from "./button.module.css";
export function DisabledExample() {
return (
<div className={styles.disabledRow}>
<Button variant="filled" disabled>
Disabled Filled
</Button>
<Button variant="light" disabled>
Disabled Light
</Button>
<Button variant="outline" disabled>
Disabled Outline
</Button>
</div>
);
}In a form
An example of using the button to submit a form.
button.tsx
button.module.css
import { useState } from "react";
import { Button, Dialog, DialogTitle, Input, Modal } from "@ginga-ui/core";
import { Send } from "lucide-react";
import styles from "./button.module.css";
export function FormExample() {
const [submittedName, setSubmittedName] = useState<string | null>(null);
return (
<>
<form
onSubmit={(e) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const name = formData.get("name");
setSubmittedName(typeof name === "string" ? name : "");
}}
className={styles.form}
>
<Input
type="text"
name="name"
placeholder="Enter your name"
aria-label="Name"
/>
<Button
type="submit"
variant="filled"
startIcon={<Send />}
className={styles.submit}
>
Submit
</Button>
</form>
<Modal
isOpen={submittedName !== null}
onOpenChange={(isOpen) => {
if (!isOpen) setSubmittedName(null);
}}
>
<Dialog>
<DialogTitle>Submitted</DialogTitle>
<p>Name: {submittedName}</p>
<div className={styles.actions}>
<Button slot="close" variant="outline">
Close
</Button>
</div>
</Dialog>
</Modal>
</>
);
}Props
Button
| Name | Type | Default | Description |
|---|---|---|---|
variant | "filled" | "light" | "outline" | "ghost" | "reverse" | "filled" | Visual style of the button. |
size | "sm" | "md" | "lg" | "md" | Size of the button. |
disabled | boolean | false | Disables the button. |
startIcon | ReactNode | - | Icon shown before the label. |
endIcon | ReactNode | - | Icon shown after the label. |
Also accepts the props of React Aria's Button (opens in a new tab).
ButtonGroup
Accepts the props of React Aria's Group (opens in a new tab).