-
Notifications
You must be signed in to change notification settings - Fork 13
feat: adding date description texts #45
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| EventEmitter, | ||
| h, | ||
| Host, | ||
| Method, | ||
| Prop, | ||
| State, | ||
| Watch | ||
|
|
@@ -92,14 +93,19 @@ export class WCDatepicker { | |
| @Prop() maxSearchDays?: number = 365; | ||
| @Prop() goToRangeStartOnSelect?: boolean = true; | ||
|
|
||
| @Prop({ mutable: true }) showDayDescriptions?: boolean = false; | ||
| @Prop({ mutable: true }) addDateDescription?: (date: Date) => string; | ||
|
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. issue: I don't think we need the 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. suggestion: Allow it to return |
||
|
|
||
| @State() currentDate: Date; | ||
| @State() hoveredDate: Date; | ||
| @State() weekdays: string[][]; | ||
|
|
||
|
|
||
| @Event() selectDate: EventEmitter<string | string[] | undefined>; | ||
| @Event() changeMonth: EventEmitter<MonthChangedEventDetails>; | ||
|
|
||
| private moveFocusAfterMonthChanged: Boolean; | ||
| private dayDescriptions: Record<string, string> = {}; | ||
|
|
||
| componentWillLoad() { | ||
| this.init(); | ||
|
|
@@ -154,6 +160,16 @@ export class WCDatepicker { | |
| } | ||
| } | ||
|
|
||
| @Method() | ||
| async getDescriptionForDay(date: Date): Promise<string> { | ||
| return this.dayDescriptions[getISODateString(date)] || ''; | ||
| } | ||
|
|
||
| @Method() | ||
| async getAllDayDescriptions(): Promise<Record<string, string>> { | ||
| return { ...this.dayDescriptions }; | ||
| } | ||
|
|
||
|
Comment on lines
+163
to
+172
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. question: Is there a need to make these methods part of the public component API with the |
||
| private init = () => { | ||
| this.currentDate = this.startDate | ||
| ? removeTimezoneOffset(new Date(this.startDate)) | ||
|
|
@@ -224,6 +240,18 @@ export class WCDatepicker { | |
| } | ||
| } | ||
|
|
||
| private setDescriptionForDay(date: Date): string { | ||
|
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. question: Do you expect the |
||
| if (!this.showDayDescriptions || !this.addDateDescription) { | ||
| return ''; | ||
| } | ||
|
|
||
| if (!this.dayDescriptions[getISODateString(date)]) { | ||
| this.dayDescriptions[getISODateString(date)] = this.addDateDescription(date) || ''; | ||
| } | ||
|
|
||
| return this.dayDescriptions[getISODateString(date)] || ''; | ||
| } | ||
|
|
||
| private focusDate(date: Date) { | ||
| this.el | ||
| .querySelector<HTMLTableCellElement>( | ||
|
|
@@ -573,7 +601,8 @@ export class WCDatepicker { | |
| aria-label={this.labels.picker} | ||
| class={{ | ||
| [this.getClassName()]: true, | ||
| [`${this.getClassName()}--disabled`]: this.disabled | ||
| [`${this.getClassName()}--disabled`]: this.disabled, | ||
| [`${this.getClassName()}--with-descriptions`]: this.showDayDescriptions | ||
| }} | ||
| role="group" | ||
| > | ||
|
|
@@ -777,6 +806,8 @@ export class WCDatepicker { | |
| const isDisabled = this.disableDate(day); | ||
|
|
||
| const cellKey = `cell-${day.getMonth()}-${day.getDate()}`; | ||
|
|
||
| const dayDescription = this.setDescriptionForDay(day); | ||
|
|
||
| const className = { | ||
| [this.getClassName('date')]: true, | ||
|
|
@@ -817,12 +848,20 @@ export class WCDatepicker { | |
| : -1 | ||
| } | ||
| > | ||
| <Tag aria-hidden="true">{day.getDate()}</Tag> | ||
| <div class={this.getClassName('date-content')}> | ||
| <Tag aria-hidden="true">{day.getDate()}</Tag> | ||
| {this.showDayDescriptions && dayDescription && ( | ||
| <span class={this.getClassName('date-description')} aria-hidden="true"> | ||
|
Comment on lines
+851
to
+854
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. issue: The new classnames here should be documented in the index.html. |
||
| {dayDescription} | ||
| </span> | ||
| )} | ||
| </div> | ||
| <span class="visually-hidden"> | ||
| {Intl.DateTimeFormat(this.locale, { | ||
| day: 'numeric', | ||
| month: 'long' | ||
| }).format(day)} | ||
| {this.showDayDescriptions && dayDescription && `, ${dayDescription}`} | ||
| </span> | ||
| </td> | ||
| ); | ||
|
|
@@ -864,4 +903,4 @@ export class WCDatepicker { | |
| </Host> | ||
| ); | ||
| } | ||
| } | ||
| } | ||
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.
question: Do we need this prop? This could be implicit information by looking at
addDateDescription,. right? IfaddDateDescriptionis not set or returns undefined, the description should not be shown.