haya-select 1.0.23 → 1.0.24

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.24",
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",
@@ -485,6 +485,9 @@ export default class HayaSelect extends React.PureComponent {
485
485
  newState.currentOptions = currentOptions.filter((currentOption) => currentOption.value != loadedOption.value)
486
486
  }
487
487
  } else {
488
+ // Don't do anything if the clicked option is disabled
489
+ if (loadedOption.disabled) return
490
+
488
491
  if (toggleOptions) {
489
492
  newToggled[loadedOption.value] = 0
490
493
  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)
@@ -46,6 +46,15 @@
46
46
  padding: 4px 8px;
47
47
  color: #000;
48
48
 
49
+ &[data-disabled="true"] {
50
+ cursor: default;
51
+ opacity: .6;
52
+ }
53
+
54
+ &[data-disabled="false"] {
55
+ cursor: pointer;
56
+ }
57
+
49
58
  &[data-selected="true"] {
50
59
  background-color: #80b2ff;
51
60
  }