-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add DateTimePicker #1220
Merged
Merged
Add DateTimePicker #1220
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
330f3dc
Install react-datepicker
gabescarbrough fac8591
Install date-fns
gabescarbrough 82c6781
Add DateTimePicker components
gabescarbrough 3880ada
Add react-datepicker css
gabescarbrough a8f3f3d
Move css import into scss file
gabescarbrough 614f1d7
Fix tests but getting act warning
gabescarbrough 8cb4b7f
Fix act warning in tests
gabescarbrough e3bbdf1
Cleanup
gabescarbrough 71282e5
Convert components to TS
gabescarbrough 26734c0
Fix react-datepicker type error
gabescarbrough 7c401be
Remove dateViewMode in favor of showMonthAndYearSelects
gabescarbrough 8b41592
Add more stories
gabescarbrough 597d6b8
Convert js to ts
gabescarbrough cdbeb6d
Fix type error
gabescarbrough 689e5a1
Improve SCSS
gabescarbrough 056c0b5
Add date-fns and date-fns-tz to peer deps
gabescarbrough 37d4071
Update lockfile
gabescarbrough 1057939
Use CSS var for border-radius
gabescarbrough 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 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 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,143 @@ | ||
@import 'react-datepicker/dist/react-datepicker.css'; | ||
@import '../../scss/theme.scss'; | ||
|
||
.date-time-picker { | ||
align-items: flex-start; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
width: 100%; | ||
|
||
@include media-breakpoint-up(sm) { | ||
align-items: center; | ||
flex-direction: row; | ||
} | ||
|
||
.react-datepicker__header { | ||
background-color: var(--ux-white); | ||
border-bottom: 1px solid var(--ux-gray-200); | ||
} | ||
|
||
.react-datepicker__day-names { | ||
font-weight: var(--synth-font-weight-bold); | ||
} | ||
|
||
.react-datepicker__day--outside-month { | ||
color: var(--ux-gray-300); | ||
} | ||
|
||
|
||
.date-time-picker { | ||
&__input-group { | ||
background-color: var(--ux-white); | ||
border-radius: var(--ux-border-radius); | ||
border: thin solid var(--ux-gray-400); | ||
padding: .46875rem .75rem; | ||
justify-content: space-between; | ||
width: inherit; | ||
} | ||
} | ||
|
||
.react-datepicker { | ||
@include font-type-30; | ||
border: none; | ||
box-shadow: 0 1px 3px var(--ux-gray-400); | ||
} | ||
|
||
.react-datepicker__time { | ||
@include font-type-20; | ||
} | ||
|
||
.react-datepicker__day--selected { | ||
background: var(--ux-blue-500); | ||
} | ||
|
||
.react-datepicker__day--keyboard-selected { | ||
background: none; | ||
color: var(--ux-black); | ||
} | ||
|
||
.react-datepicker__time-container | ||
.react-datepicker__time | ||
.react-datepicker__time-box | ||
ul.react-datepicker__time-list | ||
li.react-datepicker__time-list-item--selected { | ||
background: var(--ux-blue-500); | ||
} | ||
|
||
.react-datepicker__day--today { | ||
color: var(--ux-blue-500); | ||
} | ||
|
||
.react-datepicker__day--selected { | ||
color: var(--ux-white); | ||
} | ||
|
||
.react-datepicker__triangle { | ||
display: none; | ||
} | ||
|
||
// Override form-control's default greying of read only inputs | ||
input:read-only, .form-control[readonly] { | ||
background-color: var(--ux-white); | ||
} | ||
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. |
||
|
||
.form-control:focus { | ||
box-shadow: none; | ||
border: 1px solid $input-focus-border-color; | ||
} | ||
|
||
.react-datepicker { | ||
width: 100%; | ||
|
||
> div:first-child { | ||
width: 100%; | ||
} | ||
|
||
&:not(:first-child) { | ||
margin-top: .5rem; | ||
|
||
@include media-breakpoint-up(sm) { | ||
margin-top: 0; | ||
margin-left: .5rem; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
// override some of the form group invalid styles | ||
.FormGroup--is-invalid | ||
.date-time-picker | ||
select { | ||
border: thin solid var(--ux-gray-400); | ||
border-radius: var(--ux-border-radius); | ||
} | ||
|
||
// override some of the form group invalid styles | ||
// inputs need more specificity to override the above styling | ||
.FormGroup--is-invalid | ||
.date-time-picker | ||
.react-datepicker-wrapper | ||
.react-datepicker__input-container | ||
input { | ||
border: thin solid var(--ux-red); | ||
} | ||
|
||
// Undoing some styles when this is nested within a bootstrap table | ||
.table .date-time-picker { | ||
td, th { | ||
border-top: 0; | ||
padding: 0; | ||
vertical-align: middle; | ||
} | ||
|
||
thead th { | ||
border-bottom: 0; | ||
vertical-align: middle; | ||
} | ||
} | ||
|
||
.react-datepicker-wrapper { | ||
width: 100%; | ||
} |
This file contains 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,24 @@ | ||
import React from 'react'; | ||
|
||
import { DateTimePicker } from '.'; | ||
|
||
export default { | ||
title: 'Components/DateTimePicker', | ||
component: DateTimePicker, | ||
}; | ||
|
||
export const Default = () => ( | ||
<DateTimePicker /> | ||
); | ||
|
||
export const EnforcedInput = () => ( | ||
<DateTimePicker showPickerEnforcedInput /> | ||
); | ||
|
||
export const ShowMonthAndYearSelects = () => ( | ||
<DateTimePicker showMonthAndYearSelects /> | ||
); | ||
|
||
export const ShowTimeSelect = () => ( | ||
<DateTimePicker showTimeSelect /> | ||
); |
This file contains 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,60 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import DateTimePicker, { DateTimePickerProps } from './DateTimePicker'; | ||
|
||
const PLACEHOLDER = 'YYYY-MM-DD'; | ||
|
||
const VALID_DATE = '1999-12-31'; | ||
const INVALID_DATE = '99999'; | ||
|
||
describe('DateTimePicker', () => { | ||
function Setup(overrides: DateTimePickerProps) { | ||
return ( | ||
<DateTimePicker | ||
{...overrides} | ||
/> | ||
); | ||
} | ||
|
||
describe('when initializing', () => { | ||
describe('when passed a (date) prop', () => { | ||
it('sets input value', () => { | ||
render(<Setup date={VALID_DATE} />); | ||
|
||
expect(screen.getByDisplayValue(VALID_DATE)).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('interactions', () => { | ||
describe('when typing in date', () => { | ||
describe('with a valid value', () => { | ||
it('keeps value', async () => { | ||
render(<Setup />); | ||
|
||
const input = screen.getByPlaceholderText(PLACEHOLDER); | ||
userEvent.type(input, `${VALID_DATE}{enter}`); | ||
|
||
await waitFor(() => { | ||
expect(input).toHaveValue(VALID_DATE); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with an invalid value', () => { | ||
it('clears value', async () => { | ||
render(<Setup />); | ||
|
||
const input = screen.getByPlaceholderText(PLACEHOLDER); | ||
userEvent.type(input, `${INVALID_DATE}{enter}`); | ||
|
||
await waitFor(() => { | ||
expect(input).toHaveValue(''); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
should we put these in as peer deps as well? We may want to lock this in btwn here & rails-server to prevent version drift
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.
Good call