Skip to content

Inputs

Button

Trigger actions with five visual variants, three sizes, leading and trailing icons, and a loading state.

<script>
  import { Button } from "@codeatlasdev/ui";
</script>

<Button variant="filled" onclick={save}>Save</Button>

Secondary actions use tone="neutral". One brand filled button per card; the actions beside it (Edit, Snooze, Previous, Skip) are variant="outlined" or "ghost" with tone="neutral": --ca-text-primary label (--ca-text-secondary for ghost), --ca-outline-control border, --ca-action-hover / --ca-action-selected hover and pressed fills, and the same sizes, loading, disabled and focus ring. Never override .ca-btn colours from the app. IconButton takes the same tone on its outlined variant (its text variant is already neutral); extra attributes such as aria-expanded are forwarded, so both work as Popover triggers. Label and border contrast on the raised and overlay surfaces is measured for every preset in tests/contrast.test.ts.

On touch devices every size grows to a 44px target and presses scale down slightly, like a native control.

#006

Variants

filled, glass (a tinted surface button that follows the theme: opaque under solid), outlined, ghost and destructive.

Reference #006 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button } from '@codeatlasdev/ui';
</script>

<Button variant="filled">Filled</Button>
<Button variant="glass">Glass</Button>
<Button variant="outlined">Outlined</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="destructive">Destructive</Button>
#004

Sizes

Reference #004 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button } from '@codeatlasdev/ui';
</script>

<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
#002

With icons

Leading and trailing snippets.

Reference #002 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button } from '@codeatlasdev/ui';
  import { ArrowRight, Download, Star } from '@lucide/svelte';
</script>

