@instructure/ui-time-select 11.7.2-snapshot-48 → 11.7.2-snapshot-49

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,327 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { InputHTMLAttributes } from 'react'
26
+
27
+ import type { FormMessage } from '@instructure/ui-form-field/latest'
28
+ import type { OtherHTMLAttributes } from '@instructure/shared-types'
29
+ import type {
30
+ PlacementPropValues,
31
+ PositionConstraint,
32
+ PositionMountNode
33
+ } from '@instructure/ui-position'
34
+ import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
35
+ import { Renderable } from '@instructure/shared-types'
36
+ import type { Moment } from 'moment-timezone'
37
+
38
+ type PropKeys = keyof TimeSelectOwnProps
39
+
40
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
41
+
42
+ type TimeSelectProps = TimeSelectOwnProps &
43
+ OtherHTMLAttributes<
44
+ TimeSelectOwnProps,
45
+ InputHTMLAttributes<TimeSelectOwnProps & Element>
46
+ > &
47
+ WithDeterministicIdProps
48
+
49
+ type TimeSelectOwnProps = {
50
+ /**
51
+ * The form field label.
52
+ */
53
+ renderLabel: Renderable
54
+ /**
55
+ * Whether to default to the first option when `defaultValue` hasn't been specified.
56
+ */
57
+ defaultToFirstOption?: boolean
58
+ /**
59
+ * An ISO 8601 formatted date string representing the current selected value. If defined,
60
+ * the component will act controlled and will not manage its own state.
61
+ */
62
+ value?: string // TODO: controllable(I18nPropTypes.iso8601, 'onChange'),
63
+ /**
64
+ * An ISO 8601 formatted date string to use if `value` isn't provided.
65
+ */
66
+ defaultValue?: string
67
+ /**
68
+ * The id of the text input. One is generated if not supplied.
69
+ */
70
+ id?: string
71
+ /**
72
+ * The format to use when displaying the possible and currently selected options.
73
+ * This component currently rounds seconds down to the minute.
74
+ * Defaults to `LT`, which is localized time without seconds, e.g. "16:45" or
75
+ * "4:45 PM"
76
+ *
77
+ * See [moment](https://momentjs.com/docs/#/displaying/format/) for the list
78
+ * of available formats.
79
+ */
80
+ format?: string
81
+ /**
82
+ * The number of minutes to increment by when generating the allowable options.
83
+ */
84
+ step?: 5 | 10 | 15 | 20 | 30 | 60
85
+ /**
86
+ * Specifies if interaction with the input is enabled, disabled, or readonly.
87
+ * When "disabled", the input changes visibly to indicate that it cannot
88
+ * receive user interactions. When "readonly" the input still cannot receive
89
+ * user interactions, but it keeps the same styles as if it were enabled.
90
+ */
91
+ interaction?: 'enabled' | 'disabled' | 'readonly'
92
+ /**
93
+ * Html placeholder text to display when the input has no value. This should
94
+ * be hint text, not a label replacement.
95
+ */
96
+ placeholder?: string
97
+ isRequired?: boolean
98
+ /**
99
+ * Whether the input is rendered inline with other elements or if it
100
+ * is rendered as a block level element.
101
+ */
102
+ isInline?: boolean
103
+ /**
104
+ * The width of the text input.
105
+ */
106
+ width?: string
107
+ /**
108
+ * The max width the options list can be before option text wraps. If not
109
+ * set, the list will only display as wide as the text input.
110
+ */
111
+ optionsMaxWidth?: string
112
+ /**
113
+ * The number of options that should be visible before having to scroll.
114
+ */
115
+ visibleOptionsCount?: number
116
+ /**
117
+ * Displays messages and validation for the input. It should be an array of
118
+ * objects with the following shape:
119
+ * `{
120
+ * text: ReactNode,
121
+ * type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
122
+ * }`
123
+ */
124
+ messages?: FormMessage[]
125
+ /**
126
+ * The placement of the options list.
127
+ */
128
+ placement?: PlacementPropValues
129
+ /**
130
+ * The parent in which to constrain the placement.
131
+ */
132
+ constrain?: PositionConstraint
133
+ /**
134
+ * An element or a function returning an element to use mount the options
135
+ * list to in the DOM (defaults to `document.body`)
136
+ */
137
+ mountNode?: PositionMountNode
138
+ /**
139
+ * Callback fired when a new option is selected. This can happen in the
140
+ * following ways:
141
+ * 1. User clicks/presses enter on an option in the dropdown and focuses away
142
+ * 2. User enters a valid time manually and focuses away
143
+ * @param event - the event object
144
+ * @param data - additional data containing the value and the input string
145
+ */
146
+ onChange?: (
147
+ event: React.SyntheticEvent,
148
+ data: { value: string; inputText: string }
149
+ ) => void
150
+ /**
151
+ * Callback fired when text input receives focus.
152
+ */
153
+ onFocus?: (event: React.FocusEvent<HTMLInputElement>) => void
154
+ /**
155
+ * Callback fired when text input loses focus.
156
+ */
157
+ onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void
158
+ /**
159
+ * Callback fired when the options list is shown.
160
+ */
161
+ onShowOptions?: (event: React.SyntheticEvent) => void
162
+ /**
163
+ * Callback fired when the options list is hidden.
164
+ */
165
+ onHideOptions?: (event: React.SyntheticEvent) => void
166
+ /**
167
+ * A ref to the html `input` element.
168
+ */
169
+ inputRef?: (inputElement: HTMLInputElement | null) => void
170
+ /**
171
+ * A ref to the html `ul` element.
172
+ */
173
+ listRef?: (listElement: HTMLUListElement | null) => void
174
+ /**
175
+ * Content to display in the list when no options are available.
176
+ */
177
+ renderEmptyOption?: Renderable
178
+ /**
179
+ * Content to display before the text input. This will commonly be an icon.
180
+ */
181
+ renderBeforeInput?: Renderable
182
+ /**
183
+ * Content to display after the text input. This content will replace the
184
+ * default arrow icons.
185
+ */
186
+ renderAfterInput?: Renderable
187
+ /**
188
+ * A standard language identifier.
189
+ *
190
+ * See [moment.js i18n](https://momentjs.com/docs/#/i18n/) for more details.
191
+ *
192
+ * This property can also be set via a context property and if both are set then the component property takes
193
+ * precedence over the context property.
194
+ *
195
+ * The web browser's locale will be used if no value is set via a component property or a context
196
+ * property.
197
+ */
198
+ locale?: string
199
+ /**
200
+ * A timezone identifier in the format: Area/Location
201
+ *
202
+ * See [List of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for the list
203
+ * of possible options.
204
+ *
205
+ * This property can also be set via a context property and if both are set then the component property takes
206
+ * precedence over the context property.
207
+ *
208
+ * The web browser's timezone will be used if no value is set via a component property or a context
209
+ * property.
210
+ */
211
+ timezone?: string
212
+ /**
213
+ * Whether to allow the user to enter non-step divisible values in the input field.
214
+ * Note that even if this is set to `false` one can enter non-step divisible values programatically.
215
+ * The user will need to enter the value exactly (except for lower/uppercase) as specified by the `format` prop for
216
+ * it to be accepted.
217
+ *
218
+ * Default is `false`
219
+ */
220
+ allowNonStepInput?: boolean
221
+ /**
222
+ * Callback fired when text input value changes.
223
+ */
224
+ onInputChange?: (
225
+ /**
226
+ * The raw HTML input event
227
+ */
228
+ event: React.ChangeEvent<HTMLInputElement>,
229
+ /**
230
+ * The text value in the input field.
231
+ */
232
+ value: string,
233
+ /**
234
+ * Current value as ISO datetime string, undefined it its a non-valid value.
235
+ */
236
+ valueAsISOString?: string
237
+ ) => void
238
+ /**
239
+ * Whether to allow for the user to clear the selected option in the input field.
240
+ * If `false`, the input field will return the last selected option after the input is cleared and loses focus.
241
+ */
242
+ allowClearingSelection?: boolean
243
+ }
244
+ const allowedProps: AllowedPropKeys = [
245
+ 'renderLabel',
246
+ 'defaultToFirstOption',
247
+ 'value',
248
+ 'defaultValue',
249
+ 'id',
250
+ 'format',
251
+ 'step',
252
+ 'interaction',
253
+ 'placeholder',
254
+ 'isRequired',
255
+ 'isInline',
256
+ 'width',
257
+ 'optionsMaxWidth',
258
+ 'mountNode',
259
+ 'visibleOptionsCount',
260
+ 'messages',
261
+ 'placement',
262
+ 'constrain',
263
+ 'onChange',
264
+ 'onFocus',
265
+ 'onBlur',
266
+ 'onShowOptions',
267
+ 'onHideOptions',
268
+ 'inputRef',
269
+ 'listRef',
270
+ 'renderEmptyOption',
271
+ 'renderBeforeInput',
272
+ 'renderAfterInput',
273
+ 'locale',
274
+ 'timezone',
275
+ 'allowNonStepInput',
276
+ 'onInputChange',
277
+ 'allowClearingSelection'
278
+ ]
279
+
280
+ type TimeSelectOptions = {
281
+ // the ID of this option, ISO date without spaces
282
+ id: string
283
+ // the actual date value
284
+ value: Moment
285
+ // the label shown to the user
286
+ label: string
287
+ }
288
+
289
+ type TimeSelectState = {
290
+ /**
291
+ * The current value in the input field, not necessarily a valid time
292
+ */
293
+ inputValue: string
294
+ /**
295
+ * All possible options. Filtered down because if `allowNonStepInput` is true
296
+ * it'd be 24*60 options and filtered by user input.
297
+ */
298
+ options: TimeSelectOptions[]
299
+ /**
300
+ * The options shown in the options list.
301
+ */
302
+ filteredOptions: TimeSelectOptions[]
303
+ /**
304
+ * Whether to show the options list.
305
+ */
306
+ isShowingOptions: boolean
307
+ /**
308
+ * The highlighted option in the dropdown e.g. by hovering,
309
+ * not necessarily selected
310
+ */
311
+ highlightedOptionId?: string
312
+ /**
313
+ * The ID of the selected option in the options list dropdown
314
+ */
315
+ selectedOptionId?: string
316
+ /**
317
+ * fire onChange event when the popup closes?
318
+ */
319
+ fireChangeOnBlur?: TimeSelectOptions
320
+ /**
321
+ * Whether to selected option is cleared
322
+ */
323
+ isInputCleared: boolean
324
+ }
325
+
326
+ export type { TimeSelectProps, TimeSelectState, TimeSelectOptions }
327
+ export { allowedProps }
@@ -0,0 +1,26 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export { TimeSelect } from '../TimeSelect/v2'
26
+ export type { TimeSelectProps } from '../TimeSelect/v2/props'