Skip to content
Likable Aurora @likable-hair/svelte 5

HorizontalStackedProgress

One bar split into colored segments, one per entry of progresses, each as wide as its share of the total, with a legend below. Without total the segments fill the bar; with total the rest of it stays empty. Colors come from the data palette unless an entry sets its own. label and showValue add a header like ProgressBar, segmentLabels writes each label under its segment, and hovering a segment shows its value in a tooltip. Screen readers read the legend, which stays in the page (visually hidden) when legend is false.

import { HorizontalStackedProgress } from '@likable-hair/svelte';

src/lib/components/composed/progress/HorizontalStackedProgress.svelte · Markdown for LLMs

Legend and total

Each entry takes its share of the bar; colors come from the data palette. With total the part not taken by the entries stays empty and showValue shows how much is taken. Hover a segment to see its value.

Agenda occupancy 86%
  • Colour 44%
  • Cut 24%
  • Treatments 18%
Code
<script lang="ts">
	import { HorizontalStackedProgress } from '@likable-hair/svelte';

	const bookings = [
		{ label: 'Colour', value: 44, valueLabel: '44%' },
		{ label: 'Cut', value: 24, valueLabel: '24%' },
		{ label: 'Treatments', value: 18, valueLabel: '18%' }
	];
</script>

<div class="box">
	<HorizontalStackedProgress progresses={bookings} total={100} label="Agenda occupancy" showValue />
</div>

<style>
	.box {
		width: min(100%, 420px);
	}
</style>

Labels under the segments

segmentLabels writes each label and value under its segment; minLabelPercentage hides them on segments too narrow to hold them. legend={false} hides the legend, which stays readable for screen readers. Entries can be plain numbers or set their own color.

Hours this week
  • Booked 31h
  • Walk-in 9h
  • Blocked 2h
  • 5
  • 3
  • 2
  • 1
Code
<script lang="ts">
	import { HorizontalStackedProgress } from '@likable-hair/svelte';

	const hours = [
		{ label: 'Booked', value: 31, valueLabel: '31h' },
		{ label: 'Walk-in', value: 9, valueLabel: '9h' },
		{ label: 'Blocked', value: 2, valueLabel: '2h', color: 'var(--global-color-error)' }
	];
</script>

<div class="stack">
	<HorizontalStackedProgress
		progresses={hours}
		label="Hours this week"
		segmentLabels
		minLabelPercentage={8}
		legend={false}
	/>
	<HorizontalStackedProgress progresses={[5, 3, 2, 1]} aria-label="Ratings" --horizontal-stacked-progress-height="6px" />
</div>

<style>
	.stack {
		display: grid;
		gap: 28px;
		width: min(100%, 420px);
	}
</style>

Props

NameTypeDefaultDescription
progresses (number | ProgressItem)[][]Entries of the bar: numbers or ProgressItem objects with label, color and value text.
total numberValue of the whole bar. Default: the sum of the entries, so the segments fill it.
label stringText above the bar, on the left. It also names the group for screen readers.
showValue booleanfalseShows the share of total taken by the entries above the bar, on the right.
legend booleantrueShows the legend below the bar. When false it stays in the page for screen readers only.
segmentLabels booleanfalseWrites each label and value under its segment.
minLabelPercentage numberHides the labels of segments that take this percentage of the bar or less.
valueTooltip booleantrueShows the label and value of a segment in a tooltip when the pointer is over it.
class string''Extra classes on the root element.

It also accepts the native attributes and events of <div> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
labelSnippet{ label: string | undefined }Replaces the text of the label.
valueSnippet{ value: number; total: number; percent: number }Replaces the percentage shown with showValue. Receives the sum of the entries, the total and the percentage (0–100).
legendItemSnippet{ item: Segment; percentage: number }Replaces the content of a legend entry (the colored dot stays).
segmentLabelSnippet{ item: Segment; percentage: number }Replaces the content under a segment.

Types

Exported by the package: import type { ProgressItem } from '@likable-hair/svelte';

ProgressItem

type ProgressItem = { … }

