Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork48
Multi-Thumb, Accessible, Beautiful Range Slider with Pips
License
simeydotme/svelte-range-slider-pips
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A reactive, accessible, multi-thumb, range slider with the ability to display "pips" or "notches" along the range.
Importable as asvelte-component, or able to beused directly in any javascript application / framework.
| 📔🔍 | Docs | Full Documentation & Examples |
|---|---|---|
| 📝⚙ | REPL | Svelte component demo |
| ❤✒ | Codepen | Plain JS component demo |
- ✨ fully customisable
- ♿ accessible
- 👍🏽 multi-thumb
- 🎚 ranges
- 🏷 floating labels
- 📏 ruler values (pips)
- 🏷 labels for values
- 🧮 step function
- 🖍 formatter
- 🎭 animated
- 🖋 css variables
Open your project and use the command line to install the package;
yarn add svelte-range-slider-pips --dev# ornpm install svelte-range-slider-pips --save-dev# if you prefer npm
Note: Please read theupgrade guide for details, as there's some changes which might break your styling/ui.
Assuming you have a Svelte app up and running;
<script>importRangeSliderfrom'svelte-range-slider-pips';</script><RangeSlidervalues={[50]}pips />
seetest folder for examples ofusage with Svelte 4
orSvelte 5
Svelte 5 works almost exactly the same as Svelte 4.
⚠Note: Runes Mode -- specifically$state() -- has some issues when binding with an<input /> element.My suggestion would be to use legacy mode if you can (not runes), orread this issue for a workaround.
⚠Version 3 of Range Slider Pips is not compatible with Svelte 3.see below
If you're not building a svelte-app, you can use the/dist/version of the script/dist/svelte-range-slider-pips.js and include itwith a regular<script> tag.
This should even work with jQuery.
<!-- in the <head> of your html --><scriptsrc="./js/vendor/svelte-range-slider-pips.js"/><!-- in the <body> of your html --><divid="my-slider"></div><script>// this script will be run when the DOM is ready// and the slider is initialiseddocument.addEventListener('DOMContentLoaded',()=>{varmySlider=newRangeSliderPips({target:document.querySelector('#my-slider'),props:{values:[50],pips:true}});});</script>
see examples ofusage with Vanilla JS
orrunning with jQuery
If you're building a bleeding-edge JS application (maybe Vue or React), you mightwant to use js imports (import)
importRangeSliderfrom'./node_modules/svelte-range-slider-pips/dist/svelte-range-slider-pips.mjs';varmySlider=newRangeSlider({target:node,// js reference to a DOM elementprops:{values:[50],pips:true}});
see examples ofusage with ES modules
orusage with VueJS
orimporting with ReactJS
| prop | type | default | description |
|---|---|---|---|
| value | Number | 50 | Value to apply on the slider. |
| values | Array | [50] | Array of values to apply on the slider. Multiple values creates multiple handles. (note: A slider withrange property set can only have two values max) |
| min | Number | 0 | Minimum value for the slider(should be< max) |
| max | Number | 100 | Maximum value for the slider(should be> min) |
| step | Number | 1 | Everynth value to allow handle to stop at(should be a positive value) |
| range | Boolean/String | false | Whether to style as a range picker. Userange='min' orrange='max' for min/max variants |
| pushy | Boolean | false | Ifrange istrue, then this boolean decides if one handle will push the other along |
| draggy | Boolean | false | Ifrange istrue, enables dragging the range area between handles |
| rangeGapMin | Number | 0 | Ifrange istrue, sets the minimum allowed distance between handles |
| rangeGapMax | Number | Infinity | Ifrange istrue, sets the maximum allowed distance between handles |
| float | Boolean | false | Set true to add a floating label above focussed handles |
| rangeFloat | Boolean | false | Ifrange istrue, shows the range values between handles |
| vertical | Boolean | false | Make the slider render vertically (lower value on bottom) |
| pips | Boolean | false | Whether to show pips/notches on the slider |
| pipstep | Number | 1/10/20 | Everynth step to show a pip for. This has multiple defaults depending onvalues property |
| first | Boolean/String | false | Whether to show a pip or label for the first value on slider. Usefirst='label' to show a label value |
| last | Boolean/String | false | Whether to show a pip or label for the last value on slider. Uselast='label' to show a label value |
| rest | Boolean/String | false | Whether to show a pip or label for all other values. Userest='label' to show a label value |
| all | Boolean/String | false | Whether to show a pip or label for all values. Same as combiningfirst,last andrest. Useall='label' to show a label value |
| prefix | String | "" | A string to prefix to all displayed values |
| suffix | String | "" | A string to suffix to all displayed values |
| limits | Array | [0, 100] | An array of two numbers to set a limit on the handles. This overridesmin andmax if set, while still using them for the range display. |
| reversed | Boolean | false | Reverse the orientation of min/max |
| hoverable | Boolean | true | Whether hover styles are enabled for both handles and pips/values |
| disabled | Boolean | false | Determine if the slider is disabled, or enabled(only disables interactions, and events) |
| id | String | "" | Give the slider a unique ID for use in styling |
| class | String | "" | Add custom CSS classes to the slider |
| style | String | undefined | Pass CSS variables or style declarations directly to the slider |
| darkmode | False/"auto"/"force" | false | Set to"auto" to automatically detect the system's dark mode, or"light" or"dark" to force a specific mode |
| ariaLabels | Array | [] | Array of strings to use for thearia-label attribute on the handles. |
| formatter | Function | (v,i,p) => v | A function to re-format values before they are displayed (v = value, i = pip index, p = percent) |
| handleFormatter | Function | formatter | A function to re-format values on the handle/float before they are displayed. Defaults to the same function given to theformatter property (v = value, i = handle index, p = percent) |
| rangeFormatter | Function | null | A function to re-format range float values (v1 = first value, v2 = second value, p1 = first percent, p2 = second percent) |
| spring | Boolean | true | Whether to enable spring animations on handles |
| springValues | Object | { stiffness: 0.15, damping: 0.4 } | Svelte spring physics object to change the behaviour of the handle when moving |
| precision | Number | 2 | Precision of the values for fixing floating errors |
| slider | Element | undefined | DOM reference for binding to the main<div /> of the component (bind:slider='ref') |
📔🔍 | Documentation for Options
| event | example | event.detail | description |
|---|---|---|---|
| start | on:start={(e) => { ... }} | { activeHandle: Integer, value: Float, values: Float[] } | Event fired when the user begins interaction with the slider |
| change | on:change={(e) => { ... }} | { activeHandle: Integer, startValue: Float / Float[], previousValue: Float / Float[], value: Float, values: Float[] } | Event fired when the user changes the value; returns the previous value, also |
| stop | on:stop={(e) => { ... }} | { activeHandle: Integer, startValue: Float / Float[], value: Float, values: Float[] } | Event fired when the user stops interacting with slider; returns the beginning value, also |
Styling should mostly be done with CSS.
There's abunch of css variables for controlling the colors of the elements.And the slider is fluid horizontally, with the size of things controlled by font-size. So you may change thefont-size on the.rangeSlider baseelement to change the scale of everything.
If you require more fine control of the widths, heights, etc, then you may override the default css. This can be easier by using theid propto give your slider a unique id.
Values of labels can be styled with CSS, and the format can be modified with theformatter() function prop. And animation of the handles iscontrolled by thespringValues object prop.
📔🔍 | Documentation for Styling
Note: In
v4, most CSS class names have been prefixed withrsto prevent conflicts with generic CSS frameworks like DaisyUI or UnoCSS. See theupgrade guide for details.
I am very happy to accept;
- 🌟 suggestions/requests for new features or changes
- 🛠 pull-requests for bug fixes, or issue resolution
- 📝 new recipes/examples for the docs site
- 🧪 help with adding more tests
But pleaseread the CONTRIBUTING.md first.
⚠ Because of new code added in Range Slider v3, it is incompatible with Svelte version 3.
If you are unable to upgrade your project to Svelte4/Svelte5, then I suggest looking forSvelte-Range-Slider-Pips version2.3.1 whichwill not be upgraded, but it's still pretty robust. You can install it like so;
yarn add svelte-range-slider-pips@2.3.1 --dev# ornpm install svelte-range-slider-pips@2.3.1 --save-dev# if you prefer npm
I'd be super excited if you find this project useful and wish to donate a small amount for my efforts!
![]() | ![]() | £1 GBP Tip |
|---|---|---|
![]() | ![]() | £5 GBP Tip |
![]() | ![]() | £10 GBP Tip |
About
Multi-Thumb, Accessible, Beautiful Range Slider with Pips
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.





