haya-select 1.0.56 → 1.0.58

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haya-select",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -88,6 +88,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
88
88
  currentOptions: () => this.defaultCurrentOptions(),
89
89
  selectContainerLayout: null,
90
90
  endOfSelectLayout: null,
91
+ height: null,
91
92
  loadedOptions: () => this.defaultLoadedOptions(),
92
93
  opened: false,
93
94
  optionsContainerLayout: null,
@@ -145,9 +146,9 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
145
146
  getValues = () => ("values" in this.props) ? this.p.values : this.s.currentOptions.map((currentOption) => currentOption.value)
146
147
  getCurrentOptions = () => {
147
148
  if ("values" in this.props && typeof this.props.values != "undefined") {
148
- if (Array.isArray(this.props.options)) {
149
+ if (Array.isArray(this.props.options) && this.props.values) {
149
150
  return this.p.values.map((value) => this.p.options.find((option) => option.value == value))
150
- } else if (this.s.loadedOptions) {
151
+ } else if (this.s.loadedOptions && this.props.values) {
151
152
  return this.p.values.map((value) => {
152
153
  let foundOption = this.s.loadedOptions.find((option) => option.value == value)
153
154
 
@@ -164,9 +165,9 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
164
165
 
165
166
  return foundOption
166
167
  })
167
- } else if (typeof this.props.options == "function") {
168
+ } else if (typeof this.props.options == "function" && this.props.values) {
168
169
  this.setCurrentFromGivenValues()
169
- } else {
170
+ } else if (this.props.values) {
170
171
  return this.p.values.map((value) => ({value}))
171
172
  }
172
173
  }
@@ -212,7 +213,6 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
212
213
  const {opened, optionsPlacement} = this.s
213
214
  const currentOptions = this.getCurrentOptions()
214
215
  const selectContainerStyleActual = this.stylingFor("selectContainer", {
215
- display: "flex",
216
216
  flexDirection: "row",
217
217
  alignItems: "center",
218
218
  backgroundColor: "#fff",
@@ -226,6 +226,9 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
226
226
  })
227
227
 
228
228
  if (opened) {
229
+ // Prevent select from changing size once the content is replaced with search text once opened
230
+ selectContainerStyleActual.height = this.s.height
231
+
229
232
  if (optionsPlacement == "above") {
230
233
  selectContainerStyleActual.borderTopLeftRadius = 0
231
234
  selectContainerStyleActual.borderTopRightRadius = 0
@@ -246,7 +249,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
246
249
  const chevronStyle = this.stylingFor("chevron", {fontSize: 24})
247
250
 
248
251
  if (opened) {
249
- chevronStyle.marginBottom = -9
252
+ chevronStyle.marginBottom = -15
250
253
  } else {
251
254
  chevronStyle.marginTop = -9
252
255
  }
@@ -272,7 +275,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
272
275
  >
273
276
  <View
274
277
  dataSet={{class: "current-selected"}}
275
- style={this.stylingFor("currentSelected", {width: "calc(100% - 27px)", flexWrap: "wrap"})}
278
+ style={this.stylingFor("currentSelected", {width: "calc(100% - 25px)", flexWrap: "wrap"})}
276
279
  >
277
280
  {opened &&
278
281
  <TextInput
@@ -328,7 +331,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
328
331
  value={digg(currentOption, "value")}
329
332
  />
330
333
  }
331
- {this.presentOption(currentOption)}
334
+ {this.presentOption(currentOption, "current")}
332
335
  </>
333
336
  }
334
337
  </View>
@@ -339,11 +342,9 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
339
342
  <View
340
343
  className="chevron-container"
341
344
  style={this.stylingFor("chevronContainer", {
342
- display: "flex",
343
345
  alignItems: "center",
344
346
  justifyContent: "center",
345
347
  height: "100%",
346
- marginRight: 8,
347
348
  marginLeft: "auto"
348
349
  })}
349
350
  >
@@ -460,6 +461,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
460
461
 
461
462
  closeOptions() {
462
463
  this.setState({
464
+ height: null,
463
465
  loadedOptions: undefined,
464
466
  opened: false,
465
467
  optionsContainerLayout: null
@@ -478,6 +480,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
478
480
  this.callOptionsPositionAboveIfOutsideScreen = true
479
481
  this.setState(
480
482
  {
483
+ height: this.s.selectContainerLayout.height,
481
484
  opened: true,
482
485
  scrollLeft: Platform.OS == "web" ? document.documentElement.scrollLeft : null,
483
486
  scrollTop: Platform.OS == "web" ? document.documentElement.scrollTop : null,
@@ -751,11 +754,11 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
751
754
  }
752
755
  }
753
756
 
754
- presentOption = (currentValue) => {
757
+ presentOption = (option, mode) => {
755
758
  const {toggleOptions} = this.props || {}
756
759
  const toggled = this.getToggled()
757
- const icon = this.iconForOption(currentValue)
758
- const toggleValue = toggled[currentValue.value]
760
+ const icon = this.iconForOption(option)
761
+ const toggleValue = toggled[option.value]
759
762
  const toggleOption = toggleOptions?.find((toggleOptionI) => toggleOptionI.value == toggleValue)
760
763
 
761
764
  return (
@@ -764,27 +767,32 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
764
767
  class: "option-presentation",
765
768
  toggleIcon: toggleOption?.icon,
766
769
  toggleValue: toggleOption?.value,
767
- value: currentValue.value
770
+ value: option.value
768
771
  }}
769
772
  >
770
- {toggleOptions && !(currentValue.value in toggled) &&
773
+ {toggleOptions && !(option.value in toggled) &&
771
774
  <View dataSet={{class: "toggle-icon-placeholder"}} style={{width: 25}} />
772
775
  }
773
- {toggleOptions && (currentValue.value in toggled) &&
776
+ {toggleOptions && (option.value in toggled) &&
774
777
  <FontAwesomeIcon dataSet={{class: "toggle-icon"}} name={icon} style={{width: 25}} />
775
778
  }
776
- {currentValue.content}
777
- {!currentValue.content &&
778
- <Text dataSet={{class: "option-presentation-text"}} style={this.stylingFor("optionPresentationText", {whiteSpace: "nowrap"})}>
779
- {currentValue.text}
780
- </Text>
781
- }
782
- {("html" in currentValue) && Platform.OS != "web" &&
783
- <RenderHtml source={{html: digg(currentValue, "html")}} />
784
- }
785
- {("html" in currentValue) && Platform.OS == "web" &&
786
- <div dangerouslySetInnerHTML={{__html: digg(currentValue, "html")}} />
787
- }
779
+ {(() => {
780
+ if (mode == "current" && option.currentContent) {
781
+ return option.currentContent()
782
+ } else if (option.content) {
783
+ return option.content()
784
+ } else if ("html" in option && Platform.OS != "web") {
785
+ return <RenderHtml source={{html: digg(option, "html")}} />
786
+ } else if ("html" in option && Platform.OS == "web") {
787
+ return <div dangerouslySetInnerHTML={{__html: digg(option, "html")}} />
788
+ } else {
789
+ return (
790
+ <Text dataSet={{class: "option-presentation-text"}} style={this.stylingFor("optionPresentationText", {whiteSpace: "nowrap"})}>
791
+ {option.text}
792
+ </Text>
793
+ )
794
+ }
795
+ })()}
788
796
  </View>
789
797
  )
790
798
  }
@@ -795,6 +803,8 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
795
803
  const currentValues = currentOptions?.map((currentOption) => currentOption.value)
796
804
  const stateValues = this.s.currentOptions?.map((currentOption) => currentOption.value)
797
805
 
806
+ console.log("setCurrentFromGivenValues", {stateValues})
807
+
798
808
  if (anythingDifferent(currentValues, stateValues)) {
799
809
  this.setState({currentOptions})
800
810
  }
@@ -59,7 +59,7 @@ export default memo(shapeComponent(class Option extends ShapeComponent {
59
59
  onPointerOut={this.tt.onPointerOut}
60
60
  style={style}
61
61
  >
62
- {this.props.presentOption(option)}
62
+ {this.props.presentOption(option, "option")}
63
63
  </View>
64
64
  )
65
65
  }