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-tick-slider

v0.0.2

Published

A set of primitives to build simple, React tick slider components

Downloads

10

Readme

The problem

You need an tick slider experience in your application and you want it to be accessible. You also want it to be simple and flexible to account for your use cases.

This solution

This is a component that controls user interactions and state for you so you can create tick slider components. It uses a render prop which gives you maximum flexibility with a minimal API because you are responsible for the rendering of everything and you simply apply props to what you're rendering.

This differs from other solutions which render things for their use case and then expose many options to allow for extensibility resulting in a bigger API that is less flexible as well as making the implementation more complicated and harder to contribute to.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save react-tick-slider

This package also depends on react and prop-types. Please make sure you have those installed as well.

Usage

Try it out in the browser

import React from 'react'
import TickSlider from 'react-tick-slider'

<TickSlider
    rootStyle={containerStyle}
    options={[{label: 'value 1',value: 1}, {label: 'value 2',value: 2}]} // your tick
    value={2} // default tick selected
    onValueChange={handleValueChange}
>
    {({ choices, selectedChoice, selectChoice }) => (
    <Fragment>
        <div className="slider">
            ...render your slider here
        </div>
        <CircleContainer>
            {choices.map(choice => (
                ...render your tick here
            ))}
            <div className="cricle">
                ...render your circle here
            </div>
        </CircleContainer>
    </Fragment>
    )}
</TickSlider>

is the only component. It doesn't render anything itself, it just calls the render function and renders that. "Use a render prop!"

Props

rootStyle

object | defaults to {}

This is an object with any inline styles you want applied to the root div.

options

array of object | defaults to []

This represent your tick. The object you are passed to generate your tick:

| property | type | description | | -------- | ------------- | ---------------------------------------------------------- | | label | string/number | Tick label, you can use it in title or aria-label property | | value | number | Tick value | | | | |

value

number | defaults to null

This is the default tick selected.

onValueChange

function(value: number) | optional, no useful default

This return the value of the tick selected.

children

function

This is calls the render function and renders that.

Render Prop Function

actions

These are functions you can call to change the state of the downshift component.

| property | type | description | | ------------ | ------------------------ | ---------------------------------------------------------- | | selectChoice | function(choice: object) | selects the selectedChoice and trigger onValueChange event | | | | |

state

These are values that represent the current state of the tick-slider component.

| property | type | description | | -------------- | -------------------------------------------------------------- | -------------------------------------- | | choices | object {label: string/number, value: number, position: number} | This is your ticks with multiple props | | selectedChoice | object {label: string/number, value: number, position: number} | This is tick selected | | | | |

Inspiration

I was heavily inspired by Kent C. Dodds and this repository Awesome react render props.

Other Solutions

You can implement these other solutions using tick-slider, but if you'd prefer to use these out of the box solutions, then that's fine too:

LICENSE

MIT