haya-select 1.0.23 → 1.0.25

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.23",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "debounce": "^1.2.1",
14
14
  "diggerize": "^1.0.4",
15
15
  "fetching-object": "^1.0.1",
16
- "set-state-compare": "^1.0.19"
16
+ "set-state-compare": "^1.0.27"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "prop-types": ">= 15.7.2",
@@ -220,6 +220,9 @@ export default class HayaSelect extends React.PureComponent {
220
220
  )}
221
221
  </>
222
222
  }
223
+ <div className="haya-select-chevron-down-container">
224
+ <i className="fa fa-chevron-down" />
225
+ </div>
223
226
  </div>
224
227
  <div ref={endOfSelectRef} />
225
228
  </div>
@@ -485,6 +488,9 @@ export default class HayaSelect extends React.PureComponent {
485
488
  newState.currentOptions = currentOptions.filter((currentOption) => currentOption.value != loadedOption.value)
486
489
  }
487
490
  } else {
491
+ // Don't do anything if the clicked option is disabled
492
+ if (loadedOption.disabled) return
493
+
488
494
  if (toggleOptions) {
489
495
  newToggled[loadedOption.value] = 0
490
496
  newState.toggled = newToggled
@@ -1,16 +1,16 @@
1
1
  import PropTypes from "prop-types"
2
- import React from "react"
2
+ import {memo} from "react"
3
3
 
4
- export default class OptionGroup extends React.PureComponent {
5
- static propTypes = {
6
- option: PropTypes.object.isRequired
7
- }
4
+ const OptionGroup = ({option}) => {
5
+ return (
6
+ <div className="haya-select--option-group">
7
+ {option.text}
8
+ </div>
9
+ )
10
+ }
8
11
 
9
- render() {
10
- return (
11
- <div className="haya-select--option-group">
12
- {this.props.option.text}
13
- </div>
14
- )
15
- }
12
+ OptionGroup.propTypes = {
13
+ option: PropTypes.object.isRequired
16
14
  }
15
+
16
+ export default memo(OptionGroup)
@@ -1,34 +1,32 @@
1
- import {digs} from "diggerize"
2
1
  import PropTypes from "prop-types"
3
- import React from "react"
2
+ import {memo, useMemo} from "react"
3
+ import useShape from "set-state-compare/src/use-shape.js"
4
4
 
5
- export default class Option extends React.PureComponent {
6
- static propTypes = {
7
- currentOptions: PropTypes.array.isRequired,
8
- icon: PropTypes.string,
9
- onOptionClicked: PropTypes.func.isRequired,
10
- option: PropTypes.object.isRequired,
11
- presentOption: PropTypes.func.isRequired
12
- }
5
+ const Option = (props) => {
6
+ const s = useShape(props)
7
+ const onClick = useCallback((e) => s.p.onOptionClicked(e, s.p.option), [])
8
+ const selected = Boolean(s.p.currentOptions.find((currentOption) => currentOption.value == s.p.option.value))
13
9
 
14
- style = {cursor: "pointer"}
15
-
16
- render() {
17
- const {currentOptions, option} = digs(this.props, "currentOptions", "option")
18
- const selected = Boolean(currentOptions.find((currentOption) => currentOption.value == option.value))
19
-
20
- return (
21
- <div
22
- className="haya-select-option"
23
- data-selected={selected}
24
- data-value={option.value}
25
- onClick={this.onClick}
26
- style={this.style}
27
- >
28
- {this.props.presentOption(option)}
29
- </div>
30
- )
31
- }
10
+ return (
11
+ <div
12
+ className="haya-select-option"
13
+ data-disabled={Boolean(s.p.option.disabled)}
14
+ data-selected={selected}
15
+ data-value={s.p.option.value}
16
+ onClick={onClick}
17
+ >
18
+ {props.presentOption(s.p.option)}
19
+ </div>
20
+ )
21
+ }
32
22
 
33
- onClick = (e) => this.props.onOptionClicked(e, this.props.option)
23
+ Option.propTypes = {
24
+ currentOptions: PropTypes.array.isRequired,
25
+ disabled: PropTypes.bool,
26
+ icon: PropTypes.string,
27
+ onOptionClicked: PropTypes.func.isRequired,
28
+ option: PropTypes.object.isRequired,
29
+ presentOption: PropTypes.func.isRequired
34
30
  }
31
+
32
+ export default memo(Option)
@@ -2,6 +2,7 @@
2
2
  .haya-select-current-selected {
3
3
  display: flex;
4
4
  flex-wrap: wrap;
5
+ position: relative;
5
6
  background-color: #fff;
6
7
  border: 1px solid #999;
7
8
  color: #000;
@@ -26,6 +27,16 @@
26
27
  margin-right: 6px;
27
28
  }
28
29
  }
30
+
31
+ .haya-select-chevron-down-container {
32
+ display: flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+
36
+ position: absolute;
37
+ right: 20px;
38
+ height: calc(100% - 33px);
39
+ }
29
40
  }
30
41
 
31
42
  .haya-select-search-text-input {
@@ -46,6 +57,15 @@
46
57
  padding: 4px 8px;
47
58
  color: #000;
48
59
 
60
+ &[data-disabled="true"] {
61
+ cursor: default;
62
+ opacity: .6;
63
+ }
64
+
65
+ &[data-disabled="false"] {
66
+ cursor: pointer;
67
+ }
68
+
49
69
  &[data-selected="true"] {
50
70
  background-color: #80b2ff;
51
71
  }