-
Notifications
You must be signed in to change notification settings - Fork 12
date picker wrapper for react-day-picker #346
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
lihnick
wants to merge
1
commit into
master
Choose a base branch
from
EVER-15862-add-date-picker-to-rover-ui
base: master
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
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
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,132 @@ | ||
| .container { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| .wrapper { | ||
| border-radius: var(--rvr-border-radius); | ||
| } | ||
|
|
||
| .interactionDisabled { | ||
| cursor: default; | ||
| } | ||
|
|
||
| .navBar { | ||
| position: relative; | ||
| } | ||
|
|
||
| .navButtonPrev, | ||
| .navButtonNext { | ||
| position: absolute; | ||
| border: solid var(--rvr-color-font); | ||
| border-width: 3px 3px 0px 0px; | ||
| display: inline-block; | ||
| padding: 5px; | ||
| } | ||
|
|
||
| .navButtonPrev { | ||
| transform: rotate(-135deg); | ||
| top: 18px; | ||
| left: 18px; | ||
| } | ||
|
|
||
| .navButtonNext { | ||
| transform: rotate(45deg); | ||
| top: 18px; | ||
| right: 18px; | ||
| } | ||
|
|
||
| .navButtonInteractionDisabled { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| .months { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .month { | ||
| padding: 12px; | ||
| } | ||
|
|
||
| .caption { | ||
| font-weight: var(--rvr-font-weight-bold); | ||
| text-align: center; | ||
| color: var(--rvr-black); | ||
| } | ||
|
|
||
| .weekdaysBody { | ||
| display: table-header-group; | ||
| } | ||
|
|
||
| .weekdaysRow { | ||
| display: table-row; | ||
| } | ||
|
|
||
| .weekday { | ||
| color: var(--rvr-color-font); | ||
| display: table-cell; | ||
| text-align: center; | ||
| padding: 4px 6px; | ||
| } | ||
| .weekday > abbr { | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .weekNumber { | ||
| display: table-cell; | ||
| color: var(--rvr-color-font); | ||
| padding: 4px 6px; | ||
| border-right: solid 1px var(--rvr-color-disabled); | ||
| } | ||
|
|
||
| .body { | ||
| display: table-row-group; | ||
| } | ||
|
|
||
| .week { | ||
| display: table-row; | ||
| } | ||
|
|
||
| .day { | ||
| display: table-cell; | ||
| text-align: center; | ||
| padding: 4px 6px; | ||
| border-radius: var(--rvr-border-radius); | ||
| color: var(--rvr-black); | ||
| } | ||
|
|
||
| .day[aria-disabled='false'] { | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .day:hover[aria-disabled='false'][aria-selected='false'] { | ||
| background-color: var(--rvr-color-highlight); | ||
| } | ||
|
|
||
| .footer { | ||
| display: flex; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .todayButton { | ||
| color: var(--rvr-btn-color-link-active); | ||
| } | ||
|
|
||
| .today { | ||
| text-decoration: underline; | ||
| font-weight: var(--rvr-font-weight-bold); | ||
| } | ||
|
|
||
| .selected { | ||
| background-color: var(--rvr-color-primary); | ||
| color: var(--rvr-white); | ||
| } | ||
|
|
||
| .disabled { | ||
| color: var(--rvr-color-disabled); | ||
| } | ||
|
|
||
| .outside { | ||
| color: var(--rvr-color-disabled); | ||
| } |
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,29 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { render } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| import DatePicker from '.'; | ||
|
|
||
| describe('DatePicker', () => { | ||
| it('renders', () => { | ||
| render(<DatePicker />); | ||
| }); | ||
|
|
||
| describe('when rendered with classnames props', () => { | ||
| it('should append the custom class to the exisiting class', () => { | ||
| const styleOverride = { wrapper: 'customWrapperClass' }; | ||
| const { getByTestId } = render( | ||
| <div data-testid="datePickerElem"> | ||
| <DatePicker classNames={styleOverride} /> | ||
| </div> | ||
| ); | ||
|
|
||
| const DatePickerElem = getByTestId('datePickerElem') as HTMLDivElement; | ||
| const wrapperElem = DatePickerElem.firstChild | ||
| ?.firstChild as HTMLDivElement; | ||
|
|
||
| expect(wrapperElem.className).toContain('customWrapperClass'); | ||
| }); | ||
| }); | ||
| }); |
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,78 @@ | ||
| import React from 'react'; | ||
|
|
||
| import DayPicker from 'react-day-picker'; | ||
| import { DayPickerProps } from 'react-day-picker/types/Props'; | ||
|
|
||
| import 'react-day-picker/lib/style.css'; | ||
| import { ClassNames } from 'react-day-picker/types/ClassNames'; | ||
| import styles from './DatePicker.module.css'; | ||
|
|
||
| interface DatePickerProps extends Omit<DayPickerProps, 'classNames'> { | ||
| classNames?: { | ||
| container?: string; | ||
| wrapper?: string; | ||
| interactionDisabled?: string; | ||
| navBar?: string; | ||
| navButtonPrev?: string; | ||
| navButtonNext?: string; | ||
| navButtonInteractionDisabled?: string; | ||
| months?: string; | ||
| month?: string; | ||
| caption?: string; | ||
| weekdays?: string; | ||
| weekdaysRow?: string; | ||
| weekday?: string; | ||
| weekNumber?: string; | ||
| body?: string; | ||
| week?: string; | ||
| day?: string; | ||
| footer?: string; | ||
| todayButton?: string; | ||
| today?: string; | ||
| selected?: string; | ||
| disabled?: string; | ||
| outside?: string; | ||
| }; | ||
| } | ||
|
|
||
| const DatePicker: React.FC<DatePickerProps> = ({ ...passedProps }) => { | ||
| const styleOverride = { | ||
| container: styles.container, | ||
| wrapper: styles.wrapper, | ||
| interactionDisabled: styles.interactionDisabled, | ||
| navBar: styles.navBar, | ||
| navButtonPrev: styles.navButtonPrev, | ||
| navButtonNext: styles.navButtonNext, | ||
| navButtonInteractionDisabled: styles.navButtonInteractionDisabled, | ||
| months: styles.months, | ||
| month: styles.month, | ||
| caption: styles.caption, | ||
| weekdays: styles.weekdaysBody, | ||
| weekdaysRow: styles.weekdaysRow, | ||
| weekday: styles.weekday, | ||
| weekNumber: styles.weekNumber, | ||
| body: styles.body, | ||
| week: styles.week, | ||
| day: styles.day, | ||
| footer: styles.footer, | ||
| todayButton: styles.todayButton, | ||
| today: styles.today, | ||
| selected: styles.selected, | ||
| disabled: styles.disabled, | ||
| outside: styles.outside, | ||
| } as ClassNames; | ||
|
|
||
| if (passedProps.classNames) { | ||
| Object.entries(passedProps.classNames).forEach((classes) => { | ||
| if (classes.length === 2) { | ||
| styleOverride[classes[0]] = `${styleOverride[classes[0]]} ${ | ||
| classes[1] | ||
| }`; | ||
| } | ||
| }); | ||
| } | ||
|
Comment on lines
+65
to
+73
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This pass-through Date-Picker component allows consuming apps to overwrite specific attribute (e.g. footer attribute) of the class object without overriding the entire |
||
|
|
||
| return <DayPicker {...passedProps} classNames={styleOverride} />; | ||
| }; | ||
|
|
||
| export default DatePicker; | ||
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,11 @@ | ||
| # \<DatePicker \\\> | ||
|
|
||
| Render a date picker UI, this is a pass-through component to the [react-day-picker](https://react-day-picker.js.org/) library. | ||
|
|
||
| ### Override Classes | ||
|
|
||
| This date picker has been restyle using rover-ui themes/colors. Consuming application can override these classes with their own classes via `classNames` prop, see [/api/Daypicker#classNames](https://react-day-picker.js.org/api/DayPicker#classNames) | ||
|
|
||
| ```jsx | ||
| <DatePicker classNames={{ navBar: 'AdditionalClassToRestyle' }} /> | ||
| ``` |
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 @@ | ||
| export { default } from './DatePicker'; |
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.
This is an example of what it might look like to extend the DatePicker component to make it inline.