- Button
- Examples
- Auto Click
- Variants
- Sizes
- Outline
- Text
- Icon
- Icon-Only Buttons
- Icon Buttons
- Plain Icon Buttons
- Icon Library
- Icon Position
- Icon Size and Color
- Square Buttons
- Pill Buttons
- Grow
- Loading State
- Processing While a Request Runs
- Notifications
- Tooltip
- Links
- Form Integration
- Long Press Menu
- Dropdown Closer
- Importing
- Properties
- Methods
Button
<zn-button>
ZnButton
<zn-button>Button</zn-button>
Examples
Auto Click
The auto-click attribute can be added to a button to make it automatically click after a given
time
<zn-button auto-click> Test Auto Button </zn-button auto-click> <br> <br> <zn-button color="transparent" auto-click auto-click-delay="5000"> Test Auto Button <zn-button slot="cancel" icon="close" icon-size="18" type="button" color="transparent" ></zn-button> </zn-button auto-click> <br> <br> <zn-button color="success" auto-click auto-click-delay="10000" loading-text="Accepting"> Test Auto Button <zn-style slot="cancel" margin="l"> <zn-button icon="call_end" icon-size="18" type="button" color="error" ></zn-button></zn-style> </zn-button>
Variants
Use the color attribute to set the button’s color.
<zn-button color="default">Default</zn-button> <zn-button color="secondary">Secondary</zn-button> <zn-button color="success">Success</zn-button> <zn-button color="info">Info</zn-button> <zn-button color="warning">Warning</zn-button> <zn-button color="error">Error</zn-button> <zn-button color="ai" icon="auto_awesome">AI</zn-button> <zn-button color="transparent">Transparent</zn-button>
Reserve color="ai" for actions that invoke AI or act on AI-generated content.
Sizes
Use the size attribute to pick a smaller or larger button. Heights follow the theme’s density.
<zn-button size="small">Small</zn-button> <zn-button>Medium</zn-button> <zn-button size="large">Large</zn-button>
Outline
Use the outline attribute to set the button’s outline.
<zn-button outline>Outline</zn-button> <zn-button outline color="secondary">Outline</zn-button> <zn-button outline color="success">Outline</zn-button> <zn-button outline color="info">Outline</zn-button> <zn-button outline color="warning">Outline</zn-button> <zn-button outline color="error">Outline</zn-button> <zn-button outline color="transparent">Outline</zn-button>
Text
Use the text attribute to set the button’s style to text.
<zn-button text>Outline</zn-button> <zn-button text color="secondary">Text</zn-button> <zn-button text color="success">Text</zn-button> <zn-button text color="info">Text</zn-button> <zn-button text color="warning">Text</zn-button> <zn-button text color="error">Text</zn-button> <zn-button text color="transparent">Text</zn-button>
Icon
Use the icon attribute to add an icon to the button.
<zn-button icon="add_circle">Icon</zn-button> <zn-button icon="file_download" color="secondary">Icon</zn-button> <zn-button icon="check" color="success">Icon</zn-button> <zn-button icon="help" color="info">Icon</zn-button> <zn-button icon="report_problem" color="warning">Icon</zn-button> <zn-button icon="cancel" color="error">Icon</zn-button> <zn-button icon="pending" color="transparent">Icon</zn-button>
Icon-Only Buttons
Buttons can be used with just an icon and no text by omitting the button label.
<zn-button icon="settings"></zn-button> <zn-button icon="favorite" color="error"></zn-button> <zn-button icon="share" color="success"></zn-button> <zn-button icon="add" color="info"></zn-button>
An icon-only button has no text for assistive technology to read, so give it a name with the
label attribute. A tooltip is used as the name when no label is set,
which covers most icon-only buttons without extra markup.
<zn-button icon="settings" label="Settings"></zn-button> <zn-button icon="delete" color="error" tooltip="Delete"></zn-button>
Icon Buttons
Use icon-button to render a chromed icon button: a 40x36 white button with a border, a 6px
radius, and a centred 20px icon. Pass small for the 36x36 variant or round for a
36x36 circle on the tab tint. The icon button style takes precedence over color variants like
secondary — the color attribute only tints the icon.
<zn-button icon-button icon="inventory_2"></zn-button> <zn-button icon-button="small" icon="inventory_2"></zn-button> <zn-button icon-button="round" icon="search"></zn-button> <zn-button icon-button icon="favorite" color="error"></zn-button> <zn-button icon-button icon="check" color="success"></zn-button>
Plain Icon Buttons
Add plain to remove the white background and border while keeping the button’s size, for quiet
inline actions. Hovering tints the background with the tab colour; add no-hover to suppress
that too, for placements where the tint doesn’t fit (e.g. on an already-tinted surface).
<zn-button icon-button plain icon="settings"></zn-button> <zn-button icon-button="small" plain icon="close" color="error" tooltip="Remove"></zn-button> <zn-button icon-button plain no-hover icon="close" color="error" tooltip="Remove Note"></zn-button>
Icon Library
Use icon-library to load the button’s icon from a different icon library, passed through to the
nested zn-icon.
<zn-button icon-button icon="flag" icon-library="lucide"></zn-button> <zn-button icon="rocket" icon-library="lucide">Launch</zn-button>
Icon Position
Use the icon-position attribute to control whether the icon appears before or after the button
text.
<zn-button icon="arrow_back" icon-position="left">Back</zn-button> <zn-button icon="arrow_forward" icon-position="right">Next</zn-button>
Icon Size and Color
Use icon-size and icon-color attributes to customize the icon appearance.
<zn-button icon="star" icon-size="24" icon-color="warning">Large Star</zn-button> <zn-button icon="favorite" icon-size="20" icon-color="error">Favorite</zn-button> <zn-button icon="info" icon-size="16" icon-color="info">Info</zn-button>
Square Buttons
Use the square attribute to create square-shaped buttons, useful for icon-only buttons.
<zn-button icon="delete" square></zn-button> <zn-button icon="edit" square color="info"></zn-button> <zn-button icon="save" square color="success"></zn-button> <zn-button icon="close" square color="error"></zn-button>
Pill Buttons
Use the pill attribute for a label-like trigger rather than an action: fully rounded, sentence
case and regular weight, so it reads as a value you can change rather than a command.
<zn-button pill panel-bg icon="chevron-down@lu" icon-position="right">Role</zn-button> <zn-button pill panel-bg icon="chevron-down@lu" icon-position="right">Status: Active</zn-button>
Grow
Use the grow attribute to make the button expand to fill its container width.
<zn-button grow>Full Width Button</zn-button> <zn-button grow color="success">Submit Form</zn-button>
Loading State
Use the loading attribute to show a loading state on the button.
<zn-button loading loading-text="Processing...">Click Me</zn-button> <zn-button loading loading-text="Saving" color="success">Save</zn-button> <zn-button loading loading-text="Loading" color="info">Load Data</zn-button>
Processing While a Request Runs
Add processing-on-request to a link button to show its spinner from when the console sends the
request it started until that request completes, fails or is cancelled. Use it where nothing else on screen
shows the load, such as a refresh button.
<zn-button icon="refresh-cw@lu" icon-button="small" tooltip="Refresh" href="/" data-target="self" processing-on-request plain></zn-button>
Notifications
Use the notification attribute to display a notification badge on the button. Positive numbers
show the count, while negative numbers show a dot indicator.
<zn-button icon="notifications" notification="5">Notifications</zn-button> <zn-button icon="mail" notification="12" color="info">Messages</zn-button> <zn-button icon="chat" notification="-1" color="success">Chat</zn-button> <zn-button icon="notifications" notification="0">No Notifications</zn-button>
Use muted-notifications for a subtle notification style.
<zn-button icon="notifications" notification="3" muted-notifications>Muted</zn-button>
Tooltip
Use the tooltip attribute to add a tooltip to the button. On a button with no text, the tooltip
also becomes the accessible name — see Icon-Only Buttons.
<zn-button icon="info" tooltip="This button provides additional information"></zn-button> <zn-button icon="help" tooltip="Click for help" color="info">Help</zn-button>
Links
Buttons can work as hyperlinks by using the href attribute.
<zn-button href="https://example.com" target="_blank">External Link</zn-button> <zn-button href="/dashboard" icon="dashboard">Dashboard</zn-button> <zn-button href="/settings" icon="settings" text>Settings</zn-button>
Form Integration
Buttons can be used in forms with various form-related attributes.
<form> <zn-input name="email" type="email" label="Email" value="test@example.com"></zn-input> <br /> <zn-button type="submit" color="success">Submit</zn-button> <zn-button type="reset" color="secondary">Reset</zn-button> </form>
You can also override form attributes using formaction, formmethod,
formenctype, formnovalidate, and formtarget.
<form action="/default" method="post"> <zn-input name="query" label="Search"></zn-input> <br /> <zn-button type="submit">Default Submit</zn-button> <zn-button type="submit" formaction="/search" formmethod="get">Search</zn-button> </form>
Long Press Menu
Put a <zn-menu> in the menu slot to give a button advanced options, the way
an app in the macOS Dock shows its menu when held. A click still runs the button’s own action; holding it
for long-press-delay milliseconds (500 by default) opens the menu instead. Keep holding and
drag onto an item, then release, to choose it in one gesture.
Right click, Arrow Down, Shift+F10 and the context menu key also open the
menu. Use menu-placement to change where it opens.
Clicks on menu items bubble through the button, so a click listener on the button also hears
them. Wire item actions through the menu’s zn-select event, or check event.target.
<zn-button color="primary" class="long-press-example" long-press-delay="400"> Send <zn-menu slot="menu"> <zn-menu-item value="schedule">Schedule send</zn-menu-item> <zn-menu-item value="draft">Save as draft</zn-menu-item> <zn-menu-item value="test">Send a test to myself</zn-menu-item> </zn-menu> </zn-button> <script type="module"> const button = document.querySelector('.long-press-example'); button.addEventListener('click', e => { if (e.target === button) alert('Send'); }); button.querySelector('zn-menu').addEventListener('zn-select', e => alert(e.detail.item.value)); </script>
Dropdown Closer
Use the dropdown-closer attribute to automatically close parent dropdowns when the button is
clicked.
<zn-dropdown> <zn-button slot="trigger">Menu</zn-button> <zn-menu> <zn-menu-item> <zn-button dropdown-closer text>Close on Click</zn-button> </zn-menu-item> <zn-menu-item> <zn-button text>Stays Open</zn-button> </zn-menu-item> </zn-menu> </zn-dropdown>
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/@kubex/zinc@2.0.44/dist/components/button/button.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/@kubex/zinc@2.0.44/dist/components/button/button.js';
To import this component using a bundler:
import '@kubex/zinc/dist/components/button/button.js';
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
color
|
ai is reserved for actions that invoke or act on AI-generated content. |
'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | 'ai' |
'transparent' | 'star' | (string & Record
|
'default'
|
|
solid
|
Keeps the filled look where a container forces text, such as a page header’s action
menu.
|
boolean
|
false
|
|
iconButton
icon-button
|
Renders the button as an icon button (40x36). Pass small for the 36x36 variant or
round for a 36x36 circle: icon-button, icon-button="small" or
icon-button="round".
|
boolean | 'small' | 'round'
|
false
|
|
plain
|
With icon-button, removes the white background and border while keeping the button’s
size.
|
boolean
|
false
|
|
noHover
no-hover
|
Disables the hover background, for contexts where the tint doesn’t fit. |
boolean
|
false
|
|
pill
|
Renders the button as a pill: fully rounded, sentence case and regular weight. For label-like triggers such as filter chips. |
|
boolean
|
false
|
longPressDelay
long-press-delay
|
How long, in milliseconds, the button must be held to open the menu slot. |
number
|
500
|
|
menuPlacement
menu-placement
|
Where the menu slot opens relative to the button. |
'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' |
'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end'
|
'bottom-start'
|
|
label
|
Accessible name for the button. Icon-only buttons fall back to tooltip. |
string
|
- | |
pressed
aria-pressed
|
Toggle state, forwarded to the inner button’s aria-pressed. |
'true' | 'false' | 'mixed'
|
- | |
expanded
aria-expanded
|
Popup state, forwarded to the inner button’s aria-expanded. |
'true' | 'false'
|
- | |
hasPopup
aria-haspopup
|
Popup type, forwarded to the inner button’s aria-haspopup. |
string
|
- | |
processing
|
Shows a spinner and ignores clicks, e.g. while a request is in flight. |
|
boolean
|
false
|
processingText
processing-text
|
Replaces the label while processing. |
string
|
''
|
|
processingOnRequest
processing-on-request
|
Shows the processing state while a pagelet request this button started is in flight, e.g. a refresh link. |
boolean
|
false
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Methods
| Name | Description | Arguments |
|---|---|---|
showMenu() |
Opens the advanced options in the menu slot. |
- |
hideMenu() |
Closes the advanced options in the menu slot. |
- |
Learn more about methods.