range-slider
Pick a number by dragging, on a native <input type="range">: arrow keys, Page Up and Down, Home and End work as the browser's own, and it submits under name. The value shows beside the label, with unit after it. value is two-way.
Try it: events appear here (valuechange).
Source: range-slider.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/range-slider.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/range-slider.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/range-slider.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/range-slider.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/range-slider.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/range-slider.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/range-slider.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/range-slider.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/range-slider.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/range-slider.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/range-slider.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/range-slider.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/range-slider.js"></script>The compiled install writes src/components/zubra/range-slider.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<range-slider label="Budget" unit="" name="budget"></range-slider>
<script type="module">
import './components/zubra/range-slider.js';
const element = document.querySelector('range-slider');
element.value = 400;
element.min = 0;
element.max = 1000;
element.step = 50;
element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>import './components/zubra/range-slider.js';
const value = 400;
const min = 0;
const max = 1000;
const step = 50;
export function RangeSliderExample() {
return (
<range-slider
label="Budget"
unit=""
name="budget"
value={value}
min={min}
max={max}
step={step}
onvaluechange={(event) => console.log('valuechange', event.detail)}
></range-slider>
);
}<script setup>
import './components/zubra/range-slider.js';
const value = 400;
const min = 0;
const max = 1000;
const step = 50;
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>
<template>
<range-slider
label="Budget"
unit=""
name="budget"
:value.prop="value"
:min.prop="min"
:max.prop="max"
:step.prop="step"
@valuechange="onValuechange"
></range-slider>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/range-slider.js';
const value = 400;
const min = 0;
const max = 1000;
const step = 50;
</script>
<range-slider
label="Budget"
unit=""
name="budget"
{value}
{min}
{max}
{step}
onvaluechange={(event) => console.log('valuechange', event.detail)}
></range-slider>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/range-slider.js';
@Component({
selector: 'app-range-slider-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<range-slider
label="Budget"
unit=""
name="budget"
[value]="value"
[min]="min"
[max]="max"
[step]="step"
(valuechange)="onValuechange($event)"
></range-slider>
`,
})
export class RangeSliderExample {
value = 400;
min = 0;
max = 1000;
step = 50;
onValuechange(event: Event) {
console.log('valuechange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
value | number | 50 |
min | number | 0 |
max | number | 100 |
step | number | 1 |
label | string | "Value" |
unit | string | "" |
name | string | "" |
disabled | boolean | false |
| Event | When |
|---|---|
valuechange | The value changed; detail is the number. |
Size
1.5 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 17.8 KB.