@symbo.ls/range 2.11.212 → 2.11.218

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 +45 -11
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -85,8 +85,8 @@ export const Range = {
85
85
  attr: { type: 'range' }
86
86
  }
87
87
 
88
- const listenProp = (el, prop, def) => {
89
- const val = el.props && el.props[prop]
88
+ const returnPropertyValue = (el, property, def) => {
89
+ const val = el.props && el.props[property]
90
90
  const r = (isFunction(val) ? val(el, el.state) : val !== undefined ? val : def !== undefined ? def : 50)
91
91
  return r + ''
92
92
  }
@@ -97,15 +97,25 @@ export const RangeWithButtons = {
97
97
  props: { theme: 'tertiary', icon: 'minus' },
98
98
  on: {
99
99
  click: (ev, el, s) => {
100
- el.props && isFunction(el.props.onClick) && el.props.onClick(ev, el, s)
100
+ const parentProps = el.parent.props
101
+ if (isFunction(parentProps.onDecrease)) {
102
+ parentProps.onDecrease(ev, el.parent, s)
103
+ } else {
104
+ const value = parseFloat(s.value)
105
+ const min = returnPropertyValue(el.parent, 'min', 1)
106
+ const step = returnPropertyValue(el.parent, 'step', 1)
107
+ if (value > min) {
108
+ s.update({ value: value - step })
109
+ }
110
+ }
101
111
  }
102
112
  }
103
113
  },
104
114
  value: {
105
- style: { width: '4ch' },
115
+ props: { width: '4ch' },
106
116
  tag: 'span',
107
117
  text: ({ state, parent }) => {
108
- const unit = listenProp(parent.input, 'unit', '')
118
+ const unit = returnPropertyValue(parent, 'unit', '')
109
119
  return '' + (state.value || 50) + unit
110
120
  }
111
121
  },
@@ -113,13 +123,27 @@ export const RangeWithButtons = {
113
123
  extend: Range,
114
124
  attr: {
115
125
  value: (el, s) => parseFloat(el.state.value),
116
- min: (el, s) => listenProp(el, 'min', 0),
117
- max: (el, s) => listenProp(el, 'max', 100),
118
- step: (el, s) => listenProp(el, 'step', 1)
126
+ min: (el, s) => returnPropertyValue(el.parent, 'min', 0),
127
+ max: (el, s) => returnPropertyValue(el.parent, 'max', 100),
128
+ step: (el, s) => returnPropertyValue(el.parent, 'step', 1)
119
129
  },
120
130
  on: {
121
- input: (ev, el, s) => el.props && isFunction(el.props.onInput) && el.props.onInput(ev, el, el.state),
122
- change: (ev, el, s) => el.props && isFunction(el.props.onChange) && el.props.onChange(ev, el, el.state)
131
+ input: (ev, el, s) => {
132
+ const parentProps = el.parent.props
133
+ if (isFunction(parentProps.onInput)) {
134
+ parentProps.onInput(ev, el, s)
135
+ } else {
136
+ s.update({ value: parseFloat(el.node.value) })
137
+ }
138
+ },
139
+ change: (ev, el, s) => {
140
+ const parentProps = el.parent.props
141
+ if (isFunction(parentProps.onChange)) {
142
+ parentProps.onChange(ev, el, s)
143
+ } else {
144
+ s.update({ value: parseFloat(el.node.value) })
145
+ }
146
+ }
123
147
  }
124
148
  },
125
149
  plus: {
@@ -127,7 +151,17 @@ export const RangeWithButtons = {
127
151
  props: { theme: 'tertiary', icon: 'plus' },
128
152
  on: {
129
153
  click: (ev, el, s) => {
130
- el.props && isFunction(el.props.onClick) && el.props.onClick(ev, el, el.state)
154
+ const parentProps = el.parent.props
155
+ if (isFunction(parentProps.onIncrease)) {
156
+ parentProps.onIncrease(ev, el.parent, s)
157
+ } else {
158
+ const value = parseFloat(s.value)
159
+ const max = returnPropertyValue(el.parent, 'max', 1)
160
+ const step = returnPropertyValue(el.parent, 'step', 1)
161
+ if (value < max) {
162
+ s.update({ value: value + step })
163
+ }
164
+ }
131
165
  }
132
166
  }
133
167
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/range",
3
- "version": "2.11.212",
3
+ "version": "2.11.218",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "12914eac8527ac1df36183098bbf3dfcfaa2e027",
6
+ "gitHead": "a8a73474549ed4af1fa251a811fd1a32dea2b393",
7
7
  "dependencies": {
8
8
  "@domql/utils": "latest",
9
9
  "@symbo.ls/button": "latest",