-
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
Add DateTimePicker #1220
Changes from 13 commits
330f3dc
fac8591
82c6781
3880ada
a8f3f3d
614f1d7
8cb4b7f
e3bbdf1
71282e5
26734c0
7c401be
8b41592
597d6b8
cdbeb6d
689e5a1
056c0b5
37d4071
1057939
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,139 @@ | ||||||
@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: $font-weight-bold; | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
.react-datepicker__day--outside-month { | ||||||
color: var(--ux-gray-300); | ||||||
} | ||||||
|
||||||
|
||||||
.date-time-picker { | ||||||
&__input-group { | ||||||
background-color: var(--ux-white); | ||||||
border-radius: $border-radius; | ||||||
border: thin solid var(--ux-gray-400); | ||||||
padding: .46875rem .75rem; | ||||||
justify-content: space-between; | ||||||
width: inherit; | ||||||
} | ||||||
} | ||||||
|
||||||
.react-datepicker { | ||||||
@include font-type-30; | ||||||
// font-family: $body-fonts; | ||||||
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. |
||||||
|
||||||
.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: $border-radius; | ||||||
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. I think this scss var comes from bootstrap, but could it potentially use:
Suggested change
|
||||||
} | ||||||
|
||||||
// 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%; | ||||||
} |
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 /> | ||
); |
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(''); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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