Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

range-slider-input

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

range-slider-input

Customizable range slider input to capture a range of values with two drag handles

  • 1.0.9
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
increased by6.17%
Maintainers
1
Weekly downloads
 
Created
Source

range-slider-input

travis npm size javascript style guide

Customizable range slider input to capture a range of values with two drag handles.

Examples / CodePen

Demo

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/range-slider-input@1/dist/rangeslider.umd.min.js"></script>

or

<script src="https://unpkg.com/range-slider-input@1"></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:

  • min

    Default value: 0

    Number that specifies the lowest value in the range of permitted values. Its value must be less than that of max.

  • max

    Default value: 1

    Number that specifies the greatest value in the range of permitted values. Its value must be greater than that of min.

  • step

    Default value: any

    Number that specifies the amount by which the slider value(s) will change upon user interaction. Other than numbers, the value of step can be a string value of any, which is the default value in this package.

    From MDN,

    A string value of any means that no stepping is implied, and any value is allowed (barring other constraints, such as min and max).

  • value

    Default value: [0.25, 0.75]

    Array of two numbers that specify the values of the lower and upper offsets of the range slider element respectively.

  • onInput

    Default value: false

    Function to be called when there is a change in the value(s) of range sliders upon user interaction or upon calling min(), max(), step() or value().

  • disabled

    Default value: false

    Boolean that specifies if the range slider element is disabled or not.

  • rangeSlideDisabled

    Default value: false

    Boolean that specifies if the range is slidable or not.

  • thumbsDisabled

    Default value: [false, false]

    Array of two Booleans which specify if the lower and upper thumbs are disabled or not, respectively. If only one Boolean value is passed instead of an array, the value will apply to both thumbs.

  • orientation

    Default value: horizontal

    String that specifies the axis along which the user interaction is to be registered. By default, the range slider element registers the user interaction along the X-axis. It takes two different values: horizontal and vertical. If the range slider element is styled to look vertical visually (e.g. transform: rotate(90deg)), setting orientation to vertical will make it register the user interaction along the Y-axis.

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

Elements

<div class="range-slider"><!-- range slider element -->
    <input type="range" /><!-- hidden -->
    <input type="range" /><!-- hidden -->
    <thumb data-lower></thumb>
    <thumb data-upper></thumb>
    <range></range>
</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.

<thumb> elements are the slidable thumbs replacing the original thumbs from the <input type="range" /> elements.

<range> 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 {
    /* CSS for <range> */
}
element-selector range[data-focused] {
    /* CSS for focused <range> */
}
element-selector thumb {
    /* CSS for <thumb>s */
}
element-selector thumb[data-lower] {
    /* CSS for lower <thumb> */
}
element-selector thumb[data-upper] {
    /* CSS for upper <thumb> */
}
element-selector thumb[data-focused] {
    /* CSS for focused <thumb>s */
}
element-selector thumb[data-disabled] {
    /* CSS for disabled <thumb>s */
}

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

Keywords

FAQs

Package last updated on 09 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc