-
Notifications
You must be signed in to change notification settings - Fork 6
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
E&A Date Picker (Part One) - Integration and usage within the E&A Timeline header #1044
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c697f0d
Base setup for using react-uswds in the veda-ui
dzole0311 097131c
Update parcel version and include required dependencies
dzole0311 7621e32
Add react-uswds import
dzole0311 fcd9f64
Use uncss as a plugin
hanbyul-here 969d958
Use purgecss, add uswds css to content
hanbyul-here ce9e582
Modify the gulpfile config to copy the assets from uswds
dzole0311 da4a0bc
Merge branch 'main' into base-setup-for-react-uswds
dzole0311 59d6605
Remove obsolete import after merge conflict
dzole0311 b7e05fb
Make uswds logging less verbose
dzole0311 27b8cf2
Improve parcel build time
dzole0311 ddf1d6d
Remove purgecss dependency
dzole0311 b1839b2
Integrate the USWDS date picker in E&A
dzole0311 1aaa6fc
Cleanup, add isStrokeDashed param for the timeline head
dzole0311 0e27d0c
Remove transition CSS prop
dzole0311 448551c
Replace moment with date-fns
dzole0311 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,9 @@ | ||
const path = require('path') | ||
|
||
const CWD = process.cwd() | ||
|
||
module.exports = { | ||
"includePaths": [ | ||
path.resolve(CWD, 'node_modules/@uswds/uswds/packages') | ||
] | ||
} |
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,30 @@ | ||
@use "usa-date-picker/src/styles"; | ||
|
||
.usa-date-picker { | ||
position: relative; | ||
width: 0; | ||
height: 0; | ||
|
||
&__calendar { | ||
width: 20rem; | ||
position: absolute; | ||
top: 100%; | ||
border: 1px solid rgb(230, 230, 230); | ||
} | ||
|
||
&--open-upwards .usa-date-picker__calendar { | ||
top: auto; | ||
bottom: 100%; | ||
} | ||
|
||
& *:not(:focus), & *:not(:active) { | ||
font-family: themeVal('type.base.family'); | ||
z-index: 9999; | ||
} | ||
|
||
.usa-input, | ||
&__button, | ||
&__status { | ||
display: none; | ||
} | ||
} |
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,57 @@ | ||
import React, { ReactNode, useRef, ReactElement } from "react"; | ||
import { DatePicker } from "@trussworks/react-uswds"; | ||
import { format } from 'date-fns'; | ||
|
||
import './index.scss'; | ||
|
||
interface SimpleDatePickerProps { | ||
disabled: boolean; | ||
tipContent: ReactNode; | ||
onConfirm: (date: string) => void; | ||
triggerHeadReference: string; | ||
id: string; | ||
selectedDay: Date | null; | ||
renderTriggerElement: (props: { | ||
onClick: () => void; | ||
disabled: boolean; | ||
tipContent: ReactNode; | ||
triggerHeadReference: string; | ||
selectedDay: Date | null; | ||
}) => ReactElement; | ||
} | ||
|
||
export const SimpleDatePicker = ({ disabled, tipContent, onConfirm, id, triggerHeadReference, selectedDay, renderTriggerElement }: SimpleDatePickerProps) => { | ||
const datePickerRef = useRef<HTMLDivElement>(null); | ||
|
||
const toggleCalendar = () => { | ||
// We have no reference to the internals of the react-uswds DatePicker, so we have to query for it's trigger. | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
if (datePickerRef.current) { | ||
const button = datePickerRef.current.querySelector('button.usa-date-picker__button')! as HTMLButtonElement; | ||
button.click(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{renderTriggerElement({ | ||
onClick: toggleCalendar, | ||
disabled, | ||
tipContent, | ||
triggerHeadReference, | ||
selectedDay, | ||
})} | ||
<div ref={datePickerRef}> | ||
<DatePicker | ||
key={selectedDay ? selectedDay.toISOString() : 'default'} | ||
aria-describedby='veda-date-hint' | ||
aria-labelledby='veda-date-label' | ||
id={id} | ||
name={id} | ||
onChange={onConfirm} | ||
defaultValue={format(selectedDay ?? new Date(), 'yyyy-MM-dd')} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; |
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
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.
Ah I see. This is a sticky problem 😬 . Can we control the visibility of the calendar in this way? If we do a conditional render like
{showCalendar && <DatePicker...>}
, we will lose the access to this button. (Calendar is not toggling right now, it just re-renders when renderTriggerElement is pressed I think. )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.
We can't unfortunately, since the
<Calendar />
comes coupled with the<DatePicker />
and we can't conditionally render only that component. So the only thing I could think of is programmatically toggling it via theusa-date-picker__button
.This gets trickier when we will have to show the
MONTH_PICKER
or theYEAR_PICKER
based on the dataset time density, because these calendar modes exist as a local state in the Calendar. So the only solution I can think of is to click the picker button to open the calendar, then query and click eitherusa-date-picker__calendar__month-selection
orusa-date-picker__calendar__year-selection
to toggle the corresponding calendar mode depending on the time density 😰I opened two issues on
react-uswds
side: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.
Throwing some ideas here. (It might be a terrible idea) Can it be something that we can solve by overwriting the style? I feel like they (calendar trigger element for both uswds date picker and our date picker) are eventually doing the same thing, showing the date, and then a button to trigger the calendar. (I understand our original design wants the whole thing to be a button to trigger - including the text- but maybe we can adjust the design a bit to accommodate USWDS system?)
ex. overwriting the text input style, calendar icon (to show the caret) here?
Maybe we can at least leave the button to trigger and overwrite the style?
Which will be roughly like this - #1047
Orrr 🤔 is this a good component to write React components for our own just using uswds style?
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.
Thanks for the idea @hanbyul-here. As you pointed out, we will need to do a lot of manual triggering if we want to sync the calendar with the time density of the dataset, which I think is very error prone.
Yes, I think so. We need a more robust approach but at the same time not to reinvent the wheel (e.g. implementing basic date picker functionality from scratch). What do you think about using
react-calendar
(https://www.npmjs.com/package/react-calendar)?Here's a PR with it: #1048 and here's the deployment:
We could override some of the styles using uswds mixins / functions: https://github.com/NASA-IMPACT/veda-ui/pull/1048/files#diff-88b2701907396a34bbe38997d6970f2f6824389dbefe1dcc112a5fdfaa35d811R24
Also:
maxDetail
), so it will save us a lot of timeAny opinions on this?
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.
Yeh, I Agree that we should not invent the wheel. I will vote for using ReactCalendar for now 👍