@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,85 @@
1
+ ---
2
+ describes: TimeSelect
3
+ ---
4
+
5
+ `TimeSelect` component is a higher level abstraction of [Select](Select) specifically for selecting time values. The list of possible values can be configured via the component's props.
6
+
7
+ ### Uncontrolled
8
+
9
+ For the most basic implementations, `TimeSelect` can be uncontrolled. If desired, the `defaultValue` prop can be used to set the initial selection.
10
+
11
+ ```javascript
12
+ ---
13
+ type: example
14
+ ---
15
+ <TimeSelect
16
+ renderLabel="Choose a time"
17
+ onChange={(e, { value }) => console.log(value)}
18
+ onHideOptions={(e)=> console.log("hide opts")}
19
+ // defaultValue={new Date().toISOString()}
20
+ />
21
+ ```
22
+
23
+ ### Controlled
24
+
25
+ To use `TimeSelect` controlled, simply provide the `value` prop an ISO string. The `onChange` callback provides the ISO value of the corresponding option that was selected. Use this value to update the state.
26
+
27
+ ```js
28
+ ---
29
+ type: example
30
+ ---
31
+ const Example = () => {
32
+ const [value, setValue] = useState('2020-05-18T23:59:00')
33
+
34
+ const handleChange = (e, { value }) => {
35
+ setValue(value)
36
+ }
37
+
38
+ return (
39
+ <TimeSelect
40
+ renderLabel="Choose a time"
41
+ placeholder="e.g., 4:00:00 PM"
42
+ value={value}
43
+ step={15}
44
+ format="LTS"
45
+ onChange={handleChange}
46
+ />
47
+ )
48
+ }
49
+
50
+ render(<Example />)
51
+ ```
52
+
53
+ ### Freeform input
54
+
55
+ By default, the user can only set a value that is divisible by `step` (although the component allows to set any valid time value programmatically). You can allow the user to set any valid value with typing in by setting `allowNonStepInput` to `true`. You can use the `onInputChange` event to see whether the current input is valid and its current value.
56
+ Note that the exact value needed to be typed by the user depends on their `locale`:
57
+
58
+ ```javascript
59
+ ---
60
+ type: example
61
+ ---
62
+ <TimeSelect
63
+ renderLabel="Choose a time"
64
+ onChange={(e, { value }) => console.log("change",value)}
65
+ onInputChange={(e, value, isoValue)=> console.log("inputChange", value, isoValue)}
66
+ defaultValue="2022-05-12T05:30:00.000Z"
67
+ locale="en_AU"
68
+ timezone='US/Eastern'
69
+ allowNonStepInput
70
+ />
71
+ ```
72
+
73
+ ### Guidelines
74
+
75
+ ```js
76
+ ---
77
+ type: embed
78
+ ---
79
+ <Guidelines>
80
+ <Figure recommendation="yes" title="Do">
81
+ <Figure.Item>Use a default value of 11:59 pm for implementations that have to do with due dates</Figure.Item>
82
+ <Figure.Item>Respect the user's `locale` and `timezone` browser settings (the component does this by itself when not setting `locale` or `timezone`).</Figure.Item>
83
+ </Figure>
84
+ </Guidelines>
85
+ ```