@symbo.ls/range 2.11.204 → 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.
- package/index.js +46 -11
- 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
|
|
89
|
-
const val = el.props && el.props[
|
|
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
|
-
|
|
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
|
-
|
|
116
|
+
props: { width: '4ch' },
|
|
106
117
|
tag: 'span',
|
|
107
118
|
text: ({ state, parent }) => {
|
|
108
|
-
const 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) =>
|
|
117
|
-
max: (el, s) =>
|
|
118
|
-
step: (el, s) =>
|
|
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) =>
|
|
122
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "2.11.215",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"gitHead": "
|
|
6
|
+
"gitHead": "1dc01c98b5717566aaee3155b73829e428d51055",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@domql/utils": "latest",
|
|
9
9
|
"@symbo.ls/button": "latest",
|