perfect-gui 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -91,12 +91,16 @@ gui.image('Click this', 'path/to/image', () => {
91
91
 
92
92
  ```javascript
93
93
  // Simple slider, only returns a value to the callback
94
+ // min parameter is optional, default is 0
95
+ // max parameter is optional, default is 1
96
+ // step parameter is optional, default is (max - min) * 0.01
94
97
  gui.slider('Slide this', { value: 5, min: 0, max: 10, step: .1 }, value => {
95
98
  console.log('Slider value : ' + value);
96
99
  });
97
100
 
98
101
  // Object-based slider, automatically updates the value of the object property.
99
102
  // Directly updating the property will also update the slider.
103
+ // callback is optional
100
104
  gui.slider('Slide this', { object: foo, prop: 'bar', min: 0, max: 10, step: .1 });
101
105
  ```
102
106
  </td></tr>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perfect-gui",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Nice and simple GUI for JavaScript.",
5
5
  "main": "src/index.js",
6
6
  "directories": {
package/src/index.js CHANGED
@@ -221,16 +221,14 @@ export default class GUI {
221
221
  }
222
222
 
223
223
  slider (text, sliderParams, callback) {
224
- this._checkMandatoryParams({
225
- min: 'number',
226
- max: 'number',
227
- step: 'number'
228
- }, sliderParams);
229
-
230
224
  let isObject = false;
231
225
  let propReferenceIndex = null;
232
226
  let object;
233
227
  let prop;
228
+
229
+ const min = sliderParams.min ?? 0;
230
+ const max = sliderParams.max ?? 1;
231
+ const step = sliderParams.step || (max - min) / 100;
234
232
 
235
233
  if ( typeof sliderParams.value == 'number' ) {
236
234
  this._checkMandatoryParams({
@@ -261,9 +259,9 @@ export default class GUI {
261
259
  class: 'p-gui__slider-ctrl',
262
260
  customAttributes: {
263
261
  type: 'range',
264
- min: sliderParams.min,
265
- max: sliderParams.max,
266
- step: sliderParams.step,
262
+ min,
263
+ max,
264
+ step,
267
265
  value: isObject ? object[prop] : sliderParams.value
268
266
  }
269
267
  });
@@ -19,7 +19,7 @@ export default function basics() {
19
19
  });
20
20
 
21
21
  gui.slider('Slider (simple callback)',
22
- { min: 0, max: 1, value: 1, step: .2 },
22
+ { value: 1 },
23
23
  value => {
24
24
  element.style.opacity = value;
25
25
  }