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

react-rangeslider-extended

v1.0.10

Published

A lightweight react component that acts as a HTML5 input range slider polyfill and supports customizable segmented position to value mapping

Downloads

3

Readme

React Rangeslider Extended NPM Package

A lightweight responsive react range slider component forked from whoisandie/react-rangeslider.

Check out examples.

Install

Install via npm (use --save to include it in your package.json)

$ npm install react-rangeslider-extended --save

Usage

React Rangeslider is bundled with a single slider component. You can require them in plain old ES5 syntax or import them in ES6 syntax.

...plain old ES5

var React = require('react');
var Slider = require('react-rangeslider-extended');

var Volume = React.createClass({
	getInitialState: function(){
		return {
			value: 10,
		};
	}

	handleChange: function(value) {
		this.setState({
			value: value,
		});
	}

	render: function() {
		return (
			<Slider
        value={value}
        orientation="vertical"
        onChange={this.handleChange} />
		);
	}
});

module.exports = Volume;

... or use ES6 syntax

import React, { Component } from 'react';
import Slider from 'react-rangeslider-extended';

export default Volume extends Component {
  constructor(props, context) {
    super(props, context);
    this.state = {
      value: 10 /** Start value **/
    };
  }

  handleChange(value) {
    this.setState({
      value: value
    });
  }

  render() {
    return (
      <Slider
        value={value}
        orientation="vertical"
        onChange={this.handleChange} />
    );
  }
}

There's also a umd version available at lib/umd. The component is available on window.ReactRangeslider. To style the slider, please refer the rangeslider styles in demo/demo.less file.

API

Rangeslider is bundled with a single component, that accepts data and callbacks only as props.

Component

import Slider from 'react-rangeslider-extended'

// inside render
<Slider
	min={String or Number}
	max={String or Number}
	step={String or Number}
	orientation={String}
  value={Number}
  onChange={Function}
  onChangeComplete={Function}
  valueMapping={Function} />

Props

Prop | Default | Description --------- | ------- | ----------- min | 0 | minimum value the slider can hold max | 100 | maximum value the slider can hold step | 1 | step in which increments/decrements have to be made orientation | horizontal | orientation of the slider value | - | current value of the slider onChange | - | function the slider takes, current value of the slider as the first parameter onChangeComplete | - | function the slider takes and fires after interaction has ended, current value of the slider as the first parameter valueMapping | default func | function returning an object that defines segments and toValue and toPos methods to controll position to value (and vice versa) mapping

Value Mapping

The valueMapping prop takes a function taking the arguments min and max that returns an object with definitions of segments on the slider’s range and how positions within these segments are mapped to values. This allows for example to let you set lower values more precisely and higher ones in larger steps. For each segment there is toValue (position to value) and a toPos (value to position) function defined. The keys of the definition object define the segements start position. See example below.

...

class myComponent extends React.Component {
	...

	valueMapping = (min, max) => ({
		'0': {
			toValue: (percentage, range) => Math.round(
				(percentage < range ? percentage : range) * 100 * 2
			),
			toPos: value => value / 2 / 100,
		},
		'.25': {
			toValue: (percentage, range) => Math.round(
				(percentage < range ? percentage : range) * 100
			),
			toPos: value => value / 100,
		},
		'.5': {
			toValue: (percentage, range, value) => Math.round(
				percentage / range * (max - value)
			),
			toPos: (value, range, span) => (
				value / span * range
			),
		}
	});

	render() {
		return (
			<Slider
				min={0}
				max={1000}
				value={this.state.value}
				onChange={this.handleChange}
				valueMapping={this.valueMapping} />
			<div className="value">Value: {this.state.value}</div>
		);
	}
}

Issues

Feel free to contribute. Submit a Pull Request or open an issue for further discussion.

Todo

  • Ship styles along with component
  • Tests using Enzyme

License

MIT © whoisandie & Oliver Wehn