-
Notifications
You must be signed in to change notification settings - Fork 31
feat(DatePicker): New DatePicker component #3286
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
Open
aresnik11
wants to merge
92
commits into
main
Choose a base branch
from
ajr-datepicker-localization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
fd2fbce
calendar phase 1
aresnik11 0ffb424
add focus management
aresnik11 b8a856d
add input
aresnik11 c096fe9
datepicker
aresnik11 9346ac9
clean up
aresnik11 00a8584
refactor datepicker
aresnik11 1946d73
clean up hooks
aresnik11 39d0de0
update exports
aresnik11 23f593d
add missing validation file
aresnik11 c1c9245
clean up inputref
aresnik11 9a8f70d
wip fix for typing date
aresnik11 82854c8
cleaning up
aresnik11 4f39ff9
update range logic
aresnik11 d194237
range logic when specific input is focused
aresnik11 3bbeb01
deselect logic
aresnik11 a6cbe80
fix lint
aresnik11 a56426f
fix story
aresnik11 f79ce4a
fix lint again
aresnik11 e0ee942
update snapshot
aresnik11 a417554
fix lint
aresnik11 cf4a438
show 2 months on larger screens
aresnik11 d3f6fac
style updates
aresnik11 e615f9f
PR feedback
aresnik11 a19fc7b
fix today in range color
aresnik11 9c30d34
clean up context
aresnik11 b657556
update placeholder text to be locale based
aresnik11 1924433
update next/last month text to be locale based
aresnik11 a83a99a
capitalize
aresnik11 40a0c8b
Merge branch 'main' into ajr-datepicker-styles
aresnik11 bfd8206
translations
aresnik11 f6463b4
add formgroup
aresnik11 7de8b27
Merge branch 'ajr-datepicker-styles' into ajr-datepicker-localization
aresnik11 c9a7576
fix calendar alignment and add shadow
aresnik11 d3f6fba
clear button logic
aresnik11 2834206
more translations
aresnik11 b436daa
fix disabled hover
aresnik11 5b7a8be
make disabledDates optional and add to story
aresnik11 496e740
disabled date in range logic
aresnik11 5df9d1a
fix keyboard nav now that showing 2 months
aresnik11 38f81a9
PR feedback
aresnik11 b9aa903
toLocaleUpperCase
aresnik11 b400a75
small fixes
aresnik11 0e10748
fix range styling
aresnik11 dfdabe8
fix alignments
aresnik11 1ee01fc
rename props
aresnik11 a6c8388
move around helpers
aresnik11 3bfab02
fix calendar story
aresnik11 afaea71
support small input size
aresnik11 e4e15be
initial focus a11y updates
aresnik11 422e220
PR feedback
aresnik11 8072692
clean up utils
aresnik11 ca9a66b
add full date aria label to date cells
aresnik11 13d1a3d
move around files and clean up exports
aresnik11 6d9082a
update locale
aresnik11 15ceaf4
week starts on from locale + polyfill
aresnik11 2effd5f
remove button from DateCell
aresnik11 e6d8f15
refactor CalendarHeader
aresnik11 af18ad7
Merge branch 'main' into ajr-datepicker-localization
aresnik11 d189e1c
fix errors
aresnik11 4df63bb
fix ci errors
aresnik11 5005ee6
Merge branch 'main' into ajr-datepicker-localization
aresnik11 23458a7
input segments
aresnik11 bab532a
fix segments typing
aresnik11 8f4c3c2
Merge branch 'main' into ajr-datepicker-localization
aresnik11 dc273f3
dedupe and format
aresnik11 43007af
version plan
aresnik11 aa6748d
fix sb import
aresnik11 cd040bb
tests round 1
aresnik11 e086026
CalendarBody tests
aresnik11 3b676f2
style updates
aresnik11 878339f
utils tests
aresnik11 c87e08d
segmentUtils tests
aresnik11 e8fe147
segment tests
aresnik11 0394f4b
fix segment refs
aresnik11 1d7671a
close on date select
aresnik11 ed8e59c
fix focus & active range part
aresnik11 6431e61
move DatePicker to organism
aresnik11 464b82a
WIP mdx file
aresnik11 533625b
quick actions
aresnik11 32ce0ff
evan pr feedback
aresnik11 e4b9092
dont render empty border in footer
aresnik11 1cc29cd
first passthrough of PR feedback
aresnik11 decc8ec
reorg files
aresnik11 5283400
update disabled date logic
aresnik11 cedb664
fix icon button tip sticking around
aresnik11 e8d2435
discriminated union context
aresnik11 589f1e5
change to object syntax
aresnik11 0e746bc
PR feedback
aresnik11 de8c1f6
fix date keyboard nav
aresnik11 dda6e47
more tests & tweaks
aresnik11 5fbe2b9
more tests
aresnik11 94c7a2d
sync segment input and calendar month shown
aresnik11 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
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,5 @@ | ||
| --- | ||
| gamut: minor | ||
| --- | ||
|
|
||
| New DatePicker component |
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
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,174 @@ | ||
| import { MiniArrowRightIcon } from '@codecademy/gamut-icons'; | ||
| import { useCallback, useId, useMemo, useRef, useState } from 'react'; | ||
|
|
||
| import { Box, FlexBox } from '../Box'; | ||
| import { PopoverContainer } from '../PopoverContainer'; | ||
| import { DatePickerCalendar } from './DatePickerCalendar'; | ||
| import { | ||
| getDefaultRangeQuickActions, | ||
| getDefaultSingleQuickActions, | ||
| } from './DatePickerCalendar/utils/quickActions'; | ||
| import { DatePickerProvider } from './DatePickerContext'; | ||
| import type { | ||
| DatePickerContextValue, | ||
| DatePickerRangeContextValue, | ||
| } from './DatePickerContext/types'; | ||
| import { DatePickerInput } from './DatePickerInput'; | ||
| import type { DatePickerProps } from './types'; | ||
| import { useResolvedLocale } from './utils/locale'; | ||
| import { DEFAULT_DATE_PICKER_TRANSLATIONS } from './utils/translations'; | ||
|
|
||
| export const DatePicker: React.FC<DatePickerProps> = (props) => { | ||
| const { | ||
| locale, | ||
| shouldDisableDate, | ||
| children, | ||
| mode, | ||
| translations: translationsProp, | ||
| inputSize, | ||
| quickActions, | ||
| } = props; | ||
| const [isCalendarOpen, setIsCalendarOpen] = useState(false); | ||
| const [focusGridSignal, setFocusGridSignal] = useState(false); | ||
| const [gridFocusRequested, setGridFocusRequested] = useState(false); | ||
| const [activeRangePart, setActiveRangePart] = | ||
| useState<DatePickerRangeContextValue['activeRangePart']>(null); | ||
| const inputRef = useRef<HTMLDivElement | null>(null); | ||
| const dialogId = useId(); | ||
| const calendarDialogId = `datepicker-dialog-${dialogId.replace(/:/g, '')}`; | ||
|
|
||
| const clearGridFocusRequest = useCallback(() => { | ||
| setGridFocusRequested(false); | ||
| }, []); | ||
|
|
||
| const resolvedLocale = useResolvedLocale(locale); | ||
|
|
||
| const openCalendar = useCallback(() => { | ||
| setIsCalendarOpen(true); | ||
| }, []); | ||
|
|
||
| const focusCalendar = useCallback(() => { | ||
| setGridFocusRequested(true); | ||
| setFocusGridSignal((signal) => !signal); | ||
| }, []); | ||
|
|
||
| const closeCalendar = useCallback(() => { | ||
| setIsCalendarOpen(false); | ||
| setActiveRangePart(null); | ||
| setGridFocusRequested(false); | ||
| const shell = inputRef.current; | ||
| const toFocus = | ||
| shell?.querySelector<HTMLElement>('[role="spinbutton"]') ?? shell; | ||
| toFocus?.focus(); | ||
| }, []); | ||
|
|
||
| const contextValue = useMemo<DatePickerContextValue>(() => { | ||
| const translations = { | ||
| ...DEFAULT_DATE_PICKER_TRANSLATIONS, | ||
| ...translationsProp, | ||
| }; | ||
| const resolvedQuickActions = | ||
| quickActions ?? | ||
| (mode === 'range' | ||
| ? getDefaultRangeQuickActions(translations) | ||
| : getDefaultSingleQuickActions(resolvedLocale)); | ||
| const base = { | ||
| isCalendarOpen, | ||
| openCalendar, | ||
| focusCalendar, | ||
| focusGridSignal, | ||
| gridFocusRequested, | ||
| clearGridFocusRequest, | ||
| closeCalendar, | ||
| locale: resolvedLocale, | ||
| shouldDisableDate, | ||
| calendarDialogId, | ||
| translations, | ||
| quickActions: quickActions === null ? [] : resolvedQuickActions, | ||
| }; | ||
| return mode === 'range' | ||
| ? { | ||
| ...base, | ||
| mode: 'range', | ||
| startDate: props.startDate, | ||
| endDate: props.endDate, | ||
| activeRangePart, | ||
| setActiveRangePart, | ||
| onRangeSelection: (startDate: Date | null, endDate: Date | null) => { | ||
| props.onStartSelected(startDate); | ||
| props.onEndSelected(endDate); | ||
| }, | ||
| } | ||
| : { | ||
| ...base, | ||
| mode: 'single', | ||
| selectedDate: props.selectedDate, | ||
| onSelection: props.onSelected, | ||
| }; | ||
| }, [ | ||
| translationsProp, | ||
| quickActions, | ||
| mode, | ||
| resolvedLocale, | ||
| isCalendarOpen, | ||
| openCalendar, | ||
| focusCalendar, | ||
| focusGridSignal, | ||
| gridFocusRequested, | ||
| clearGridFocusRequest, | ||
| closeCalendar, | ||
| shouldDisableDate, | ||
| calendarDialogId, | ||
| props, | ||
| activeRangePart, | ||
| ]); | ||
|
|
||
| const content = | ||
| children !== undefined ? ( | ||
| children | ||
| ) : ( | ||
| <> | ||
| <FlexBox | ||
| gap={inputSize === 'small' ? 4 : 8} | ||
| ref={inputRef} | ||
| width="fit-content" | ||
| > | ||
| {mode === 'range' ? ( | ||
| <> | ||
| <DatePickerInput rangePart="start" size={inputSize} /> | ||
| <Box alignSelf="center" mt={32}> | ||
| {/* TODO: Adjust for RTL */} | ||
| <MiniArrowRightIcon /> | ||
|
aresnik11 marked this conversation as resolved.
|
||
| </Box> | ||
| <DatePickerInput rangePart="end" size={inputSize} /> | ||
| </> | ||
| ) : ( | ||
| <DatePickerInput size={inputSize} /> | ||
| )} | ||
| </FlexBox> | ||
| <PopoverContainer | ||
| alignment="bottom-left" | ||
| allowPageInteraction | ||
| focusOnProps={{ autoFocus: false, focusLock: false }} | ||
| invertAxis="x" | ||
| isOpen={isCalendarOpen} | ||
| targetRef={inputRef} | ||
| x={-20} | ||
| y={-16} | ||
| onRequestClose={closeCalendar} | ||
| > | ||
| <div | ||
| aria-label={contextValue.translations.calendarDialogAriaLabel} | ||
| id={calendarDialogId} | ||
| role="dialog" | ||
| > | ||
| <DatePickerCalendar dialogId={calendarDialogId} /> | ||
| </div> | ||
| </PopoverContainer> | ||
| </> | ||
| ); | ||
|
|
||
| return ( | ||
| <DatePickerProvider value={contextValue}>{content}</DatePickerProvider> | ||
| ); | ||
| }; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want all of these exported? seems like some are internal components