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-touch-knob

v0.2.3

Published

Knob UI element for React with touch capabilities

Downloads

64

Readme

React Touch Knob

A canvas-based, ReactJs Knob optimized for both mouse and touch events with support for responsive design and CSS styling.

Installation

npm install react-touch-knob

Usage

Assuming you are using react and react-dom:

import TouchKnob from "react-touch-knob"

<Touch Knob
    class="my-knob-class"
    name="score"
    min="0"
    max="100"
    value="44"
    onChange={this.handleChange}
    onEnd={this.handleEnd}
    showNumber={true}
    />

TouchKnob contains a hidden input[type=number] element, so that it can be used within a form in a familiar way.

TouchKnob can be styled using existing CSS properties, repurposed for this component:

.my-knob-class {
    width: 100px; /* the canvas's width and height will be based only on the width of the element */
    height: 100px; 
    font-size: 2vw; /* font-size of the text output */
    line-height: 60%; /* width of the knob's "lane" */
    border-bottom-color: #ccc; /* background color of "lane" */
    border-top-color: "blue"; /* color of knob's value indicator */
}

TouchKnob can be included in a responsive design with one caveat: if there is a CSS transition on the width of the knob element (or on a parent element that subsequently affects the width of the knob), the knob's canvas element will not resize properly.

Properties

  • min: The minimum value of the knob (default: 0)
  • max: The maximum value of the knob (default: 1)
  • value: The current value of the knob (default: 0 or min)
  • fineness: Affects the amount the knob moves when adjusting outside the "lane" for potentially fine adjustments -- higher values = finer adjustment (default: 10)
  • class: The CSS class (note: do not use React's className property, here)
  • name: The name attribute of the hidden input field
  • showNumber: If true, show the current value of the knob in the center of the element (default: false)
  • rounded: If true, draw lane and value indicator with rounded ends (default: false)
  • disableAnimation: If true, disable animation on setValue method and when the knob is "flung" (default: false)
  • disabled: If true, knob is read-only (default: false)

Methods

  • getValue(): Returns the knob's value (note: during an animation, this value is changing)
  • setValue(value, disableAnimation): Set the value of the knob with option to disable animation if it isn't already disabled via the disableAnimation property

Events

  • onChange: Returns the knob's value whenever that value is changed
  • onEnd: Returns the knob's value after an adjustment is complete (on mouseup, touchend, or at the end of an animation)
  • valueTransformDisplay: Returns the knob's value whenever that value is changed. You may then transform and return that value to a string for display if showNumber is true; i.e., round the value to a certain precision, append a string to the end of the number, etc. This does not affect the actual value, only the way it is displayed.

User Interaction

TouchKnob can be adjusted directly by starting a mousedown or touch in the knob's lane and dragging circularly around the knob. Additionally, for potentially finer adjustments and to avoid sudden value changes, a mousedown or touch in the center of the knob (without touching the lane), followed by dragging up or to the right increases the knob value, while dragging down or to the left decreases it. A fast adjustment will "fling" the knob, animating to a value based on the momentum of the fling unless the disableAnimation property is set to true.

Examples

Coming soon... Though you can see some knobs in action on snap-to-emo