Actions
Button
Triggers an action.
Variants
Only one primary action per context (a page, or an open modal). Other actions take a lower level: secondary, outline, then link.
import { CrButton } from '@cristal-ui/react';
export default function ButtonVariants() {
return (
<>
<CrButton>Primary</CrButton>
<CrButton variant="secondary">Secondary</CrButton>
<CrButton variant="outline">Outline</CrButton>
<CrButton variant="link">Link</CrButton>
</>
);
}Sizes
Size depends on the container, not on the variant: two buttons side by side have the same size. Guidelines: m in a form or a modal, s in a card or a toolbar, xs in a dense table, l for the primary action on mobile.
import { CrButton } from '@cristal-ui/react';
export default function ButtonSizes() {
return (
<>
<CrButton size="xs">XS · 30px</CrButton>
<CrButton size="s">S · 36px</CrButton>
<CrButton size="m">M · 40px</CrButton>
<CrButton size="l">L · 48px</CrButton>
</>
);
}States
loading shows an indicator, marks the button as busy (aria-busy) and blocks clicks, while keeping focus.
import { CrButton } from '@cristal-ui/react';
export default function ButtonStates() {
return (
<>
<CrButton disabled>Disabled</CrButton>
<CrButton loading>Saving</CrButton>
</>
);
}Icons
Put the icon in slot="start" (before the label) or slot="end" (after). It is sized automatically: 20px in xs, 24px otherwise. A decorative icon gets aria-hidden="true".
import { CrButton } from '@cristal-ui/react';
import { ChevronRight, Plus } from 'lucide-react';
export default function ButtonIcons() {
return (
<>
<CrButton>
<Plus slot="start" aria-hidden="true" />
Add product
</CrButton>
<CrButton variant="outline">
Continue
<ChevronRight slot="end" aria-hidden="true" />
</CrButton>
</>
);
}In a form
type="submit" submits the parent form and type="reset" resets it, like a native button. See the full example on the Text field page.
Link
With href, the button becomes a real link: Ctrl/Cmd+click, middle click, Shift+click and "Open in new tab" stay the browser's own, which an onClick that changes page cannot offer. target="_blank" opens a new tab (rel="noopener noreferrer" is added). When disabled or loading, the link loses its address and cannot be opened. Also works on CrIconButton.
<CrButton href="/docs" variant="secondary">Read the documentation</CrButton>Accessibility
- Native button under the hood: activated with Enter and Space, announced as "button". With
href, a native link: activated with Enter, announced as "link". - Visible focus, label contrast above 4.5:1 in every variant.
- The label must describe the action: "Add a product" rather than "OK".
API
Properties
| Property | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Désactive le bouton. |
fullWidth | boolean | false | Occupe toute la largeur du conteneur. |
href | string | — | Adresse : le bouton devient un vrai lien (Ctrl+clic, clic molette et « Ouvrir dans un nouvel onglet » natifs). |
loading | boolean | false | Affiche l'indicateur de chargement et bloque les clics. |
size | "l" | "m" | "s" | "xs" | 'm' | Hauteur : xs 30px, s 36px, m 40px, l 48px. |
target | string | — | Où ouvrir le lien (avec href), par exemple _blank ; rel="noopener noreferrer" est ajouté pour _blank. |
type | "button" | "reset" | "submit" | 'button' | Comportement dans un formulaire (sans effet avec href). |
variant | "link" | "outline" | "primary" | "secondary" | 'primary' | Niveau de hiérarchie visuelle. |
Slots
| Slot | Description |
|---|---|
| default | Libellé du bouton. |
slot="end" | Icône après le libellé. |
slot="start" | Icône avant le libellé. |
CSS parts
To style it from outside: cr-button::part(name) { … }
| Part | Description |
|---|---|
button | Le bouton natif, ou le lien natif avec href. |
spinner | L'indicateur de chargement. |