UNPKG

@esri/calcite-components

Version:

Web Components for Esri's Calcite Design System.

892 lines (881 loc) • 62 kB
/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.5.0-next.4 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-55f8a3b7.js'); const utils = require('./utils-75548d4a.js'); const loadable = require('./loadable-53f729bb.js'); const locale = require('./locale-fc347462.js'); const t9n = require('./t9n-14d528c4.js'); const dom = require('./dom-18ca68ff.js'); const interactive = require('./interactive-26294f2c.js'); const key = require('./key-2ce02f02.js'); const resources = require('./resources-45d84c94.js'); const Heading = require('./Heading-e1a3c7e4.js'); require('./observers-83b3999d.js'); require('./guid-db20443e.js'); require('./browser-28ea2ce1.js'); const HEADING_LEVEL = 2; const DATE_PICKER_FORMAT_OPTIONS = { dateStyle: "full" }; const datePickerCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host{position:relative;display:inline-block;inline-size:100%;overflow:visible;border-radius:0px;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-1);background-color:var(--calcite-ui-foreground-1);vertical-align:top}:host([scale=s]){max-inline-size:216px}:host([scale=m]){max-inline-size:286px}:host([scale=l]){max-inline-size:398px}"; const DatePicker = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteDatePickerChange = index.createEvent(this, "calciteDatePickerChange", 6); this.calciteDatePickerRangeChange = index.createEvent(this, "calciteDatePickerRangeChange", 6); //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- this.keyDownHandler = (event) => { if (event.key === "Escape") { this.reset(); } }; this.monthHeaderSelectChange = (event) => { const date = new Date(event.detail); if (!this.range) { this.activeDate = date; } else { if (this.activeRange === "end") { this.activeEndDate = date; } else { this.activeStartDate = date; } this.mostRecentRangeValue = date; } }; this.monthActiveDateChange = (event) => { const date = new Date(event.detail); if (!this.range) { this.activeDate = date; } else { if (this.activeRange === "end") { this.activeEndDate = date; } else { this.activeStartDate = date; } this.mostRecentRangeValue = date; } }; this.monthHoverChange = (event) => { if (!this.range) { this.hoverRange = undefined; return; } const { valueAsDate } = this; const start = Array.isArray(valueAsDate) && valueAsDate[0]; const end = Array.isArray(valueAsDate) && valueAsDate[1]; const date = new Date(event.detail); this.hoverRange = { focused: this.activeRange || "start", start, end }; if (!this.proximitySelectionDisabled) { if (end) { const startDiff = utils.getDaysDiff(date, start); const endDiff = utils.getDaysDiff(date, end); 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 (start) { if (date < start) { this.hoverRange = { focused: "start", start: date, end: start }; } else { this.hoverRange.end = date; this.hoverRange.focused = "end"; } } } } else { if (!end) { if (date < start) { this.hoverRange = { focused: "start", start: date, end: start }; } else { this.hoverRange.end = date; this.hoverRange.focused = "end"; } } else { this.hoverRange = undefined; } } event.stopPropagation(); }; this.monthMouseOutChange = () => { if (this.hoverRange) { this.hoverRange = undefined; } }; /** * Reset active date and close */ this.reset = () => { const { valueAsDate } = this; if (!Array.isArray(valueAsDate) && valueAsDate && valueAsDate?.getTime() !== this.activeDate?.getTime()) { this.activeDate = new Date(valueAsDate); } if (Array.isArray(valueAsDate)) { if (valueAsDate[0] && valueAsDate[0]?.getTime() !== (this.activeStartDate instanceof Date && this.activeStartDate?.getTime())) { this.activeStartDate = new Date(valueAsDate[0]); } if (valueAsDate[1] && valueAsDate[1]?.getTime() !== (this.activeStartDate instanceof Date && this.activeEndDate?.getTime())) { this.activeEndDate = new Date(valueAsDate[1]); } } }; /** * Event handler for when the selected date changes * * @param event */ this.monthDateChange = (event) => { const date = new Date(event.detail); const isoDate = utils.dateToISO(date); if (!this.range && isoDate === utils.dateToISO(this.valueAsDate)) { return; } if (!this.range) { this.value = isoDate || ""; this.valueAsDate = date || null; this.activeDate = date || null; this.calciteDatePickerChange.emit(); return; } const start = this.getStartDate(); const end = this.getEndDate(); if (!start || (!end && date < start)) { if (start) { this.setEndDate(new Date(start)); } if (this.activeRange == "end") { this.setEndDate(date); } else { this.setStartDate(date); } } else if (!end) { this.setEndDate(date); } else { if (!this.proximitySelectionDisabled) { if (this.activeRange) { if (this.activeRange == "end") { this.setEndDate(date); } else { this.setStartDate(date); } } else { const startDiff = utils.getDaysDiff(date, start); const endDiff = utils.getDaysDiff(date, end); 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.calciteDatePickerChange.emit(); }; this.activeDate = undefined; this.activeRange = undefined; this.value = undefined; this.headingLevel = undefined; this.valueAsDate = undefined; this.minAsDate = undefined; this.maxAsDate = undefined; this.min = undefined; this.max = undefined; this.numberingSystem = undefined; this.scale = "m"; this.range = false; this.proximitySelectionDisabled = false; this.messageOverrides = undefined; this.messages = undefined; this.activeEndDate = undefined; this.activeStartDate = undefined; this.dateTimeFormat = undefined; this.defaultMessages = undefined; this.effectiveLocale = ""; this.endAsDate = undefined; this.hoverRange = undefined; this.localeData = undefined; this.startAsDate = undefined; } activeDateWatcher(newActiveDate) { if (this.activeRange === "end") { this.activeEndDate = newActiveDate; } } valueAsDateWatcher(newValueAsDate) { if (this.range && Array.isArray(newValueAsDate)) { const { activeStartDate, activeEndDate } = this; const newActiveStartDate = newValueAsDate[0]; const newActiveEndDate = newValueAsDate[1]; this.activeStartDate = activeStartDate !== newActiveStartDate && newActiveStartDate; this.activeEndDate = activeEndDate !== newActiveEndDate && newActiveEndDate; } else if (newValueAsDate && newValueAsDate !== this.activeDate) { this.activeDate = newValueAsDate; } } onMinChanged(min) { if (min) { this.minAsDate = utils.dateFromISO(min); } } onMaxChanged(max) { if (max) { this.maxAsDate = utils.dateFromISO(max); } } onMessagesChange() { /* wired up by t9n util */ } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** Sets focus on the component's first focusable element. */ async setFocus() { await loadable.componentLoaded(this); this.el.focus(); } // -------------------------------------------------------------------------- // // Lifecycle // // -------------------------------------------------------------------------- connectedCallback() { locale.connectLocalized(this); t9n.connectMessages(this); if (Array.isArray(this.value)) { this.valueAsDate = utils.getValueAsDateRange(this.value); } else if (this.value) { this.valueAsDate = utils.dateFromISO(this.value); } if (this.min) { this.minAsDate = utils.dateFromISO(this.min); } if (this.max) { this.maxAsDate = utils.dateFromISO(this.max); } } disconnectedCallback() { locale.disconnectLocalized(this); t9n.disconnectMessages(this); } async componentWillLoad() { loadable.setUpLoadableComponent(this); await this.loadLocaleData(); this.onMinChanged(this.min); this.onMaxChanged(this.max); await t9n.setUpMessages(this); } componentDidLoad() { loadable.setComponentLoaded(this); } render() { const date = utils.dateFromRange(this.range && Array.isArray(this.valueAsDate) ? this.valueAsDate[0] : this.valueAsDate, this.minAsDate, this.maxAsDate); let activeDate = this.getActiveDate(date, this.minAsDate, this.maxAsDate); const endDate = this.range && Array.isArray(this.valueAsDate) ? utils.dateFromRange(this.valueAsDate[1], this.minAsDate, this.maxAsDate) : null; const activeEndDate = this.getActiveEndDate(endDate, this.minAsDate, this.maxAsDate); if ((this.activeRange === "end" || (this.hoverRange?.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, onKeyDown: this.keyDownHandler }, this.renderCalendar(activeDate, maxDate, minDate, date, endDate))); } effectiveLocaleChange() { t9n.updateMessages(this, this.effectiveLocale); } valueHandler(value) { if (Array.isArray(value)) { this.valueAsDate = utils.getValueAsDateRange(value); } else if (value) { this.valueAsDate = utils.dateFromISO(value); } } async loadLocaleData() { locale.numberStringFormatter.numberFormatOptions = { numberingSystem: this.numberingSystem, locale: this.effectiveLocale, useGrouping: false }; this.localeData = await utils.getLocaleData(this.effectiveLocale); this.dateTimeFormat = locale.getDateTimeFormat(this.effectiveLocale, DATE_PICKER_FORMAT_OPTIONS); } /** * Render calcite-date-picker-month-header and calcite-date-picker-month * * @param activeDate * @param maxDate * @param minDate * @param date * @param endDate */ renderCalendar(activeDate, maxDate, minDate, date, endDate) { return (this.localeData && [ index.h("calcite-date-picker-month-header", { activeDate: activeDate, headingLevel: this.headingLevel || HEADING_LEVEL, localeData: this.localeData, max: maxDate, messages: this.messages, min: minDate, onCalciteInternalDatePickerSelect: this.monthHeaderSelectChange, scale: this.scale, selectedDate: this.activeRange === "end" ? endDate : date || new Date() }), index.h("calcite-date-picker-month", { activeDate: activeDate, dateTimeFormat: this.dateTimeFormat, endDate: this.range ? endDate : undefined, hoverRange: this.hoverRange, localeData: this.localeData, max: maxDate, min: minDate, onCalciteInternalDatePickerActiveDateChange: this.monthActiveDateChange, onCalciteInternalDatePickerHover: this.monthHoverChange, onCalciteInternalDatePickerMouseOut: this.monthMouseOutChange, onCalciteInternalDatePickerSelect: this.monthDateChange, scale: this.scale, selectedDate: this.activeRange === "end" ? endDate : date, startDate: this.range ? date : undefined }) ]); } getEndDate() { return (Array.isArray(this.valueAsDate) && this.valueAsDate[1]) || undefined; } setEndDate(date) { const startDate = this.getStartDate(); const newEndDate = date ? utils.setEndOfDay(date) : date; this.value = [utils.dateToISO(startDate), utils.dateToISO(date)]; this.valueAsDate = [startDate, date]; this.mostRecentRangeValue = newEndDate; this.calciteDatePickerRangeChange.emit(); this.activeEndDate = date || null; } getStartDate() { return Array.isArray(this.valueAsDate) && this.valueAsDate[0]; } setStartDate(date) { const endDate = this.getEndDate(); this.value = [utils.dateToISO(date), utils.dateToISO(endDate)]; this.valueAsDate = [date, endDate]; this.mostRecentRangeValue = date; this.calciteDatePickerRangeChange.emit(); this.activeStartDate = date || null; } /** * Get an active date using the value, or current date as default * * @param value * @param min * @param max */ getActiveDate(value, min, max) { return utils.dateFromRange(this.activeDate, min, max) || value || utils.dateFromRange(new Date(), min, max); } getActiveEndDate(value, min, max) { return (utils.dateFromRange(this.activeEndDate, min, max) || value || utils.dateFromRange(new Date(), min, max)); } static get delegatesFocus() { return true; } static get assetsDirs() { return ["assets"]; } get el() { return index.getElement(this); } static get watchers() { return { "activeDate": ["activeDateWatcher"], "valueAsDate": ["valueAsDateWatcher"], "min": ["onMinChanged"], "max": ["onMaxChanged"], "messageOverrides": ["onMessagesChange"], "effectiveLocale": ["effectiveLocaleChange", "loadLocaleData"], "value": ["valueHandler"] }; } }; DatePicker.style = datePickerCss; const datePickerDayCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:flex;cursor:pointer;color:var(--calcite-ui-text-3)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.day-v-wrapper{flex:1 1 auto}.day-wrapper{display:flex;flex-direction:column;align-items:center}.day{display:flex;align-items: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);outline-color:transparent;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;background:none;box-shadow:0 0 0 2px transparent}.text{margin-block:1px 0px;margin-inline-start:0px}:host([scale=s]) .day-v-wrapper{padding-block:0.125rem}:host([scale=s]) .day-wrapper{padding:0px}:host([scale=s]) .day{block-size:27px;inline-size:27px;font-size:var(--calcite-font-size--2)}:host([scale=m]) .day-v-wrapper{padding-block:0.25rem}:host([scale=m]) .day-wrapper{padding-inline:0.25rem}:host([scale=m]) .day{block-size:33px;inline-size:33px;font-size:var(--calcite-font-size--1)}:host([scale=l]) .day-v-wrapper{padding-block:0.25rem}:host([scale=l]) .day-wrapper{padding-inline:0.25rem}:host([scale=l]) .day{block-size:43px;inline-size: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}:host(:focus:not([disabled])) .day{outline:2px solid var(--calcite-ui-focus-color, var(--calcite-ui-brand));outline-offset:calc(\n 2px *\n calc(\n 1 -\n 2 * clamp(\n 0,\n var(--calcite-ui-focus-offset-invert),\n 1\n )\n )\n );box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([selected]) .day{font-weight:var(--calcite-font-weight-medium);background-color:var(--calcite-ui-brand) !important;color:var(--calcite-ui-foreground-1) !important}: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{box-shadow:inset 4px 0 var(--calcite-ui-foreground-1)}:host([start-of-range]) .calcite--rtl .day-wrapper{box-shadow:inset -4px 0 var(--calcite-ui-foreground-1)}:host([start-of-range]) .day{opacity:1}:host([end-of-range]) :not(.calcite--rtl) .day-wrapper{box-shadow:inset -4px 0 var(--calcite-ui-foreground-1)}:host([end-of-range]) .calcite--rtl .day-wrapper{box-shadow:inset 4px 0 var(--calcite-ui-foreground-1)}:host([end-of-range]) .day{opacity:1}:host([start-of-range]:not(:focus)) :not(.calcite--rtl) .day,:host([end-of-range]:not(:focus)) :not(.calcite--rtl) .day{box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([start-of-range]:not(:focus)) .calcite--rtl .day,:host([end-of-range]:not(:focus)) .calcite--rtl .day{box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([start-of-range][scale=l]) :not(.calcite--rtl) .day-wrapper{box-shadow:inset 8px 0 var(--calcite-ui-foreground-1)}:host([start-of-range][scale=l]) .calcite--rtl .day-wrapper{box-shadow:inset -8px 0 var(--calcite-ui-foreground-1)}:host([end-of-range][scale=l]) :not(.calcite--rtl) .day-wrapper{box-shadow:inset -8px 0 var(--calcite-ui-foreground-1)}:host([end-of-range][scale=l]) .calcite--rtl .day-wrapper{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{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([start-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper{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;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]) .calcite--rtl .day-wrapper{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;box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([end-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper{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;box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([end-of-range][range-hover]) .calcite--rtl .day-wrapper{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;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: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;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: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;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--start) :not(.calcite--rtl) .day-wrapper{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) .calcite--rtl .day-wrapper{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--start) .day{border-radius:9999px;opacity:1;box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--end) :not(.calcite--rtl) .day-wrapper{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) .calcite--rtl .day-wrapper{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--end) .day{border-radius:9999px;opacity: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: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;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: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;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][range-edge=end]) :not(.calcite--rtl) .day-wrapper,:host([range-hover][range-edge=end]) :not(.calcite--rtl) .day-wrapper,:host([highlighted][range-edge=start]) .calcite--rtl .day-wrapper,:host([range-hover][range-edge=start]) .calcite--rtl .day-wrapper{box-shadow:inset -4px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([highlighted][range-edge=start]) :not(.calcite--rtl) .day-wrapper,:host([range-hover][range-edge=start]) :not(.calcite--rtl) .day-wrapper,:host([highlighted][range-edge=end]) .calcite--rtl .day-wrapper,:host([range-hover][range-edge=end]) .calcite--rtl .day-wrapper{box-shadow:inset 4px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=s][highlighted][range-edge=end]) :not(.calcite--rtl) .day-wrapper,:host([scale=s][range-hover][range-edge=end]) :not(.calcite--rtl) .day-wrapper,:host([scale=s][highlighted][range-edge=start]) .calcite--rtl .day-wrapper,:host([scale=s][range-hover][range-edge=start]) .calcite--rtl .day-wrapper{box-shadow:inset -1px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=s][highlighted][range-edge=start]) :not(.calcite--rtl) .day-wrapper,:host([scale=s][range-hover][range-edge=start]) :not(.calcite--rtl) .day-wrapper,:host([scale=s][highlighted][range-edge=end]) .calcite--rtl .day-wrapper,:host([scale=s][range-hover][range-edge=end]) .calcite--rtl .day-wrapper{box-shadow:inset 1px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=l][highlighted][range-edge=start]) :not(.calcite--rtl) .day-wrapper,:host([scale=l][range-hover][range-edge=start]) :not(.calcite--rtl) .day-wrapper,:host([scale=l][highlighted][range-edge=end]) .calcite--rtl .day-wrapper,:host([scale=l][range-hover][range-edge=end]) .calcite--rtl .day-wrapper{box-shadow:inset 6px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([highlighted][range-edge=start]) .day-wrapper,:host([range-hover][range-edge=start]) .day-wrapper{border-start-start-radius:45%;border-end-start-radius:45%}:host([highlighted][range-edge=end]) .day-wrapper,:host([range-hover][range-edge=end]) .day-wrapper{border-start-end-radius:45%;border-end-end-radius:45%}:host([scale=l][highlighted][range-edge=end]) :not(.calcite--rtl) .day-wrapper,:host([scale=l][range-hover][range-edge=end]) :not(.calcite--rtl) .day-wrapper,:host([scale=l][highlighted][range-edge=start]) .calcite--rtl .day-wrapper,:host([scale=l][range-hover][range-edge=start]) .calcite--rtl .day-wrapper{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}: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", 6); this.calciteInternalDayHover = index.createEvent(this, "calciteInternalDayHover", 6); //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- this.onClick = () => { if (this.disabled) { return; } this.calciteDaySelect.emit(); }; this.keyDownHandler = (event) => { if (key.isActivationKey(event.key)) { !this.disabled && this.calciteDaySelect.emit(); event.preventDefault(); } }; this.day = undefined; this.dateTimeFormat = undefined; this.disabled = false; this.currentMonth = false; this.selected = false; this.highlighted = false; this.range = false; this.rangeEdge = undefined; this.startOfRange = false; this.endOfRange = false; this.rangeHover = false; this.active = false; this.scale = undefined; this.value = undefined; } pointerOverHandler() { if (this.disabled) { return; } this.calciteInternalDayHover.emit(); } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- componentWillLoad() { this.parentDatePickerEl = dom.closestElementCrossShadowBoundary(this.el, "calcite-date-picker"); } render() { const dayId = utils.dateToISO(this.value).replaceAll("-", ""); if (this.parentDatePickerEl) { const { numberingSystem, lang: locale$1 } = this.parentDatePickerEl; locale.numberStringFormatter.numberFormatOptions = { useGrouping: false, ...(numberingSystem && { numberingSystem }), ...(locale$1 && { locale: locale$1 }) }; } const formattedDay = locale.numberStringFormatter.localize(String(this.day)); const dir = dom.getElementDir(this.el); const dayLabel = this.dateTimeFormat.format(this.value); return (index.h(index.Host, { "aria-disabled": dom.toAriaBoolean(this.disabled), "aria-label": dayLabel, "aria-selected": dom.toAriaBoolean(this.active), id: dayId, onClick: this.onClick, onKeyDown: this.keyDownHandler, role: "button" }, index.h("div", { "aria-hidden": "true", class: { "day-v-wrapper": true, [resources.CSS_UTILITY.rtl]: dir === "rtl" } }, index.h("div", { class: "day-wrapper" }, index.h("span", { class: "day" }, index.h("span", { class: "text" }, formattedDay)))))); } connectedCallback() { interactive.connectInteractive(this); } componentDidRender() { interactive.updateHostInteraction(this, this.isTabbable); } disconnectedCallback() { interactive.disconnectInteractive(this); } isTabbable() { return this.active; } get el() { return index.getElement(this); } }; DatePickerDay.style = datePickerDayCss; const datePickerMonthCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-right{0%{opacity:0;transform:translate3D(-5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-left{0%{opacity:0;transform:translate3D(5px, 0, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-right{animation-name:in-right}.calcite-animate__in-left{animation-name:in-left}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing);--calcite-floating-ui-z-index:var(--calcite-app-z-index-dropdown)}:host([hidden]){display:none}.calendar{margin-block-end:0.25rem}.week-headers{display:flex;border-width:0px;border-block-start-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-block:0px;padding-inline:0.25rem}.week-header{text-align:center;font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-3);inline-size:14.2857142857%}.day{display:flex;min-inline-size:0px;justify-content:center;inline-size:14.2857142857%}:host([scale=s]) .week-header{padding-inline:0px;padding-block:0.5rem 0.75rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]) .week-header{padding-inline:0px;padding-block:0.75rem 1rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=l]) .week-header{padding-inline:0px;padding-block:1rem 1.25rem;font-size:var(--calcite-font-size--1);line-height:1rem}.week-days{display:flex;flex-direction:row;padding-block:0px;padding-inline:6px}.week-days:focus{outline:2px solid transparent;outline-offset:2px}"; const DAYS_PER_WEEK = 7; const DAYS_MAXIMUM_INDEX = 6; const DatePickerMonth = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.calciteInternalDatePickerSelect = index.createEvent(this, "calciteInternalDatePickerSelect", 6); this.calciteInternalDatePickerHover = index.createEvent(this, "calciteInternalDatePickerHover", 6); this.calciteInternalDatePickerActiveDateChange = index.createEvent(this, "calciteInternalDatePickerActiveDateChange", 6); this.calciteInternalDatePickerMouseOut = index.createEvent(this, "calciteInternalDatePickerMouseOut", 6); //-------------------------------------------------------------------------- // // Event Listeners // //-------------------------------------------------------------------------- this.keyDownHandler = (event) => { if (event.defaultPrevented) { return; } const isRTL = this.el.dir === "rtl"; switch (event.key) { case "ArrowUp": event.preventDefault(); this.addDays(-7); break; case "ArrowRight": event.preventDefault(); this.addDays(isRTL ? -1 : 1); break; case "ArrowDown": event.preventDefault(); this.addDays(7); break; case "ArrowLeft": event.preventDefault(); this.addDays(isRTL ? 1 : -1); break; case "PageUp": event.preventDefault(); this.addMonths(-1); break; case "PageDown": event.preventDefault(); this.addMonths(1); break; case "Home": event.preventDefault(); this.activeDate.setDate(1); this.addDays(); break; case "End": event.preventDefault(); this.activeDate.setDate(new Date(this.activeDate.getFullYear(), this.activeDate.getMonth() + 1, 0).getDate()); this.addDays(); break; case "Enter": case " ": event.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 = (event) => { const target = event.target; if (target.disabled) { this.calciteInternalDatePickerMouseOut.emit(); } else { this.calciteInternalDatePickerHover.emit(target.value); } event.stopPropagation(); }; this.daySelect = (event) => { const target = event.target; this.calciteInternalDatePickerSelect.emit(target.value); }; this.dateTimeFormat = undefined; this.selectedDate = undefined; this.activeDate = new Date(); this.startDate = undefined; this.endDate = undefined; this.min = undefined; this.max = undefined; this.scale = undefined; this.localeData = undefined; this.hoverRange = undefined; } pointerOutHandler() { this.calciteInternalDatePickerMouseOut.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.getPreviousMonthDays(month, year, startOfWeek); const nextMonDays = this.getNextMonthDays(month, year, startOfWeek); let dayInWeek = 0; const getDayInWeek = () => dayInWeek++ % 7; const days = [ ...prevMonDays.map((day) => { return { active: false, day, dayInWeek: getDayInWeek(), date: new Date(year, month - 1, day) }; }), ...curMonDays.map((day) => { const date = new Date(year, month, day); const active = utils.sameDate(date, this.activeDate); return { active, currentMonth: true, day, dayInWeek: getDayInWeek(), date, ref: true }; }), ...nextMonDays.map((day) => { return { active: false, day, dayInWeek: getDayInWeek(), date: new Date(year, month + 1, day) }; }) ]; 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: "calendar", 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.map((day) => this.renderDateDay(day)))))))); } //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- /** * Add n months to the current month * * @param step */ addMonths(step) { const nextDate = new Date(this.activeDate); nextDate.setMonth(this.activeDate.getMonth() + step); this.calciteInternalDatePickerActiveDateChange.emit(utils.dateFromRange(nextDate, this.min, this.max)); this.activeFocus = true; } /** * Add n days to the current date * * @param step */ addDays(step = 0) { const nextDate = new Date(this.activeDate); nextDate.setDate(this.activeDate.getDate() + step); this.calciteInternalDatePickerActiveDateChange.emit(utils.dateFromRange(nextDate, this.min, this.max)); this.activeFocus = true; } /** * Get dates for last days of the previous month * * @param month * @param year * @param startOfWeek */ getPreviousMonthDays(month, year, startOfWeek) { const lastDate = new Date(year, month, 0); const date = lastDate.getDate(); const startDay = lastDate.getDay(); const days = []; if (startDay === (startOfWeek + DAYS_MAXIMUM_INDEX) % DAYS_PER_WEEK) { return days; } if (startDay === startOfWeek) { return [date]; } for (let i = (DAYS_PER_WEEK + startDay - startOfWeek) % DAYS_PER_WEEK; i >= 0; i--) { days.push(date - i); } return days; } /** * Get dates for the current month * * @param month * @param year */ 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 * * @param month * @param year * @param startOfWeek */ getNextMonthDays(month, year, startOfWeek) { const endDay = new Date(year, month + 1, 0).getDay(); const days = []; if (endDay === (startOfWeek + DAYS_MAXIMUM_INDEX) % DAYS_PER_WEEK) { return days; } for (let i = 0; i < (DAYS_MAXIMUM_INDEX - (endDay - startOfWeek)) % DAYS_PER_WEEK; i++) { days.push(i + 1); } return days; } /** * Determine if the date is in between the start and end dates * * @param date */ 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 * * @param date */ isSelected(date) { return !!(utils.sameDate(date, this.selectedDate) || (this.startDate && utils.sameDate(date, this.startDate)) || (this.endDate && utils.sameDate(date, this.endDate))); } /** * Determine if the date is the start of the date range * * @param date */ isStartOfRange(date) { return !!(this.startDate && !utils.sameDate(this.startDate, this.endDate) && utils.sameDate(this.startDate, date) && !this.isEndOfRange(date)); } isEndOfRange(date) { return !!((this.endDate && !utils.sameDate(this.startDate, this.endDate) && utils.sameDate(this.endDate, date)) || (!this.endDate && this.hoverRange && utils.sameDate(this.startDate, this.hoverRange.end) && utils.sameDate(date, this.hoverRange.end))); } /** * Render calcite-date-picker-day * * @param active.active * @param active * @param day * @param dayInWeek * @param date * @param currentMonth * @param ref * @param active.currentMonth * @param active.date * @param active.day * @param active.dayInWeek * @param active.ref */ renderDateDay({ active, currentMonth, date, day, dayInWeek, ref }) { const isFocusedOnStart = this.isFocusedOnStart(); const isHoverInRange = this.isHoverInRange() || (!this.endDate && this.hoverRange && utils.sameDate(this.hoverRange?.end, this.startDate)); return (index.h("div", { class: "day", key: date.toDateString(), role: "gridcell" }, 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, dateTimeFormat: this.dateTimeFormat, day: day, disabled: !utils.inRange(date, this.min, this.max), endOfRange: this.isEndOfRange(date), highlighted: this.betweenSelectedRange(date), onCalciteDaySelect: this.daySelect, onCalciteInternalDayHover: this.dayHover, range: !!this.startDate && !!this.endDate && !utils.sameDate(this.startDate, this.endDate), rangeEdge: dayInWeek === 0 ? "start" : dayInWeek === 6 ? "end" : undefined, rangeHover: this.isRangeHover(date), scale: this.scale, selected: this.isSelected(date), startOfRange: this.isStartOfRange(date), value: date, // eslint-disable-next-line react/jsx-sort-props ref: (el) => { // when moving via keyboard, focus must be updated on active date if (ref && active && this.activeFocus) { el?.focus(); } } }))); } isFocusedOnStart() { return this.hoverRange?.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 || utils.sameDate(date, end))) || (isStart && date < this.endDate && (date > start || utils.sameDate(date, start)))); const cond2 = !insideRange && ((!isStart && date >= this.endDate && (date < end || utils.sameDate(date, end))) || (isStart && ((this.startDate && date < this.startDate) || (this.endDate && utils.sameDate(date, this.startDate))) && ((start && date > start) || utils.sameDate(date, start)))); return cond1 || cond2; } get el() { return index.getElement(this); } }; DatePickerMonth.style = datePickerMonthCss; const CSS = { header: "header", month: "month", chevron: "chevron", suffix: "suffix", yearSuffix: "year--suffix", yearWrap: "year-wrap", textReverse: "text--reverse" }; const ICON = { chevronLeft: "chevron-left", chevronRight: "chevron-right" }; const datePickerMonthHeaderCss = "@keyframes in{