action-button
A button in six variants and three sizes, on a native <button> (or <a> with href), so it submits forms, takes type, and works with the keyboard and screen readers as the browser's own. loading keeps its size, shows a spinner, marks it busy and stops it being pressed again.
Try it: events appear here (click).
Every variant and size
Source: action-button.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/action-button.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/action-button.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/action-button.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/action-button.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/action-button.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/action-button.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/action-button.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/action-button.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/action-button.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/action-button.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/action-button.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/action-button.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/action-button.js"></script>The compiled install writes src/components/zubra/action-button.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<action-button variant="primary">
Save changes
</action-button>
<script type="module">
import './components/zubra/action-button.js';
const element = document.querySelector('action-button');
element.addEventListener('click', (event) => console.log('click', event.detail));
</script>import './components/zubra/action-button.js';
export function ActionButtonExample() {
return (
<action-button
variant="primary"
onclick={(event) => console.log('click', event.detail)}
>
Save changes
</action-button>
);
}<script setup>
import './components/zubra/action-button.js';
const onClick = (event) => console.log('click', event.detail);
</script>
<template>
<action-button variant="primary" @click="onClick">
Save changes
</action-button>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/action-button.js';
</script>
<action-button
variant="primary"
onclick={(event) => console.log('click', event.detail)}
>
Save changes
</action-button>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/action-button.js';
@Component({
selector: 'app-action-button-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<action-button variant="primary" (click)="onClick($event)">
Save changes
</action-button>
`,
})
export class ActionButtonExample {
onClick(event: Event) {
console.log('click', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
variant | "primary" | "secondary" | "outline" | "ghost" | "destructive" | "link" | "primary" |
size | "sm" | "md" | "lg" | "md" |
type | "button" | "submit" | "reset" | "button" |
disabled | boolean | false |
loading | boolean | false |
name | string | "" |
value | string | "" |
label | string | "" |
href | string | "" |
target | string | "" |
| Slot | For |
|---|---|
(default) | The button's text, and an icon if you want one. |
Size
1.6 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.8 KB.