@instructure/ui-simple-select 8.33.1-snapshot-1 → 8.33.2-snapshot-5

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.
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var _SimpleSelect = require("../../SimpleSelect");
13
-
14
10
  /*
15
11
  * The MIT License (MIT)
16
12
  *
@@ -1,44 +1,27 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.default = exports.SimpleSelect = void 0;
11
-
12
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
-
14
10
  var _react = _interopRequireWildcard(require("react"));
15
-
16
11
  var _testable = require("@instructure/ui-testable/lib/testable.js");
17
-
18
12
  var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
19
-
20
13
  var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
21
-
22
14
  var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
23
-
24
15
  var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
25
-
26
16
  var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
27
-
28
17
  var _Select = require("@instructure/ui-select/lib/Select");
29
-
30
18
  var _Option = require("./Option");
31
-
32
19
  var _Group = require("./Group");
33
-
34
20
  var _props = require("./props");
35
-
36
21
  const _excluded = ["id", "value", "children", "renderBeforeLabel", "renderAfterLabel"],
37
- _excluded2 = ["id", "renderLabel", "children"],
38
- _excluded3 = ["renderLabel", "value", "defaultValue", "id", "size", "assistiveText", "placeholder", "interaction", "isRequired", "isInline", "width", "optionsMaxWidth", "optionsMaxHeight", "visibleOptionsCount", "messages", "placement", "constrain", "mountNode", "inputRef", "listRef", "renderEmptyOption", "renderBeforeInput", "renderAfterInput", "onFocus", "onBlur", "onShowOptions", "onHideOptions", "children"];
39
-
22
+ _excluded2 = ["id", "renderLabel", "children"],
23
+ _excluded3 = ["renderLabel", "value", "defaultValue", "id", "size", "assistiveText", "placeholder", "interaction", "isRequired", "isInline", "width", "optionsMaxWidth", "optionsMaxHeight", "visibleOptionsCount", "messages", "placement", "constrain", "mountNode", "inputRef", "listRef", "renderEmptyOption", "renderBeforeInput", "renderAfterInput", "onFocus", "onBlur", "onShowOptions", "onHideOptions", "children"];
40
24
  var _dec, _dec2, _class, _class2;
41
-
42
25
  /**
43
26
  ---
44
27
  category: components
@@ -51,62 +34,48 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
51
34
  super(props);
52
35
  this.ref = null;
53
36
  this._emptyOptionId = void 0;
54
-
55
37
  this.getOption = (field, value) => {
56
38
  const children = _react.Children.toArray(this.props.children);
57
-
58
39
  let match;
59
-
60
40
  for (let i = 0; i < children.length; ++i) {
61
41
  const child = children[i];
62
-
63
42
  if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
64
43
  if (child.props[field] === value) {
65
44
  match = child;
66
45
  }
67
46
  } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
68
47
  const groupChildren = _react.Children.toArray(child.props.children);
69
-
70
48
  for (let j = 0; j < groupChildren.length; ++j) {
71
49
  const groupChild = groupChildren[j];
72
-
73
50
  if (groupChild.props[field] === value) {
74
51
  match = groupChild;
75
52
  break;
76
53
  }
77
54
  }
78
55
  }
79
-
80
56
  if (match) break;
81
57
  }
82
-
83
58
  return match;
84
59
  };
85
-
86
60
  this.handleRef = node => {
87
61
  this.ref = node;
88
62
  };
89
-
90
63
  this.handleBlur = event => {
91
64
  this.setState({
92
65
  highlightedOptionId: void 0
93
66
  });
94
-
95
67
  if (typeof this.props.onBlur === 'function') {
96
68
  this.props.onBlur(event);
97
69
  }
98
70
  };
99
-
100
71
  this.handleShowOptions = event => {
101
72
  this.setState({
102
73
  isShowingOptions: true
103
74
  });
104
-
105
75
  if (typeof this.props.onShowOptions === 'function') {
106
76
  this.props.onShowOptions(event);
107
77
  }
108
78
  };
109
-
110
79
  this.handleHideOptions = event => {
111
80
  this.setState(state => {
112
81
  const option = this.getOption('id', state.selectedOptionId);
@@ -116,12 +85,10 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
116
85
  inputValue: option ? option.props.children : ''
117
86
  };
118
87
  });
119
-
120
88
  if (typeof this.props.onHideOptions === 'function') {
121
89
  this.props.onHideOptions(event);
122
90
  }
123
91
  };
124
-
125
92
  this.handleHighlightOption = (event, _ref) => {
126
93
  let id = _ref.id;
127
94
  if (id === this._emptyOptionId) return;
@@ -133,10 +100,8 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
133
100
  inputValue
134
101
  });
135
102
  };
136
-
137
103
  this.handleSelectOption = (event, _ref2) => {
138
104
  let id = _ref2.id;
139
-
140
105
  if (id === this._emptyOptionId) {
141
106
  // selected option is the empty option
142
107
  this.setState({
@@ -144,10 +109,8 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
144
109
  });
145
110
  return;
146
111
  }
147
-
148
112
  const option = this.getOption('id', id);
149
113
  const value = option && option.props.value;
150
-
151
114
  if (this.isControlled) {
152
115
  this.setState({
153
116
  isShowingOptions: false
@@ -158,24 +121,20 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
158
121
  selectedOptionId: id,
159
122
  inputValue: option ? option.props.children : state.inputValue
160
123
  }));
161
- } // fire onChange if selected option changed
162
-
163
-
124
+ }
125
+ // fire onChange if selected option changed
164
126
  if (option && typeof this.props.onChange === 'function') {
165
127
  this.props.onChange(event, {
166
128
  value,
167
129
  id
168
130
  });
169
- } // hide options list whenever selection is made
170
-
171
-
131
+ }
132
+ // hide options list whenever selection is made
172
133
  if (typeof this.props.onHideOptions === 'function') {
173
134
  this.props.onHideOptions(event);
174
135
  }
175
136
  };
176
-
177
137
  const _option = this.getInitialOption(props);
178
-
179
138
  this.state = {
180
139
  inputValue: _option ? _option.props.children : '',
181
140
  isShowingOptions: false,
@@ -184,112 +143,87 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
184
143
  };
185
144
  this._emptyOptionId = props.deterministicId('Select-EmptyOption');
186
145
  }
187
-
188
146
  get _select() {
189
147
  return this.ref;
190
148
  }
191
-
192
149
  focus() {
193
150
  this.ref && this.ref.focus();
194
151
  }
195
-
196
152
  get focused() {
197
153
  return this.ref ? this.ref.focused : false;
198
154
  }
199
-
200
155
  get id() {
201
156
  return this.ref ? this.ref.id : void 0;
202
157
  }
203
-
204
158
  get isControlled() {
205
159
  return typeof this.props.value !== 'undefined';
206
160
  }
207
-
208
161
  get interaction() {
209
162
  return (0, _getInteraction.getInteraction)({
210
163
  props: this.props
211
164
  });
212
165
  }
213
-
214
166
  componentDidUpdate(prevProps) {
215
167
  if (this.props.value !== prevProps.value) {
216
168
  let option = this.getOption('value', this.props.value);
217
-
218
169
  if (typeof this.props.value === 'undefined') {
219
170
  // preserve current value when changing from controlled to uncontrolled
220
171
  option = this.getOption('value', prevProps.value);
221
172
  }
222
-
223
173
  this.setState({
224
174
  inputValue: option ? option.props.children : '',
225
175
  selectedOptionId: option ? option.props.id : ''
226
176
  });
227
177
  }
228
178
  }
229
-
230
179
  getInitialOption(props) {
231
180
  const value = props.value,
232
- defaultValue = props.defaultValue;
181
+ defaultValue = props.defaultValue;
233
182
  const initialValue = value || defaultValue;
234
-
235
183
  if (typeof initialValue === 'string' || typeof initialValue === 'number') {
236
184
  // get option based on value or defaultValue, if provided
237
185
  return this.getOption('value', initialValue);
238
- } // otherwise get the first option
239
-
240
-
186
+ }
187
+ // otherwise get the first option
241
188
  return this.getFirstOption();
242
189
  }
243
-
244
190
  getOptionLabelById(id) {
245
191
  const option = this.getOption('id', id);
246
192
  return option ? option.props.children : '';
247
193
  }
248
-
249
194
  getFirstOption() {
250
195
  const children = _react.Children.toArray(this.props.children);
251
-
252
196
  let match;
253
-
254
197
  for (let i = 0; i < children.length; i++) {
255
198
  const child = children[i];
256
-
257
199
  if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
258
200
  match = child;
259
201
  } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
260
202
  // first child is a group, not an option, find first child in group
261
203
  match = _react.Children.toArray(child.props.children)[0];
262
204
  }
263
-
264
205
  if (match) {
265
206
  break;
266
207
  }
267
208
  }
268
-
269
209
  return match;
270
210
  }
271
-
272
211
  renderChildren() {
273
212
  let children = _react.Children.toArray(this.props.children);
274
-
275
213
  children = _react.Children.map(children, child => {
276
214
  if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Option.Option])) {
277
215
  return this.renderOption(child);
278
216
  } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Group.Group])) {
279
217
  return this.renderGroup(child);
280
218
  }
281
-
282
219
  return null;
283
220
  }).filter(child => !!child);
284
-
285
221
  if (children.length === 0) {
286
222
  // no valid children, render empty option
287
223
  return this.renderEmptyOption();
288
224
  }
289
-
290
225
  return children;
291
226
  }
292
-
293
227
  renderEmptyOption() {
294
228
  return /*#__PURE__*/_react.default.createElement(_Select.Select.Option, {
295
229
  id: this._emptyOptionId,
@@ -297,22 +231,19 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
297
231
  isSelected: false
298
232
  }, (0, _callRenderProp.callRenderProp)(this.props.renderEmptyOption));
