haya-select 1.0.16 → 1.0.17

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.16",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,8 @@
11
11
  "dependencies": {
12
12
  "classnames": "^2.3.1",
13
13
  "debounce": "^1.2.1",
14
- "diggerize": "^1.0.4"
14
+ "diggerize": "^1.0.4",
15
+ "fetching-object": "^1.0.1"
15
16
  },
16
17
  "peerDependencies": {
17
18
  "prop-types": ">= 15.7.2",
@@ -47,6 +47,10 @@ export default class HayaSelect extends React.PureComponent {
47
47
  }))
48
48
  }
49
49
 
50
+ p = fetchingObject(() => this.props)
51
+ s = fetchingObject(() => this.state)
52
+ t = fetchingObject(this)
53
+
50
54
  endOfSelectRef = React.createRef()
51
55
  optionsContainerRef = React.createRef()
52
56
  searchTextInputRef = React.createRef()
@@ -65,7 +69,7 @@ export default class HayaSelect extends React.PureComponent {
65
69
 
66
70
  defaultCurrentOptions() {
67
71
  const {defaultValue, defaultValues} = this.props
68
- const {options} = digs(this.props, "options")
72
+ const {options} = this.p
69
73
 
70
74
  if (!Array.isArray(options)) return []
71
75
 
@@ -76,7 +80,7 @@ export default class HayaSelect extends React.PureComponent {
76
80
  }
77
81
 
78
82
  defaultLoadedOptions() {
79
- const {options} = digs(this.props, "options")
83
+ const {options} = this.p
80
84
 
81
85
  if (typeof options == "function") {
82
86
  return undefined
@@ -96,7 +100,7 @@ export default class HayaSelect extends React.PureComponent {
96
100
  }
97
101
 
98
102
  render() {
99
- const {endOfSelectRef} = digs(this, "endOfSelectRef")
103
+ const {endOfSelectRef} = this.t
100
104
  const {
101
105
  attribute,
102
106
  className,
@@ -113,7 +117,7 @@ export default class HayaSelect extends React.PureComponent {
113
117
  toggleOptions,
114
118
  ...restProps
115
119
  } = this.props
116
- const {currentOptions, opened} = digs(this.state, "currentOptions", "opened")
120
+ const {currentOptions, opened} = this.s
117
121
  const BodyPortal = config.getBodyPortal()
118
122
 
119
123
  return (
@@ -208,7 +212,7 @@ export default class HayaSelect extends React.PureComponent {
208
212
  }
209
213
 
210
214
  loadOptions = async () => {
211
- const {options} = digs(this.props, "options")
215
+ const {options} = this.p
212
216
  const searchValue = digg(this, "searchTextInputRef", "current")?.value
213
217
 
214
218
  if (Array.isArray(options)) {
@@ -225,7 +229,14 @@ export default class HayaSelect extends React.PureComponent {
225
229
  return <OptionGroup key={key} option={loadedOption} />
226
230
  }
227
231
 
228
- return <Option currentOptions={this.state.currentOptions} key={key} option={loadedOption} onOptionClicked={this.onOptionClicked} presentOption={this.presentOption} />
232
+ return <Option
233
+ currentOptions={this.state.currentOptions}
234
+ icon={this.iconForOption(loadedOption)}
235
+ key={key}
236
+ option={loadedOption}
237
+ onOptionClicked={this.onOptionClicked}
238
+ presentOption={this.presentOption}
239
+ />
229
240
  }
230
241
 
231
242
  loadOptionsFromArray(options, searchValue) {
@@ -239,7 +250,7 @@ export default class HayaSelect extends React.PureComponent {
239
250
  e.preventDefault()
240
251
  e.stopPropagation()
241
252
 
242
- const {opened} = digs(this.state, "opened")
253
+ const {opened} = this.s
243
254
 
244
255
  if (opened) {
245
256
  this.closeOptions()
@@ -258,7 +269,7 @@ export default class HayaSelect extends React.PureComponent {
258
269
  }
259
270
 
260
271
  openOptions() {
261
- const {endOfSelectRef} = digs(this, "endOfSelectRef")
272
+ const {endOfSelectRef} = this.t
262
273
  const position = endOfSelectRef.current.getBoundingClientRect()
263
274
  const {left, top, width} = digs(position, "left", "top", "width")
264
275
 
@@ -278,8 +289,8 @@ export default class HayaSelect extends React.PureComponent {
278
289
  }
279
290
 
280
291
  onWindowClicked = (e) => {
281
- const {optionsContainerRef} = digs(this, "optionsContainerRef")
282
- const {opened} = digs(this.state, "opened")
292
+ const {optionsContainerRef} = this.t
293
+ const {opened} = this.s
283
294
 
284
295
  // If options are open and a click is made outside of the options container
285
296
  if (opened && optionsContainerRef.current && !optionsContainerRef.current?.contains(e.target)) {
@@ -288,25 +299,8 @@ export default class HayaSelect extends React.PureComponent {
288
299
  }
289
300
 
290
301
  optionsContainer() {
291
- const {optionsContainerRef} = digs(this, "endOfSelectRef", "optionsContainerRef")
292
- const {
293
- loadedOptions,
294
- optionsLeft,
295
- optionsTop,
296
- optionsWidth,
297
- scrollLeft,
298
- scrollTop
299
- } = digs(
300
- this.state,
301
- "loadedOptions",
302
- "currentOptions",
303
- "opened",
304
- "optionsLeft",
305
- "optionsTop",
306
- "optionsWidth",
307
- "scrollLeft",
308
- "scrollTop"
309
- )
302
+ const {optionsContainerRef} = this.t
303
+ const {loadedOptions, optionsLeft, optionsTop, optionsWidth, scrollLeft, scrollTop} = this.s
310
304
 
311
305
  return (
312
306
  <div
@@ -340,7 +334,7 @@ export default class HayaSelect extends React.PureComponent {
340
334
  e.stopPropagation()
341
335
 
342
336
  const {onChange, toggleOptions} = this.props
343
- const {multiple} = digs(this.props, "multiple")
337
+ const {multiple} = this.p
344
338
 
345
339
  this.setState(
346
340
  (prevState) => {
@@ -402,9 +396,21 @@ export default class HayaSelect extends React.PureComponent {
402
396
  if (!multiple) this.closeOptions()
403
397
  }
404
398
 
399
+ iconForOption(option) {
400
+ const {toggleOptions} = this.props || {}
401
+ const {toggled} = this.s
402
+
403
+ if (toggleOptions && (option.value in toggled)) {
404
+ const icon = toggleOptions[toggled[option.value]].icon
405
+
406
+ return icon
407
+ }
408
+ }
409
+
405
410
  presentOption = (currentValue) => {
406
411
  const {toggleOptions} = this.props || {}
407
- const {toggled} = digs(this.state, "toggled")
412
+ const {toggled} = this.s
413
+ const icon = this.iconForOption(currentValue)
408
414
 
409
415
  return (
410
416
  <div
@@ -417,7 +423,7 @@ export default class HayaSelect extends React.PureComponent {
417
423
  <i className="fa fa-fw" />
418
424
  }
419
425
  {toggleOptions && (currentValue.value in toggled) &&
420
- <i className={`fa fa-fw fa-${toggleOptions[toggled[currentValue.value]].icon}`} />
426
+ <i className={`fa fa-fw fa-${icon}`} />
421
427
  }
422
428
  {currentValue.text}
423
429
  {("html" in currentValue) &&
@@ -5,11 +5,14 @@ import React from "react"
5
5
  export default class Option extends React.PureComponent {
6
6
  static propTypes = {
7
7
  currentOptions: PropTypes.array.isRequired,
8
+ icon: PropTypes.string,
8
9
  onOptionClicked: PropTypes.func.isRequired,
9
10
  option: PropTypes.object.isRequired,
10
11
  presentOption: PropTypes.func.isRequired
11
12
  }
12
13
 
14
+ style = {cursor: "pointer"}
15
+
13
16
  render() {
14
17
  const {currentOptions, option} = digs(this.props, "currentOptions", "option")
15
18
  const selected = Boolean(currentOptions.find((currentOption) => currentOption.value == option.value))
@@ -20,7 +23,7 @@ export default class Option extends React.PureComponent {
20
23
  data-selected={selected}
21
24
  data-value={option.value}
22
25
  onClick={this.onClick}
23
- style={{cursor: "pointer"}}
26
+ style={this.style}
24
27
  >
25
28
  {this.props.presentOption(option)}
26
29
  </div>
@@ -1,10 +1,13 @@
1
1
  .haya-select {
2
2
  .haya-select-current-selected {
3
3
  display: flex;
4
+ flex-wrap: wrap;
4
5
  background-color: #fff;
5
6
  border: 1px solid #999;
6
7
  cursor: pointer;
7
- padding: 5px;
8
+ padding-top: 5px;
9
+ padding-bottom: 5px;
10
+ padding-left: 5px;
8
11
 
9
12
  &[data-opened="false"] {
10
13
  border-radius: 4px;
@@ -14,8 +17,8 @@
14
17
  border-radius: 4px 4px 0 0;
15
18
  }
16
19
 
17
- .current-option + .current-option {
18
- margin-left: 6px;
20
+ .current-option {
21
+ margin-right: 6px;
19
22
  }
20
23
  }
21
24
  }