Skip to content

Commit

Permalink
feat: add OnHeaderCellAddedArgs (#22)
Browse files Browse the repository at this point in the history
to allow th to contain custom element
  • Loading branch information
jpvmrcd authored Oct 14, 2024
1 parent 239129d commit aa6b8cc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
16 changes: 14 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export interface OnHeaderCellAddedArgs {
th: HTMLTableCellElement,
day: string
}

export interface OnCellAddedArgs {
td: HTMLTableCellElement,
dateISOString: string
Expand All @@ -9,6 +14,7 @@ export interface OnDateClickedArgs {
}

export interface CalendarOptions {
onHeaderCellAdded?: (arg: OnHeaderCellAddedArgs) => void,
onCellAdded?: (arg: OnCellAddedArgs) => void,
onDateClicked?: (arg: OnDateClickedArgs) => void,
dayNames: [string, string, string, string, string, string, string],
Expand Down Expand Up @@ -42,7 +48,7 @@ export class Calendar {
tableHead.appendChild(thr);

const {
dayNames, startDay, onCellAdded, onDateClicked,
dayNames, startDay, onHeaderCellAdded, onCellAdded, onDateClicked,
} = this.options;
let startDayIndex = 0;

Expand Down Expand Up @@ -80,7 +86,13 @@ export class Calendar {
for (let i = 0; i < dayNamesWithDayNumber.length; i++) {
const th = document.createElement('th');
const d = dayNamesWithDayNumber[i];
th.appendChild(document.createTextNode(d.day));

if (onHeaderCellAdded && typeof onHeaderCellAdded === 'function') {
onHeaderCellAdded({ th, day: d.day });
} else {
th.appendChild(document.createTextNode(d.day));
}

thr.appendChild(th);

if (firstDay === d.index) {
Expand Down
Loading

0 comments on commit aa6b8cc

Please sign in to comment.