Skip to content
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

Feat: add calendar component #4748

Merged
merged 108 commits into from
Oct 13, 2021
Merged

Conversation

robarbms
Copy link
Contributor

Pull Request

πŸ“– Description

This adds a basic calendar component. This will be used for a date picker component.

🎫 Issues

πŸ‘©β€πŸ’» Reviewer Notes

Localization is particularly difficult because of all the market, calendar and numbering permutations. I have localization mostly baked in. I wasn't able to find an exact list of what calendar and numbering types each market uses. I haven't tested localization defaults outside of the en-US market.

πŸ“‘ Test Plan

Need to figure out how to test other markets, calendar types and numbering systems.

βœ… Checklist

General

  • I have included a change request file using $ yarn change
  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

⏭ Next Steps

Find a solution for calendars that don't align with the Gregorian calendar system.

@EisenbergEffect
Copy link
Contributor

@robarbms Would you mind dropping a few screenshots in? I probably won't get a chance to pull down the code and run it, but I'd love to see how this is looking.

Copy link
Member

@chrisdholt chrisdholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having an issue running this in Safari and Firefox - can you look into what might be happening there and if we need fallbacks somewhere?

@robarbms
Copy link
Contributor Author

robarbms commented Oct 7, 2021

I'm having an issue running this in Safari and Firefox - can you look into what might be happening there and if we need fallbacks somewhere?

This was an issue on date construction differences. Chrome and IE allow for new Date('10-7-2021'). FireFox doesn't and I had to use a more universal constructor new Date(2021, 10, 7)

Copy link
Contributor

@nicholasrice nicholasrice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@robarbms robarbms requested review from scomea and chrisdholt October 12, 2021 15:35
Copy link
Member

@chrisdholt chrisdholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the flexibility supported here. Thanks for the hard work getting this done!

@chrisdholt chrisdholt merged commit 4457690 into master Oct 13, 2021
@chrisdholt chrisdholt deleted the users/robarb/calendar-component branch October 13, 2021 18:32
* @public
*/
public handleDateSelect(event: Event, day: CalendarDateInfo): void {
event.preventDefault;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a function call

? date
: `${date.getMonth() + 1}-${date.getDate()}-${date.getFullYear()}`;

return !!dates.find(d => d === date);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return !!dates.find(d => d === date);
return dates.some(d => d === date);

Comment on lines +295 to +311
let className: string = "day";

if (todayString === `${month}-${day}-${year}`) {
className += " today";
}

if (this.month !== month) {
className += " inactive";
}

if (disabled) {
className += " disabled";
}

if (selected) {
className += " selected";
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be turned into an array to improve readability.

Suggested change
let className: string = "day";
if (todayString === `${month}-${day}-${year}`) {
className += " today";
}
if (this.month !== month) {
className += " inactive";
}
if (disabled) {
className += " disabled";
}
if (selected) {
className += " selected";
}
const today = todayString === `${month}-${day}-${year}`;
const inactive = this.month !== month;
return [
"day",
today && "today",
inactive && "inactive",
disabled && "disabled",
selected && "selected",
]
.filter(Boolean)
.join(" ");

*/
public handleDateSelect(event: Event, day: CalendarDateInfo): void {
event.preventDefault;
(this as FASTElement).$emit("dateselected", day);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(this as FASTElement).$emit("dateselected", day);
this.$emit("dateselected", day);

Comment on lines +96 to +98
parseInt(dates[2]),
parseInt(dates[0]) - 1,
parseInt(dates[1])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be safer to specify the radix here. There are possible historical bugs which can show up when omitting the radix with parseInt: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#octal_interpretations_with_no_radix

Suggested change
parseInt(dates[2]),
parseInt(dates[0]) - 1,
parseInt(dates[1])
parseInt(dates[2], 10),
parseInt(dates[0], 10) - 1,
parseInt(dates[1], 10)

locale: string = this.locale
): string {
const dateObj = this.getDateObject(date);
const optionsWithTimeZone = Object.assign({}, { timeZone: "utc" }, format);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const optionsWithTimeZone = Object.assign({}, { timeZone: "utc" }, format);
const optionsWithTimeZone = { timeZone: "utc", ...format };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add calendar component to/in FAST