Button
ActionsA button, or a link styled as one when it has href. loading shows a spinner while the action it started runs: the button keeps focus, is marked busy and ignores clicks.
import { Button } from '@limerdev/zest'; href, a navigation that should look like an action.<div> or <span> with onclick. A Button without text: give an icon-only button aria-label. variant="link" for in-text links: use a plain <a>. disabled while an action runs: use loading, which keeps focus on the button.Examples
Variants
The variants, by the theme's colour roles: primary for the main action, error for deleting, secondary, neutral and outline for the rest, ghost in toolbars, link for a navigation that looks like text.
<script lang="ts">
import { Button } from '@limerdev/zest';
</script>
<Button>Save</Button>
<Button variant="error">Delete</Button>
<Button variant="outline">Cancel</Button>
<Button variant="secondary">Duplicate</Button>
<Button variant="neutral">Export</Button>
<Button variant="ghost">Archive</Button>
<Button variant="link">Details</Button> Sizes
sm, default and lg follow the theme's field size; the icon sizes are square. Give an icon-only button an aria-label.
<script lang="ts">
import Plus from '@lucide/svelte/icons/plus';
import { Button } from '@limerdev/zest';
</script>
<Button size="sm">Small</Button>
<Button>Default</Button>
<Button size="lg">Large</Button>
<Button size="icon-sm" variant="outline" aria-label="Add"><Plus /></Button>
<Button size="icon" variant="outline" aria-label="Add"><Plus /></Button>
<Button size="icon-lg" variant="outline" aria-label="Add"><Plus /></Button> With an icon
An icon before the text gets a little less padding.
<script lang="ts">
import Plus from '@lucide/svelte/icons/plus';
import Download from '@lucide/svelte/icons/download';
import { Button } from '@limerdev/zest';
</script>
<Button><Plus /> New order</Button>
<Button variant="outline"><Download /> Export</Button> Link and disabled
With href the button is a link. A disabled link loses its href and leaves the tab order.
<script lang="ts">
import { Button } from '@limerdev/zest';
</script>
<Button href="#orders" variant="secondary">All orders</Button>
<Button disabled>Disabled</Button>
<Button href="#orders" disabled variant="outline">Disabled link</Button> Loading
loading shows a spinner while the action runs: the button keeps focus, is marked busy, and ignores clicks until it is done.
<script lang="ts">
import RefreshCw from '@lucide/svelte/icons/refresh-cw';
import { Button } from '@limerdev/zest';
let saving = $state(false);
function save(): void {
saving = true;
setTimeout(() => (saving = false), 1500);
}
</script>
<Button loading={saving} onclick={save}>{saving ? 'Saving…' : 'Save'}</Button>
<Button size="icon" variant="outline" aria-label="Refresh" loading={saving} onclick={save}>
<RefreshCw />
</Button> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Button
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | null | false | true | false | |
| href | string | null | undefined | |
| loading | boolean | false | Waiting for the action it started: a spinner shows (in place of the icon of an icon-size button), it is marked busy and unavailable, and clicks do nothing. Unlike disabled, it keeps keyboard focus. |
| size | "default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | 'default' | The height and padding, from the theme's field size; the icon sizes are square. |
| type | null | "button" | "submit" | "reset" | 'button' | |
| variant | "link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost" | 'primary' | The look, by the theme's colour roles: primary for the main action, error for deleting, secondary, neutral and outline for the rest, ghost in toolbars, link for a navigation that looks like text. |