haya-select 1.0.18 → 1.0.20

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.18",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,8 @@
12
12
  "classnames": "^2.3.1",
13
13
  "debounce": "^1.2.1",
14
14
  "diggerize": "^1.0.4",
15
- "fetching-object": "^1.0.1"
15
+ "fetching-object": "^1.0.1",
16
+ "set-state-compare": "^1.0.19"
16
17
  },
17
18
  "peerDependencies": {
18
19
  "prop-types": ">= 15.7.2",
@@ -10,6 +10,7 @@ import Option from "./option"
10
10
  import OptionGroup from "./option-group"
11
11
  import PropTypes from "prop-types"
12
12
  import React from "react"
13
+ import {anythingDifferent} from "set-state-compare"
13
14
 
14
15
  const nameForComponentWithMultiple = (component) => {
15
16
  let name = nameForComponent(component)
@@ -21,7 +22,6 @@ const nameForComponentWithMultiple = (component) => {
21
22
 
22
23
  export default class HayaSelect extends React.PureComponent {
23
24
  static defaultProps = {
24
- defaultToggled: {},
25
25
  multiple: false,
26
26
  search: false
27
27
  }
@@ -41,11 +41,13 @@ export default class HayaSelect extends React.PureComponent {
41
41
  options: PropTypes.oneOfType([PropTypes.array, PropTypes.func]).isRequired,
42
42
  placeholder: PropTypes.node,
43
43
  search: PropTypes.bool.isRequired,
44
+ toggled: PropTypes.object,
44
45
  toggleOptions: PropTypes.arrayOf(PropTypes.shape({
45
46
  icon: PropTypes.string.isRequired,
46
47
  label: PropTypes.string.isRequired,
47
48
  value: PropTypes.string.isRequired
48
- }))
49
+ })),
50
+ values: PropTypes.array
49
51
  }
50
52
 
51
53
  p = fetchingObject(() => this.props)
@@ -65,18 +67,19 @@ export default class HayaSelect extends React.PureComponent {
65
67
  optionsWidth: undefined,
66
68
  scrollLeft: undefined,
67
69
  scrollTop: undefined,
68
- toggled: digg(this, "props", "defaultToggled")
70
+ toggled: this.defaultToggled()
69
71
  }
70
72
 
71
73
  defaultCurrentOptions() {
72
- const {defaultValue, defaultValues} = this.props
74
+ const {defaultValue, defaultValues, values} = this.props
73
75
  const {options} = this.p
74
76
 
75
77
  if (!Array.isArray(options)) return []
76
78
 
77
79
  return options.filter(({value}) =>
78
80
  (defaultValue && value == defaultValue) ||
79
- (defaultValues && defaultValues.includes(value))
81
+ (defaultValues && defaultValues.includes(value)) ||
82
+ (values && values.includes(value))
80
83
  )
81
84
  }
82
85
 
@@ -92,6 +95,10 @@ export default class HayaSelect extends React.PureComponent {
92
95
  throw new Error(`Unknown type of options: ${typeof options}`)
93
96
  }
94
97
 
98
+ defaultToggled() {
99
+ return this.props.defaultToggled || this.props.toggled || {}
100
+ }
101
+
95
102
  componentDidMount() {
96
103
  const {attribute, defaultValue, defaultValues, defaultValuesFromOptions, model, options} = this.props
97
104
 
@@ -100,6 +107,30 @@ export default class HayaSelect extends React.PureComponent {
100
107
  }
101
108
  }
102
109
 
110
+ componentDidUpdate() {
111
+ this.setState((prevState) => {
112
+ const stateUpdate = {}
113
+
114
+ if ("values" in this.props) {
115
+ const newCurrentOptions = this.defaultCurrentOptions()
116
+
117
+ if (anythingDifferent(prevState.currentOptions, newCurrentOptions)) {
118
+ stateUpdate.currentOptions = newCurrentOptions
119
+ }
120
+ }
121
+
122
+ if ("toggled" in this.props) {
123
+ const newToggled = digg(this, "props", "toggled")
124
+
125
+ if (anythingDifferent(prevState.toggled, newToggled)) {
126
+ stateUpdate.toggled = newToggled
127
+ }
128
+ }
129
+
130
+ return stateUpdate
131
+ })
132
+ }
133
+
103
134
  render() {
104
135
  const {endOfSelectRef} = this.t
105
136
  const {
@@ -269,7 +300,9 @@ export default class HayaSelect extends React.PureComponent {
269
300
  opened: false
270
301
  })
271
302
 
272
- if (this.props.onOptionsClosed) this.props.onOptionsClosed()
303
+ if (this.props.onOptionsClosed) {
304
+ this.props.onOptionsClosed({options: this.state.currentOptions})
305
+ }
273
306
  }
274
307
 
275
308
  openOptions() {
@@ -4,6 +4,7 @@
4
4
  flex-wrap: wrap;
5
5
  background-color: #fff;
6
6
  border: 1px solid #999;
7
+ color: #000;
7
8
  cursor: pointer;
8
9
  padding-top: 5px;
9
10
  padding-bottom: 5px;