Skip to content

Commit 2de2734

Browse files
committed
feat(date-picker): update theme attribute to use data-theme for better styling compatibility
1 parent 82205c5 commit 2de2734

2 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/components/date-picker/date-picker.ts

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export class DatePicker extends HTMLElement {
126126

127127
private initializeComponent() {
128128
// Create the main structure
129+
this.classList.add('odyssey-date-picker');
129130
this.innerHTML = `
130-
<div class="odyssey-date-picker">
131131
<div class="date-picker-input-wrapper">
132132
<input type="text" class="date-picker-input" placeholder="Select date" readonly>
133133
<span class="date-picker-icon material-icons">calendar_today</span>
@@ -155,7 +155,6 @@ export class DatePicker extends HTMLElement {
155155
</div>
156156
</div>
157157
</div>
158-
</div>
159158
`;
160159

161160
// Get references to DOM elements
@@ -500,14 +499,6 @@ export class DatePicker extends HTMLElement {
500499

501500
yearsContent += '</div>';
502501

503-
// Add navigation for decades
504-
yearsContent += `
505-
<div style="display: flex; justify-content: space-between; padding: 0.5rem;">
506-
<button class="date-picker-btn prev-decade">« Prev</button>
507-
<button class="date-picker-btn next-decade">Next »</button>
508-
</div>
509-
`;
510-
511502
this.calendarElement.innerHTML = yearsContent;
512503

513504
// Attach click events to year cells
@@ -520,21 +511,6 @@ export class DatePicker extends HTMLElement {
520511
this.renderCalendar();
521512
});
522513
});
523-
524-
// Attach decade navigation events
525-
this.querySelector('.prev-decade')?.addEventListener('click', (e) => {
526-
e.stopPropagation(); // Prevent event from closing calendar
527-
this.viewDate.setFullYear(this.viewDate.getFullYear() - 10);
528-
this.renderYearsView();
529-
this.updateHeaderText();
530-
});
531-
532-
this.querySelector('.next-decade')?.addEventListener('click', (e) => {
533-
e.stopPropagation(); // Prevent event from closing calendar
534-
this.viewDate.setFullYear(this.viewDate.getFullYear() + 10);
535-
this.renderYearsView();
536-
this.updateHeaderText();
537-
});
538514
}
539515

540516
private attachDateCellListeners() {
@@ -608,16 +584,18 @@ export class DatePicker extends HTMLElement {
608584
const monthSelector = this.querySelector('.date-picker-month-selector') as HTMLElement;
609585
const yearSelector = this.querySelector('.date-picker-year-selector') as HTMLElement;
610586

611-
if (this.currentView === 'calendar' || this.currentView === 'months') {
587+
if (this.currentView === 'calendar') {
588+
monthSelector.textContent = this.getMonthName(this.viewDate.getMonth());
589+
yearSelector.textContent = this.viewDate.getFullYear().toString();
590+
} else if (this.currentView === 'months') {
612591
monthSelector.textContent = this.getMonthName(this.viewDate.getMonth());
613592
yearSelector.textContent = this.viewDate.getFullYear().toString();
614593
} else if (this.currentView === 'years') {
615594
const currentYear = this.viewDate.getFullYear();
616595
const startYear = currentYear - (currentYear % 12) - 3;
617596
const endYear = startYear + 14;
618-
monthSelector.textContent = '';
597+
monthSelector.textContent = this.getMonthName(this.viewDate.getMonth());
619598
yearSelector.textContent = `${startYear} - ${endYear}`;
620-
yearSelector.classList.add('center');
621599
}
622600
}
623601

@@ -723,14 +701,30 @@ export class DatePicker extends HTMLElement {
723701

724702
private previousMonth() {
725703
const newViewDate = new Date(this.viewDate);
726-
newViewDate.setMonth(newViewDate.getMonth() - 1);
704+
705+
if (this.currentView === 'calendar') {
706+
newViewDate.setMonth(newViewDate.getMonth() - 1);
707+
} else if (this.currentView === 'months') {
708+
newViewDate.setFullYear(newViewDate.getFullYear() - 1);
709+
} else if (this.currentView === 'years') {
710+
newViewDate.setFullYear(newViewDate.getFullYear() - 15);
711+
}
712+
727713
this.viewDate = newViewDate;
728714
this.renderCalendar();
729715
}
730716

731717
private nextMonth() {
732718
const newViewDate = new Date(this.viewDate);
733-
newViewDate.setMonth(newViewDate.getMonth() + 1);
719+
720+
if (this.currentView === 'calendar') {
721+
newViewDate.setMonth(newViewDate.getMonth() + 1);
722+
} else if (this.currentView === 'months') {
723+
newViewDate.setFullYear(newViewDate.getFullYear() + 1);
724+
} else if (this.currentView === 'years') {
725+
newViewDate.setFullYear(newViewDate.getFullYear() + 15);
726+
}
727+
734728
this.viewDate = newViewDate;
735729
this.renderCalendar();
736730
}

src/components/date-picker/services/date-picker-service-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ export class DatePickerServiceManager {
10581058
*/
10591059
setTheme(theme: string): void {
10601060
this._themeService.setTheme(this._element, theme);
1061-
this._element.setAttribute('theme', theme);
1061+
this._element.setAttribute('data-theme', theme);
10621062

10631063
if (this._container) {
10641064
this._themeService.setTheme(this._container, theme);

0 commit comments

Comments
 (0)