Button
A button that starts an action; with href it is rendered as a link.
zb:button zubazar/ui · free (MIT)
Variant and size
Pick the color with variant and the size with size; primary is for the page's main action, danger for irreversible actions.
<zb:button variant="primary" size="md">Save</zb:button>
<zb:button variant="primary" size="sm">Save</zb:button>
<zb:button variant="primary" size="lg">Save</zb:button>
<zb:button variant="success" size="md">Save</zb:button>
<zb:button variant="success" size="sm">Save</zb:button>
<zb:button variant="success" size="lg">Save</zb:button>
<zb:button variant="danger" size="md">Save</zb:button>
<zb:button variant="danger" size="sm">Save</zb:button>
<zb:button variant="danger" size="lg">Save</zb:button>
<zb:button variant="secondary" size="md">Save</zb:button>
<zb:button variant="secondary" size="sm">Save</zb:button>
<zb:button variant="secondary" size="lg">Save</zb:button>
<zb:button variant="white" size="md">Save</zb:button>
<zb:button variant="white" size="sm">Save</zb:button>
<zb:button variant="white" size="lg">Save</zb:button>
<zb:button variant="ghost" size="md">Save</zb:button>
<zb:button variant="ghost" size="sm">Save</zb:button>
<zb:button variant="ghost" size="lg">Save</zb:button>
<zb:button variant="outline" size="md">Save</zb:button>
<zb:button variant="outline" size="sm">Save</zb:button>
<zb:button variant="outline" size="lg">Save</zb:button>
<zb:button variant="soft" size="md">Save</zb:button>
<zb:button variant="soft" size="sm">Save</zb:button>
<zb:button variant="soft" size="lg">Save</zb:button>
| Prop | Values |
|---|---|
variant | primary | success | danger | warning | info | secondary | dark | light | white | ghost | link; outline-* and soft-* (e.g. outline-danger, soft-success) |
size | sm | md | lg | icon |
With icons
Put the icon in the slot together with the text; for a square icon-only button, pass size="icon".
<div class="flex flex-wrap items-center gap-2">
<zb:button><zb:icon name="plus" size="4" /> New order</zb:button>
<zb:button variant="white"><zb:icon name="arrow-down-tray" size="4" /> Export to Excel</zb:button>
<zb:button variant="outline" size="icon" aria-label="Edit" title="Edit">
<zb:icon name="pencil-square" size="4" />
</zb:button>
<zb:button variant="soft-danger" size="icon" aria-label="Delete" title="Delete">
<zb:icon name="trash" size="4" />
</zb:button>
</div>
| Prop | Values |
|---|---|
size | icon (icon only) |
States
loading adds a spinning icon and disables the button, and disabled fades the button and blocks clicks.
<div class="flex flex-wrap items-center gap-2">
<zb:button loading disabled>Saving</zb:button>
<zb:button disabled>Disabled</zb:button>
<zb:button variant="white" disabled>Disabled</zb:button>
</div>
| Prop | Values |
|---|---|
loading | true | false |
disabled | true | false |
Link and form button
With href the button is rendered as an <a>; inside a form, pass type="submit".
<zb:button :href="route('orders.index')" variant="white" wire:navigate>Back to list</zb:button>
<form wire:submit="save">
…
<zb:button type="submit" wire:loading.attr="disabled" wire:target="save">Save</zb:button>
</form>
| Prop | Values |
|---|---|
href | Renders an <a> when given |
type | button | submit | reset |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
variant | — | primary | Solid: primary · success · danger · warning · info · secondary · dark · light — outline-* and soft-* in the same colors (outline = outline-primary, soft = soft-primary; gray = secondary) — neutral: white · ghost · link |
shadow | boolean | false | A shadow in the button's own color below solid buttons; goes away on hover |
badge | — | null | A count after the text (unread, items in the cart) |
size | — | md | sm · md · lg · icon |
href | — | null | Renders an <a> when given |
external | boolean | false | With href: opens in a new tab (target="_blank" rel="noopener"), adds an arrow icon and a screen reader note |
type | — | button | button · submit · reset |
disabled | boolean | false | Disables the button; with href, sets aria-disabled and tabindex="-1" |
loading | boolean | false | Spinning icon and aria-busy="true"; disables the button |
appearance | — | null | Form modal compatibility: outline (turns variant into outline-*) · text (ghost); use variant in new code |
(attributes) | — | — | class and other attributes are added to the button; a display class in class (hidden, block, flex …) replaces the default inline-flex |
Slots: default (button text and icon)
Advanced
With shadow
When shadow is given to solid buttons (primary, success, danger, warning, info, secondary, dark, light), a soft shadow in the button's color appears below it; the shadow goes away on hover. Use it to make the single main action of the page stand out.
<div class="flex flex-wrap gap-3">
<zb:button shadow>Save</zb:button>
<zb:button variant="success" shadow>Confirm</zb:button>
<zb:button variant="danger" shadow>Delete</zb:button>
<zb:button variant="warning" shadow>Hold</zb:button>
<zb:button variant="info" shadow>Info</zb:button>
<zb:button variant="secondary" shadow>Archive</zb:button>
<zb:button variant="dark" shadow>Draft</zb:button>
<zb:button variant="light" shadow>Preview</zb:button>
</div>
| Prop | Values |
|---|---|
shadow | true | false (solid buttons only) |
Count badge
badge adds a small count after the text: unread messages, items in the cart. The badge is an unfilled thin frame in the button's text colour, so it reads in every colour.
<div class="flex flex-wrap gap-3">
<zb:button badge="3">Orders</zb:button>
<zb:button variant="white" badge="12">Notifications</zb:button>
<zb:button variant="outline-success" badge="5">Awaiting approval</zb:button>
</div>
| Prop | Values |
|---|---|
badge | A number or short text |
Color table
Every color comes in three styles: solid (primary), outlined (outline-primary) and light-background (soft-primary). The names are consistent; to keep a color and change its style, change only the prefix.
<div class="grid gap-3">
@foreach (['primary', 'success', 'danger', 'warning', 'info', 'secondary', 'dark'] as $color)
<div class="flex flex-wrap items-center gap-2">
<span class="w-16 text-xs font-medium text-muted">{{ $color }}</span>
<zb:button :variant="$color">Solid</zb:button>
<zb:button :variant="'outline-'.$color">Outline</zb:button>
<zb:button :variant="'soft-'.$color">Soft</zb:button>
</div>
@endforeach
</div>
| Prop | Values |
|---|---|
colors | primary · success · danger · warning · info · secondary · dark |
style | (solid) · outline-{color} · soft-{color} |
Changing the colors
To change a color in every button (and in other components such as badges and alerts), set the --zb-tone-{color} variable in your CSS file to the color's bright shade (the palette's 500). The fill, its hover, the text and the shadow derive from it.
/* resources/css/app.css, after the @import lines */
@layer base {
:root, [data-theme] {
--zb-tone-primary: #0f766e;
--zb-tone-success: #22c55e;
}
}
| Prop | Values |
|---|---|
--zb-tone-{color} | primary · secondary · success · info · warning · danger · dark · accent |
Color names | {color} · {color}-hover · on-{color} · {color}-line · {color}-soft · {color}-tint-ink |
External link
On link buttons that go to another site, pass external together with href: the link opens in a new tab (target="_blank", rel="noopener"), a small arrow icon is added after the text, and screen readers are told "(opens in a new tab)". Icon-only buttons (size="icon") get no arrow, but the note is still read.
<div class="flex flex-wrap items-center gap-2">
<zb:button href="https://laravel.com/docs" variant="white" external>Laravel docs</zb:button>
<zb:button href="https://livewire.laravel.com/docs" variant="ghost" external>Livewire docs</zb:button>
</div>
| Prop | Values |
|---|---|
external | true | false (with href) |
Hiding on small screens
If you give a display class (hidden, block, flex, grid, contents …) in class, it is used instead of the default inline-flex. So class="hidden sm:inline-flex" hides the button on phones and shows it at sm and up.
<div class="flex flex-wrap items-center gap-2">
<zb:button><zb:icon name="plus" size="4" /> New order</zb:button>
<zb:button variant="white" class="hidden sm:inline-flex">
<zb:icon name="arrow-down-tray" size="4" /> Export to Excel
</zb:button>
</div>
| Prop | Values |
|---|---|
class | hidden sm:inline-flex · block · flex · grid … |
Developer notes
secondaryis a gray filled button,whitea white, bordered neutral button (Cancel, toolbars, pagination).ghosthas no background or border and is for light actions such as "clear selection";linklooks like a link but keeps the button's height.- Buttons paint with color names: the solid
successbutton usesbg-success,bg-success-hoveron hover andtext-on-successfor text. The fill is the dark shade white text reads on. primaryis the primary color; the color the user picks in the theme switcher takes precedence over it.loadingalso setsaria-busy="true". Hover, press and shadow do not work on a disabled button; an enabled button moves down by 1 pixel when pressed.- On a link,
typeandloadingare not used;disabledgives the linkaria-disabled="true", removes it from the Tab order and makes it unclickable. - To lock the button while a Livewire action runs, add
wire:loading.attr="disabled".
Accessibility
- Keyboard
- The component renders a real
<button>(defaulttype="button"), so Enter and Space come from the browser. Withhrefit renders an<a>, which opens with Enter. - Focus
- Keyboard focus draws a 2px outline, 2px off the edge (
focus-visible). A mouse click does not show it. - Disabled and loading
disabledsets the realdisabledattribute.loadingalso disables the button and addsaria-busy="true"; the spinner is hidden from screen readers. On a link,disabledbecomesaria-disabled="true"andtabindex="-1": the link leaves the tab order and ignores clicks.- New tab
externaladdstarget="_blank" rel="noopener"and a visually hidden "(opens in a new tab)" note for screen readers.- What you provide
- An icon-only button (
size="icon") has no visible text: give it anaria-label, plus atitlefor mouse users. Thebadgecount is read as part of the button name ("Orders 3"); if the number needs context, complete the name witharia-label.