/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.82 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-5c65e149.js'); const resources = require('./resources-247d05d5.js'); const dom = require('./dom-9ac0341c.js'); const interactive = require('./interactive-e294111f.js'); const Heading = require('./Heading-0cb5902d.js'); require('./locale-f2ebe4fa.js'); require('./number-364babbc.js'); require('./guid-8b6d6cb4.js'); const datePickerCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:inline-block;width:100%;overflow:visible;border-radius:0px;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-2);background-color:var(--calcite-ui-foreground-1);vertical-align:top}:host([scale=s]){max-width:216px}:host([scale=m]){max-width:286px}:host([scale=l]){max-width:398px}"; const DatePicker = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteDatePickerChange = index.createEvent(this, "calciteDatePickerChange", 7); this.calciteDatePickerRangeChange = index.createEvent(this, "calciteDatePickerRangeChange", 7); /** Localized string for "previous month" (used for aria label) * @default "Previous month" */ this.intlPrevMonth = resources.TEXT.prevMonth; /** Localized string for "next month" (used for aria label) * @default "Next month" */ this.intlNextMonth = resources.TEXT.nextMonth; /** Localized string for "year" (used for aria label) * @default "Year" */ this.intlYear = resources.TEXT.year; /** BCP 47 language tag for desired language and country format */ this.locale = document.documentElement.lang || "en"; /** specify the scale of the date picker */ this.scale = "m"; /** Range mode activation */ this.range = false; /** Disables the default behaviour on the third click of narrowing or extending the range and instead starts a new range. */ this.proximitySelectionDisabled = false; //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- this.keyUpHandler = (e) => { if (e.key === "Escape") { this.reset(); } }; this.monthHeaderSelectChange = (e) => { const date = new Date(e.detail); if (!this.range) { this.activeDate = date; } else { if (this.activeRange === "end") { this.activeEndDate = date; } else { this.activeStartDate = date; } this.mostRecentRangeValue = date; } }; this.monthActiveDateChange = (e) => { const date = new Date(e.detail); if (!this.range) { this.activeDate = date; } else { if (this.activeRange === "end") { this.activeEndDate = date; } else { this.activeStartDate = date; } this.mostRecentRangeValue = date; } }; this.monthHoverChange = (e) => { if (!this.startAsDate) { this.hoverRange = undefined; return; } const date = new Date(e.detail); this.hoverRange = { focused: this.activeRange || "start", start: this.startAsDate, end: this.endAsDate }; if (!this.proximitySelectionDisabled) { if (this.endAsDate) { const startDiff = resources.getDaysDiff(date, this.startAsDate); const endDiff = resources.getDaysDiff(date, this.endAsDate); if (endDiff > 0) { this.hoverRange.end = date; this.hoverRange.focused = "end"; } else if (startDiff < 0) { this.hoverRange.start = date; this.hoverRange.focused = "start"; } else if (startDiff > endDiff) { this.hoverRange.start = date; this.hoverRange.focused = "start"; } else { this.hoverRange.end = date; this.hoverRange.focused = "end"; } } else { if (date < this.startAsDate) { this.hoverRange = { focused: "start", start: date, end: this.startAsDate }; } else { this.hoverRange.end = date; this.hoverRange.focused = "end"; } } } else { if (!this.endAsDate) { if (date < this.startAsDate) { this.hoverRange = { focused: "start", start: date, end: this.startAsDate }; } else { this.hoverRange.end = date; this.hoverRange.focused = "end"; } } else { this.hoverRange = undefined; } } }; this.monthMouseOutChange = () => { if (this.hoverRange) { this.hoverRange = undefined; } }; /** * Reset active date and close */ this.reset = () => { var _a, _b, _c, _d, _e, _f; if (!Array.isArray(this.valueAsDate) && this.valueAsDate && ((_a = this.valueAsDate) === null || _a === void 0 ? void 0 : _a.getTime()) !== ((_b = this.activeDate) === null || _b === void 0 ? void 0 : _b.getTime())) { this.activeDate = new Date(this.valueAsDate); } if (this.startAsDate && ((_c = this.startAsDate) === null || _c === void 0 ? void 0 : _c.getTime()) !== ((_d = this.activeStartDate) === null || _d === void 0 ? void 0 : _d.getTime())) { this.activeStartDate = new Date(this.startAsDate); } if (this.endAsDate && ((_e = this.endAsDate) === null || _e === void 0 ? void 0 : _e.getTime()) !== ((_f = this.activeEndDate) === null || _f === void 0 ? void 0 : _f.getTime())) { this.activeEndDate = new Date(this.endAsDate); } }; /** * Event handler for when the selected date changes */ this.monthDateChange = (e) => { const date = new Date(e.detail); if (!this.range) { this.value = date ? resources.dateToISO(date) : ""; this.valueAsDate = date || null; this.activeDate = date || null; this.calciteDatePickerChange.emit(date); return; } if (!this.startAsDate || (!this.endAsDate && date < this.startAsDate)) { if (this.startAsDate) { this.setEndDate(new Date(this.startAsDate)); } if (this.activeRange == "end") { this.setEndDate(date); } else { this.setStartDate(date); } } else if (!this.endAsDate) { this.setEndDate(date); } else { if (!this.proximitySelectionDisabled) { if (this.activeRange) { if (this.activeRange == "end") { this.setEndDate(date); } else { this.setStartDate(date); } } else { const startDiff = resources.getDaysDiff(date, this.startAsDate); const endDiff = resources.getDaysDiff(date, this.endAsDate); if (endDiff === 0 || startDiff < 0) { this.setStartDate(date); } else if (startDiff === 0 || endDiff < 0) { this.setEndDate(date); } else if (startDiff < endDiff) { this.setStartDate(date); } else { this.setEndDate(date); } } } else { this.setStartDate(date); this.endAsDate = this.activeEndDate = this.end = undefined; } } this.calciteDatePickerChange.emit(date); }; } handleValueAsDate(date) { if (!Array.isArray(date) && date && date !== this.activeDate) { this.activeDate = date; } } handleRangeChange() { const { startAsDate: startDate, endAsDate: endDate } = this; this.activeEndDate = endDate; this.activeStartDate = startDate; } onMinChanged(min) { if (min) { this.minAsDate = resources.dateFromISO(min); } } onMaxChanged(max) { if (max) { this.maxAsDate = resources.dateFromISO(max); } } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { if (Array.isArray(this.value)) { this.valueAsDate = this.value.map((v) => resources.dateFromISO(v)); this.start = this.value[0]; this.end = this.value[1]; } else if (this.value) { this.valueAsDate = resources.dateFromISO(this.value); } if (this.start) { this.setStartAsDate(resources.dateFromISO(this.start)); } if (this.end) { this.setEndAsDate(resources.dateFromISO(this.end)); } if (this.min) { this.minAsDate = resources.dateFromISO(this.min); } if (this.max) { this.maxAsDate = resources.dateFromISO(this.max); } } async componentWillLoad() { await this.loadLocaleData(); this.onMinChanged(this.min); this.onMaxChanged(this.max); } render() { var _a; const date = resources.dateFromRange(this.range ? this.startAsDate : this.valueAsDate, this.minAsDate, this.maxAsDate); const activeStartDate = this.range ? this.getActiveStartDate(date, this.minAsDate, this.maxAsDate) : this.getActiveDate(date, this.minAsDate, this.maxAsDate); let activeDate = activeStartDate; const endDate = this.range ? resources.dateFromRange(this.endAsDate, this.minAsDate, this.maxAsDate) : null; const activeEndDate = this.getActiveEndDate(endDate, this.minAsDate, this.maxAsDate); if ((this.activeRange === "end" || (((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.focused) === "end" && (!this.proximitySelectionDisabled || endDate))) && activeEndDate) { activeDate = activeEndDate; } if (this.range && this.mostRecentRangeValue) { activeDate = this.mostRecentRangeValue; } const minDate = this.range && this.activeRange ? this.activeRange === "start" ? this.minAsDate : date || this.minAsDate : this.minAsDate; const maxDate = this.range && this.activeRange ? this.activeRange === "start" ? endDate || this.maxAsDate : this.maxAsDate : this.maxAsDate; return (index.h(index.Host, { onBlur: this.reset, onKeyUp: this.keyUpHandler, role: "application" }, this.renderCalendar(activeDate, maxDate, minDate, date, endDate))); } valueHandler(value) { if (Array.isArray(value)) { this.valueAsDate = value.map((v) => resources.dateFromISO(v)); this.start = value[0]; this.end = value[1]; } else if (value) { this.valueAsDate = resources.dateFromISO(value); this.start = ""; this.end = ""; } } startWatcher(start) { this.setStartAsDate(resources.dateFromISO(start)); } endWatcher(end) { this.setEndAsDate(resources.dateFromISO(end)); } async loadLocaleData() { const { locale } = this; this.localeData = await resources.getLocaleData(locale); } /** * Render calcite-date-picker-month-header and calcite-date-picker-month */ renderCalendar(activeDate, maxDate, minDate, date, endDate) { return (this.localeData && [ index.h("calcite-date-picker-month-header", { activeDate: activeDate, headingLevel: this.headingLevel || resources.HEADING_LEVEL, intlNextMonth: this.intlNextMonth, intlPrevMonth: this.intlPrevMonth, intlYear: this.intlYear, localeData: this.localeData, max: maxDate, min: minDate, onCalciteDatePickerSelect: this.monthHeaderSelectChange, scale: this.scale, selectedDate: this.activeRange === "end" ? endDate : date || new Date() }), index.h("calcite-date-picker-month", { activeDate: activeDate, endDate: this.range ? endDate : undefined, hoverRange: this.hoverRange, localeData: this.localeData, max: maxDate, min: minDate, onCalciteDatePickerActiveDateChange: this.monthActiveDateChange, onCalciteDatePickerHover: this.monthHoverChange, onCalciteDatePickerMouseOut: this.monthMouseOutChange, onCalciteDatePickerSelect: this.monthDateChange, scale: this.scale, selectedDate: this.activeRange === "end" ? endDate : date, startDate: this.range ? date : undefined }) ]); } /** * Update date instance of start if valid */ setStartAsDate(startDate, emit) { this.startAsDate = startDate; this.mostRecentRangeValue = this.startAsDate; if (emit) { this.calciteDatePickerRangeChange.emit({ startDate, endDate: this.endAsDate }); } } /** * Update date instance of end if valid */ setEndAsDate(endDate, emit) { this.endAsDate = endDate; this.mostRecentRangeValue = this.endAsDate; if (emit) { this.calciteDatePickerRangeChange.emit({ startDate: this.startAsDate, endDate }); } } setEndDate(date) { this.end = date ? resources.dateToISO(date) : ""; this.setEndAsDate(date, true); this.activeEndDate = date || null; } setStartDate(date) { this.start = date ? resources.dateToISO(date) : ""; this.setStartAsDate(date, true); this.activeStartDate = date || null; } /** * Get an active date using the value, or current date as default */ getActiveDate(value, min, max) { return resources.dateFromRange(this.activeDate, min, max) || value || resources.dateFromRange(new Date(), min, max); } getActiveStartDate(value, min, max) { return (resources.dateFromRange(this.activeStartDate, min, max) || value || resources.dateFromRange(new Date(), min, max)); } getActiveEndDate(value, min, max) { return (resources.dateFromRange(this.activeEndDate, min, max) || value || resources.dateFromRange(new Date(), min, max)); } static get assetsDirs() { return ["assets"]; } get el() { return index.getElement(this); } static get watchers() { return { "valueAsDate": ["handleValueAsDate"], "startAsDate": ["handleRangeChange"], "endAsDate": ["handleRangeChange"], "min": ["onMinChanged"], "max": ["onMaxChanged"], "value": ["valueHandler"], "start": ["startWatcher"], "end": ["endWatcher"], "locale": ["loadLocaleData"] }; } }; DatePicker.style = datePickerCss; const datePickerDayCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:-ms-flexbox;display:flex;min-width:0px;cursor:pointer;-ms-flex-pack:center;justify-content:center;color:var(--calcite-ui-text-3);width:14.2857142857%}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.day-v-wrapper{-ms-flex:1 1 auto;flex:1 1 auto}.day-wrapper{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center}.day{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-radius:9999px;font-size:var(--calcite-font-size--2);line-height:1rem;line-height:1;color:var(--calcite-ui-text-3);opacity:var(--calcite-ui-opacity-disabled);-webkit-transition-property:all;transition-property:all;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-duration:150ms;transition-duration:150ms;background:none;-webkit-box-shadow:0 0 0 2px transparent, 0 0 0 0px transparent;box-shadow:0 0 0 2px transparent, 0 0 0 0px transparent}.text{margin-top:1px;margin-right:0px;margin-bottom:0px;margin-left:1px}:host([scale=s]) .day-v-wrapper{padding-top:0.125rem;padding-bottom:0.125rem}:host([scale=s]) .day-wrapper{padding:0px}:host([scale=s]) .day{height:27px;width:27px;font-size:var(--calcite-font-size--2)}:host([scale=m]) .day-v-wrapper{padding-top:0.25rem;padding-bottom:0.25rem}:host([scale=m]) .day-wrapper{padding-left:0.25rem;padding-right:0.25rem}:host([scale=m]) .day{height:33px;width:33px;font-size:var(--calcite-font-size--1)}:host([scale=l]) .day-v-wrapper{padding-top:0.25rem;padding-bottom:0.25rem}:host([scale=l]) .day-wrapper{padding-left:0.25rem;padding-right:0.25rem}:host([scale=l]) .day{height:43px;width:43px;font-size:var(--calcite-font-size-0)}:host([current-month]) .day{opacity:1}:host(:hover:not([disabled])) .day,:host([active]:not([range])) .day{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}:host(:focus),:host([active]){outline:2px solid transparent;outline-offset:2px;z-index:1}:host(:focus:not([disabled])) .day{-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1), 0 0 0 4px var(--calcite-ui-brand);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1), 0 0 0 4px var(--calcite-ui-brand)}:host([selected]) .day{font-weight:var(--calcite-font-weight-medium);background-color:var(--calcite-ui-brand) !important;color:var(--calcite-ui-foreground-1) !important;z-index:1}:host([range][selected]) .day-wrapper{background-color:var(--calcite-ui-foreground-current)}:host([start-of-range]) .day-wrapper{border-start-start-radius:40%;border-end-start-radius:40%}:host([end-of-range]) .day-wrapper{border-start-end-radius:40%;border-end-end-radius:40%}:host([start-of-range]) :not(.calcite--rtl) .day-wrapper,:host([end-of-range]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 4px 0 var(--calcite-ui-foreground-1);box-shadow:inset 4px 0 var(--calcite-ui-foreground-1)}:host([start-of-range]) :not(.calcite--rtl) .day,:host([end-of-range]) .calcite--rtl .day{opacity:1}:host([start-of-range]:not(:focus)) :not(.calcite--rtl) .day,:host([end-of-range]:not(:focus)) .calcite--rtl .day{-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([end-of-range]) :not(.calcite--rtl) .day-wrapper,:host([start-of-range]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -4px 0 var(--calcite-ui-foreground-1);box-shadow:inset -4px 0 var(--calcite-ui-foreground-1)}:host([end-of-range]) :not(.calcite--rtl) .day,:host([start-of-range]) .calcite--rtl .day{opacity:1}:host([end-of-range]:not(:focus)) :not(.calcite--rtl) .day,:host([start-of-range]:not(:focus)) .calcite--rtl .day{-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([end-of-range][scale=l]) :not(.calcite--rtl) .day-wrapper,:host([start-of-range][scale=l]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -8px 0 var(--calcite-ui-foreground-1);box-shadow:inset -8px 0 var(--calcite-ui-foreground-1)}:host([start-of-range][scale=l]) :not(.calcite--rtl) .day-wrapper,:host([end-of-range][scale=l]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 8px 0 var(--calcite-ui-foreground-1);box-shadow:inset 8px 0 var(--calcite-ui-foreground-1)}:host([highlighted]) .day-wrapper{background-color:var(--calcite-ui-foreground-current)}:host([highlighted]) .day-wrapper .day{color:var(--calcite-ui-text-1)}:host([highlighted]:not([active]:focus)) .day{border-radius:0px;color:var(--calcite-ui-text-1)}:host([range-hover]:not([selected])) .day-wrapper{background-color:var(--calcite-ui-foreground-2)}:host([range-hover]:not([selected])) .day{border-radius:0px}:host([end-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host([start-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([start-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host([end-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, right top, left top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to left, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host(:hover[end-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host(:hover[start-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-1)), to(var(--calcite-ui-foreground-1)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host(:hover[start-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host(:hover[end-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, right top, left top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-1)), to(var(--calcite-ui-foreground-1)));background-image:linear-gradient(to left, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host(:hover[range-hover]:not([selected]).focused--end) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--start) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-current)), to(var(--calcite-ui-foreground-current)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current))}:host(:hover[range-hover]:not([selected]).focused--end) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--start) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--start) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--end) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2))}:host(:hover[range-hover]:not([selected]).focused--start) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--end) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-1)), color-stop(var(--calcite-ui-foreground-1)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2))}:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-1)), to(var(--calcite-ui-foreground-1)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1))}:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[start-of-range].hover--inside-range.focused--end) .day-wrapper,:host(:hover[end-of-range].hover--inside-range.focused--start) .day-wrapper{background-image:none}:host([start-of-range].hover--inside-range.focused--end) .day-wrapper,:host([end-of-range].hover--inside-range.focused--start) .day-wrapper{background-color:var(--calcite-ui-foreground-2)}:host([highlighted]:last-child) :not(.calcite--rtl) .day-wrapper,:host([range-hover]:last-child) :not(.calcite--rtl) .day-wrapper,:host([highlighted]:first-child) .calcite--rtl .day-wrapper,:host([range-hover]:first-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -4px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset -4px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([highlighted]:first-child) :not(.calcite--rtl) .day-wrapper,:host([range-hover]:first-child) :not(.calcite--rtl) .day-wrapper,:host([highlighted]:last-child) .calcite--rtl .day-wrapper,:host([range-hover]:last-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 4px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset 4px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=s][highlighted]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][range-hover]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][highlighted]:first-child) .calcite--rtl .day-wrapper,:host([scale=s][range-hover]:first-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -1px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset -1px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=s][highlighted]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][range-hover]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][highlighted]:last-child) .calcite--rtl .day-wrapper,:host([scale=s][range-hover]:last-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 1px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset 1px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=l][highlighted]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][range-hover]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][highlighted]:last-child) .calcite--rtl .day-wrapper,:host([scale=l][range-hover]:last-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 6px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset 6px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([highlighted]:first-child) .day-wrapper,:host([range-hover]:first-child) .day-wrapper{border-start-start-radius:45%;border-end-start-radius:45%}:host([highlighted]:last-child) .day-wrapper,:host([range-hover]:last-child) .day-wrapper{border-start-end-radius:45%;border-end-end-radius:45%}:host([scale=l][highlighted]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][range-hover]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][highlighted]:first-child) .calcite--rtl .day-wrapper,:host([scale=l][range-hover]:first-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -6px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset -6px 0px 0px 0px var(--calcite-ui-foreground-1)}@media (forced-colors: active){:host(:hover:not([disabled])) .day,:host([active]:not([range])) .day{border-radius:0px}:host([selected]){outline:2px solid canvasText;z-index:1}:host([selected]) .day{border-radius:0px;background-color:highlight}:host([range][selected]) .day-wrapper,:host([highlighted]) .day-wrapper,:host([range-hover]:not([selected])) .day-wrapper{background-color:highlight}:host([range][selected][start-of-range]) .day-wrapper,:host([range][selected][end-of-range]) .day-wrapper{background-color:canvas}}"; const DatePickerDay = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteDaySelect = index.createEvent(this, "calciteDaySelect", 7); this.calciteDayHover = index.createEvent(this, "calciteDayHover", 7); /** Date is outside of range and can't be selected */ this.disabled = false; /** Date is in the current month. */ this.currentMonth = false; /** Date is the current selected date of the picker */ this.selected = false; /** Date is currently highlighted as part of the range */ this.highlighted = false; /** Showing date range */ this.range = false; /** Date is the start of date range */ this.startOfRange = false; /** Date is the end of date range */ this.endOfRange = false; /** Date is being hovered and within the set range */ this.rangeHover = false; /** Date is actively in focus for keyboard navigation */ this.active = false; //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- this.onClick = () => { !this.disabled && this.calciteDaySelect.emit(); }; this.keyDownHandler = (e) => { const key = e.key; if (key === " " || key === "Enter") { !this.disabled && this.calciteDaySelect.emit(); } }; } mouseoverHandler() { this.calciteDayHover.emit({ disabled: this.disabled }); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- render() { const formattedDay = String(this.day) .split("") .map((i) => this.localeData.numerals[i]) .join(""); const dir = dom.getElementDir(this.el); return (index.h(index.Host, { onClick: this.onClick, onKeyDown: this.keyDownHandler, role: "gridcell" }, index.h("div", { class: { "day-v-wrapper": true, [dom.CSS_UTILITY.rtl]: dir === "rtl" } }, index.h("div", { class: "day-wrapper" }, index.h("span", { class: "day" }, index.h("span", { class: "text" }, formattedDay)))))); } componentDidRender() { interactive.updateHostInteraction(this, this.isTabbable); } isTabbable() { return this.active; } get el() { return index.getElement(this); } }; DatePickerDay.style = datePickerDayCss; const datePickerMonthCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}.calender{margin-bottom:0.25rem}.week-headers{display:-ms-flexbox;display:flex;border-width:0px;border-top-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem}.week-header{text-align:center;font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-3);width:14.2857142857%}:host([scale=s]) .week-header{padding-left:0px;padding-right:0px;padding-top:0.5rem;padding-bottom:0.75rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]) .week-header{padding-left:0px;padding-right:0px;padding-top:0.75rem;padding-bottom:1rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=l]) .week-header{padding-left:0px;padding-right:0px;padding-top:1rem;padding-bottom:1.25rem;font-size:var(--calcite-font-size--1);line-height:1rem}.week-days{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;padding-top:0px;padding-bottom:0px;padding-left:6px;padding-right:6px}.week-days:focus{outline:2px solid transparent;outline-offset:2px}"; const DatePickerMonth = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteDatePickerSelect = index.createEvent(this, "calciteDatePickerSelect", 7); this.calciteDatePickerHover = index.createEvent(this, "calciteDatePickerHover", 7); this.calciteDatePickerActiveDateChange = index.createEvent(this, "calciteDatePickerActiveDateChange", 7); this.calciteDatePickerMouseOut = index.createEvent(this, "calciteDatePickerMouseOut", 7); /** Date currently active.*/ this.activeDate = new Date(); //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- this.keyDownHandler = (e) => { const isRTL = this.el.dir === "rtl"; switch (e.key) { case "ArrowUp": e.preventDefault(); this.addDays(-7); break; case "ArrowRight": e.preventDefault(); this.addDays(isRTL ? -1 : 1); break; case "ArrowDown": e.preventDefault(); this.addDays(7); break; case "ArrowLeft": e.preventDefault(); this.addDays(isRTL ? 1 : -1); break; case "PageUp": e.preventDefault(); this.addMonths(-1); break; case "PageDown": e.preventDefault(); this.addMonths(1); break; case "Home": e.preventDefault(); this.activeDate.setDate(1); this.addDays(); break; case "End": e.preventDefault(); this.activeDate.setDate(new Date(this.activeDate.getFullYear(), this.activeDate.getMonth() + 1, 0).getDate()); this.addDays(); break; case "Enter": case " ": e.preventDefault(); break; case "Tab": this.activeFocus = false; } }; /** * Once user is not interacting via keyboard, * disable auto focusing of active date */ this.disableActiveFocus = () => { this.activeFocus = false; }; this.dayHover = (e) => { const target = e.target; if (e.detail.disabled) { this.calciteDatePickerMouseOut.emit(); } else { this.calciteDatePickerHover.emit(target.value); } }; this.daySelect = (e) => { const target = e.target; this.calciteDatePickerSelect.emit(target.value); }; } mouseoutHandler() { this.calciteDatePickerMouseOut.emit(); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- render() { const month = this.activeDate.getMonth(); const year = this.activeDate.getFullYear(); const startOfWeek = this.localeData.weekStart % 7; const { abbreviated, short, narrow } = this.localeData.days; const weekDays = this.scale === "s" ? narrow || short || abbreviated : short || abbreviated || narrow; const adjustedWeekDays = [...weekDays.slice(startOfWeek, 7), ...weekDays.slice(0, startOfWeek)]; const curMonDays = this.getCurrentMonthDays(month, year); const prevMonDays = this.getPrevMonthdays(month, year, startOfWeek); const nextMonDays = this.getNextMonthDays(month, year, startOfWeek); const days = [ ...prevMonDays.map((day) => { const date = new Date(year, month - 1, day); return this.renderDateDay(false, day, date); }), ...curMonDays.map((day) => { const date = new Date(year, month, day); const active = resources.sameDate(date, this.activeDate); return this.renderDateDay(active, day, date, true, true); }), ...nextMonDays.map((day) => { const date = new Date(year, month + 1, day); return this.renderDateDay(false, day, date); }) ]; const weeks = []; for (let i = 0; i < days.length; i += 7) { weeks.push(days.slice(i, i + 7)); } return (index.h(index.Host, { onFocusOut: this.disableActiveFocus, onKeyDown: this.keyDownHandler }, index.h("div", { class: "calender", role: "grid" }, index.h("div", { class: "week-headers", role: "row" }, adjustedWeekDays.map((weekday) => (index.h("span", { class: "week-header", role: "columnheader" }, weekday)))), weeks.map((days) => (index.h("div", { class: "week-days", role: "row" }, days)))))); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- /** * Add n months to the current month */ addMonths(step) { const nextDate = new Date(this.activeDate); nextDate.setMonth(this.activeDate.getMonth() + step); this.calciteDatePickerActiveDateChange.emit(resources.dateFromRange(nextDate, this.min, this.max)); this.activeFocus = true; } /** * Add n days to the current date */ addDays(step = 0) { const nextDate = new Date(this.activeDate); nextDate.setDate(this.activeDate.getDate() + step); this.calciteDatePickerActiveDateChange.emit(resources.dateFromRange(nextDate, this.min, this.max)); this.activeFocus = true; } /** * Get dates for last days of the previous month */ getPrevMonthdays(month, year, startOfWeek) { const lastDate = new Date(year, month, 0); const date = lastDate.getDate(); const day = lastDate.getDay(); const days = []; if (day - 6 === startOfWeek) { return days; } for (let i = Math.abs(lastDate.getDay() - startOfWeek); i >= 0; i--) { days.push(date - i); } return days; } /** * Get dates for the current month */ getCurrentMonthDays(month, year) { const num = new Date(year, month + 1, 0).getDate(); const days = []; for (let i = 0; i < num; i++) { days.push(i + 1); } return days; } /** * Get dates for first days of the next month */ getNextMonthDays(month, year, startOfWeek) { const endDay = new Date(year, month + 1, 0).getDay(); const days = []; if (endDay === (startOfWeek + 6) % 7) { return days; } for (let i = 0; i < (6 - (endDay - startOfWeek)) % 7; i++) { days.push(i + 1); } return days; } /** * Determine if the date is in between the start and end dates */ betweenSelectedRange(date) { return !!(this.startDate && this.endDate && date > this.startDate && date < this.endDate && !this.isRangeHover(date)); } /** * Determine if the date should be in selected state */ isSelected(date) { return !!(resources.sameDate(date, this.selectedDate) || (this.startDate && resources.sameDate(date, this.startDate)) || (this.endDate && resources.sameDate(date, this.endDate))); } /** * Determine if the date is the start of the date range */ isStartOfRange(date) { return !!(this.startDate && !resources.sameDate(this.startDate, this.endDate) && resources.sameDate(this.startDate, date) && !this.isEndOfRange(date)); } isEndOfRange(date) { return !!((this.endDate && !resources.sameDate(this.startDate, this.endDate) && resources.sameDate(this.endDate, date)) || (!this.endDate && this.hoverRange && resources.sameDate(this.startDate, this.hoverRange.end) && resources.sameDate(date, this.hoverRange.end))); } /** * Render calcite-date-picker-day */ renderDateDay(active, day, date, currentMonth, ref) { var _a; const isFocusedOnStart = this.isFocusedOnStart(); const isHoverInRange = this.isHoverInRange() || (!this.endDate && this.hoverRange && resources.sameDate((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.end, this.startDate)); return (index.h("calcite-date-picker-day", { active: active, class: { "hover--inside-range": this.startDate && isHoverInRange, "hover--outside-range": this.startDate && !isHoverInRange, "focused--start": isFocusedOnStart, "focused--end": !isFocusedOnStart }, currentMonth: currentMonth, day: day, disabled: !resources.inRange(date, this.min, this.max), endOfRange: this.isEndOfRange(date), highlighted: this.betweenSelectedRange(date), key: date.toDateString(), localeData: this.localeData, onCalciteDayHover: this.dayHover, onCalciteDaySelect: this.daySelect, range: !!this.startDate && !!this.endDate && !resources.sameDate(this.startDate, this.endDate), rangeHover: this.isRangeHover(date), ref: (el) => { // when moving via keyboard, focus must be updated on active date if (ref && active && this.activeFocus) { el === null || el === void 0 ? void 0 : el.focus(); } }, scale: this.scale, selected: this.isSelected(date), startOfRange: this.isStartOfRange(date), value: date })); } isFocusedOnStart() { var _a; return ((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.focused) === "start"; } isHoverInRange() { if (!this.hoverRange) { return false; } const { start, end } = this.hoverRange; return !!((!this.isFocusedOnStart() && this.startDate && (!this.endDate || end < this.endDate)) || (this.isFocusedOnStart() && this.startDate && start > this.startDate)); } isRangeHover(date) { if (!this.hoverRange) { return false; } const { start, end } = this.hoverRange; const isStart = this.isFocusedOnStart(); const insideRange = this.isHoverInRange(); const cond1 = insideRange && ((!isStart && date > this.startDate && (date < end || resources.sameDate(date, end))) || (isStart && date < this.endDate && (date > start || resources.sameDate(date, start)))); const cond2 = !insideRange && ((!isStart && date >= this.endDate && (date < end || resources.sameDate(date, end))) || (isStart && (date < this.startDate || (this.endDate && resources.sameDate(date, this.startDate))) && (date > start || resources.sameDate(date, start)))); return cond1 || cond2; } get el() { return index.getElement(this); } }; DatePickerMonth.style = datePickerMonthCss; const datePickerMonthHeaderCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}.header{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem}:host([scale=s]) .text{margin-top:0.5rem;margin-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=s]) .chevron{height:2.25rem}:host([scale=m]) .text{margin-top:0.75rem;margin-bottom:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([scale=m]) .chevron{height:3rem}:host([scale=l]) .text{margin-top:1rem;margin-bottom:1rem;font-size:var(--calcite-font-size-1);line-height:1.5rem}:host([scale=l]) .chevron{height:3.5rem}.chevron{margin-left:-0.25rem;margin-right:-0.25rem;-webkit-box-sizing:content-box;box-sizing:content-box;display:-ms-flexbox;display:flex;-ms-flex-positive:0;flex-grow:0;cursor:pointer;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-style:none;background-color:var(--calcite-ui-foreground-1);padding-left:0.25rem;padding-right:0.25rem;color:var(--calcite-ui-text-3);outline:2px solid transparent;outline-offset:2px;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;width:14.2857142857%}.chevron:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.chevron:hover,.chevron:focus{background-color:var(--calcite-ui-foreground-2);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}.chevron:active{background-color:var(--calcite-ui-foreground-3)}.chevron[aria-disabled=true]{pointer-events:none;opacity:0}.text{margin-top:auto;margin-bottom:auto;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;text-align:center;line-height:1}.text-nreverse{-ms-flex-direction:row-reverse;flex-direction:row-reverse}.month,.year,.suffix{margin-left:0.25rem;margin-right:0.25rem;margin-top:auto;margin-bottom:auto;display:inline-block;background-color:var(--calcite-ui-foreground-1);font-weight:var(--calcite-font-weight-medium);line-height:1.25;color:var(--calcite-ui-text-1);font-size:inherit}.year{position:relative;width:3rem;border-style:none;background-color:transparent;text-align:center;font-family:inherit;outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;z-index:2}.year:hover{-webkit-transition-duration:100ms;transition-duration:100ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-property:outline-color;transition-property:outline-color;outline:2px solid var(--calcite-ui-border-2);outline-offset:2px}.year:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.year--suffix{width:4rem;text-align:left}.year-wrap{position:relative}.suffix{position:absolute;top:0px;left:0px;width:4rem;white-space:nowrap;text-align:left}.suffix__invisible{visibility:hidden}"; const DatePickerMonthHeader = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteDatePickerSelect = index.createEvent(this, "calciteDatePickerSelect", 7); //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- /** * Increment year on UP/DOWN keys */ this.onYearKey = (e) => { const localizedYear = e.target.value; switch (e.key) { case "ArrowDown": e.preventDefault(); this.setYear({ localizedYear, offset: -1 }); break; case "ArrowUp": e.preventDefault(); this.setYear({ localizedYear, offset: 1 }); break; } }; this.onYearChange = (event) => { this.setYear({ localizedYear: event.target.value }); }; this.onYearInput = (event) => { this.setYear({ localizedYear: event.target.value, commit: false }); }; this.prevMonthClick = (e) => { this.handleArrowClick(e, this.prevMonthDate); }; this.prevMonthKeydown = (e) => { const key = e.key; if (key === " " || key === "Enter") { this.prevMonthClick(e); } }; this.nextMonthClick = (e) => { this.handleArrowClick(e, this.nextMonthDate); }; this.nextMonthKeydown = (e) => { const key = e.key; if (key === " " || key === "Enter") { this.nextMonthClick(e); } }; /* * Update active month on clicks of left/right arrows */ this.handleArrowClick = (e, date) => { e === null || e === void 0 ? void 0 : e.preventDefault(); e.stopPropagation(); this.calciteDatePickerSelect.emit(date); }; } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { this.setNextPrevMonthDates(); } render() { return index.h("div", { class: "header" }, this.renderContent()); } renderContent() { var _a; if (!this.activeDate || !this.localeData) { return null; } const activeMonth = this.activeDate.getMonth(); const { months, unitOrder } = this.localeData; const localizedMonth = (months.wide || months.narrow || months.abbreviated)[activeMonth]; const localizedYear = resources.localizeNumber(this.activeDate.getFullYear(), this.localeData); const iconScale = this.scale === "l" ? "m" : "s"; const order = resources.getOrder(unitOrder); const reverse = order.indexOf("y") < order.indexOf("m"); const suffix = (_a = this.localeData.year) === null || _a === void 0 ? void 0 : _a.suffix; return (index.h(index.Fragment, null, index.h("a", { "aria-disabled": (this.prevMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlPrevMonth, class: "chevron", href: "#", onClick: this.prevMonthClick, onKeyDown: this.prevMonthKeydown, role: "button", tabindex: this.prevMonthDate.getMonth() === activeMonth ? -1 : 0 }, index.h("calcite-icon", { "flip-rtl": true, icon: "chevron-left", scale: iconScale })), index.h("div", { class: { text: true, "text--reverse": reverse } }, index.h(Heading.Heading, { class: "month", level: this.headingLevel }, localizedMonth), index.h("span", { class: "year-wrap" }, index.h("input", { "aria-label": this.intlYear, class: { year: true, "year--suffix": !!suffix }, inputmode: "numeric", maxlength: "4", minlength: "1", onChange: this.onYearChange, onInput: this.onYearInput, onKeyDown: this.onYearKey, pattern: "\\d*", ref: (el) => (this.yearInput = el), type: "text", value: localizedYear }), suffix && (index.h("span", { class: "suffix" }, index.h("span", { "aria-hidden": "true", class: "suffix__invisible" }, localizedYear), " " + suffix)))), index.h("a", { "aria-disabled": (this.nextMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlNextMonth, class: "chevron", href: "#", onClick: this.nextMonthClick, onKeyDown: this.nextMonthKeydown, role: "button", tabindex: this.nextMonthDate.getMonth() === activeMonth ? -1 : 0 }, index.h("calcite-icon", { "flip-rtl": true, icon: "chevron-right", scale: iconScale })))); } setNextPrevMonthDates() { if (!this.activeDate) { return; } this.nextMonthDate = resources.dateFromRange(resources.nextMonth(this.activeDate), this.min, this.max); this.prevMonthDate = resources.dateFromRange(resources.prevMonth(this.activeDate), this.min, this.max); } getInRangeDate({ localizedYear, offset = 0 }) { const { min, max, activeDate, localeData } = this; const parsedYear = resources.parseNumber(localizedYear, localeData); const length = parsedYear.toString().length; const year = isNaN(parsedYear) ? false : parsedYear + offset; const inRange = year && (!min || min.getFullYear() <= year) && (!max || max.getFullYear() >= year); // if you've supplied a year and it's in range if (year && inRange && length === localizedYear.length) { const nextDate = new Date(activeDate); nextDate.setFullYear(year); return resources.dateFromRange(nextDate, min, max); } } /** * Parse localized year string from input, * set to active if in range */ setYear({ localizedYear, commit = true, offset = 0 }) { const { yearInput, activeDate, localeData } = this; const inRangeDate = this.getInRangeDate({ localizedYear, offset }); // if you've supplied a year and it's in range, update active date if (inRangeDate) { this.calciteDatePickerSelect.emit(inRangeDate); } if (commit) { yearInput.value = resources.localizeNumber((inRangeDate || activeDate).getFullYear(), localeData); } } get el() { return index.getElement(this); } static get watchers() { return { "min": ["setNextPrevMonthDates"], "max": ["setNextPrevMonthDates"], "activeDate": ["setNextPrevMonthDates"] }; } }; DatePickerMonthHeader.style = datePickerMonthHeaderCss; exports.calcite_date_picker = DatePicker; exports.calcite_date_picker_day = DatePickerDay; exports.calcite_date_picker_month = DatePickerMonth; exports.calcite_date_picker_month_header = DatePickerMonthHeader;