Bar List
A ranked list whose rows carry their own bar: top pages, referrers, countries, or the changes between two periods.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
items | BarListItem[] | [] | The rows. As an attribute, a JSON array of { label, value, href, icon }. |
sort | 'descending' | 'ascending' | 'none' | descending | The order of the rows: largest value first, smallest first, or as given. |
max-items | number | 0 | How many rows show before a button reveals the rest. 0 shows them all. |
diverging | boolean | false | Draws changes: positive bars grow right from a centre line, negative ones left, and values carry their sign. |
value-format | Intl.NumberFormatOptions | undefined | undefined | Intl.NumberFormat options for the values, as an object or JSON: {"style":"percent"}, {"style":"currency","currency":"EUR"}. |
max | number | undefined | undefined | The value the longest bar stands for. Defaults to the largest value (in absolute terms when diverging). |
interactive | boolean | false | Makes the rows without an href buttons that fire item-select. |
target | string | — | Where row links open. |
label-header | string | — | Title above the labels; with value-header, shows a header row. |
value-header | string | — | Title above the values. |
label | string | — | The accessible name of the list. Defaults to "Ranking" in the page's language. |
Events
| Name | Type | Description |
|---|---|---|
item-select | CustomEvent<{ item: BarListItem; index: number }> | An interactive row was pressed. index is its position in items. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
list | The list of rows. |
header | The row of column titles, shown when label-header or value-header is set. |
row | One row. |
bar | A row's bar. |
label | A row's label, drawn on its bar. |
icon | A row's icon. |
value | A row's value. |
toggle | The button that shows or hides the rows past max-items. |
empty | The message shown when there are no items. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-bar-list--width | length | 100% | The list fills its container by default, so the bars have room in a centred or flex layout. |
--c2-bar-list--gap | pixel | 6px | Space between the rows. |
--c2-bar-list__row--height | pixel | 32px | |
--c2-bar-list__row--column-gap | pixel | 16px | Space between the bar and the value. |
--c2-bar-list__row__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-bar-list__bar--background-color | color | #edf1fe | |
--c2-bar-list__bar--border-radius | border-radius | 4px | |
--c2-bar-list__bar__hover--background-color | color | #dce4fd | The bar of a link or an interactive row under the pointer. |
--c2-bar-list__bar__positive--background-color | color | #dcfce7 | A positive bar in diverging mode. |
--c2-bar-list__bar__negative--background-color | color | #fee2e2 | A negative bar in diverging mode. |
--c2-bar-list__axis--color | color | #e4e4e7 | The centre line in diverging mode. |
--c2-bar-list__label--padding | padding | 0 8px | Space around the label inside its bar. |
--c2-bar-list__label--color | color | #18181b | |
--c2-bar-list__label--font-size | font-size | 14px | |
--c2-bar-list__icon--size | pixel | 16px | |
--c2-bar-list__icon--border-radius | border-radius | 4px | |
--c2-bar-list__value--color | color | #18181b | |
--c2-bar-list__value--font-size | font-size | 14px | |
--c2-bar-list__value--font-weight | font-weight | 500 | |
--c2-bar-list__value__positive--color | color | #15803d | A positive value in diverging mode. |
--c2-bar-list__value__negative--color | color | #dc2626 | A negative value in diverging mode. |
--c2-bar-list__header--color | color | #71717a | |
--c2-bar-list__header--font-size | font-size | 12px | |
--c2-bar-list__header--font-weight | font-weight | 500 | |
--c2-bar-list__toggle--color | color | rgb(2, 101, 220) | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under bar-list, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Ranking | — |
showAll | Show all {0} | {0} count |
showFewer | Show fewer | — |
empty | No data | — |