Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (2.9 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuenumber50
minnumber0
maxnumber100
stepnumber1
labelstring"Value"
unitstring""
namestring""
disabledbooleanfalse
Events
EventWhen
valuechangeThe 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour