Range Multiple Thresholds
Style every thumb of a range on its own, like one threshold per level. A list in value adds the thumbs, the one-based thumb-{n} slot and part and the tooltip-{n} slot restyle each one, and each fill-{n} part colors the stretch between two thresholds. min-steps-between keeps the thresholds apart, and push-thumbs moves the neighbors along.
Cool Ideal Warm
Code
The following example assumes that you have imported the component and set up the theme.
<div class="threshold-example">52 collapsed lines
<div class="threshold-heading"> <label for="comfort-thresholds">Comfort thresholds</label>
<div class="threshold-values"> <span> <i class="cool" aria-hidden="true"></i> Cool <output data-value-index="0">16 °C</output> </span> <span> <i class="ideal" aria-hidden="true"></i> Ideal <output data-value-index="1">22 °C</output> </span> <span> <i class="warm" aria-hidden="true"></i> Warm <output data-value-index="2">28 °C</output> </span> </div> </div>
<sv-range id="comfort-thresholds" class="threshold-slider" invert-tooltip max="40" min-steps-between="3" push-thumbs value="16 22 28" > <span class="threshold-thumb" aria-hidden="true" slot="thumb-1"></span> <span class="threshold-thumb" aria-hidden="true" slot="thumb-2"></span> <span class="threshold-thumb" aria-hidden="true" slot="thumb-3"></span>
<span aria-label="Cool limit" slot="thumb-label-1"></span> <span aria-label="Ideal temperature" slot="thumb-label-2"></span> <span aria-label="Warm limit" slot="thumb-label-3"></span>
<span aria-hidden="true" slot="tooltip-1"> <span data-sv-range-value></span> °C </span> <span aria-hidden="true" slot="tooltip-2"> <span data-sv-range-value></span> °C </span> <span aria-hidden="true" slot="tooltip-3"> <span data-sv-range-value></span> °C </span> </sv-range></div>
<script type="application/x-typescript" module>21 collapsed lines
const example = document.querySelector<HTMLElement>(".threshold-example")!; const slider = example.querySelector<RangeSlider>(".threshold-slider")!; const outputs = example.querySelectorAll<HTMLOutputElement>("[data-value-index]");
const descriptions = ["lower boundary", "preferred temperature", "upper boundary"];
slider.valueLabelHandler = (value, index) => { return `${value} degrees Celsius, ${descriptions[index]}`; };
updateOutputs(); slider.addEventListener("valuechange", updateOutputs);
function updateOutputs() { const values = slider.value; if (!Array.isArray(values)) return;
for (const [index, output] of outputs.entries()) { output.value = `${values[index]} °C`; } }</script>
<style>111 collapsed lines
.threshold-example { display: grid; gap: 1.75rem; padding: clamp(1rem, 4vw, 2rem); background: var(--sv-gray-7); border: 1px solid var(--sv-gray-5); border-radius: var(--sv-bdr-rad-lg); }
.threshold-heading { display: grid; gap: 0.8rem;
> label { font-weight: 700; } }
.threshold-values { display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; font-size: 0.85rem; color: var(--sv-gray-3);
span { display: inline-flex; gap: 0.4rem; align-items: center; }
i { inline-size: 0.65rem; block-size: 0.65rem; background: currentcolor; border-radius: 50%; }
output { font-weight: 700; color: var(--sv-gray-1); }
.cool { color: #3b82f6; }
.ideal { color: #22c55e; }
.warm { color: #f97316; } }
.threshold-slider { --sv-slider-track-thickness: 0.8rem; --sv-slider-thumb-sz: 1.65rem; --sv-slider-tooltip-offset: 1.5rem;
inline-size: 100%;
&::part(fill-1) { background: linear-gradient(90deg, #3b82f6, #22c55e); }
&::part(fill-2) { background: linear-gradient(90deg, #22c55e, #f97316); }
&:dir(rtl)::part(fill-1) { background: linear-gradient(270deg, #3b82f6, #22c55e); }
&:dir(rtl)::part(fill-2) { background: linear-gradient(270deg, #22c55e, #f97316); }
&::part(thumb-1) { color: #3b82f6; }
&::part(thumb-2) { color: #22c55e; }
&::part(thumb-3) { color: #f97316; }
&::part(tooltip) { background: transparent; border-color: currentcolor; backdrop-filter: blur(7px); }
&::part(tooltip-arrow) { fill: currentcolor; stroke: currentcolor; } }
.threshold-thumb { inline-size: var(--sv-slider-thumb-sz); block-size: var(--sv-slider-thumb-sz); background: currentcolor; border: 3px solid var(--sv-gray-7); border-radius: 50%; box-shadow: 0 2px 5px rgb(0 0 0 / 30%); }</style>