Button
@codeui/styles v0.3.0
A labeled action in plain HTML, styled by variant, size, and ghost attributes.
Load @codeui/styles/button.css, or all.css. The Solid component is documented in Button.
Demo
<button type="button" class="cui-button" data-cui="button" data-size="sm" data-variant="primary"> Export PNG</button>Markup
| Part | Element | Class | data-cui |
|---|---|---|---|
| Root | button or a | cui-button | button |
| Leading icon | span | cui-button-icon | None |
| Loading overlay | div | cui-loading | None |
| Attribute | Values | Default |
|---|---|---|
data-variant | primary, secondary, tertiary, caution, negative | None. Set one. |
data-size | xs, sm, md, lg | sm |
data-ghost | Presence | Off |
data-pill | Presence | Off |
data-block | Presence | Off |
Variants
Colors
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="primary">Export PNG</button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary">Copy snippet</button> <button type="button" class="cui-button" data-cui="button" data-variant="tertiary">Share snippet</button> <button type="button" class="cui-button" data-cui="button" data-variant="caution">Overwrite export</button> <button type="button" class="cui-button" data-cui="button" data-variant="negative">Delete snippet</button></div>primary uses brand fill. secondary is neutral. tertiary uses soft brand fill. caution and negative use warning and danger colors. Keep one primary action in each group.
Sizes
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="xs">Extra small</button> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="sm">Small</button> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="md">Medium</button> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="lg">Large</button></div>xs, sm, md, and lg are 28px, 36px, 44px, and 52px at comfortable density. Omitting data-size renders sm.
Ghost
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="secondary" data-ghost>Cancel</button> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-ghost>Preview</button> <button type="button" class="cui-button" data-cui="button" data-variant="negative" data-ghost>Discard</button></div>data-ghost removes the idle fill. The data-variant colors appear on hover.
Pill
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-pill>Export PNG</button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary" data-pill>Copy snippet</button></div>Block
<div class="cui-stack" data-gap="2" style="max-width: 360px; margin-inline: auto"> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-size="md" data-block>Export PNG</button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary" data-size="md" data-block>Copy snippet</button></div>data-block sets width to 100% and flex to 1.
Icons
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="secondary"> <span class="cui-button-icon"> <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"> <rect x="8" y="8" width="12" height="12" rx="2" /> <path d="M16 8V4H4v12h4" /> </svg> </span> Copy snippet </button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary"> Next snippet <svg class="cui-icon" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd" /> </svg> </button></div>Wrap a leading icon in span.cui-button-icon. A trailing icon goes after the label. Give decorative icons aria-hidden="true".
Link
<a href="#changelog" class="cui-button" data-cui="button" data-variant="secondary"> Read the changelog</a>The classes work on an anchor. It keeps link semantics: Enter follows it and Space does not.
States
Disabled
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="primary" disabled data-disabled>Export PNG</button> <button type="button" class="cui-button" data-cui="button" data-variant="secondary" disabled data-disabled>Copy snippet</button></div>Set both disabled and data-disabled. The native attribute removes the button from the tab order and blocks clicks. The dimmed fill selects on data-disabled.
Loading
<div class="cui-stack" data-direction="row" data-gap="3" data-align="center" data-wrap="true"> <button type="button" class="cui-button" data-cui="button" data-variant="primary" data-loading aria-busy="true" aria-disabled="true"> <div class="cui-loading"> <span class="cui-loading-pointer-group" aria-label="Loading"> <i class="cui-loading-pointer"></i> <i class="cui-loading-pointer" style="--cui-loading-pointer-delay: 0.2s"></i> <i class="cui-loading-pointer" style="--cui-loading-pointer-delay: 0.4s"></i> </span> </div> Export PNG </button></div>data-loading blocks pointer events and dims the label under three animated dots. The dots are plain markup, so the animation runs without a script. Set aria-busy="true" and aria-disabled="true" yourself, and ignore activation while the work runs.
What you supply
- Click handlers and form submission.
aria-busyandaria-disabledwhile loading, plus a guard that ignores Enter, Space, and clicks.- An accessible name for a button whose only content is an icon. Use IconButton for that case.
Helper
import "@codeui/styles/button.css";
import { applyStyleProps } from "@codeui/styles";
import { buttonStyleProps } from "@codeui/styles/button";
const save = document.querySelector("button")!;
applyStyleProps(save, buttonStyleProps({ variant: "primary", size: "md" }));
// class="cui-button" data-cui="button" data-size="md" data-variant="primary"