<Button variant="filled">
  {#snippet leading()}<Star size={15} />{/snippet}
  Starred
</Button>
<Button variant="outlined">
  Continue
  {#snippet trailing()}<ArrowRight size={15} />{/snippet}
</Button>
<Button variant="ghost">
  {#snippet leading()}<Download size={15} />{/snippet}
  Download
</Button>
#003

Loading

Swaps the leading icon for a spinner, sets aria-busy and blocks clicks while keeping the label.

Reference #003 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button } from '@codeatlasdev/ui';

  let saving = $state(false);

  function save() {
    saving = true;
    setTimeout(() => (saving = false), 2000);
  }
</script>

<Button variant="filled" loading>Saving</Button>
<Button variant="outlined" loading>Outlined</Button>
<Button variant="filled" loading={saving} onclick={save}>
  {saving ? 'Saving…' : 'Save (2s)'}
</Button>
#005

States

Disabled buttons, a destructive action and a link rendered as a button.

Link button

Reference #005 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button } from '@codeatlasdev/ui';
  import { Trash2 } from '@lucide/svelte';
</script>

<Button variant="filled" disabled>Filled</Button>
<Button variant="outlined" disabled>Outlined</Button>
<Button variant="glass" disabled>Glass</Button>
<Button variant="destructive">
  {#snippet leading()}<Trash2 size={15} stroke-width={2} />{/snippet}
  Delete account
</Button>
<Button variant="outlined" href="https://github.com/codeatlasdev/ui" target="_blank">Link button</Button>
#640

Neutral tone

`tone="neutral"` on `outlined` and `ghost` (Button) and on `outlined` (IconButton): neutral label and border for a secondary action beside a brand `filled` one.

Reference #640 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button, IconButton } from '@codeatlasdev/ui';
  import { MoreHorizontal } from '@lucide/svelte';
</script>

<div class="row">
  <Button variant="filled">Send reply</Button>
  <Button variant="outlined" tone="neutral">Edit message</Button>
  <Button variant="ghost" tone="neutral" size="sm">Snooze</Button>
  <IconButton variant="outlined" tone="neutral" aria-label="More actions">
    <MoreHorizontal size={18} />
  </IconButton>
</div>

<style>
  .row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ca-space-3); }
</style>
#001

Full width

fullWidth stretches the button to its container.

Reference #001 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button } from '@codeatlasdev/ui';
</script>

<div class="col">
  <Button fullWidth>Continue</Button>
  <Button fullWidth variant="outlined">Cancel</Button>
</div>

<style>
  .col {
    display: flex;
    flex-direction: column;
    gap: var(--ca-space-2);
    width: 100%;
    max-width: 320px;
  }
</style>
#880

Component tokens

Weight, gap, padding, ghost border and icon size set on one wrapper.

Next lead N

Reference #880 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button, IconButton, Kbd } from '@codeatlasdev/ui';
  import { X } from '@lucide/svelte';
</script>

<div class="dense">
  <Button variant="filled" size="lg">Call next lead</Button>
  <Button variant="outlined" tone="neutral" size="sm">Snooze</Button>
  <Button variant="ghost" tone="neutral" size="sm">Skip</Button>
  <Button variant="outlined" tone="neutral" size="sm" disabled>Reassign</Button>
  <IconButton variant="text" size="sm" aria-label="Close focus mode"><X size={16} /></IconButton>
  <span class="hint">Next lead <Kbd>N</Kbd></span>
</div>

<style>
  /* Component tokens only: no selector against a ca-* class, defaults untouched outside this wrapper. */
  .dense {
    --ca-btn-gap: var(--ca-space-2);
    --ca-btn-line-height: 1.25;
    --ca-btn-letter-spacing: normal;
    --ca-btn-lg-font-weight: 400;
    --ca-btn-lg-font-size: var(--ca-font-size-button);
    --ca-btn-sm-padding-x: var(--ca-space-3);
    --ca-btn-sm-font-size: var(--ca-font-size-body2);
    --ca-btn-ghost-border-width: 0px;
    --ca-icon-btn-size-sm: 36px;
    --ca-kbd-size: var(--ca-space-5);
    --ca-kbd-font-size: var(--ca-font-size-caption);
    --ca-kbd-line-height: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ca-space-3);
  }
  .hint { display: inline-flex; align-items: center; gap: var(--ca-space-1-5); color: var(--ca-text-secondary); }
</style>

Tokens

Weight, tracking, line-height, gap, padding and size are component tokens: set them on :root, a wrapper or ThemeOptions.components. Unset, a button draws what it always did; a size token wins over the all-sizes one (--ca-btn-lg-font-weight changes lg only).

  • Every size: --ca-btn-font-weight (500), --ca-btn-letter-spacing (--ca-label-tracking), --ca-btn-line-height (inherited), --ca-btn-gap (--ca-space-1-5).
  • One size, --ca-btn-{sm,md,lg}-: height, padding-x, font-size, font-weight, letter-spacing.
  • --ca-btn-ghost-border-width: 0px makes a ghost button as wide as a text one. --ca-btn-disabled-bg: e.g. var(--ca-brand-fill).
  • --ca-btn-touch-height, --ca-icon-btn-touch-size: the pointer: coarse minimum, 44px unless you set it.
  • IconButton: --ca-icon-btn-size-{sm,md,lg} (32/40/48px) and --ca-icon-btn-font-weight.

Keyboard hint: trailingHint. Put a <Kbd> in trailing and add trailingHint: below md and on touch screens the slot is display: none, so it takes no space and the button is as wide as its label alone. Never hide .ca-btn__trailing with a media query in the app. Label start, hint end: align="between". With fullWidth (or a fixed width) the label stays at the start and trailing goes to the end; the loading spinner stays in the leading slot. Do not write justify-content: flex-start plus margin-left: auto on .ca-btn__trailing.

#901

Responsive keyboard hint

`trailingHint` hides the `Kbd` below md and on touch, without leaving a gap.

Reference #901 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button, Kbd } from '@codeatlasdev/ui';
</script>

<div class="row">
  <Button variant="outlined" tone="neutral" trailingHint>
    Next lead
    {#snippet trailing()}<Kbd>K</Kbd>{/snippet}
  </Button>
  <Button variant="outlined" tone="neutral" trailingHint>
    Snooze
    {#snippet trailing()}<Kbd>S</Kbd>{/snippet}
  </Button>
</div>

<style>
  .row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ca-space-3); }
</style>
#902

Align between

`align="between"`: label at the start, hint at the end; the spinner keeps its place.

Reference #902 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Button, Kbd } from '@codeatlasdev/ui';
</script>

<div class="grid">
  <Button variant="outlined" tone="neutral" align="between" fullWidth trailingHint>
    Open lead
    {#snippet trailing()}<Kbd>O</Kbd>{/snippet}
  </Button>
  <Button variant="outlined" tone="neutral" align="between" fullWidth trailingHint>
    Assign to me
    {#snippet trailing()}<Kbd>A</Kbd>{/snippet}
  </Button>
  <Button variant="outlined" tone="neutral" align="between" fullWidth loading trailingHint>
    Syncing
    {#snippet trailing()}<Kbd>R</Kbd>{/snippet}
  </Button>
</div>

<style>
  .grid { display: grid; gap: var(--ca-space-2); max-width: 20rem; }
</style>

Props

PropTypeDefaultDescription
variant'filled' | 'glass' | 'outlined' | 'ghost' | 'destructive''filled'Visual style. `filled` is the primary action; `glass` is a tinted surface button whose blur only shows under the `glass` and `frosted` styles.
tone'brand' | 'neutral''brand'`'neutral'` draws `outlined` and `ghost` with neutral label, border and hover fills (adds `ca-btn--neutral`). Other variants ignore it. `IconButton` has the same prop for its `outlined` variant (new, adds `ca-icon-btn--outlined`).
size'sm' | 'md' | 'lg''md'Height, padding and font size.
disabledbooleanfalsePrevents interaction.
loadingbooleanfalseShows a spinner in place of leading, sets aria-busy, blocks interaction and keeps the label. Adds ca-btn--loading. Screen readers hear "Finished loading" when it ends.
type'button' | 'submit' | 'reset' | string'button'Without href: the HTML button type (`submit` inside a `<form>` submits it). With href: the MIME type hint of the linked resource.
formstring–Without href, the `id` of the `<form>` this button submits, for a button outside it: the footer of a `Dialog` (`actions`) or a sticky action bar. `formaction`, `name` and `value` are forwarded the same way. A link rejects them.
fullWidthbooleanfalseStretches the button to the width of its container.
hrefstring–Renders an anchor styled as a button. The props then accept the anchor's attributes: download, rel, hreflang, ping, referrerpolicy.
targetstring–Anchor target, used with href. "_blank" adds rel="noopener noreferrer" to any rel you pass.
childrenSnippet–Button label.
leadingSnippet–Content before the label. Replaced by a spinner while loading.
trailingSnippet–Content after the label.
trailingHintbooleanfalseMarks `trailing` as a keyboard hint: hidden below `md` and under `(pointer: coarse)`, with no reserved gap (adds `ca-btn__trailing--hint`).
align'center' | 'between''center'`'between'` pins the label to the start and `trailing` to the end (adds `ca-btn--between`). The loading spinner stays in the leading slot.
onclick(e: MouseEvent) => void–Click handler. Not called while disabled or loading.
aria-labelstring–Accessible name for icon-only buttons.
classstring–Extra classes on the root element.