Comparison Bar
Segmented ratio bar comparing two or three quantities, such as the bid/ask balance of an order book.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
start-value | number | 0 | Amount of the start segment (bids, buyers, wins). Negative values count as 0. |
middle-value | number | undefined | undefined | Amount of the optional middle segment (draws, abstentions). Leave unset for a two-segment bar. |
end-value | number | 0 | Amount of the end segment (asks, sellers, losses). Negative values count as 0. |
start-label | string | — | Name of the start segment, announced before its share. |
middle-label | string | — | Name of the middle segment, announced before its share. |
end-label | string | — | Name of the end segment, announced before its share. |
show-value | boolean | false | Print each segment's percentage. Always on for a segment whose slot has content. |
precision | number | 2 | Fraction digits of the printed and announced percentages. |
locale | string | undefined | undefined | BCP 47 locale used to format the percentages; the document's locale when unset. |
Slots
| Name | Description |
|---|---|
start | Replaces the start segment's percentage text (e.g. "Buy 22%"). |
middle | Replaces the middle segment's percentage text. Only rendered when middle-value is set. |
end | Replaces the end segment's percentage text. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
start-value | Text region at the start edge containing the custom start slot or the start percentage fallback. |
middle-value | Text region under the middle segment containing the custom middle slot or the middle percentage fallback. |
end-value | Text region at the end edge containing the custom end slot or the end percentage fallback. |
track | Row holding the segments. |
start-segment | Segment sized by start-value. |
middle-segment | Segment sized by middle-value. |
end-segment | Segment sized by end-value. |
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-comparison-bar--width | pixel | 100% | Width of the whole component; the host is a block by default. |
--c2-comparison-bar--height | pixel | 6px | Thickness of the segments. |
--c2-comparison-bar--gap | pixel | 12px | Space between the edge percentages and the track. |
--c2-comparison-bar--border-radius | border-radius | 999px | Rounding of the bar's two outer ends. |
--c2-comparison-bar--transition-duration | time | 0.3s | How long a segment takes to resize when a value changes. |
--c2-comparison-bar__track--gap | pixel | 0px | Space between two segments; 0 makes them one continuous bar. |
--c2-comparison-bar__middle-value--margin-top | pixel | 4px | Space between the track and the middle percentage. |
--c2-comparison-bar__middle-value--color | color | #71717a | Colour of the middle percentage. |
--c2-comparison-bar__segment--border-radius | border-radius | 0px | Rounding of each segment's own ends; raise it with a track gap for separate pills. |
--c2-comparison-bar__start-segment--background-color | color | #0265dc | Colour of the start segment. |
--c2-comparison-bar__middle-segment--background-color | color | #a1a1aa | Colour of the middle segment. |
--c2-comparison-bar__end-segment--background-color | color | #dc2626 | Colour of the end segment. |
--c2-comparison-bar__start-value--color | color | #0265dc | Colour of the start percentage. |
--c2-comparison-bar__end-value--color | color | #dc2626 | Colour of the end percentage. |
--c2-comparison-bar__value--font-size | font-size | 14px | Size of the percentages. |
--c2-comparison-bar__value--font-weight | font-weight | 500 | Weight of the percentages. |