299
233
  }
300
-
301
234
  renderOption(option) {
302
235
  const _option$props = option.props,
303
- id = _option$props.id,
304
- value = _option$props.value,
305
- children = _option$props.children,
306
- renderBeforeLabel = _option$props.renderBeforeLabel,
307
- renderAfterLabel = _option$props.renderAfterLabel,
308
- rest = (0, _objectWithoutProperties2.default)(_option$props, _excluded);
236
+ id = _option$props.id,
237
+ value = _option$props.value,
238
+ children = _option$props.children,
239
+ renderBeforeLabel = _option$props.renderBeforeLabel,
240
+ renderAfterLabel = _option$props.renderAfterLabel,
241
+ rest = (0, _objectWithoutProperties2.default)(_option$props, _excluded);
309
242
  const isDisabled = option.props.isDisabled;
310
243
  const isSelected = id === this.state.selectedOptionId;
311
244
  const isHighlighted = id === this.state.highlightedOptionId;
312
-
313
245
  const getRenderLabel = renderLabel => {
314
246
  var _renderLabel$prototyp;
315
-
316
247
  return typeof renderLabel === 'function' && !(renderLabel !== null && renderLabel !== void 0 && (_renderLabel$prototyp = renderLabel.prototype) !== null && _renderLabel$prototyp !== void 0 && _renderLabel$prototyp.isReactComponent) ? renderLabel.bind(null, {
317
248
  id,
318
249
  isDisabled,
@@ -321,7 +252,6 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
321
252
  children
322
253
  }) : renderLabel;
323
254
  };
324
-
325
255
  return /*#__PURE__*/_react.default.createElement(_Select.Select.Option, Object.assign({
326
256
  id: id,
327
257
  value: value,
@@ -333,50 +263,48 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
333
263
  renderAfterLabel: getRenderLabel(renderAfterLabel)
334
264
  }, (0, _passthroughProps.passthroughProps)(rest)), children);
335
265
  }
