haya-select 1.0.42 → 1.0.44
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/package.json +1 -1
- package/src/select/index.jsx +40 -3
- package/src/select/option.jsx +8 -7
package/package.json
CHANGED
package/src/select/index.jsx
CHANGED
|
@@ -39,6 +39,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
39
39
|
multiple: PropTypes.bool.isRequired,
|
|
40
40
|
name: PropTypes.string,
|
|
41
41
|
onChange: PropTypes.func,
|
|
42
|
+
onChangeValue: PropTypes.func,
|
|
42
43
|
onOptionsClosed: PropTypes.func,
|
|
43
44
|
options: PropTypes.oneOfType([PropTypes.array, PropTypes.func]).isRequired,
|
|
44
45
|
placeholder: PropTypes.node,
|
|
@@ -127,7 +128,21 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
127
128
|
if ("values" in this.props && typeof this.props.values != "undefined") {
|
|
128
129
|
if (this.s.loadedOptions || typeof this.props.options == "function" && this.props.values) {
|
|
129
130
|
if (this.s.loadedOptions) {
|
|
130
|
-
|
|
131
|
+
const result = this.p.values.map((value) => {
|
|
132
|
+
let foundOption = this.s.loadedOptions.find((option) => option.value == value)
|
|
133
|
+
|
|
134
|
+
if (!foundOption) {
|
|
135
|
+
foundOption = this.s.currentOptions.find((option) => option.value == value)
|
|
136
|
+
|
|
137
|
+
if (!foundOption) {
|
|
138
|
+
throw new Error(`Couldn't find option: ${value} in loadedOptions or state currentOptions`)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return foundOption
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
return result
|
|
131
146
|
} else {
|
|
132
147
|
this.setCurrentFromGivenValues()
|
|
133
148
|
}
|
|
@@ -141,6 +156,14 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
141
156
|
return this.s.currentOptions
|
|
142
157
|
}
|
|
143
158
|
|
|
159
|
+
getCurrentOptionValues() {
|
|
160
|
+
if ("values" in this.props) {
|
|
161
|
+
return this.p.values
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return this.getCurrentOptions().map((option) => option.value)
|
|
165
|
+
}
|
|
166
|
+
|
|
144
167
|
componentDidMount() {
|
|
145
168
|
const {attribute, defaultValue, defaultValues, defaultValuesFromOptions, model, options} = this.props
|
|
146
169
|
|
|
@@ -382,7 +405,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
382
405
|
|
|
383
406
|
return (
|
|
384
407
|
<Option
|
|
385
|
-
|
|
408
|
+
currentOptionValues={this.getCurrentOptionValues()}
|
|
386
409
|
icon={this.iconForOption(loadedOption)}
|
|
387
410
|
key={key}
|
|
388
411
|
option={loadedOption}
|
|
@@ -624,14 +647,28 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
|
|
|
624
647
|
}
|
|
625
648
|
}
|
|
626
649
|
|
|
650
|
+
const options = newState.currentOptions || currentOptions
|
|
651
|
+
|
|
627
652
|
if (onChange) {
|
|
628
653
|
onChange({
|
|
629
654
|
event,
|
|
630
|
-
options
|
|
655
|
+
options,
|
|
631
656
|
toggles: newToggled
|
|
632
657
|
})
|
|
633
658
|
}
|
|
634
659
|
|
|
660
|
+
if (this.props.onChangeValue) {
|
|
661
|
+
let optionValue
|
|
662
|
+
|
|
663
|
+
if (multiple) {
|
|
664
|
+
optionValue = options.map((option) => option.value)
|
|
665
|
+
} else {
|
|
666
|
+
optionValue = dig(options, 0, "value")
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
this.p.onChangeValue(optionValue)
|
|
670
|
+
}
|
|
671
|
+
|
|
635
672
|
if (!multiple) this.closeOptions()
|
|
636
673
|
this.setState(newState)
|
|
637
674
|
}
|
package/src/select/option.jsx
CHANGED
|
@@ -5,7 +5,7 @@ import {View} from "react-native"
|
|
|
5
5
|
|
|
6
6
|
export default memo(shapeComponent(class Option extends ShapeComponent {
|
|
7
7
|
static propTypes = {
|
|
8
|
-
|
|
8
|
+
currentOptionValues: PropTypes.array.isRequired,
|
|
9
9
|
disabled: PropTypes.bool,
|
|
10
10
|
icon: PropTypes.string,
|
|
11
11
|
onOptionClicked: PropTypes.func.isRequired,
|
|
@@ -20,8 +20,9 @@ export default memo(shapeComponent(class Option extends ShapeComponent {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
render() {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const {currentOptionValues, option} = this.p
|
|
24
|
+
const disabled = Boolean(option.disabled)
|
|
25
|
+
const selected = Boolean(currentOptionValues.find((currentOptionValue) => currentOptionValue == option.value))
|
|
25
26
|
const style = {
|
|
26
27
|
paddingTop: 4,
|
|
27
28
|
paddingRight: 8,
|
|
@@ -53,12 +54,12 @@ export default memo(shapeComponent(class Option extends ShapeComponent {
|
|
|
53
54
|
selected,
|
|
54
55
|
value: this.props.option.value
|
|
55
56
|
}}
|
|
56
|
-
onClick={this.onClick}
|
|
57
|
-
onPointerOver={this.onPointerOver}
|
|
58
|
-
onPointerOut={this.onPointerOut}
|
|
57
|
+
onClick={this.tt.onClick}
|
|
58
|
+
onPointerOver={this.tt.onPointerOver}
|
|
59
|
+
onPointerOut={this.tt.onPointerOut}
|
|
59
60
|
style={style}
|
|
60
61
|
>
|
|
61
|
-
{this.props.presentOption(
|
|
62
|
+
{this.props.presentOption(option)}
|
|
62
63
|
</View>
|
|
63
64
|
)
|
|
64
65
|
}
|