-
Notifications
You must be signed in to change notification settings - Fork 2.9k
#25730: TimePicker Default Value Fix, Controllable Usage, Example Updates #26482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
behowell
merged 75 commits into
microsoft:master
from
CheerfulSatchel:fix-time-picker-initial-date
Apr 25, 2023
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
86b9648
Update prop names, make renamed currentDate prop controlled
CheerfulSatchel 4a6766b
Added DatePicker and TimePicker combination example
CheerfulSatchel 2f2e08a
Rephrase example text
CheerfulSatchel d8f04f6
Combine ComboBox imports
CheerfulSatchel 4729af9
Fixed ComboBox import and updated DateTimePicker example
CheerfulSatchel a78b720
Moved examples into standalone files
CheerfulSatchel 0337ed1
Refactors and use new dateAnchor prop
CheerfulSatchel 27c2b3c
Updated all examples
CheerfulSatchel 7a2b6b9
This should resolve the rest
CheerfulSatchel f706133
This should resolve the outstanding issues...
CheerfulSatchel 6114244
Updated example strings
CheerfulSatchel 83704dd
Updated examples
CheerfulSatchel f649c52
Merge branch 'master' into fix-time-picker-initial-date
CheerfulSatchel 86ee51a
More changes to the basic example
CheerfulSatchel caa4604
Removed useComboBoxAsMenuWidth prop
CheerfulSatchel ea37cb2
Update formatTimeString function to return 00 if hours is 24
CheerfulSatchel 712e838
Addressed comments
CheerfulSatchel 49a7a64
Renamed baseDate parameter to dateStartAnchor
CheerfulSatchel 794406e
Added prop onGetErrorMessage to get validation result
CheerfulSatchel 3682ec8
Set selectedTime to invalid or undefined
CheerfulSatchel 01bfdc7
Clamp value to updated dateAnchor
CheerfulSatchel e79e7b0
Make docs look nice and readable
CheerfulSatchel 1ff24d6
Removed unneeded imports
CheerfulSatchel c8ca944
Updated clampedStartAnchor initialization value
CheerfulSatchel 00ae9ec
Use internalDateAnchor
CheerfulSatchel d4f49ff
Use fallbackDateAnchor and update DateTimePicker example
CheerfulSatchel e8b0b50
Merged with master and resolved merge conflicts
CheerfulSatchel 791eb11
Revert to ITimePickerProps to extend original omitted IComboBoxProps
CheerfulSatchel c43adaa
Addressed comments
CheerfulSatchel ae6be38
API snapshot update
CheerfulSatchel 4d58798
Updated TimePicker tests and added test for new controlled component …
CheerfulSatchel b36ac86
Added test for handling changed base date anchor
CheerfulSatchel 368ebaf
Verify selected time changes on dateAnchor change
CheerfulSatchel 7553c61
Added yarn change files
CheerfulSatchel f14f5e0
Resolve linting errors
CheerfulSatchel 11d58b9
Resolved more linting errors
CheerfulSatchel dcf3e7d
Resolved linting import error by in-lining stack and styles
CheerfulSatchel 2d36ed1
Addressed comments
CheerfulSatchel 89e62ff
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 4a22df1
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 2705874
Revert onChange prop types to avoid breaking changes and pass React.F…
CheerfulSatchel a09fa50
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 12300fe
Added explicit undefined pass to setSelectedTime in cases the dateAnc…
CheerfulSatchel 3576bcf
Updated examples and call onChange outside of useControllableValue to…
CheerfulSatchel 0e30b38
Control snapping of TimePicker values on DatePicker anchor change
CheerfulSatchel a872cdc
Added tests for using defaultValue or value as date anchors
CheerfulSatchel bd3d5b6
Took snapping logic out, fixed invalid key bug, and shared getDateAnc…
CheerfulSatchel 19472bc
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 382f0dd
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 314ad0e
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel c78af1e
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel a0ebfe3
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 33409c8
Pass in placeholder since placeholder prop no longer has default value
CheerfulSatchel 9d1d7a4
Reflect optional timeOutOfBoundsErrorMessage string
CheerfulSatchel b45529c
Updated tests and snapshot
CheerfulSatchel c6b4468
Addressed comments
CheerfulSatchel 20e9d8d
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 2bef609
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 1831864
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 0959c73
Removed unnecessary string state variables
CheerfulSatchel 8a3b218
Followed comment suggestion and replaced onGetErrorMessage with onVal…
CheerfulSatchel e5f3953
Added onValidationError example
CheerfulSatchel b342a02
Added onValidationError test case
CheerfulSatchel 80a6224
Export TimePickerErrorData
CheerfulSatchel f32c0aa
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 44927f9
Renamed onValidationError and TimePickerErrorData to onValidationResu…
CheerfulSatchel de5c8a2
Renamed example to reflect new callback prop
CheerfulSatchel 2839b97
Use new example and fix casing
CheerfulSatchel 55cba39
Use onValidationResult and only call when stored error message differ…
CheerfulSatchel 55cc1a5
Added test for verifying onValidateResult only gets called on error m…
CheerfulSatchel 4e32ecb
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel fd1a0ba
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel dc8f33d
Split big test into two smaller tests
CheerfulSatchel d403881
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel 77faac5
Merge branch 'master' of github.com:microsoft/fluentui into fix-time-…
CheerfulSatchel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-date-time-utilities-d63c5a5c-4853-4fc8-b329-739b7176136a.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
CheerfulSatchel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "type": "patch", | ||
| "comment": "chore: Refactored getDateFromTimeSelection variable names.", | ||
| "packageName": "@fluentui/date-time-utilities", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-956c059f-a412-4dce-8d66-05ce162223fc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "feat(TimePicker): Updated TimePicker controlled and uncontrolled props to work correctly.", | ||
| "packageName": "@fluentui/react", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/react-examples/src/react/TimePicker/TimePicker.Basic.Example.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import * as React from 'react'; | ||
| import { | ||
| TimePicker, | ||
| ITimeRange, | ||
| Text, | ||
| IStackTokens, | ||
| Stack, | ||
| IStackStyles, | ||
| IComboBoxStyles, | ||
| IComboBox, | ||
| } from '@fluentui/react'; | ||
|
|
||
| const stackStyles: Partial<IStackStyles> = { root: { width: 500 } }; | ||
| const stackTokens: IStackTokens = { childrenGap: 20 }; | ||
|
|
||
| const timePickerStyles: Partial<IComboBoxStyles> = { | ||
| optionsContainerWrapper: { | ||
| height: '500px', | ||
| }, | ||
| root: { | ||
| width: '500px', | ||
| }, | ||
| }; | ||
|
|
||
| export const TimePickerBasicExample: React.FC = () => { | ||
| const [basicExampleTimeString, setBasicExampleTimeString] = React.useState<string>(''); | ||
| const [nonDefaultOptionsExampleTimeString, setNonDefaultOptionsExampleTimeString] = React.useState<string>(''); | ||
| const basicDateAnchor = new Date('November 25, 2021 09:00:00'); | ||
| const nonDefaultOptionsDateAnchor = new Date('February 27, 2023 08:00:00'); | ||
|
|
||
| const onBasicExampleChange = React.useCallback((_ev: React.FormEvent<IComboBox>, basicExampleTime: Date) => { | ||
| setBasicExampleTimeString(basicExampleTime.toString()); | ||
| }, []); | ||
|
|
||
| const onNonDefaultOptionsExampleChange = React.useCallback((_, nonDefaultOptionsExampleTime: Date) => { | ||
| setNonDefaultOptionsExampleTimeString(nonDefaultOptionsExampleTime?.toString()); | ||
| }, []); | ||
|
|
||
| const timeRange: ITimeRange = { | ||
| start: 8, | ||
| end: 14, | ||
| }; | ||
|
|
||
| return ( | ||
| <Stack tokens={stackTokens} styles={stackStyles}> | ||
| <TimePicker | ||
| placeholder="Basic example placeholder" | ||
| styles={timePickerStyles} | ||
| useHour12 | ||
| allowFreeform | ||
| autoComplete="on" | ||
| label="TimePicker basic example" | ||
| onChange={onBasicExampleChange} | ||
| dateAnchor={basicDateAnchor} | ||
| /> | ||
| <Text>{`⚓ Date anchor: ${basicDateAnchor.toString()}`}</Text> | ||
| <Text>{`⌚ Selected time: ${basicExampleTimeString ? basicExampleTimeString : '<no time selected>'}`}</Text> | ||
|
|
||
| <TimePicker | ||
| styles={timePickerStyles} | ||
| showSeconds | ||
| allowFreeform | ||
| increments={15} | ||
| autoComplete="on" | ||
| label="TimePicker with non default options" | ||
| placeholder="Non default options placeholder" | ||
| timeRange={timeRange} | ||
| dateAnchor={nonDefaultOptionsDateAnchor} | ||
| onChange={onNonDefaultOptionsExampleChange} | ||
| /> | ||
| <Text>{`⚓ Date anchor: ${nonDefaultOptionsDateAnchor.toString()}`}</Text> | ||
| <Text>{`⌚ Selected time: ${ | ||
| nonDefaultOptionsExampleTimeString ? nonDefaultOptionsExampleTimeString : '<no time selected>' | ||
| }`}</Text> | ||
| </Stack> | ||
| ); | ||
| }; |
41 changes: 41 additions & 0 deletions
41
packages/react-examples/src/react/TimePicker/TimePicker.Controlled.Example.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import * as React from 'react'; | ||
| import { TimePicker, Text, IStackTokens, Stack, IStackStyles, IComboBoxStyles } from '@fluentui/react'; | ||
|
|
||
| const stackStyles: Partial<IStackStyles> = { root: { width: 500 } }; | ||
| const stackTokens: IStackTokens = { childrenGap: 20 }; | ||
|
|
||
| const timePickerStyles: Partial<IComboBoxStyles> = { | ||
| optionsContainerWrapper: { | ||
| height: '500px', | ||
| }, | ||
| root: { | ||
| width: '500px', | ||
| }, | ||
| }; | ||
|
|
||
| export const TimePickerControlledExample: React.FC = () => { | ||
| const dateAnchor = new Date('February 27, 2023 08:00:00'); | ||
| const [time, setTime] = React.useState<Date>(new Date('February 27, 2023 10:00:00')); | ||
|
|
||
| const onControlledExampleChange = React.useCallback((_, newTime: Date) => { | ||
| setTime(newTime); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Stack tokens={stackTokens} styles={stackStyles}> | ||
| <TimePicker | ||
| styles={timePickerStyles} | ||
| showSeconds | ||
| allowFreeform | ||
| increments={15} | ||
| autoComplete="on" | ||
| label="Controlled TimePicker with non default options" | ||
| dateAnchor={dateAnchor} | ||
| value={time} | ||
| onChange={onControlledExampleChange} | ||
| /> | ||
| <Text>{`⚓ Date anchor: ${dateAnchor.toString()}`}</Text> | ||
| <Text>{`⌚ Selected time: ${time ? time.toString() : '<no time selected>'}`}</Text> | ||
| </Stack> | ||
| ); | ||
| }; |
50 changes: 50 additions & 0 deletions
50
packages/react-examples/src/react/TimePicker/TimePicker.CustomTimeStrings.Example.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import * as React from 'react'; | ||
| import { TimePicker, Text, IStackTokens, Stack, IStackStyles, IComboBoxStyles } from '@fluentui/react'; | ||
|
|
||
| const stackStyles: Partial<IStackStyles> = { root: { width: 500 } }; | ||
| const stackTokens: IStackTokens = { childrenGap: 20 }; | ||
|
|
||
| const timePickerStyles: Partial<IComboBoxStyles> = { | ||
| optionsContainerWrapper: { | ||
| height: '500px', | ||
| }, | ||
| root: { | ||
| width: '500px', | ||
| }, | ||
| }; | ||
|
|
||
| export const TimePickerCustomTimeStringsExample: React.FC = () => { | ||
| const [customTimeString, setCustomTimeString] = React.useState<string>(''); | ||
| const dateAnchor = new Date('February 27, 2023 08:00:00'); | ||
| const onFormatDate = React.useCallback((date: Date) => `Custom prefix + ${date.toLocaleTimeString()}`, []); | ||
| const onValidateUserInput = React.useCallback((userInput: string) => { | ||
| if (!userInput.includes('Custom prefix +')) { | ||
| return 'Your input is missing "Custom prefix +"'; | ||
| } | ||
| return ''; | ||
| }, []); | ||
|
|
||
| const onChange = React.useCallback((_, time: Date) => { | ||
| console.log('Selected time: ', time); | ||
| setCustomTimeString(time.toString()); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Stack tokens={stackTokens} styles={stackStyles}> | ||
| <TimePicker | ||
| placeholder="Custom time strings example placeholder" | ||
| styles={timePickerStyles} | ||
| onFormatDate={onFormatDate} | ||
| onValidateUserInput={onValidateUserInput} | ||
| onChange={onChange} | ||
| useHour12 | ||
| allowFreeform={false} | ||
| dateAnchor={dateAnchor} | ||
| autoComplete="on" | ||
| label="TimePicker with custom time strings" | ||
| /> | ||
| <Text>{`⚓ Date anchor: ${dateAnchor.toString()}`}</Text> | ||
| <Text>{`⌚ Selected time: ${customTimeString ? customTimeString : '<no time selected>'}`}</Text> | ||
| </Stack> | ||
| ); | ||
| }; |
62 changes: 62 additions & 0 deletions
62
packages/react-examples/src/react/TimePicker/TimePicker.DateTimePicker.Example.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import * as React from 'react'; | ||
| import { TimePicker, DatePicker, Label, Text, IStackTokens, Stack, IStackStyles, IComboBox } from '@fluentui/react'; | ||
|
|
||
| const stackStyles: Partial<IStackStyles> = { root: { width: 500 } }; | ||
| const stackTokens: IStackTokens = { childrenGap: 20 }; | ||
|
|
||
| const snapTimeToUpdatedDateAnchor = (datePickerDate: Date, currentTime: Date) => { | ||
| let snappedTime = new Date(currentTime); | ||
|
|
||
| if (currentTime && !isNaN(currentTime.valueOf())) { | ||
| const startAnchor = new Date(datePickerDate); | ||
| const endAnchor = new Date(startAnchor); | ||
| endAnchor.setDate(startAnchor.getDate() + 1); | ||
| if (currentTime < startAnchor || currentTime > endAnchor) { | ||
| snappedTime = new Date(startAnchor); | ||
| snappedTime.setHours(currentTime.getHours()); | ||
| snappedTime.setMinutes(currentTime.getMinutes()); | ||
| snappedTime.setSeconds(currentTime.getSeconds()); | ||
| snappedTime.setMilliseconds(currentTime.getMilliseconds()); | ||
| } | ||
| } | ||
|
|
||
| return snappedTime; | ||
| }; | ||
|
|
||
| export const TimePickerDateTimePickerExample: React.FC = () => { | ||
| const currentDate = new Date('2023-02-01 05:00:00'); | ||
| const [datePickerDate, setDatePickerDate] = React.useState<Date>(currentDate); | ||
| const [currentTime, setCurrentTime] = React.useState<Date>(); | ||
|
|
||
| const onSelectDate = React.useCallback( | ||
| (selectedDate: Date) => { | ||
| setDatePickerDate(selectedDate); | ||
| if (currentTime) { | ||
| const snappedTime = snapTimeToUpdatedDateAnchor(selectedDate, currentTime); | ||
| setCurrentTime(snappedTime); | ||
| } | ||
| }, | ||
| [currentTime], | ||
| ); | ||
|
|
||
| const onTimePickerChange = React.useCallback((_ev: React.FormEvent<IComboBox>, date: Date) => { | ||
| setCurrentTime(date); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Stack tokens={stackTokens} styles={stackStyles}> | ||
| <Label>{'DatePicker and TimePicker combination'}</Label> | ||
| <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gridColumnGap: '3px' }}> | ||
| <DatePicker placeholder="Select a date..." value={datePickerDate} onSelectDate={onSelectDate} /> | ||
| <TimePicker | ||
| placeholder="Select a time" | ||
| dateAnchor={datePickerDate} | ||
| value={currentTime} | ||
| onChange={onTimePickerChange} | ||
| /> | ||
| </div> | ||
| <Text>{`⚓ Date anchor: ${datePickerDate.toString()}`}</Text> | ||
| <Text>{`⌚ Selected time: ${currentTime ? currentTime.toString() : '<no time selected>'}`}</Text> | ||
| </Stack> | ||
| ); | ||
| }; |
60 changes: 0 additions & 60 deletions
60
packages/react-examples/src/react/TimePicker/TimePicker.Example.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.