@symbo.ls/range 2.11.212 → 2.11.215

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