@symbo.ls/range 2.11.267 → 2.11.315

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.
Files changed (2) hide show
  1. package/index.js +34 -9
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -78,17 +78,42 @@ const props = {
78
78
  }
79
79
  }
80
80
 
81
+ const returnPropertyValue = (el, property, def) => {
82
+ const val = el.props && el.props[property]
83
+ const r = (isFunction(val) ? val(el, el.state) : val !== undefined ? val : def !== undefined ? def : 0)
84
+ return r + ''
85
+ }
86
+
81
87
  export const Range = {
82
88
  props,
83
-
84
89
  tag: 'input',
85
- attr: { type: 'range' }
86
- }
87
90
 
88
- const returnPropertyValue = (el, property, def) => {
89
- const val = el.props && el.props[property]
90
- const r = (isFunction(val) ? val(el, el.state) : val !== undefined ? val : def !== undefined ? def : 50)
91
- return r + ''
91
+ attr: {
92
+ type: 'range',
93
+ value: (el, s) => parseFloat(el.state.value || el.props.value || el.props.defaultValue),
94
+ min: (el, s) => returnPropertyValue(el, 'min', 0),
95
+ max: (el, s) => returnPropertyValue(el, 'max', 100),
96
+ step: (el, s) => returnPropertyValue(el, 'step', 1)
97
+ },
98
+
99
+ on: {
100
+ input: (ev, el, s) => {
101
+ const props = el.props
102
+ if (isFunction(props.onInput)) {
103
+ props.onInput(ev, el, s)
104
+ } else {
105
+ s.update({ value: parseFloat(el.node.value) })
106
+ }
107
+ },
108
+ change: (ev, el, s) => {
109
+ const props = el.props
110
+ if (isFunction(props.onChange)) {
111
+ props.onChange(ev, el, s)
112
+ } else {
113
+ s.update({ value: parseFloat(el.node.value) })
114
+ }
115
+ }
116
+ }
92
117
  }
93
118
 
94
119
  export const RangeWithButtons = {
@@ -116,13 +141,13 @@ export const RangeWithButtons = {
116
141
  tag: 'span',
117
142
  text: ({ state, parent }) => {
118
143
  const unit = returnPropertyValue(parent, 'unit', '')
119
- return '' + (state.value || 50) + unit
144
+ return '' + (state.value || state.defaultValue || 0) + unit
120
145
  }
121
146
  },
122
147
  input: {
123
148
  extend: Range,
124
149
  attr: {
125
- value: (el, s) => parseFloat(el.state.value),
150
+ value: (el, s) => parseFloat(s.value || s.defaultValue),
126
151
  min: (el, s) => returnPropertyValue(el.parent, 'min', 0),
127
152
  max: (el, s) => returnPropertyValue(el.parent, 'max', 100),
128
153
  step: (el, s) => returnPropertyValue(el.parent, 'step', 1)
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/range",
3
- "version": "2.11.267",
3
+ "version": "2.11.315",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "8641ea0f87d8ae5c7c0266f94a38f5714cac1e34",
6
+ "gitHead": "f7e5836ff0fad163a721cd8a823e2da1a7f346ef",
7
7
  "dependencies": {
8
8
  "@domql/utils": "latest",
9
9
  "@symbo.ls/button": "latest",