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

Copy button and keyboard key

Two small helpers: zb:copy-button copies a text to the clipboard with one click, and zb:kbd shows keyboard keys styled as keys.

zb:copy-button · zb:kbd zubazar/ui · free (MIT)

Copying text

Copying text: view
BLADE

Pass the text to copy in text; variant and size set the look and label the text.

blade
<div class="flex flex-wrap items-center gap-3">
    <span class="font-mono text-sm text-ink">ORD-2026-004817</span>
    <zb:copy-button text="ORD-2026-004817" size="sm" />
    <zb:copy-button text="ORD-2026-004817" variant="soft" size="sm" label="Copy order number" />
</div>
PropValues
textText to copy
labelButton text; default "Copy"
variantzb:button variants; default white
sizesm | md | lg | icon

Copying from an element

Copying from an element: view
BLADE

Pass a CSS selector in target; the form field's value or the element's text is copied.

blade
<div class="space-y-2">
    <p id="delivery-address" class="rounded-sm bg-sunken p-3 text-sm">No. 7, Moda St., Caferağa Neighborhood, Kadıköy / Istanbul</p>
    <zb:copy-button target="#delivery-address" size="sm" label="Copy address" />
</div>

<div class="space-y-2">
    <zb:textarea id="order-note" label="Order note" rows="2">Please gift-wrap it and email the invoice separately.</zb:textarea>
    <zb:copy-button target="#order-note" size="sm" label="Copy note" />
</div>
PropValues
targetCSS selector, e.g. #delivery-address

Inside an input group

Inside an input group: view
BLADE

size="icon" shows only the icon; label then becomes the screen reader name and the tooltip.

blade
<zb:input-group id="invite-link" label="Invite link" value="https://panel.ornek.test/davet/K7M2-Q9XA" readonly>
    <zb:slot:after>
        <zb:copy-button
            target="#invite-link"
            variant="ghost"
            size="icon"
            label="Copy link"
            class="-me-1.5"
            x-on:copied="$dispatch('toast', { type: 'success', message: 'Invite link copied to the clipboard.' })"
        />
    </zb:slot:after>
</zb:input-group>
PropValues
size="icon"Icon only; the name comes from label
x-on:copiedRuns after a successful copy

Keyboard key

Keyboard key: view
BLADE

zb:kbd shows a single key within text, without breaking the flow of the line.

blade
<div class="space-y-3 text-sm text-dim">
    <p>Press <zb:kbd>Esc</zb:kbd> to close the open window.</p>
    <p>Move through the list with <zb:kbd>↑</zb:kbd> and <zb:kbd>↓</zb:kbd>, and press <zb:kbd>↵</zb:kbd> to select.</p>
</div>
PropValues
slotName or symbol of the key

Key combinations

Key combinations: view
BLADE

keys takes the keys pressed together as an array and puts separator between them; size="sm" draws smaller keys.

blade
<div class="space-y-3 text-sm text-dim">
    <p>Open search: <zb:kbd :keys="['⌘', 'K']" /> or <zb:kbd :keys="['Ctrl', 'K']" /></p>
    <p>Save your changes: <zb:kbd :keys="['Ctrl', 'Shift', 'S']" /></p>
    <div class="flex flex-wrap items-center gap-4">
        <zb:kbd :keys="['⌘', '⇧', 'P']" separator="" size="sm" />
        <zb:kbd :keys="['Alt', 'F4']" size="sm" />
    </div>
</div>
PropValues
keysArray, e.g. ['⌘', 'K']
separatorMark between the keys; default '+'
sizesm | md

Props

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

PropTypeDefaultDescription
copy-button: text—nullText written to the clipboard
copy-button: target—nullCSS selector used when text is not given: the value of a form field or the text of the element is copied
copy-button: label—CopyButton text; with size="icon", the screen reader name and the tooltip
copy-button: variant—whiteOne of the zb:button variants (primary, ghost, soft…)
copy-button: size—mdsm · md · lg · icon (icon only)
copy-button: timeoutnumber2000How many milliseconds the success or error state stays visible
copy-button: copied— — Event dispatched from the button after a successful copy; detail: { text }
kbd: keys—nullArray of keys pressed together; if omitted, the slot is a single key
kbd: separator—+Mark between the keys of a combination; an empty string removes it
kbd: size—mdsm · md

Slots: kbd: default content (a single key). copy-button takes no slot; attributes such as class, disabled, and wire:click are added to the button itself.

Developer notes

Events, hooks and details
  • On click, the button shows a check icon and "Copied" for timeout (2 seconds); the result is also announced to screen readers.
  • If the Clipboard API is not available (plain http, an iframe without permission), the older method is tried; if that fails too, the button says "Could not copy".
  • target is read at the moment of the click, so changes in the field and Livewire updates show in the copy; leading and trailing whitespace is removed.
  • After a successful copy, the button dispatches the copied event ($event.detail.text); the example shows a notification with it.
  • The default separator is +, and an empty string removes it; size="sm" is for menu rows and button hints.
  • Symbols such as ⌘, ⇧ and ↵ are read to screen readers as "Command", "Shift" and "Enter".

Events

EventdetailDescription
copied{ text }zb:copy-button: sent from the button after a successful copy; it bubbles. Not sent when copying fails.
Zubazar UI · ZubazarDesigned for people.