ShareBar
HkShareBar is a horizontal proportion bar: a row label, a track with a fill whose width is value / total, and a caption that is the raw value unless you pass pre-formatted text. It is the "X of Y" row of a usage table, a quota panel or any breakdown list — the shape that answers "how much of the whole is this line".
- The percentage is the only thing the bar draws: percentOverride sets it directly (0–100) when the number the host holds is already a share; otherwise it is value / total, with total not positive reading 0.
- A bounded quantity drawn as a bar with a label and a status is HkProgressBar; the share bar is always one line of a comparison.
- A single figure with no total belongs in HkRollingNumber or HkPrice; the bar exists to be read against its neighbours.
Import
;
use *; // ShareBar, ShareBarProps
use *; // rsx!, VNode
The Vue form is uncontrolled and stateless: every number is derived from props on each render, so a changed value simply re-renders the fill. The Rust form derives the same geometry from the same props.
Share of a total
value is the numerator, total the denominator, and the fill's width is the clamped percentage with the fraction kept (1 / 3 fills 33.333…%, not 33%) — the sheet transitions the width, so a rounded value would visibly desync the fill from the caption. The caption is the raw value through toLocaleString(), hence the grouping in 8,231.
Captions and colour
caption is pre-formatted text and wins over the raw number, which is what a usage table showing 41% instead of 8,231 wants. color paints the fill with any CSS colour in place of the sheet's primary; leave it out to keep the theme's ink. Both are presentation only — the announcement always uses the label and the one-decimal share.
The Rust mirror renders the caption's fallback number in the en-US grouped form, because the crate has no locale table to consult; a locale-less Vue host prints the same digits.
Overriding the percentage
percentOverride skips the division entirely and is clamped into 0–100: use it when the host already holds a share (41.2) and the raw value / total pair is not the number the bar should draw. A negative or over-100 override clamps instead of drawing outside the track.
The Rust mirror extends the bar with an opt-in copy path (on_copy): passing a handler turns the row into an activation surface that fires with the bar's own accessible text on click, Enter or Space. Vue's bar owns no copy affordance, so the prop has no Vue twin.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| label | String | — | ✓ |
| value | Number | — | ✓ |
| total | Number | — | ✓ |
| caption | String | undefined | — |
| percentOverride | Number | undefined | — |
| color | String | undefined | — |
Rust
Props — ShareBar
| Prop | Type | Default | Description |
|---|---|---|---|
| label | String | "" | The row label (Vue: required label). |
| value | f64 | 0.0 | The numerator (Vue: required value). |
| total | f64 | 0.0 | The denominator (Vue: required total). |
| caption | Option<String> | None | Pre-formatted value text; defaults to the raw number. |
| percent_override | Option<f64> | None | 0–100 override for the bar width; defaults to value / total. |
| color | Option<String> | None | Bar fill colour (any CSS colour); defaults to the sheet's primary. |
| on_copy | Option<EventHandler<String>> | None | Clipboard path (see the file header): fires with the bar's accessible text. |
| class | String | "" | Vue attribute fallthrough onto the root <div>. |
Accessibility
- The root is a role="img" with aria-label="<label>: <share>%", one decimal (glm-5.2: 41.2%), so the bar announces as one figure rather than as three loose spans.
- The row label is plain text with a title, so a truncated label stays readable on hover; the caption is muted, tabular-figure text.
- Nothing in the canonical node is focusable and no event is emitted, so the bar adds no stop to the Tab order.
- The Rust on_copy extension swaps the role to button and adds tabindex="0": the row then answers Enter and Space, and the payload it fires is the same string as its aria-label, so the copy contract cannot drift from the announcement. Use it only where a row is meant to be activatable.
- Colour is decorative: the share is in the text, never conveyed by the fill alone.
Related components
- HkRollingNumber — a live readout whose digits roll when the value changes.
- HkPrice — one amount, formatted with its currency's precision.
- HkProgressBar — a labelled bounded quantity with its own status semantics.
- Comment — the comment block for the text beside a breakdown row.