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

control-box

v1.1.10

Published

A convenient control box to adjust your values.

Downloads

19

Readme

ControlBox

A convenient control box to adjust your values.

API doc

usage

Initialization

const ControlBox = require('control-box').ControlBox;
const box = new ControlBox();

or with es6:

import { ControlBox } from 'control-box';
const box = new ControlBox();

spec

you can insert the specs when creating the control box:

const box = new ControlBox({
    style: { // define the style, these are the default settings.
        backgroundColor: 'rgba(0, 0, 0, 0.5)',
        position: 'fixed',
        top: '0',
        left: '0',
        zIndex: '9999',
    }
})

context

ControlBox accepts context for saving local values:

box.context['test'] = 'hhh';

check box

box.addCheckBox({
    label: 'something',
    default: false, // optional
    onChange: (checked) => {
        if (checked) { ... }
        else { ... }
    },
});

range box

Basic parameters:

box.addRangeBox({
    label: 'something',
    onChange: (value) => { ... }
})

Option parameters:

parameter | Description | Default --- | --- | --- min | the minimum value of the rangebox | -10 max | the maximum value of the rangebox | 10 step | the value's granularity | 0.01 default | the value before u change the rangebox |
turnBtn | add adjust buttons | undefined

notes:

  • turnBtn accepts a number, which defines the granularity when you click the button.

text box

box.addTextBox({
    label: 'something',
    onChange: (value) => { ... },
    default: '', // optional
})

select box

Basic parameters:

box.addSelectBox({
    label: 'something',
    options: ['select1', 'select2', 'select3', 0.5, 10, true, false],
    onChange: (value) => { ... },
})

Option parameters:

parameter | description | default --- | --- | --- default | set the default value | undefined

color box

Give a color input and RGBA number input fields.

box.addColorBox({
    label: 'something',
    range: 1, // could also be 15 or 255
    onChange: (res) => {
        console.log(res.color); // [0, 0, 0, 1]
        console.log(res.hex); // '#000000'
    }
});

add a list of boxes

a list of range boxes

addRangeBoxList needs two parameters: the spec of each range box, and the spec for all.
Each box can define as label: onChange, or label: {} for individual spec.

box.addRangeBoxList ({
    box1: (value) => { ... },
    box2: {
        min: 1,
        max: 10,
        onChange: (value) => { ... },
    }
}, { // here set the default specs for all range boxes.
    min: -1,
    max: 1,
    step: 0.01,
    turnBtn: 0.001,
})

auto add boxes from an object

const test = {
    forBoolean: true, // will insert check box
    forNumber: 10, // will insert range box
    forString: 'foo', // will insert text box
};

box.auto(test);
// or with the spec
box.auto(test, {
    spec:
        forNumber: {
            min: -1,
            max: 1,
            step: 0.1,
        },
    blacklist: ['forString'], // you can set blacklist
    whitelist: ['forNumber'], // or instead, you can set a whitelist
})