Button
HkButton is the canonical button of the design system: a native <button> element with five semantic variants, four size steps, an optional leading or trailing glyph, a keyboard-shortcut chip, a busy state and an accessible name. Reach for it whenever the user triggers an action — a form's submit, a dialog's footer, a toolbar command.
- For an icon-only trigger in a dense chrome row, use HkIconButton: the same family in a square footprint.
- For the single floating primary action of a page, use HkFab.
- For a dashed "add one more" affordance, use HkAddTile.
Import
;
use *; // Button, ButtonVariant, ButtonSize
use *; // rsx!, VNode, Icon, MdiIcon
The Rust form is a plain function, Button(ButtonProps { … }). Inside rsx! every prop may be omitted — an omitted prop takes its default — and the component's children fill its default slot. The examples below omit the imports the page has just shown.
Variants
The variant picks the ink and the fill: primary (the default) for the one main action of a surface, secondary for companions of a primary action, outline for a quieter framed action, ghost for an action that sits inside other content, and danger for a destructive action.
Sizes
Four steps, xs / sm / md / lg; md is the default. The step sets padding, minimum height and font size; the glyph stays 16px on every step.
Glyphs, labels and shortcuts
icon and suffix put a 16px glyph before and after the caption, and shortcut renders a kbd chip at the end. A button that carries a glyph but no text collapses to the same square as an icon button. Pass label instead of a default slot when the caption should also serve as the accessible name — which it must do with collapseLabel, the breakpoint below which the visible label disappears.
In the Vue form icon and suffix are registry names (lucide export names such as "Plus"); in the Rust form they are element slots, so the example passes the crate's own Icon.
States
loading replaces the glyph with a ring, sets aria-busy and disables the button while keeping it mounted; disabled is the native disabled state; block stretches the button to the full width of its container.
Interaction
The click event carries the native MouseEvent. The example counts presses; the Rust form has no snapshot here because a snapshot is a still — it never runs an event handler. onclick is the Rust prop that receives the same event.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| variant | String as PropType<ButtonVariant> | "primary" | — |
| size | String as PropType<ButtonSize> | "md" | — |
| loading | Boolean | false | — |
| disabled | Boolean | false | — |
| block | Boolean | false | — |
| ariaLabel | String | undefined | — |
| shortcut | String | undefined | — |
| icon | String | undefined | — |
| suffix | String | undefined | — |
| label | String | undefined | — |
| collapseLabel | String as PropType<ButtonLabelCollapse> | undefined | — |
Emits
| Event | Payload |
|---|---|
| click | MouseEvent |
Rust
Props — Button
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | ButtonVariant | ButtonVariant::Primary | Semantic variant (hk-btn-{variant}); also the ink/fill pair. |
| size | ButtonSize | ButtonSize::Md | Size step (hk-btn-{size}). |
| loading | bool | false | Busy state: renders the SMIL ring, hides the prefix glyph and forces disabled (Vue: <code>disabled || loading</code>) while keeping the button mounted and aria-busy. |
| disabled | bool | false | Native disabled (plus loading, which disables as well). |
| block | bool | false | Full-width presentation (hk-btn-block); also suppresses the label-collapse class (a full-width button has nothing to collapse into). |
| aria_label | Option<String> | None | Accessible name override; when unset the label text is used (Vue: ariaLabel ?? label). |
| label | Option<String> | None | Plain-text label rendered in .hk-btn-label after the glyph. |
| collapse_label | Option<ButtonLabelCollapse> | None | Breakpoint below which the label hides and the button collapses to the icon-only square. |
| shortcut | Option<String> | None | Keyboard shortcut hint, rendered as HKbd (size: sm) in a trailing chip. |
| icon | Option<Element> | None | Prefix glyph slot, rendered inside .hk-btn-icon and hidden while loading (Vue: the icon name prop through HIcon; see the file header delta). |
| suffix | Option<Element> | None | Suffix glyph slot, rendered inside .hk-btn-suffix (stays visible while loading, like Vue). |
| children | Element | (empty) | Default slot: the button body when no label text is given. |
| onclick | Option<EventHandler<MouseEvent>> | None | Click handler (Vue: the click emit). |
| onmouseenter | Option<EventHandler<MouseEvent>> | None | Pointer-enter handler on the root <button> (Vue: an onMouseenter listener reaches the root through the $attrs fallthrough). |
| onmouseleave | Option<EventHandler<MouseEvent>> | None | Pointer-leave handler on the root <button> (Vue: onMouseleave through the fallthrough). |
| attrs | Vec<(String, String)> | [] | Attributes set on the root <button> by name, after the component's own: title, id, form, data-*, aria-*, test hooks (Vue: the $attrs fallthrough). |
| class | String | "" | Extra class appended after the whole .hk-btn* family (Vue merges attrs.class last). |
| style | String | "" | Host style attribute (Vue: <code>attrs.style || undefined</code> — omitted when empty). |
| button_type | String | "button".to_string() | type attribute (Vue: <code>attrs.type || "button"</code>). |
| autofocus | bool | false | Autofocus attribute (Vue: attrs passthrough). |
Accessibility
- The button is a real <button>: it is focusable and reacts to Enter and Space. Its accessible name is the ariaLabel prop, else the label prop, else the default slot's text.
- An icon-only button needs an explicit ariaLabel — a glyph alone names nothing.
- While loading the button publishes aria-busy="true" and the native disabled attribute, so assistive technology announces the busy state instead of a vanishing control.
- With collapseLabel the visible label disappears below the breakpoint but label stays the accessible name.
Related components
- HkIconButton — the square, icon-only member of the family.
- HkFab — the floating action button, with an optional speed dial.
- HkAuthSubmitButton — a block button that runs the sign-in challenge lifecycle.
- HkSupplementInset — a button surface with a hover-revealed secondary control.