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

@node-projects/input-knob

v1.1.0

Published

A rotating, touch-sensitive knob web component that acts like an <input type="range">.

Downloads

14

Readme

<node-projects-input-knob> ⟳ custom element

A rotating, touch-sensitive knob that you can use like an <input type="range">.

Install

The dist directory contains the ES module (input-knob.js that you can use directly.

Install via npm and include via the bundler of your choice:

npm install --save @node-projects/input-knob

Include via unpkg:

<script src="https://unpkg.com/@node-projects/input-knob"></script>

Usage

This will create a knob with a minimum value of zero, a maximum of 100, a current value of 50, and each full turn of the knob will change the value by 10.

<node-projects-input-knob value="50" scale="10" min="0" max="100"></node-projects-input-knob>
  • value: Current value, this will update as the knob is turned. Optional, defaults to 0.
  • scale: The change in the value for one full turn. Optional, defaults to 1.
  • min: Minimum allowed value. Optional, defaults to null.
  • max: Maxium allowed value. Optional, defaults.to null.

If both min and max are set, then the knob can be turned multiple times to reach a different value. If only one or none of min or max is set, then a full turn of the knob will reset the value to 0.

These are also exposed as properties on the object and can be set or observed in JavaScript:

const knob = document.querySelector('node-projects-input-knob');
knob.value = 42;

Events

Three event types are dispatched for each point in an interaction:

  • knob-move-start: fired on initial touch or click.
  • knob-move-change: fired repeatedly for each change in rotation.
  • knob-move-end: fired when the touch or click is released.

Style and appearance

There are two key parts of the element that can be styled. The <node-projects-input-knob> element itself, which is the container for the inner rotator part. The rotator is accessed using the ::part(rotator) pseudo-element. The outer element does not rotate, so can be used for general positioning or changing the appearance of the outer container. The inner rotator represents the part of the knob the user interacts with and will rotate as the value changes.

Content inside the <node-projects-input-knob> tag will also rotate and can be used to do things like provide a top marker for the knob.

<style>
  node-projects-input-knob {
    width: 150px;
    padding: 10px;
    border: 2px dashed green;
    background: lightgreen;
  }

  node-projects-input-knob::part(rotator) {
    box-sizing: border-box;
    background: lightblue;
    border: 2px dashed blue;
    border-radius: 100%;
    width: 150px;
    height: 150px;
  }

  .mark {
    display: inline-block;
    width: 100%;
    text-align: center;
    font: bold 200% monospace;
    color: blue;
  }
</style>

<node-projects-input-knob value="50" scale="10" min="0" max="100">
  <div class="mark">▲</div>
</node-projects-input-knob>

A blue knob with an upward tick on a green background

Demo

Try the demo at https://input-knob.glitch.me

An example of <input-knob> in green with an upward tick indicator and slider below

Contributing

Issues and pull requests happily received. Please see CONTRIBUTING.md.