npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

range-slider-input

v2.4.4

Published

A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles

Downloads

11,955

Readme

range-slider-input

circleci npm minzipped size known vulnerabilities javascript style guide license

A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles.

Examples / CodePen

Demo

:sparkles: Features

  • High CSS customizability
  • Touch and keyboard accessible
  • Supports negative values
  • Vertical orientation
  • Small and fast
  • Zero dependencies
  • Supported by all major browsers
  • Has a React component wrapper

:warning: It is recommended that you upgrade from v1.x to v2.x! What's new and what's changed in v2.x?

Installation

npm

npm install range-slider-input

Import the rangeSlider constructor and the core CSS:

import rangeSlider from 'range-slider-input';
import 'range-slider-input/dist/style.css';

CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rangeslider.umd.min.js"></script>

or

<script src="https://unpkg.com/range-slider-input@2"></script>

The core CSS comes bundled with the jsDelivr and unpkg imports.

Usage

import rangeSlider from 'range-slider-input';
import 'range-slider-input/dist/style.css';

const rangeSliderElement = rangeSlider(element);

API

rangeSlider(element, options = {})

Returns an object of functions that can be called to read or write the properties initially set by options.

Parameters

element

HTMLElement

options

Object that specifies the characteristics of the range slider element with the following available properties:

Return value

Object of functions that can be called to read or write the properties initially set by the options parameter. Available functions:

min(), max(), step(), value() and orientation()

These are simple getter and setter functions. So, while calling these functions, if a parameter is supplied, the corresponding values will be set, and if a parameter is not supplied, the corresponding values will be returned. E.g. Calling step() will return the step value, and calling value([0, 0.5]) will set the lower and upper offsets to 0 and 0.5 respectively.

disabled(), rangeSlideDisabled()

The default parameter is set to true. So, if they are called without a parameter, they will set the corresponding values to true. Thus, calling disabled() or disabled(true) will set options.disabled = true and calling disabled(false) will set options.disabled = false.

thumbsDisabled()

The default parameter is set to [true, true]. So, if it is called without a parameter, it will disable both thumbs. Example uses:

//                          thumbs -> lower     upper
//                                    -----     -----
thumbsDisabled()                // disabled  disabled
thumbsDisabled(true)            // disabled  disabled
thumbsDisabled(false)           //  enabled   enabled
thumbsDisabled([])              //  enabled   enabled
thumbsDisabled([false])         //  enabled   enabled
thumbsDisabled([true])          // disabled   enabled
thumbsDisabled([true, false])   // disabled   enabled
thumbsDisabled([false, true])   //  enabled  disabled
thumbsDisabled([false, false])  //  enabled   enabled
thumbsDisabled([true, true])    // disabled  disabled

currentValueIndex()

Returns the index (0 for the lower value and 1 for the upper value) of the value which is currently being modified. Returns -1 when the slider is idle.

removeGlobalEventListeners()

Removes the global event listeners. It should be called when removing the range slider element from the DOM dynamically.

Elements

<div class="range-slider"><!-- range slider element -->
    <input type="range" /><!-- hidden -->
    <input type="range" /><!-- hidden -->
    <div class="range-slider__thumb" data-lower></div>
    <div class="range-slider__thumb" data-upper></div>
    <div class="range-slider__range"></div>
</div>

<div class="range-slider"></div> is the wrapper element that was used to instantiate the range slider initially and is added with a CSS class named range-slider.

<input type="range" /> elements are used to set values and are hidden.

<div class="range-slider__thumb"></div> elements are the slidable thumbs replacing the original thumbs from the <input type="range" /> elements.

<div class="range-slider__range"></div> element fills up the space between the thumbs.

Styling

View styled examples

element-selector {
    /* CSS for the wrapper element */
}
element-selector[data-disabled] {
    /* CSS for disabled range slider element */
}
element-selector .range-slider__range {
    /* CSS for range */
}
element-selector .range-slider__range[data-active] {
    /* CSS for active (actively being dragged) range */
}
element-selector .range-slider__thumb {
    /* CSS for thumbs */
}
element-selector .range-slider__thumb[data-lower] {
    /* CSS for lower thumb */
}
element-selector .range-slider__thumb[data-upper] {
    /* CSS for upper thumb */
}
element-selector .range-slider__thumb[data-active] {
    /* CSS for active (actively being dragged) thumbs */
}
element-selector .range-slider__thumb[data-disabled] {
    /* CSS for disabled thumbs */
}

Refer to the style.css file to know more about styling the range slider element and its children.

Component Wrappers

React: react-range-slider-input

License

MIT © Utkarsh Verma