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

Add a customizable, slottable day component for calendars #745

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MattCheely
Copy link
Collaborator

No description provided.

Copy link

github-actions bot commented Dec 3, 2024

if (target) {
target.focus();
}
}

private onKeyDown(event: KeyboardEvent): void {
console.log('KEYDOWN', event.key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor this can be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will also look into why linting didn't catch this

{week.dates.map(day => {
const isoDateStr = asIsoDate(day.date);
return (
<slot key={isoDateStr} name={isoDateStr}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the key property valid on the slot element ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it should be, it's a JSX/Stencil feature, not a native one: https://stenciljs.com/docs/templating-jsx#dealing-with-children. We don't do a lot of removing/rearranging dates in the calendar, but I try to always add a key when creating children in a loop as a general best practice.

return (
<slot key={isoDateStr} name={isoDateStr}>
<gux-day
day={isoDateStr}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if the day property will work for example if you have a gux-day component like
<gux-day slot="2024-05-05" day="2024-05-10"></gux-day the calendar will be out of sync. I am not sure what the best way to handle that scenario would be. My suggestion would be either a single source of truth like keeping the slot attribute and somehow accessing the value in gux-day through an attribute on the parent maybe but I am not sure how that would work with how the calendar is rendered. My other sugguestion would be to just log a warning.

font-size: var(--gse-ui-calendarMenu-date-defaultText-fontSize);
font-style: normal;
font-weight: var(--gse-ui-calendarMenu-date-defaultText-fontWeight);
line-height: 32px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Token needed here


@Component({
styleUrl: 'gux-day.scss',
tag: 'gux-day',
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think this should have -beta prefix

Comment on lines +3 to +6
export class GuxElement {
@Element()
root: HTMLElement;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think this can be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah, that was an experiment that didn't get cleaned up. Thanks for catching it.

Copy link
Collaborator

@daragh-king-genesys daragh-king-genesys left a comment

Choose a reason for hiding this comment

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

In general the API looks good to me

this.date = new Date(this.day);
const locale = getDesiredLocale(this.root);
this.dayFormatter = sparkIntl.dateTimeFormat(locale, { day: 'numeric' });
this.readerFormatter = sparkIntl.dateTimeFormat(locale);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not used

/* Watcher to sync the internal date with the day attribute on changes */
@Watch('day')
onDateAttrChange(): void {
this.date = new Date(this.day);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@MattCheely welcome to developing with Javascript Dates in the western hemisphere. This does not work as expected for timezones behind GMT.
Screenshot 2024-12-03 at 11 28 48
The calendar for someone in the US for example will be shifted a day and be incorrect

aria-current={day.selected ? 'true' : 'false'}
tabindex={day.selected || day.focused ? '0' : '-1'}
onKeyDown={e => void this.onKeyDown(e)}
aria-disabled={day.disabled ? 'true' : 'false'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If a developer slots their own gux-day they will be responsible for making sure aria-current, aria-disabled and tabindex are correct right?

@gavin-everett-genesys
Copy link
Collaborator

API looks good to me :) ,

Just one minor visual item,

  • To select a day you have select the text of the day eg 18 you cant select around the value of the element. The cursor is default when hovering over the day text but then it is pointer when hovering around the outskirts of the day text.

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.

3 participants