336
-
337
266
  renderGroup(group) {
338
267
  const _group$props = group.props,
339
- id = _group$props.id,
340
- renderLabel = _group$props.renderLabel,
341
- children = _group$props.children,
342
- rest = (0, _objectWithoutProperties2.default)(_group$props, _excluded2);
268
+ id = _group$props.id,
269
+ renderLabel = _group$props.renderLabel,
270
+ children = _group$props.children,
271
+ rest = (0, _objectWithoutProperties2.default)(_group$props, _excluded2);
343
272
  return /*#__PURE__*/_react.default.createElement(_Select.Select.Group, Object.assign({
344
273
  renderLabel: renderLabel,
345
274
  key: group.key || id
346
275
  }, (0, _passthroughProps.passthroughProps)(rest)), _react.Children.map(children, child => this.renderOption(child)));
347
276
  }
348
-
349
277
  render() {
350
278
  const _this$props = this.props,
351
- renderLabel = _this$props.renderLabel,
352
- value = _this$props.value,
353
- defaultValue = _this$props.defaultValue,
354
- id = _this$props.id,
355
- size = _this$props.size,
356
- assistiveText = _this$props.assistiveText,
357
- placeholder = _this$props.placeholder,
358
- interaction = _this$props.interaction,
359
- isRequired = _this$props.isRequired,
360
- isInline = _this$props.isInline,
361
- width = _this$props.width,
362
- optionsMaxWidth = _this$props.optionsMaxWidth,
363
- optionsMaxHeight = _this$props.optionsMaxHeight,
364
- visibleOptionsCount = _this$props.visibleOptionsCount,
365
- messages = _this$props.messages,
366
- placement = _this$props.placement,
367
- constrain = _this$props.constrain,
368
- mountNode = _this$props.mountNode,
369
- inputRef = _this$props.inputRef,
370
- listRef = _this$props.listRef,
371
- renderEmptyOption = _this$props.renderEmptyOption,
372
- renderBeforeInput = _this$props.renderBeforeInput,
373
- renderAfterInput = _this$props.renderAfterInput,
374
- onFocus = _this$props.onFocus,
375
- onBlur = _this$props.onBlur,
376
- onShowOptions = _this$props.onShowOptions,
377
- onHideOptions = _this$props.onHideOptions,
378
- children = _this$props.children,
379
- rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded3);
279
+ renderLabel = _this$props.renderLabel,
280
+ value = _this$props.value,
281
+ defaultValue = _this$props.defaultValue,
282
+ id = _this$props.id,
283
+ size = _this$props.size,
284
+ assistiveText = _this$props.assistiveText,
285
+ placeholder = _this$props.placeholder,
286
+ interaction = _this$props.interaction,
287
+ isRequired = _this$props.isRequired,
288
+ isInline = _this$props.isInline,
289
+ width = _this$props.width,
290
+ optionsMaxWidth = _this$props.optionsMaxWidth,
291
+ optionsMaxHeight = _this$props.optionsMaxHeight,
292
+ visibleOptionsCount = _this$props.visibleOptionsCount,
293
+ messages = _this$props.messages,
294
+ placement = _this$props.placement,
295
+ constrain = _this$props.constrain,
296
+ mountNode = _this$props.mountNode,
297
+ inputRef = _this$props.inputRef,
298
+ listRef = _this$props.listRef,
299
+ renderEmptyOption = _this$props.renderEmptyOption,
300
+ renderBeforeInput = _this$props.renderBeforeInput,
301
+ renderAfterInput = _this$props.renderAfterInput,
302
+ onFocus = _this$props.onFocus,
303
+ onBlur = _this$props.onBlur,
304
+ onShowOptions = _this$props.onShowOptions,
305
+ onHideOptions = _this$props.onHideOptions,
306
+ children = _this$props.children,
307
+ rest = (0, _objectWithoutProperties2.default)(_this$props, _excluded3);
380
308
  return /*#__PURE__*/_react.default.createElement(_Select.Select, Object.assign({
381
309
  renderLabel: renderLabel,
382
310
  inputValue: this.state.inputValue,
@@ -409,7 +337,6 @@ let SimpleSelect = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec
409
337
  onRequestSelectOption: this.handleSelectOption
410
338
  }, (0, _passthroughProps.passthroughProps)(rest)), this.renderChildren());
