UNPKG

984 BJavaScriptView Raw
1const num = require('input-number');
2
3module.exports = function (opts) {
4 opts = opts || {}
5 var value = document.createElement('input')
6
7 num(value, opts);
8
9 if (opts.input) {
10 value.addEventListener('input', function () {
11 let v = value.value;
12 if (opts.type === 'number') v = parseFloat(v);
13 opts.input(v)
14 })
15 }
16 if (opts.change) {
17 value.addEventListener('change', function () {
18 let v = value.value;
19 if (opts.type === 'number') v = parseFloat(v);
20 opts.change(v)
21 })
22 }
23
24 if (opts.disabled) value.disabled = true;
25
26 value.value = opts.value
27
28 if (opts.id) value.id = opts.id;
29 value.className = 'settings-panel-value';
30 if (opts.className) value.className += ' ' + opts.className;
31 opts.container.appendChild(value);
32
33 //add tip holder after value
34 let tip = opts.container.appendChild(document.createElement('div'));
35 tip.className = 'settings-panel-value-tip';
36
37 return value
38}