1.1.10 • Published 6 years ago

control-box v1.1.10

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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:

parameterDescriptionDefault
minthe minimum value of the rangebox-10
maxthe maximum value of the rangebox10
stepthe value's granularity0.01
defaultthe value before u change the rangebox
turnBtnadd adjust buttonsundefined

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:

parameterdescriptiondefault
defaultset the default valueundefined

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
})
1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0-rc.1

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago