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

@humanz/react-compound-slider

v0.12.0

Published

Futuristic react slider component

Downloads

135

Readme

react-compound-slider

Welcome to the future. React Compound Slider is a tiny (5kb) slider component with no opinion about markup or styles.

Build Status Dependency Status Coverage Status license npm downloads npm version

Installation

React Compound Slider is available as an npm package.

To install and save in your package.json dependencies, run:

npm install react-compound-slider

Live Demos

Tutorial

Documentation

CodeSandbox

Slider Features

  • Compound component design provides maximum customizability ✓

    • Makes no assumptions about your markup
    • Precise control over user interactions and styling
  • Horizontal/vertical display ✓

  • The display of values can be reversed ✓

  • Supports mouse and touch events ✓

    • Supports IE9+, Chrome, Firefox & Safari
  • Create any type of slider ✓

    • One API for all sliders types
    • Single value slider
    • Range slider (2 handles)
    • Multiple Sliders (N handles)
  • Automatically generates uniformly spaced, human-readable tick values to label your slider ✓

    • Supports passing custom sets of ticks
  • Integrates seemlessly with any app styling approach ✓

    • CSS
    • CSS-in-JS
    • Inline-styles
  • Interaction modes ✓

    • Allow crossing (mode = 1)
    • Prevent crossing (mode = 2)
    • Pushable mode (mode = 3)
    • Create your own custom mode (function)
  • Works as a controlled component ✓

Example Usage

import Slider from 'react-compound-slider'
import { Handle, Track, Tick } from './your-local-slider-components'

  <Slider
    rootStyle={sliderStyle}
    domain={[0, 100]}  // [min, max]
    step={1}
    mode={2} // 1 = allow-crossing, 2 = no crossing, 3 = pushable (also custom modes)
    values={[10, 20, 30]} // one value would be a value slider, two a range slider, etc
  >
    <Slider.Handles>
      {({ handles, getHandleProps }) => (
        <div className="slider-handles">
          {handles.map(handle => (
            ...render your handle here
          ))}
        </div>
      )}
    </Slider.Handles>
    <Slider.Tracks left={false} right={false}>  // you can toggle the left and right tracks
      {({ tracks, getTrackProps }) => (
        <div className="slider-tracks">
          {tracks.map(({ id, source, target }) => (
            ...render your track here
          ))}
        </div>
      )}
    </Slider.Tracks>
  </Slider>

Approach

This library takes a compound component approach to creating sliders that separates the data/logic from presentation.

If your familiar with Kent Dodd's work on Paypal's downshift or react-toggled then the pattern should seem familiar. The components use the function as child components pattern.

In practical terms this means you can create just about any kind of slider you can imagine and use whatever style approach you want. By taking this approach it also frees you up to render whatever markup you want to customize your slider. The Slider streams you the data and really only cares about the dimensions of the outer div where it takes its measurements from.

In general slider components are composed of a relatively positioned outer div with elements absolutely positioned inside by a percentage. In this library the Handles, Tracks, and Ticks components are used as children to the Slider component and they let you tap into a stream of values and percentages that you can then use to render your own components.