Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multi-Thumb, Accessible, Beautiful Range Slider with Pips

License

NotificationsYou must be signed in to change notification settings

zalwan/svelte-range-slider-pips

 
 

Repository files navigation

Svelte Range Slider Logo

Svelte Range Slider (with pips)

Code VersionNPM versionNPM Downloads / Month

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.

Svelte Range Slider; focussed with pips and labels prop set

📔🔍DocsFull Documentation & Examples
📝⚙REPLSvelte component demo
❤✒CodepenPlain JS component demo


Features

Features of the range slider plugin (written below)

  • ✨ fully customisable, stylable & accessible
  • 👍🏽 multi-thumb
  • 🎚 range (min/max)
  • 🏷 floating labels
  • 📏 ruler notches
  • 🏷 labels for notches
  • 🧮 step function
  • 🖍 formatter
  • 🎭 animated

Install

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

Usage

In a svelte project

Assuming you have a Svelte app up and running;

<script>importRangeSliderfrom"svelte-range-slider-pips";</script><RangeSlidervalues={[50]}pips/>

As a regular JS file

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.

<scriptsrc="./js/vendor/svelte-range-slider-pips.js"/><divid="my-slider"></div><script>varmySlider=newRangeSliderPips({target:document.querySelector("#my-slider"),props:{values:[50],pips:true}});</script>

As a JS module

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}});


Props (options)

Slider props

proptypedefaultdescription
valuesArray[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)
minNumber0Minimum value for the slider(should be< max)
maxNumber100Maximum value for the slider(should be> min)
stepNumber1Everynth value to allow handle to stop at(should be a positive value)
rangeBoolean/StringfalseWhether to style as a range picker. Userange='min' orrange='max' for min/max variants
pushyBooleanfalseIfrange istrue, then this boolean decides if one handle will push the other along
floatBooleanfalseSet true to add a floating label above focussed handles
verticalBooleanfalseMake the slider render vertically (lower value on bottom)
pipsBooleanfalseWhether to show pips/notches on the slider
pipstepNumber1/10/20Everynth step to show a pip for. This has multiple defaults depending onvalues property
firstBoolean/StringfalseWhether to show a pip or label for the first value on slider. Usefirst='label' to show a label value
lastBoolean/StringfalseWhether to show a pip or label for the last value on slider. Uselast='label' to show a label value
restBoolean/StringfalseWhether to show a pip or label for all other values. Userest='label' to show a label value
allBoolean/StringfalseWhether to show a pip or label for all values. Same as combiningfirst,last andrest. Useall='label' to show a label value
prefixString""A string to prefix to all displayed values
suffixString""A string to suffix to all displayed values
reversedBooleanfalseReverse the orientation of min/max
hoverableBooleantrueWhether hover styles are enabled for both handles and pips/values
disabledBooleanfalseDetermine if the slider is disabled, or enabled(only disables interactions, and events)
idString""Give the slider a unique ID for use in styling
ariaLabelsArray[]Array of strings to use for thearia-label attribute on the handles.
formatterFunction(v,i,p) => vA function to re-format values before they are displayed (v = value, i = pip index, p = percent)
handleFormatterFunctionformatterA 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)
springValuesObject{ stiffness: 0.15, damping: 0.4 }Svelte spring physics object to change the behaviour of the handle when moving
sliderElementundefinedDOM reference for binding to the main<div /> of the component (bind:slider='ref')

📔🔍 | Documentation for Options

Slider events (dispatched)

eventexampleevent.detaildescription
starton:start={(e) => { ... }}{ activeHandle: Integer, value: Float, values: Array }Event fired when the user begins interaction with the slider
changeon:change={(e) => { ... }}{ activeHandle: Integer, startValue: Float, previousValue: Float, value: Float, values: Array }Event fired when the user changes the value; returns the previous value, also
stopon:stop={(e) => { ... }}{ activeHandle: Integer, startValue: Float, value: Float, values: Array }Event fired when the user stops interacting with slider; returns the beginning value, also

📔🔍 | Documentation for Events



Styling

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



Contribute

I am very happy to accept;

  • 🌟 suggestions/requests for new features or changes
  • 🛠 pull-requests for bug fixes, or issue resolution
  • 🧪 help with creating a proper test-suite

Read the CONTRIBUTING.md


Support / Donate

I'd be super excited if you find this project useful and wish to donate a small amount for my efforts!

£1 One Pound Donation£1 GBP donation
£5 Five Pounds Donation£5 GBP donation
£10 Ten Pounds Donation£10 GBP donation

About

Multi-Thumb, Accessible, Beautiful Range Slider with Pips

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Svelte90.1%
  • JavaScript5.3%
  • CSS3.7%
  • HTML0.9%

[8]ページ先頭

©2009-2025 Movatter.jp