411
339
  }
412
-
413
340
  }, _class2.displayName = "SimpleSelect", _class2.componentId = 'SimpleSelect', _class2.Option = _Option.Option, _class2.Group = _Group.Group, _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
414
341
  size: 'medium',
415
342
  isRequired: false,
@@ -10,9 +10,7 @@ Object.defineProperty(exports, "SimpleSelectLocator", {
10
10
  }
11
11
  });
12
12
  exports.default = void 0;
13
-
14
13
  var _SimpleSelectLocator = require("./SimpleSelectLocator");
15
-
16
14
  /*
17
15
  * The MIT License (MIT)
18
16
  *
@@ -1,24 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.propTypes = exports.allowedProps = void 0;
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _Children = require("@instructure/ui-prop-types/lib/Children.js");
13
-
14
10
  var _FormPropTypes = require("@instructure/ui-form-field/lib/FormPropTypes.js");
15
-
16
11
  var _PositionPropTypes = require("@instructure/ui-position/lib/PositionPropTypes.js");
17
-
18
12
  var _Group = require("./Group");
19
-
20
13
  var _Option = require("./Option");
21
-
22
14
  /*
23
15
  * The MIT License (MIT)
24
16
  *
@@ -42,6 +34,7 @@ var _Option = require("./Option");
42
34
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
35
  * SOFTWARE.
44
36
  */
