@use '../abstract/base' as base;
@use '../abstract/variables' as v;
@use '../abstract/mixins' as m;
@use '../abstract/theme' as t;
@use '../abstract/direction' as d;

$component: '#{base.$prefix}-datepicker';
.#{$component} {
--#{base.$prefix}-density: 0;
position: relative;
display: inline-flex;
flex-direction: column;
width: 100%;
max-width: 360px;
contain: inline-size;
contain-intrinsic-inline-size: v.text-field('width');
color: t.color('on-surface');
--#{$component}-start: 100% 0;
--#{$component}-end: 0 0;
--#{$component}-bleed-first-left: auto;
--#{$component}-bleed-first-right: 100%;
--#{$component}-bleed-last-left: 100%;
--#{$component}-bleed-last-right: auto;
--#{$component}-flip: none;
@include m.rtl($self: true) {
--#{$component}-start: 0 0;
--#{$component}-end: 100% 0;
--#{$component}-bleed-first-left: 100%;
--#{$component}-bleed-first-right: auto;
--#{$component}-bleed-last-left: auto;
--#{$component}-bleed-last-right: 100%;
--#{$component}-flip: scaleX(-1);
}
&__anchor { display: flex; position: relative; }
&__label { @include m.typography('body-small'); margin-block-end: 4px; }
&__input {
box-sizing: border-box;
width: 100%; min-width: 0; height: 56px; padding: 12px 16px;
border: 1px solid t.color('outline'); border-radius: v.shape('extra-small');
background: transparent; color: t.color('on-surface');
@include m.typography('body-large');
&:focus-visible { outline: 2px solid t.color('primary'); outline-offset: -2px; }
&[aria-invalid='true'] { border-color: t.color('error'); }
&:disabled { opacity: 0.38; }
}
&__anchor &__input { padding-inline-end: 56px; }
&__trigger, &__mode-toggle, &__prev, &__next, &__close { font: inherit; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
&__trigger { position: absolute; top: 4px; @include d.end(4px); font-size: 24px; }
&__help, &__error { @include m.typography('body-small'); padding: 4px 16px 0; }
&__help { color: t.color('on-surface-variant'); }
&__error { color: t.color('error'); &:empty { display: none; } }
&__calendar {
--#{$component}-grid-inset: 12px;
box-sizing: border-box; padding: 0; border: 0;
width: 360px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px);
overflow: auto; color: t.color('on-surface'); background: t.color('surface-container-high');
border-radius: v.shape('extra-large'); box-shadow: v.elevation('level-3');
&::backdrop { background: t.alpha('scrim', 0.32); }
}
&--modal { position: fixed; inset: 0; margin: auto; }
&--fullscreen {
width: 100%; max-width: none; height: 100%; max-height: none;
border-radius: 0; box-shadow: none; overflow: hidden;
.#{$component}__content { height: 100%; }
.#{$component}__modal-header { min-height: 128px; padding: 64px 64px 12px; }
.#{$component}__close {
position: absolute; top: 4px; @include d.start(4px);
}
.#{$component}__save {
position: absolute; top: 8px; @include d.end(12px);
}
.#{$component}__title { margin-bottom: 0; }
.#{$component}__headline { @include m.typography('title-large'); }
.#{$component}__weekdays { padding: 0 var(--#{$component}-grid-inset); }
}
&__list { flex: 1; min-height: 0; position: relative; overflow-y: auto; overscroll-behavior: contain; }
&__subhead { @include m.typography('title-small'); color: t.color('on-surface-variant'); padding: 20px 24px 8px; }
&--docked { border-radius: v.shape('large'); }
&--docked {
position: absolute; inset: auto; top: 100%; @include d.start(0); margin: 8px 0 0; z-index: v.z-index('dropdown');
}
&__content { display: flex; flex-direction: column; }
&__modal-header {
position: relative; box-sizing: border-box; min-height: 120px; padding: 16px 64px 16px 24px;
border-bottom: 1px solid t.color('outline-variant'); color: t.color('on-surface-variant');
}
&--range &__modal-header { min-height: 128px; }
&--range &__headline { @include m.typography('title-large'); }
&__title { @include m.typography('label-large'); margin-bottom: 20px; }
&__headline { @include m.typography('headline-large'); overflow-wrap: anywhere; }
&__mode-toggle {
position: absolute; @include d.end(12px); bottom: 12px; font-size: 24px;
}
@include d.arms-self-only {
.#{$component}__trigger { right: auto; left: 4px; }
.#{$component}__mode-toggle { right: auto; left: 12px; }
}
&--fullscreen {
@include d.arms-self-only {
.#{$component}__close { left: auto; right: 4px; }
.#{$component}__save { right: auto; left: 12px; }
}
}
&--docked {
@include d.arms-self-only { left: auto; right: 0; }
}
&__header { display: flex; align-items: center; padding: 4px 12px; min-height: 56px; box-sizing: border-box; }
&__navigation { display: flex; flex: 1; }
&__month-selector, &__year-selector { @include m.typography('label-large'); padding: 0 8px; }
&__trigger, &__mode-toggle, &__prev, &__next, &__month-selector, &__year-selector,
&__cancel, &__confirm, &__close, &__save {
box-sizing: border-box; min-width: 48px; min-height: 48px; border: 0; border-radius: v.shape('full');
color: t.color('on-surface-variant'); background: transparent; cursor: pointer;
&:hover:not(:disabled) { background: t.alpha('on-surface', 0.08); }
&:focus-visible { outline: 2px solid t.color('primary'); outline-offset: -2px; background: t.alpha('on-surface', v.state('focus-state-layer-opacity')); }
&:disabled { opacity: 0.38; cursor: default; }
}
&--animate[open] { animation: #{$component}-appear v.motion('duration-short3') v.motion('easing-standard'); }
@media (prefers-reduced-motion: reduce) { &--animate[open] { animation: none; } }
&__days { padding: 0 var(--#{$component}-grid-inset); }
&__track {
display: flex; overflow-x: auto; overscroll-behavior-x: contain;
scroll-snap-type: x mandatory; scrollbar-width: none;
&::-webkit-scrollbar { display: none; }
> .#{$component}__days { flex: 0 0 100%; box-sizing: border-box; scroll-snap-align: start; scroll-snap-stop: always; }
}
&__weekdays, &__week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
&__weekday, &__cell { display: flex; align-items: center; justify-content: center; height: 48px; min-width: 0; }
&__weekday { @include m.typography('body-large'); }
&__cell--range {
position: relative;
background: linear-gradient(transparent 4px, t.color('secondary-container') 4px, t.color('secondary-container') 44px, transparent 44px) no-repeat;
.#{$component}__day:not(.#{$component}__day--selected, .#{$component}__day--outside) { color: t.color('on-secondary-container'); }
}
&__cell--range-start { background-size: 50% 100%; background-position: var(--#{$component}-start); }
&__cell--range-end { background-size: 50% 100%; background-position: var(--#{$component}-end); }
&__cell--range-start#{&}__cell--range-end { background: none; }
&__cell--range:is(:last-child:not(&__cell--range-end), :first-child:not(&__cell--range-start))::before {
content: ''; position: absolute; top: 4px; width: var(--#{$component}-grid-inset); height: 40px;
background: t.color('secondary-container');
}
&__cell--range:last-child::before {
left: var(--#{$component}-bleed-last-left);
right: var(--#{$component}-bleed-last-right);
}
&__cell--range:first-child::before {
left: var(--#{$component}-bleed-first-left);
right: var(--#{$component}-bleed-first-right);
}
&__day {
position: relative; isolation: isolate; width: 100%; height: 48px; padding: 0; border: 0;
background: transparent; color: t.color('on-surface'); cursor: pointer;
@include m.typography('body-large');
&::before, &::after { content: ''; position: absolute; z-index: -1; inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: 40px; height: 40px; border-radius: 50%; box-sizing: border-box; }
--#{$component}-day-layer: #{t.color('on-surface-variant')};
&:hover:not(:disabled)::after { background: color-mix(in srgb, var(--#{$component}-day-layer) #{v.state('hover-state-layer-opacity') * 100%}, transparent); }
&:focus-visible { outline: none; &::after { background: color-mix(in srgb, var(--#{$component}-day-layer) #{v.state('focus-state-layer-opacity') * 100%}, transparent); outline: 3px solid t.color('secondary'); outline-offset: 2px; } }
&:active:not(:disabled)::after { background: color-mix(in srgb, var(--#{$component}-day-layer) #{v.state('pressed-state-layer-opacity') * 100%}, transparent); }
&--outside { color: t.alpha('on-surface', 0.38); }
&--today { color: t.color('primary'); &::before { border: 1px solid t.color('primary'); } }
&--highlight { text-decoration: underline; }
&--selected, &--selected:hover:not(:disabled) { color: t.color('on-primary'); --#{$component}-day-layer: #{t.color('on-primary')}; &::before { background: t.color('primary'); } }
&:disabled { opacity: 0.38; cursor: default; }
}
&__months, &__years { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 8px; padding: 16px 24px; }
&__years { position: relative; box-sizing: border-box; height: 336px; overflow-y: auto; overscroll-behavior: contain; }
&__month, &__year {
position: relative; isolation: isolate; min-width: 0; height: 48px; border: 0; background: transparent;
padding: 0;
color: t.color('on-surface-variant'); @include m.typography('body-large'); cursor: pointer;
&::before { content: ''; position: absolute; z-index: -1; width: 72px; max-width: 100%; height: 36px; inset: 50% auto auto 50%; transform: translate(-50%, -50%); border-radius: v.shape('full'); }
&:hover::before { background: t.alpha('on-surface', 0.08); }
&[aria-pressed='true'] { color: t.color('on-primary'); &::before { background: t.color('primary'); } }
&:focus-visible { outline: none; &::before { outline: 2px solid t.color('primary'); outline-offset: 2px; } }
}
&__fields { display: grid; gap: 16px; padding: 24px; }
&__field { display: flex; flex-direction: column; }
&__footer { display: flex; justify-content: flex-end; gap: 8px; padding: 4px 12px; }
&__prev svg, &__next svg { transform: var(--#{$component}-flip); }
&__cancel, &__confirm, &__save { @include m.typography('label-large'); padding: 0 12px; color: t.color('primary'); }
&__sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@keyframes #{$component}-appear { from { opacity: 0; } to { opacity: 1; } }
