CopyBadge
HkCopyBadge is the house standard for interactive tags: a badge that never selects text and copies on click, with a "Click to copy" tooltip. Text selection is off on every badge; this one adds the other halves of the contract — the hover hint and the copy itself, routed through the shared clipboard-with-toast path so every host confirms with the same localized toast.
- The rendered label is the default payload; pass value when the string worth copying differs from what is displayed (a short display id backed by a longer one).
- A tag that is only a label is HkTag; a status readout is HkStatusPill. The copy badge is the one that is a button.
- action swaps the click behavior outright (open a panel, jump to a record). That is only honest when the tooltip stops claiming copy — pass tooltip alongside.
Import
;
use CopyBadge; // under `theme::copy_badge`, not at the crate root
use *; // rsx!, VNode, Callback, BadgeVariant, BadgeSize
The Rust import is deliberately the long form: CopyBadge is declared in theme/copy_badge.rs and the crate root does not re-export it — theme/mod.rs re-exports the module's items, but the root's own pub use theme::{ … } lists only the theme API, so neither use hikari_components::* nor use hikari_components::theme::CopyBadge brings the component in. The Rust form is stateless and owns no clipboard: on_copy receives the resolved payload and the host does the write and the confirming toast.
The copy face
A click stops propagation first — a tag inside a selectable row copies without selecting the row — then copies. The keyboard path is Enter or Space, which is prevented from scrolling and stopped from reaching the row, then the same activation. value keeps its whitespace verbatim; an empty value copies nothing, and with no value the trimmed label is the payload.
Only a TSX fence can show the interaction live; click the badge below and the payload is copied through the shared clipboard-with-toast path.
The Rust fence renders the static badge faces: a snapshot cannot execute a click, so the copy path there is the on_copy sink — the host wires it and owns the clipboard write and the toast.
Badge anatomy
variant and size are HkBadge's own tokens (default / primary / success / error / warning / info / muted, and sm / md), so the pill matches the badge next to it. mono switches the label to the monospace face, uppercase upcases it, pill (on by default) rounds it fully, dot adds the leading status dot — which, with no label, collapses to a dot-only badge. color, bgColor and borderColor override the tone through the badge's CSS variables.
Disabled and action faces
disabled drops the interactivity entirely: no tooltip, no pointer cursor, no button semantics — the plain inert badge face is rendered, with the copy-only class removed so the sheet's cursor and focus rules do not apply either. action replaces the copy with a callback and must come with its own tooltip, or the hover hint goes on claiming copy.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| value | String | undefined | — |
| tooltip | String | undefined | — |
| action | Function as PropType<() => void> | undefined | — |
| disabled | Boolean | false | — |
| variant | String as PropType<BadgeVariant> | "default" | — |
| dot | Boolean | false | — |
| size | <code>String as PropType<"sm" | "md"></code> | "md" | — |
| mono | Boolean | false | — |
| uppercase | Boolean | false | — |
| pill | Boolean | true | — |
| color | String | undefined | — |
| bgColor | String | undefined | — |
| borderColor | String | undefined | — |
Rust
Props — CopyBadge
| Prop | Type | Default | Description |
|---|---|---|---|
| value | Option<String> | None | What a click copies; None falls back to the rendered label (Vue: the badge root's textContent, trimmed). |
| tooltip | Option<String> | None | Tooltip override; None uses the localized "Click to copy". |
| action | Option<Callback<()>> | None | Swaps the click behavior outright (must come with a custom tooltip so the hint stops claiming copy — Vue warns otherwise). |
| disabled | bool | false | Render the inert badge face: no tooltip, no click, no cursor. |
| variant | BadgeVariant | BadgeVariant::Default | — |
| dot | bool | false | — |
| size | BadgeSize | BadgeSize::Md | — |
| mono | bool | false | — |
| uppercase | bool | false | — |
| pill | bool | true | — |
| color | Option<String> | None | — |
| bg_color | Option<String> | None | — |
| border_color | Option<String> | None | — |
| label | String | "" | The rendered badge text (also the default copy payload base). |
| class | String | "" | Host class merged onto the badge root (Vue: attrs.class). |
| on_copy | Option<Callback<String>> | None | Copy sink — receives the resolved payload (wasip2 has no clipboard; see the CLIPBOARD delta). |
Accessibility
- The tag is a real button: role="button", tabindex="0", and Enter / Space both preventDefault and stopPropagation before activating, so a tag inside a selectable row never selects or scrolls the row.
- A click stops propagation before it copies; wrapping the tag in a clickable card is therefore safe.
- While visible, the tooltip's popup is linked to the badge through aria-describedby in Vue, so the hint is announced on focus; the Rust mirror's Tooltip owns that link at the wrapper level instead.
- The disabled face keeps no button semantics and no tooltip, so it is not announced as actionable — the wording must carry the state.
- .hk-badge bans text selection at the base, so a copy badge can never be half-selected by a drag that started in surrounding prose.
Related components
- HkTag — the same pill without the copy contract, for filters and selections the user dismisses.
- HkStatusPill — a compact health readout with a dot and words.
- HkShareBar — the proportion row; its Rust mirror takes the same on_copy seam.
- Comment — the comment block, where a copyable handle usually sits beside the author.