Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
344 changes: 344 additions & 0 deletions tedi/components/form/date-picker/date-picker.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
<input
#inputElement
type="text"
class="tedi-date-picker__input"
role="combobox"
aria-autocomplete="none"
aria-haspopup="dialog"
[class.tedi-date-picker__input--small]="inputSize() === 'small'"
[class.tedi-date-picker__input--valid]="inputState() === 'valid'"
[class.tedi-date-picker__input--error]="inputState() === 'error'"
[attr.id]="inputId()"
[attr.placeholder]="inputPlaceholder()"
[attr.aria-expanded]="!inputDisabled() && popover().floatUiComponent().state"
[attr.aria-controls]="uniqueId"
[attr.aria-readonly]="!allowManualInput()"
[readOnly]="!allowManualInput()"
[value]="inputValue()"
[disabled]="inputDisabled()"
(input)="onInput($event)"
(blur)="onInputBlur()"
(click)="onInputClick()"
/>
<div class="tedi-date-picker__input-buttons">
@if (selected()) {
<button
tedi-closing-button
type="button"
size="small"
class="tedi-date-picker__clear"
[iconSize]="18"
[attr.aria-label]="translationService.track('date-picker.clear-date')()"
[disabled]="inputDisabled()"
(click)="clearInput()"
></button>
<tedi-separator axis="vertical" size="1rem" />
}
<tedi-popover
style="display: flex; align-items: center"
position="bottom-end"
[withArrow]="false"
>
<tedi-popover-trigger>
<button
tedi-button
type="button"
variant="neutral"
size="small"
class="tedi-date-picker__toggle"
[attr.aria-label]="
translationService.track('date-picker.open-calendar')()
"
[disabled]="inputDisabled()"
(click)="openCalendar()"
>
<tedi-icon name="calendar_today" size="inherit" />
</button>
</tedi-popover-trigger>
<tedi-popover-content maxWidth="none" style="padding: 0">
<div
class="tedi-date-picker__calendar"
(keydown)="onCalendarKeyDown($event)"
>
<div class="tedi-date-picker__header">
@if (currentView() === "calendar-grid") {
@if (showNavigation()) {
<button
tedi-button
variant="neutral"
size="small"
class="tedi-date-picker__nav"
[attr.aria-label]="
translationService.track('date-picker.go-prev-month')()
"
[attr.aria-controls]="uniqueId"
(click)="prevMonth()"
[disabled]="!canGoPrev()"
>
<tedi-icon name="arrow_back" />
</button>
}

<div class="tedi-date-picker__controls">
@if (monthMode() === "dropdown") {
<tedi-dropdown
[value]="month().getMonth().toString()"
(valueChange)="onMonthSelect($event)"
>
<button
tedi-dropdown-trigger
ariaHaspopup="listbox"
class="tedi-date-picker__dropdown-trigger"
[attr.aria-label]="
translationService.track('date-picker.select-month')()
"
>
{{ monthNames[month().getMonth()]() }}
<tedi-icon
name="arrow_drop_down"
class="tedi-date-picker__dropdown-arrow"
size="inherit"
/>
</button>
<tedi-dropdown-content
dropdownRole="listbox"
class="tedi-date-picker__dropdown-content tedi-date-picker__dropdown-content--month"
>
@for (month of monthNames; track i; let i = $index) {
<li tedi-dropdown-item [value]="i.toString()">
{{ month() }}
</li>
}
</tedi-dropdown-content>
</tedi-dropdown>
} @else if (monthMode() === "grid") {
<button
class="tedi-date-picker__dropdown-trigger"
[attr.aria-label]="
translationService.track('date-picker.select-month')()
"
(click)="onMonthClick()"
>
{{ monthNames[month().getMonth()]() }}
<tedi-icon
name="arrow_drop_down"
class="tedi-date-picker__dropdown-arrow"
size="inherit"
/>
</button>
} @else if (monthMode() === "label") {
<div class="tedi-date-picker__label">
{{ monthNames[month().getMonth()]() }}
</div>
}

@if (yearMode() === "dropdown") {
<tedi-dropdown
position="bottom-end"
[value]="selectedYear().toString()"
(valueChange)="onYearSelect($event)"
>
<button
tedi-dropdown-trigger
ariaHaspopup="listbox"
class="tedi-date-picker__dropdown-trigger"
[attr.aria-label]="
translationService.track('date-picker.select-year')()
"
>
{{ selectedYear() }}
<tedi-icon
name="arrow_drop_down"
class="tedi-date-picker__dropdown-arrow"
size="inherit"
/>
</button>
<tedi-dropdown-content
dropdownRole="listbox"
class="tedi-date-picker__dropdown-content tedi-date-picker__dropdown-content--year"
>
@for (year of years(); track year) {
<li tedi-dropdown-item [value]="year.toString()">
{{ year }}
</li>
}
</tedi-dropdown-content>
</tedi-dropdown>
} @else if (yearMode() === "grid") {
<button
class="tedi-date-picker__dropdown-trigger"
[attr.aria-label]="
translationService.track('date-picker.select-year')()
"
(click)="onYearClick()"
>
{{ selectedYear() }}
<tedi-icon
name="arrow_drop_down"
class="tedi-date-picker__dropdown-arrow"
size="inherit"
/>
</button>
} @else if (yearMode() === "label") {
<div class="tedi-date-picker__label">
{{ selectedYear() }}
</div>
}
</div>

@if (showNavigation()) {
<button
tedi-button
variant="neutral"
size="small"
class="tedi-date-picker__nav"
[attr.aria-label]="
translationService.track('date-picker.go-next-month')()
"
[attr.aria-controls]="uniqueId"
(click)="nextMonth()"
[disabled]="!canGoNext()"
>
<tedi-icon name="arrow_forward" />
</button>
}
} @else if (currentView() === "month-grid") {
<div class="tedi-date-picker__controls">
{{ monthNames[month().getMonth()]() }}
</div>
} @else if (currentView() === "year-grid") {
<button
tedi-button
variant="neutral"
size="small"
class="tedi-date-picker__nav"
[attr.aria-label]="
translationService.track('date-picker.previous-years')()
"
(click)="prevYearPage()"
[disabled]="!hasPrevYearPage()"
>
<tedi-icon name="arrow_back" />
</button>
<div class="tedi-date-picker__controls">{{ selectedYear() }}</div>
<button
tedi-button
variant="neutral"
size="small"
class="tedi-date-picker__nav"
[attr.aria-label]="
translationService.track('date-picker.next-years')()
"
(click)="nextYearPage()"
[disabled]="!hasNextYearPage()"
>
<tedi-icon name="arrow_forward" />
</button>
}
</div>