NameTypeDescription
label stringName of the entry, shown in the legend, under the segment and in the tooltip.
color stringAny CSS color. Default: the data palette, in order.
value requirednumberSize of the entry. Entries with 0 are not shown.
valueLabel string | numberText shown instead of the value, for example "3h 20m".

CSS variables

For a single instance, pass them as style props: <HorizontalStackedProgress --horizontal-stacked-progress-label-color="tomato">. The --horizontal-stacked-progress-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--horizontal-stacked-progress-gap
--horizontal-stacked-progress-default-gap 3px
--horizontal-stacked-progress-width
--horizontal-stacked-progress-default-width 100%
--horizontal-stacked-progress-header-gap
--horizontal-stacked-progress-default-header-gap 8px
--horizontal-stacked-progress-label-color
--horizontal-stacked-progress-default-label-color var(--global-color-text)
--horizontal-stacked-progress-label-font-size
--horizontal-stacked-progress-default-label-font-size 13px
--horizontal-stacked-progress-label-font-weight
--horizontal-stacked-progress-default-label-font-weight 600
--horizontal-stacked-progress-value-color
--horizontal-stacked-progress-default-value-color var(--global-color-text-3)
--horizontal-stacked-progress-value-font-family
--horizontal-stacked-progress-default-value-font-family var(--global-font-family-mono)
--horizontal-stacked-progress-value-font-size
--horizontal-stacked-progress-default-value-font-size 13px
--horizontal-stacked-progress-height
--horizontal-stacked-progress-default-height 12px
--horizontal-stacked-progress-segment-border-radius
--horizontal-stacked-progress-default-segment-border-radius 3px
--horizontal-stacked-progress-duration
--horizontal-stacked-progress-default-duration var(--global-duration)
--horizontal-stacked-progress-rest-background
--horizontal-stacked-progress-default-rest-background var(--global-color-surface-3)
--horizontal-stacked-progress-hover-filter
--horizontal-stacked-progress-default-hover-filter brightness(1.2)
--horizontal-stacked-progress-hover-scale
--horizontal-stacked-progress-default-hover-scale 1.3
--horizontal-stacked-progress-segment-label-gap
--horizontal-stacked-progress-default-segment-label-gap 8px
--horizontal-stacked-progress-segment-label-color
--horizontal-stacked-progress-default-segment-label-color var(--global-color-text-3)
--horizontal-stacked-progress-segment-label-font-size
--horizontal-stacked-progress-default-segment-label-font-size 12px
--horizontal-stacked-progress-segment-label-font-weight
--horizontal-stacked-progress-default-segment-label-font-weight 400
--horizontal-stacked-progress-segment-value-color
--horizontal-stacked-progress-default-segment-value-color var(--global-color-text)
--horizontal-stacked-progress-segment-value-font-size
--horizontal-stacked-progress-default-segment-value-font-size 16px
--horizontal-stacked-progress-segment-value-font-weight
--horizontal-stacked-progress-default-segment-value-font-weight 700
--horizontal-stacked-progress-dot-size
--horizontal-stacked-progress-default-dot-size 8px
--horizontal-stacked-progress-dot-border-radius
--horizontal-stacked-progress-default-dot-border-radius 2px
--horizontal-stacked-progress-legend-gap
--horizontal-stacked-progress-default-legend-gap 6px 16px
--horizontal-stacked-progress-legend-margin-top
--horizontal-stacked-progress-default-legend-margin-top 12px
--horizontal-stacked-progress-legend-color
--horizontal-stacked-progress-default-legend-color var(--global-color-text-2)
--horizontal-stacked-progress-legend-font-size
--horizontal-stacked-progress-default-legend-font-size 12.5px
--horizontal-stacked-progress-legend-value-color
--horizontal-stacked-progress-default-legend-value-color var(--global-color-text)
--horizontal-stacked-progress-legend-value-font-family
--horizontal-stacked-progress-default-legend-value-font-family var(--global-font-family-mono)
--horizontal-stacked-progress-legend-value-font-weight
--horizontal-stacked-progress-default-legend-value-font-weight 500