37
+
45
38
  const propTypes = {
46
39
  renderLabel: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
47
40
  // TODO: it was using the "controllable" util, in the TS migration mimic that behaviour
package/lib/index.js CHANGED
@@ -9,5 +9,4 @@ Object.defineProperty(exports, "SimpleSelect", {
9
9
  return _SimpleSelect.SimpleSelect;
10
10
  }
11
11
  });
12
-
13
12
  var _SimpleSelect = require("./SimpleSelect");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-simple-select",
3
- "version": "8.33.1-snapshot-1",
3
+ "version": "8.33.2-snapshot-5",
4
4
  "description": "A component for standard select element behavior.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,22 +24,22 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.13.10",
27
- "@instructure/console": "8.33.1-snapshot-1",
28
- "@instructure/shared-types": "8.33.1-snapshot-1",
29
- "@instructure/ui-form-field": "8.33.1-snapshot-1",
30
- "@instructure/ui-position": "8.33.1-snapshot-1",
31
- "@instructure/ui-prop-types": "8.33.1-snapshot-1",
32
- "@instructure/ui-react-utils": "8.33.1-snapshot-1",
33
- "@instructure/ui-select": "8.33.1-snapshot-1",
34
- "@instructure/ui-testable": "8.33.1-snapshot-1",
27
+ "@instructure/console": "8.33.2-snapshot-5",
28
+ "@instructure/shared-types": "8.33.2-snapshot-5",
29
+ "@instructure/ui-form-field": "8.33.2-snapshot-5",
30
+ "@instructure/ui-position": "8.33.2-snapshot-5",
31
+ "@instructure/ui-prop-types": "8.33.2-snapshot-5",
32
+ "@instructure/ui-react-utils": "8.33.2-snapshot-5",
33
+ "@instructure/ui-select": "8.33.2-snapshot-5",
34
+ "@instructure/ui-testable": "8.33.2-snapshot-5",
35
35
  "prop-types": "^15"
36
36
  },
37
37
  "devDependencies": {
38
- "@instructure/ui-babel-preset": "8.33.1-snapshot-1",
39
- "@instructure/ui-color-utils": "8.33.1-snapshot-1",
40
- "@instructure/ui-icons": "8.33.1-snapshot-1",
41
- "@instructure/ui-test-locator": "8.33.1-snapshot-1",
42
- "@instructure/ui-test-utils": "8.33.1-snapshot-1"
38
+ "@instructure/ui-babel-preset": "8.33.2-snapshot-5",
39
+ "@instructure/ui-color-utils": "8.33.2-snapshot-5",
40
+ "@instructure/ui-icons": "8.33.2-snapshot-5",
41
+ "@instructure/ui-test-locator": "8.33.2-snapshot-5",
42
+ "@instructure/ui-test-utils": "8.33.2-snapshot-5"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "react": ">=16.8 <=18"