feat(progress): add segmented bars Show progress as a row of rounded segments. Align single and stacked fills to whole segments and document examples with theme colors.
diff --git a/scss/_progress.scss b/scss/_progress.scss index 4d042e2..800081b 100644 --- a/scss/_progress.scss +++ b/scss/_progress.scss
@@ -8,6 +8,7 @@ $progress-tokens: () !default; +// stylelint-disable custom-property-no-missing-var-function // scss-docs-start progress-tokens // stylelint-disable-next-line scss/dollar-variable-default $progress-tokens: defaults( @@ -21,10 +22,12 @@ --progress-bar-bg: var(--primary-bg), --progress-bar-transition: width .6s ease, --progress-bar-animation: progress-bar-stripes 1s linear infinite, + --progress-segment-step: .375rem, ), $progress-tokens ); // scss-docs-end progress-tokens +// stylelint-enable custom-property-no-missing-var-function // Disable animation if transitions are disabled @@ -67,6 +70,35 @@ background-size: var(--progress-height) var(--progress-height); } + .progress-segmented { + --progress-height: .625rem; + --progress-bg: color-mix(in oklch, var(--theme-bg, var(--progress-bar-bg)) 15%, transparent); + --progress-border-radius: 0; + --progress-box-shadow: none; + --progress-segment-position: left; + + // Apply one mask to the track and fill so the segments align. + mask-image: radial-gradient(ellipse 33.333% 50%, #000 95%, transparent), linear-gradient(to right, transparent 16.667%, #000 16.667% 83.333%, transparent 83.333%), radial-gradient(ellipse 33.333% 50%, #000 95%, transparent); + mask-repeat: repeat-x; + mask-position: var(--progress-segment-position) top, var(--progress-segment-position) center, var(--progress-segment-position) bottom; + mask-size: var(--progress-segment-step) min(.25rem, 50%), var(--progress-segment-step) calc(100% - min(.25rem, 50%)), var(--progress-segment-step) min(.25rem, 50%); + + &:dir(rtl) { + --progress-segment-position: right; + } + } + + .progress-segmented, + .progress-segmented > .progress-bar { + --progress-segment-remainder: mod(100%, var(--progress-segment-step)); + + clip-path: inset(0 var(--progress-segment-remainder) 0 0); + + &:dir(rtl) { + clip-path: inset(0 0 0 var(--progress-segment-remainder)); + } + } + .progress-stacked > .progress { overflow: visible; } @@ -75,6 +107,15 @@ width: 100%; } + .progress-stacked.progress-segmented > .progress { + --progress-height: inherit; + --progress-bg: transparent; + --progress-border-radius: inherit; + --progress-box-shadow: inherit; + + flex: 0 0 round(down, var(--progress-segmented-width, 0%), var(--progress-segment-step)); + } + @if $enable-transitions { .progress-bar-animated { animation: var(--progress-bar-animation);
diff --git a/site/src/content/docs/components/progress.mdx b/site/src/content/docs/components/progress.mdx index 6e00979..c17a97c 100644 --- a/site/src/content/docs/components/progress.mdx +++ b/site/src/content/docs/components/progress.mdx
@@ -130,6 +130,35 @@ </div> </div>`} /> +## Segmented + +Add `.progress-segmented` to `.progress` to show the track and fill as a row of short vertical bars. Place visible labels outside the bar. Use `--bs-progress-segment-step` to set the approximate width of each segment and its gap. + +Apply a theme class to `.progress` to color the fill and its muted track. The fill shows only whole segments. + +<Example + class="vstack gap-3" + code={`<div class="progress progress-segmented theme-danger" role="progressbar" aria-label="Danger segmented example" aria-valuenow="53" aria-valuemin="0" aria-valuemax="100"> + <div class="progress-bar" style="width: 53%"></div> + </div> + <div class="progress progress-segmented theme-success" role="progressbar" aria-label="Success segmented example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"> + <div class="progress-bar" style="width: 75%"></div> + </div>`} /> + +For stacked bars, add `.progress-segmented` to `.progress-stacked`. Set `--bs-progress-segmented-width` on each `.progress` to size its fill. Each fill rounds down to a whole number of segments. + +<Example code={`<div class="progress-stacked progress-segmented"> + <div class="progress" role="progressbar" aria-label="Completed" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="--bs-progress-segmented-width: 25%"> + <div class="progress-bar theme-success"></div> + </div> + <div class="progress" role="progressbar" aria-label="In progress" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="--bs-progress-segmented-width: 30%"> + <div class="progress-bar theme-info"></div> + </div> + <div class="progress" role="progressbar" aria-label="Blocked" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" style="--bs-progress-segmented-width: 15%"> + <div class="progress-bar theme-danger"></div> + </div> + </div>`} /> + ## Striped Add `.progress-bar-striped` to any `.progress-bar` to apply a stripe via CSS gradient over the progress bar’s background color.