@instructure/ui-simple-select 8.14.1-snapshot.24 → 8.14.1-snapshot.27

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.
Files changed (34) hide show
  1. package/es/SimpleSelect/Group/index.js +2 -3
  2. package/es/SimpleSelect/Group/props.js +0 -7
  3. package/es/SimpleSelect/Option/index.js +2 -2
  4. package/es/SimpleSelect/Option/props.js +0 -23
  5. package/es/SimpleSelect/SimpleSelectLocator.js +3 -1
  6. package/es/SimpleSelect/index.js +74 -68
  7. package/es/SimpleSelect/props.js +0 -130
  8. package/lib/SimpleSelect/Group/index.js +2 -3
  9. package/lib/SimpleSelect/Group/props.js +0 -7
  10. package/lib/SimpleSelect/Option/index.js +2 -2
  11. package/lib/SimpleSelect/Option/props.js +0 -23
  12. package/lib/SimpleSelect/SimpleSelectLocator.js +2 -0
  13. package/lib/SimpleSelect/index.js +73 -70
  14. package/lib/SimpleSelect/props.js +0 -130
  15. package/package.json +15 -15
  16. package/src/SimpleSelect/Group/index.tsx +3 -4
  17. package/src/SimpleSelect/Group/props.ts +10 -8
  18. package/src/SimpleSelect/Option/index.tsx +2 -2
  19. package/src/SimpleSelect/Option/props.ts +35 -21
  20. package/src/SimpleSelect/index.tsx +92 -111
  21. package/src/SimpleSelect/props.ts +147 -94
  22. package/tsconfig.build.tsbuildinfo +1 -1
  23. package/types/SimpleSelect/Group/index.d.ts +4 -5
  24. package/types/SimpleSelect/Group/index.d.ts.map +1 -1
  25. package/types/SimpleSelect/Group/props.d.ts +7 -1
  26. package/types/SimpleSelect/Group/props.d.ts.map +1 -1
  27. package/types/SimpleSelect/Option/index.d.ts +7 -7
  28. package/types/SimpleSelect/Option/index.d.ts.map +1 -1
  29. package/types/SimpleSelect/Option/props.d.ts +30 -4
  30. package/types/SimpleSelect/Option/props.d.ts.map +1 -1
  31. package/types/SimpleSelect/index.d.ts +45 -61
  32. package/types/SimpleSelect/index.d.ts.map +1 -1
  33. package/types/SimpleSelect/props.d.ts +127 -16
  34. package/types/SimpleSelect/props.d.ts.map +1 -1
@@ -35,6 +35,7 @@ import { Option } from './Option'
35
35
  import type { FormMessage } from '@instructure/ui-form-field'
36
36
  import type {
37
37
  OtherHTMLAttributes,
38
+ PickPropsWithExceptions,
38
39
  PropValidators
39
40
  } from '@instructure/shared-types'
