haya-select 1.0.7 → 1.0.10

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.
@@ -0,0 +1,9 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: weekly
7
+ time: "01:00"
8
+ timezone: Europe/Copenhagen
9
+ open-pull-requests-limit: 99
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haya-select",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,5 +12,9 @@
12
12
  "classnames": "^2.3.1",
13
13
  "debounce": "^1.2.1",
14
14
  "diggerize": "^1.0.4"
15
+ },
16
+ "peerDependencies": {
17
+ "prop-types": ">= 15.7.2",
18
+ "react": ">= 16.0.0"
15
19
  }
16
20
  }
@@ -14,8 +14,9 @@ const nameForComponentWithMultiple = (component) => {
14
14
  return name
15
15
  }
16
16
 
17
- export default class CustomSelect extends React.PureComponent {
17
+ export default class HayaSelect extends React.PureComponent {
18
18
  static defaultProps = {
19
+ defaultToggled: {},
19
20
  multiple: false,
20
21
  search: false
21
22
  }
@@ -23,13 +24,16 @@ export default class CustomSelect extends React.PureComponent {
23
24
  static propTypes = {
24
25
  attribute: PropTypes.string,
25
26
  className: PropTypes.string,
27
+ defaultToggled: PropTypes.object,
26
28
  defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
27
29
  defaultValues: PropTypes.array,
28
30
  defaultValuesFromOptions: PropTypes.array,
31
+ id: PropTypes.node,
29
32
  model: PropTypes.object,
30
33
  multiple: PropTypes.bool.isRequired,
31
34
  onChange: PropTypes.func,
32
35
  options: PropTypes.oneOfType([PropTypes.array, PropTypes.func]).isRequired,
36
+ placeholder: PropTypes.node,
33
37
  search: PropTypes.bool.isRequired,
34
38
  toggleOptions: PropTypes.arrayOf(PropTypes.shape({
35
39
  icon: PropTypes.string.isRequired,
@@ -51,7 +55,7 @@ export default class CustomSelect extends React.PureComponent {
51
55
  optionsWidth: undefined,
52
56
  scrollLeft: undefined,
53
57
  scrollTop: undefined,
54
- toggled: {}
58
+ toggled: digg(this, "props", "defaultToggled")
55
59
  }
56
60
 
57
61
  defaultCurrentOptions() {
@@ -79,16 +83,31 @@ export default class CustomSelect extends React.PureComponent {
79
83
  }
80
84
 
81
85
  componentDidMount() {
82
- const {attribute, defaultValuesFromOptions, model, options} = this.props
86
+ const {attribute, defaultValue, defaultValuesFromOptions, model, options} = this.props
83
87
 
84
- if ((defaultValuesFromOptions || (attribute && model)) && typeof options == "function") {
88
+ if (((defaultValue || defaultValuesFromOptions) || (attribute && model)) && typeof options == "function") {
85
89
  this.loadDefaultValuesFromOptionsCallback()
86
90
  }
87
91
  }
88
92
 
89
93
  render() {
90
94
  const {endOfSelectRef} = digs(this, "endOfSelectRef")
91
- const {attribute, className, defaultValue, defaultValues, model, multiple, onChange, options, search, toggleOptions, ...restProps} = this.props
95
+ const {
96
+ attribute,
97
+ className,
98
+ defaultToggled,
99
+ defaultValue,
100
+ defaultValues,
101
+ id,
102
+ model,
103
+ multiple,
104
+ onChange,
105
+ options,
106
+ placeholder,
107
+ search,
108
+ toggleOptions,
109
+ ...restProps
110
+ } = this.props
92
111
  const {currentOptions, opened} = digs(this.state, "currentOptions", "opened")
93
112
  const BodyPortal = config.getBodyPortal()
94
113
 
@@ -120,17 +139,19 @@ export default class CustomSelect extends React.PureComponent {
120
139
  <>
121
140
  {currentOptions.length == 0 &&
122
141
  <div style={{color: "grey"}}>
123
- {I18n.t("haya_select.nothing_selected")}
142
+ {placeholder || I18n.t("haya_select.nothing_selected")}
124
143
  </div>
125
144
  }
126
145
  {currentOptions.map((currentOption) =>
127
146
  <div className="current-option" key={`current-value-${digg(currentOption, "value")}`}>
128
- <input
129
- id={idForComponent(this)}
130
- name={nameForComponentWithMultiple(this)}
131
- type="hidden"
132
- value={digg(currentOption, "value")}
133
- />
147
+ {nameForComponentWithMultiple(this) &&
148
+ <input
149
+ id={idForComponent(this)}
150
+ name={nameForComponentWithMultiple(this)}
151
+ type="hidden"
152
+ value={digg(currentOption, "value")}
153
+ />
154
+ }
134
155
  {this.presentOption(currentOption)}
135
156
  </div>
136
157
  )}
@@ -143,9 +164,10 @@ export default class CustomSelect extends React.PureComponent {
143
164
  }
144
165
 
145
166
  defaultValues () {
146
- const {attribute, defaultValuesFromOptions, model} = this.props
167
+ const {attribute, defaultValue, defaultValuesFromOptions, model} = this.props
147
168
 
148
169
  if (defaultValuesFromOptions) return defaultValuesFromOptions
170
+ if (defaultValue) return defaultValue
149
171
 
150
172
  if (attribute && model) {
151
173
  if (!(attribute in model)) throw new Error(`No such attribute on ${model.modelClassData().name}: ${attribute}`)
@@ -374,15 +396,19 @@ export default class CustomSelect extends React.PureComponent {
374
396
  )
375
397
 
376
398
  if (!multiple) this.closeOptions()
377
-
378
399
  }
379
400
 
380
401
  presentOption = (currentValue) => {
381
- const {toggleOptions} = this.props
402
+ const {toggleOptions} = this.props || {}
382
403
  const {toggled} = digs(this.state, "toggled")
383
404
 
384
405
  return (
385
- <div>
406
+ <div
407
+ className="haya-select-option-presentation"
408
+ data-toggle-icon={toggleOptions && toggled && toggleOptions[toggled[currentValue.value]]?.icon}
409
+ data-toggle-value={toggleOptions && toggled && toggleOptions[toggled[currentValue.value]]?.value}
410
+ data-value={currentValue.value}
411
+ >
386
412
  {toggleOptions && !(currentValue.value in toggled) &&
387
413
  <i className="fa fa-fw" />
388
414
  }