@if (currentView() === "calendar-grid") {
<div
class="tedi-date-picker__weekdays"
[class.tedi-date-picker__weekdays--numbered]="showWeekNumbers()"
role="row"
>
@if (showWeekNumbers()) {
<div role="columnheader"></div>
}
@for (wd of weekDays; track $index; let i = $index) {
<div class="tedi-date-picker__weekday" role="columnheader">
{{ wd() }}
</div>
}
</div>

<div
#gridElement
class="tedi-date-picker__grid"
role="grid"
[attr.id]="uniqueId"
aria-readonly="true"
>
@for (week of weekRows(); track row; let row = $index) {
<div
class="tedi-date-picker__row"
[class.tedi-date-picker__row--numbered]="showWeekNumbers()"
role="row"
>
@if (showWeekNumbers()) {
<div
class="tedi-date-picker__weeknumber"
role="gridcell"
aria-readonly="true"
>
{{ weekNumbers()[row] }}
</div>
}
@for (day of week; track day.date) {
<button
type="button"
role="gridcell"
class="tedi-date-picker__day"
[class.tedi-date-picker__day--other-month]="
!day.inCurrentMonth
"
[class.tedi-date-picker__day--selected]="
isSelected(day.date)
"
[disabled]="day.disabled"
[attr.aria-selected]="isSelected(day.date) ? 'true' : null"
[attr.aria-disabled]="day.disabled ? 'true' : null"
[attr.aria-current]="isToday(day.date) ? 'date' : null"
[attr.tabindex]="getTabIndex(day.date)"
[attr.data-date-key]="day.date.getTime()"
(keydown)="onDayKeydown($event, day.date)"
(click)="selectDay(day)"
>
@if (isToday(day.date)) {
<div class="tedi-date-picker__today">
{{ day.date.getDate() }}
</div>
} @else {
{{ day.date.getDate() }}
}
</button>
}
</div>
}
</div>
} @else if (currentView() === "month-grid") {
<div class="tedi-date-picker__month-year-grid" role="group">
@for (monthName of monthShortNames; track i; let i = $index) {
<button
type="button"
class="tedi-date-picker__month-year-button"
[class.tedi-date-picker__month-year-button--selected]="
month().getMonth() === i
"
(click)="onMonthSelect(i.toString())"
>
{{ monthName() }}
</button>
}
</div>
} @else if (currentView() === "year-grid") {
<div class="tedi-date-picker__month-year-grid" role="group">
@for (year of pagedYears(); track year) {
<button
type="button"
class="tedi-date-picker__month-year-button"
[class.tedi-date-picker__month-year-button--selected]="
month().getFullYear() === year
"
(click)="onYearSelect(year.toString())"
>
{{ year }}
</button>
}
</div>
}
</div>
</tedi-popover-content>
</tedi-popover>
</div>
Loading