40
41
  import type {
@@ -42,180 +43,232 @@ import type {
42
43
  PositionConstraint,
43
44
  PositionMountNode
44
45
  } from '@instructure/ui-position'
46
+ import type { SelectOwnProps } from '@instructure/ui-select'
45
47
 
46
- type SimpleSelectOwnProps = {
47
- renderLabel: React.ReactNode | ((...args: any[]) => any)
48
+ type SimpleSelectOwnProps = PropsPassedToSelect & {
49
+ /**
50
+ * The value corresponding to the value of the selected option. If defined,
51
+ * the component will act controlled and will not manage its own state.
52
+ */
48
53
  value?: string | number // TODO: it was using the "controllable" util, in the TS migration mimic that behaviour
54
+
55
+ /**
56
+ * The value of the option to select by default, when uncontrolled.
57
+ */
49
58
  defaultValue?: string
50
- id?: string
51
- size?: 'small' | 'medium' | 'large'
52
- assistiveText?: string
53
- placeholder?: string
54
- interaction?: 'enabled' | 'disabled' | 'readonly'
55
- isRequired?: boolean
56
- isInline?: boolean
57
- width?: string
58
- optionsMaxWidth?: string
59
- visibleOptionsCount?: number
60
- messages?: FormMessage[]
61
- placement?: PlacementPropValues
62
- constrain?: PositionConstraint
63
- mountNode?: PositionMountNode
64
- onChange?: (...args: any[]) => any
65
- onFocus?: (...args: any[]) => any
66
- onBlur?: (...args: any[]) => any
67
- onShowOptions?: (...args: any[]) => any
68
- onHideOptions?: (...args: any[]) => any
69
- inputRef?: (...args: any[]) => any
70
- listRef?: (...args: any[]) => any
71
- renderEmptyOption?: React.ReactNode | ((...args: any[]) => any)
72
- renderBeforeInput?: React.ReactNode | ((...args: any[]) => any)
73
- renderAfterInput?: React.ReactNode | ((...args: any[]) => any)
74
- children?: React.ReactNode
75
- }
76
59
 
77
- type PropKeys = keyof SimpleSelectOwnProps
60
+ /**
61
+ * Callback fired when a new option is selected.
62
+ */
63
+ onChange?: (
64
+ event: React.SyntheticEvent,
65
+ data: {
66
+ value?: string | number
67
+ id?: string
68
+ }
69
+ ) => void
78
70
 
79
- type AllowedPropKeys = Readonly<Array<PropKeys>>
71
+ // passed to Select as onRequestShowOptions
72
+ /**
73
+ * Callback fired when the options list is shown.
74
+ */
75
+ onShowOptions?: (event: React.SyntheticEvent) => void
80
76
 
81
- type SimpleSelectProps = SimpleSelectOwnProps &
82
- OtherHTMLAttributes<
83
- SimpleSelectOwnProps,
84
- InputHTMLAttributes<SimpleSelectOwnProps>
85
- >
77
+ // passed to Select as onRequestHideOptions
78
+ /**
79
+ * Callback fired when the options list is hidden.
80
+ */
81
+ onHideOptions?: (event: React.SyntheticEvent) => void
86
82
 
87
- const propTypes: PropValidators<PropKeys> = {
88
83
  /**
89
- * The form field label.
84
+ * Content to display in the list when no options are available.
90
85
  */
91
- renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
86
+ renderEmptyOption?: React.ReactNode | (() => React.ReactNode)
87
+
92
88
  /**
93
- * The value corresponding to the value of the selected option. If defined,
94
- * the component will act controlled and will not manage its own state.
89
+ * Children of type `<SimpleSelect.Option />` or `<SimpleSelect.Group />`.
95
90
  */
96
- // TODO: it was using the "controllable" util, in the TS migration mimic that behaviour
97
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
91
+ children?: React.ReactNode // TODO: ChildrenPropTypes.oneOf([Group, Option])
92
+ }
93
+
94
+ type PropsPassedToSelect = {
98
95
  /**
99
- * The value of the option to select by default, when uncontrolled.
96
+ * The form field label.
100
97
  */
101
- defaultValue: PropTypes.string,
98
+ renderLabel: React.ReactNode | (() => React.ReactNode)
99
+
102
100
  /**
103
101
  * The id of the text input. One is generated if not supplied.
104
102
  */
105
- id: PropTypes.string,
103
+ id?: string
104
+
106
105
  /**
107
106
  * The size of the text input.
108
107
  */
109
- size: PropTypes.oneOf(['small', 'medium', 'large']),
108
+ size?: 'small' | 'medium' | 'large'
109
+
110
110
  /**
111
111
  * Additional helpful text to provide to screen readers about the operation
112
112
  * of the component. Provided via aria-describedby.
113
113
  */
114
- assistiveText: PropTypes.string,
114
+ assistiveText?: string
115
+
115
116
  /**
116
117
  * Html placeholder text to display when the input has no value. This should
117
118
  * be hint text, not a label replacement.
118
119
  */
119
- placeholder: PropTypes.string,
120
+ placeholder?: string
121
+
120
122
  /**
121
123
  * Specifies if interaction with the input is enabled, disabled, or readonly.
122
124
  * When "disabled", the input changes visibly to indicate that it cannot
123
125
  * receive user interactions. When "readonly" the input still cannot receive
124
126
  * user interactions but it keeps the same styles as if it were enabled.
125
127
  */
126
- interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
128
+ interaction?: 'enabled' | 'disabled' | 'readonly'
129
+
127
130
  /**
128
131
  * Whether or not the text input is required.
129
132
  */
130
- isRequired: PropTypes.bool,
133
+ isRequired?: boolean
134
+
131
135
  /**
132
136
  * Whether the input is rendered inline with other elements or if it
133
137
  * is rendered as a block level element.
134
138
  */
135
- isInline: PropTypes.bool,
139
+ isInline?: boolean
140
+
136
141
  /**
137
142
  * The width of the text input.
138
143
  */
139
- width: PropTypes.string,
144
+ width?: string
145
+
140
146
  /**
141
147
  * The max width the options list can be before option text wraps. If not
142
148
  * set, the list will only display as wide as the text input.
143
149
  */
144
- optionsMaxWidth: PropTypes.string,
150
+ optionsMaxWidth?: string
151
+
145
152
  /**
146
153
  * The number of options that should be visible before having to scroll.
147
154
  */
148
- visibleOptionsCount: PropTypes.number,
155
+ visibleOptionsCount?: number
156
+
149
157
  /**
150
- * Displays messages and validation for the input. It should be an object
151
- * with the following shape:
158
+ * Displays messages and validation for the input. It should be an array of
159
+ * objects with the following shape:
152
160
  * `{
153
- * text: PropTypes.node,
154
- * type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
161
+ * text: ReactNode,
162
+ * type: One of: ['error', 'hint', 'success', 'screenreader-only']
155
163
  * }`
156
164
  */
157
- messages: PropTypes.arrayOf(FormPropTypes.message),
165
+ messages?: FormMessage[]
166
+
158
167
  /**
159
168
  * The placement of the options list.
160
169
  */
161
- placement: PositionPropTypes.placement,
170
+ placement?: PlacementPropValues
171
+
162
172
  /**
163
173
  * The parent in which to constrain the placement.
164
174
  */
165
- constrain: PositionPropTypes.constrain,
175
+ constrain?: PositionConstraint
176
+
166
177
  /**
167
178
  * An element or a function returning an element to use mount the options
168
179
  * list to in the DOM (defaults to `document.body`)
169
180
  */
170
- mountNode: PositionPropTypes.mountNode,
181
+ mountNode?: PositionMountNode
182
+
171
183
  /**
172
- * Callback fired when a new option is selected.
173
- * @param {Object} event - the event object
174
- * @param {Object} data - additional data
175
- * @param data.value - the value of selected option
176
- * @param data.id - the id of the selected option
184
+ * A ref to the html `input` element.
177
185
  */
178
- onChange: PropTypes.func,
186
+ inputRef?: (inputElement: HTMLInputElement | null) => void
187
+
179
188
  /**
180
- * Callback fired when text input receives focus.
189
+ * A ref to the html `ul` element.
181
190
  */
182
- onFocus: PropTypes.func,
191
+ listRef?: (listElement: HTMLUListElement | null) => void
192
+
183
193
  /**
184
- * Callback fired when text input loses focus.
194
+ * Content to display before the text input. This will commonly be an icon.
185
195
  */
186
- onBlur: PropTypes.func,
196
+ renderBeforeInput?: React.ReactNode | (() => React.ReactNode)
197
+
187
198
  /**
188
- * Callback fired when the options list is shown.
199
+ * Content to display after the text input. This content will replace the
200
+ * default arrow icons.
189
201
  */
190
- onShowOptions: PropTypes.func,
202
+ renderAfterInput?: React.ReactNode | (() => React.ReactNode)
203
+
191
204
  /**
192
- * Callback fired when the options list is hidden.
205
+ * Callback fired when text input receives focus.
193
206
  */
194
- onHideOptions: PropTypes.func,
207
+ onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void
208
+
195
209
  /**
196
- * A ref to the html `input` element.
210
+ * Callback fired when text input loses focus.
197
211
  */
212
+ onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void
213
+ }
214
+
215
+ type PropKeys = keyof SimpleSelectOwnProps
216
+
217
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
218
+
219
+ type SimpleSelectProps = PickPropsWithExceptions<
220
+ SelectOwnProps,
221
+ | keyof PropsPassedToSelect
222
+ | 'children'
223
+ | 'onRequestShowOptions'
224
+ | 'onRequestHideOptions'
225
+ | 'onRequestHighlightOption'
226
+ | 'onRequestSelectOption'
227
+ | 'inputValue'
228
+ | 'isShowingOptions'
229
+ > &
230
+ SimpleSelectOwnProps &
231
+ OtherHTMLAttributes<
232
+ SimpleSelectOwnProps,
233
+ InputHTMLAttributes<SimpleSelectOwnProps>
234
+ >
235
+
236
+ type SimpleSelectState = {
237
+ inputValue?: string
238
+ isShowingOptions: boolean
239
+ highlightedOptionId?: string
240
+ selectedOptionId?: string
241
+ }
242
+
243
+ const propTypes: PropValidators<PropKeys> = {
244
+ renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
245
+ // TODO: it was using the "controllable" util, in the TS migration mimic that behaviour
246
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
247
+ defaultValue: PropTypes.string,
248
+ id: PropTypes.string,
249
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
250
+ assistiveText: PropTypes.string,
251
+ placeholder: PropTypes.string,
252
+ interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
253
+ isRequired: PropTypes.bool,
254
+ isInline: PropTypes.bool,
255
+ width: PropTypes.string,
256
+ optionsMaxWidth: PropTypes.string,
257
+ visibleOptionsCount: PropTypes.number,
258
+ messages: PropTypes.arrayOf(FormPropTypes.message),
259
+ placement: PositionPropTypes.placement,
260
+ constrain: PositionPropTypes.constrain,
261
+ mountNode: PositionPropTypes.mountNode,
262
+ onChange: PropTypes.func,
263
+ onFocus: PropTypes.func,
264
+ onBlur: PropTypes.func,
265
+ onShowOptions: PropTypes.func,
266
+ onHideOptions: PropTypes.func,
198
267
  inputRef: PropTypes.func,
199
- /**
200
- * A ref to the html `ul` element.
201
- */
202
268
  listRef: PropTypes.func,
203
- /**
204
- * Content to display in the list when no options are available.
205
- */
206
269
  renderEmptyOption: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
207
- /**
208
- * Content to display before the text input. This will commonly be an icon.
209
- */
210
270
  renderBeforeInput: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
211
- /**
212
- * Content to display after the text input. This content will replace the
213
- * default arrow icons.
214
- */
215
271
  renderAfterInput: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
216
- /**
217
- * Children of type `<SimpleSelect.Option />` or `<SimpleSelect.Group />`.
218
- */
219
272
  children: ChildrenPropTypes.oneOf([Group, Option])
220
273
  }
221
274
 
@@ -250,5 +303,5 @@ const allowedProps: AllowedPropKeys = [
250
303
  'children'
251
304
  ]
252
305
 
253
- export type { SimpleSelectProps }
306
+ export type { SimpleSelectProps, SimpleSelectState }
254
307
  export { propTypes, allowedProps }