v0.0.2
Demos (demo panel, opens in a new tab)

Button

A button that starts an action; with href it is rendered as a link.

zb:button zubazar/ui · free (MIT)

Variant and size

Variant and size: view
BLADE

Pick the color with variant and the size with size; primary is for the page's main action, danger for irreversible actions.

variant
size
blade
<zb:button variant="primary" size="md">Save</zb:button>
blade
<zb:button variant="primary" size="sm">Save</zb:button>
blade
<zb:button variant="primary" size="lg">Save</zb:button>
blade
<zb:button variant="success" size="md">Save</zb:button>
blade
<zb:button variant="success" size="sm">Save</zb:button>
blade
<zb:button variant="success" size="lg">Save</zb:button>
blade
<zb:button variant="danger" size="md">Save</zb:button>
blade
<zb:button variant="danger" size="sm">Save</zb:button>
blade
<zb:button variant="danger" size="lg">Save</zb:button>
blade
<zb:button variant="secondary" size="md">Save</zb:button>
blade
<zb:button variant="secondary" size="sm">Save</zb:button>
blade
<zb:button variant="secondary" size="lg">Save</zb:button>
blade
<zb:button variant="white" size="md">Save</zb:button>
blade
<zb:button variant="white" size="sm">Save</zb:button>
blade
<zb:button variant="white" size="lg">Save</zb:button>
blade
<zb:button variant="ghost" size="md">Save</zb:button>
blade
<zb:button variant="ghost" size="sm">Save</zb:button>
blade
<zb:button variant="ghost" size="lg">Save</zb:button>
blade
<zb:button variant="outline" size="md">Save</zb:button>
blade
<zb:button variant="outline" size="sm">Save</zb:button>
blade
<zb:button variant="outline" size="lg">Save</zb:button>
blade
<zb:button variant="soft" size="md">Save</zb:button>
blade
<zb:button variant="soft" size="sm">Save</zb:button>
blade
<zb:button variant="soft" size="lg">Save</zb:button>
PropValues
variantprimary | success | danger | warning | info | secondary | dark | light | white | ghost | link; outline-* and soft-* (e.g. outline-danger, soft-success)
sizesm | md | lg | icon

With icons

With icons: view
BLADE

Put the icon in the slot together with the text; for a square icon-only button, pass size="icon".

blade
<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>
PropValues
sizeicon (icon only)

States

States: view
BLADE

loading adds a spinning icon and disables the button, and disabled fades the button and blocks clicks.

blade
<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>
PropValues
loadingtrue | false
disabledtrue | false

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
variant—primarySolid: 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
shadowbooleanfalseA shadow in the button's own color below solid buttons; goes away on hover
badge—nullA count after the text (unread, items in the cart)
size—mdsm · md · lg · icon
href—nullRenders an <a> when given
externalbooleanfalseWith href: opens in a new tab (target="_blank" rel="noopener"), adds an arrow icon and a screen reader note
type—buttonbutton · submit · reset
disabledbooleanfalseDisables the button; with href, sets aria-disabled and tabindex="-1"
loadingbooleanfalseSpinning icon and aria-busy="true"; disables the button
appearance—nullForm 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

6 examples

With shadow

With shadow: view
BLADE

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.

blade
<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>
PropValues
shadowtrue | false (solid buttons only)

Count badge

Count badge: view
BLADE

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.

blade
<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>
PropValues
badgeA number or short text

Color table

Color table: view
BLADE

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.

blade
<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>
PropValues
colorsprimary · success · danger · warning · info · secondary · dark
style(solid) · outline-{color} · soft-{color}

Changing the colors

CSS

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.

css
/* resources/css/app.css, after the @import lines */
@layer base {
    :root, [data-theme] {
        --zb-tone-primary: #0f766e;
        --zb-tone-success: #22c55e;
    }
}
PropValues
--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

Hiding on small screens

Hiding on small screens: view
BLADE

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.

blade
<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>
PropValues
classhidden sm:inline-flex · block · flex · grid …

Developer notes

Events, hooks and details
  • secondary is a gray filled button, white a white, bordered neutral button (Cancel, toolbars, pagination). ghost has no background or border and is for light actions such as "clear selection"; link looks like a link but keeps the button's height.
  • Buttons paint with color names: the solid success button uses bg-success, bg-success-hover on hover and text-on-success for text. The fill is the dark shade white text reads on.
  • primary is the primary color; the color the user picks in the theme switcher takes precedence over it.
  • loading also sets aria-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, type and loading are not used; disabled gives the link aria-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> (default type="button"), so Enter and Space come from the browser. With href it 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
disabled sets the real disabled attribute. loading also disables the button and adds aria-busy="true"; the spinner is hidden from screen readers. On a link, disabled becomes aria-disabled="true" and tabindex="-1": the link leaves the tab order and ignores clicks.
New tab
external adds target="_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 an aria-label, plus a title for mouse users. The badge count is read as part of the button name ("Orders 3"); if the number needs context, complete the name with aria-label.
Zubazar UI · ZubazarDesigned for people.