1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006 |
- /*!
- * 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.97
- */
- 'use strict';
- Object.defineProperty(exports, '__esModule', { value: true });
- const index = require('./index-a0010f96.js');
- const resources = require('./resources-4c8610b1.js');
- const locale = require('./locale-678ce361.js');
- const dom = require('./dom-2ec8c9ed.js');
- const resources$1 = require('./resources-b5a5f8a7.js');
- const interactive = require('./interactive-32293bca.js');
- const key = require('./key-6a462411.js');
- const Heading = require('./Heading-1e87a15f.js');
- require('./observers-5706326b.js');
- require('./guid-f4f03a7a.js');
- 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-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-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)}: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-2);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);
- /**
- * 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;
- /** 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;
- this.globalAttributes = {};
- //--------------------------------------------------------------------------
- //
- // Private State/Props
- //
- //--------------------------------------------------------------------------
- this.effectiveLocale = "";
- //--------------------------------------------------------------------------
- //
- // 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.startAsDate) {
- this.hoverRange = undefined;
- return;
- }
- const date = new Date(event.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;
- }
- }
- event.stopPropagation();
- };
- 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
- *
- * @param event
- */
- this.monthDateChange = (event) => {
- const date = new Date(event.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() {
- locale.connectLocalized(this);
- if (Array.isArray(this.value)) {
- this.valueAsDate = resources.getValueAsDateRange(this.value);
- 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);
- }
- }
- disconnectedCallback() {
- locale.disconnectLocalized(this);
- }
- 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, onKeyDown: this.keyDownHandler, role: "application" }, this.renderCalendar(activeDate, maxDate, minDate, date, endDate)));
- }
- valueHandler(value) {
- if (Array.isArray(value)) {
- this.valueAsDate = resources.getValueAsDateRange(value);
- 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() {
- locale.numberStringFormatter.numberFormatOptions = {
- numberingSystem: this.numberingSystem,
- locale: this.effectiveLocale,
- useGrouping: false
- };
- this.localeData = await resources.getLocaleData(this.effectiveLocale);
- }
- /**
- * 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 || 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, onCalciteDatePickerSelect: this.monthDateChange, onCalciteInternalDatePickerHover: this.monthHoverChange, onCalciteInternalDatePickerMouseOut: this.monthMouseOutChange, scale: this.scale, selectedDate: this.activeRange === "end" ? endDate : date, startDate: this.range ? date : undefined })
- ]);
- }
- /**
- * Update date instance of start if valid
- *
- * @param startDate
- * @param emit
- */
- 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
- *
- * @param endDate
- * @param emit
- */
- setEndAsDate(endDate, emit) {
- this.endAsDate = endDate ? resources.setEndOfDay(endDate) : 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
- *
- * @param value
- * @param min
- * @param max
- */
- 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"],
- "effectiveLocale": ["loadLocaleData"]
- }; }
- };
- 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-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-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)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:flex;min-inline-size:0px;cursor:pointer;justify-content:center;color:var(--calcite-ui-text-3);inline-size:14.2857142857%}: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-brand);outline-offset:2px;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{box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([start-of-range]:not(:focus)) .calcite--rtl .day{box-shadow:0 0 0 -2px var(--calcite-ui-foreground-1)}:host([end-of-range]:not(:focus)) :not(.calcite--rtl) .day{box-shadow:0 0 0 -2px var(--calcite-ui-foreground-1)}: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{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([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]: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{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{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{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{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{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{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);
- /** 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 = (event) => {
- if (key.isActivationKey(event.key)) {
- !this.disabled && this.calciteDaySelect.emit();
- event.preventDefault();
- }
- };
- }
- mouseoverHandler() {
- this.calciteInternalDayHover.emit();
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- componentWillLoad() {
- this.parentDatePickerEl = dom.closestElementCrossShadowBoundary(this.el, "calcite-date-picker");
- }
- render() {
- 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);
- return (index.h(index.Host, { onClick: this.onClick, onKeyDown: this.keyDownHandler, role: "gridcell" }, index.h("div", { class: { "day-v-wrapper": true, [resources$1.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 = "@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-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-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)}:host([hidden]){display:none}.calender{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%}: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 DatePickerMonth = class {
- constructor(hostRef) {
- index.registerInstance(this, hostRef);
- this.calciteDatePickerSelect = index.createEvent(this, "calciteDatePickerSelect", 6);
- this.calciteInternalDatePickerHover = index.createEvent(this, "calciteInternalDatePickerHover", 6);
- this.calciteDatePickerActiveDateChange = index.createEvent(this, "calciteDatePickerActiveDateChange", 6);
- this.calciteInternalDatePickerMouseOut = index.createEvent(this, "calciteInternalDatePickerMouseOut", 6);
- /** Date currently active.*/
- this.activeDate = new Date();
- //--------------------------------------------------------------------------
- //
- // 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.calciteDatePickerSelect.emit(target.value);
- };
- }
- mouseoutHandler() {
- 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.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
- *
- * @param step
- */
- 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
- *
- * @param step
- */
- 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
- *
- * @param month
- * @param year
- * @param startOfWeek
- */
- 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 = lastDate.getDay() - startOfWeek; 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 + 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
- *
- * @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 !!(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
- *
- * @param date
- */
- 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
- *
- * @param active
- * @param day
- * @param date
- * @param currentMonth
- * @param ref
- */
- 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(), onCalciteDaySelect: this.daySelect, onCalciteInternalDayHover: this.dayHover, 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 BUDDHIST_CALENDAR_YEAR_OFFSET = 543;
- const datePickerMonthHeaderCss = "@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-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-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)}:host([hidden]){display:none}:host{display:block}.header{display:flex;justify-content:space-between;padding-block:0px;padding-inline:0.25rem}:host([scale=s]) .text{margin-block:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=s]) .chevron{block-size:2.25rem}:host([scale=m]) .text{margin-block:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([scale=m]) .chevron{block-size:3rem}:host([scale=l]) .text{margin-block:1rem;font-size:var(--calcite-font-size-1);line-height:1.5rem}:host([scale=l]) .chevron{block-size:3.5rem}.chevron{margin-inline:-0.25rem;box-sizing:content-box;display:flex;flex-grow:0;cursor:pointer;align-items:center;justify-content:center;border-style:none;background-color:var(--calcite-ui-foreground-1);padding-inline:0.25rem;color:var(--calcite-ui-text-3);outline:2px solid transparent;outline-offset:2px;outline-color:transparent;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;inline-size: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-block:auto;display:flex;inline-size:100%;flex:1 1 auto;align-items:center;justify-content:center;text-align:center;line-height:1}.text--reverse{flex-direction:row-reverse}.month,.year,.suffix{margin-inline:0.25rem;margin-block: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;inline-size:2.5rem;border-style:none;background-color:transparent;text-align:center;font-family:inherit;outline-color:transparent}.year:hover{transition-duration:100ms;transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);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{text-align:start}.year-wrap{position:relative}.suffix{inset-block-start:0px;white-space:nowrap;text-align:start;inset-inline-start:0}";
- const DatePickerMonthHeader = class {
- constructor(hostRef) {
- index.registerInstance(this, hostRef);
- this.calciteDatePickerSelect = index.createEvent(this, "calciteDatePickerSelect", 6);
- //--------------------------------------------------------------------------
- //
- // Private State/Props
- //
- //--------------------------------------------------------------------------
- this.globalAttributes = {};
- //--------------------------------------------------------------------------
- //
- // Private Methods
- //
- //--------------------------------------------------------------------------
- /**
- * Increment year on UP/DOWN keys
- *
- * @param event
- */
- this.onYearKey = (event) => {
- const localizedYear = this.parseCalendarYear(event.target.value);
- switch (event.key) {
- case "ArrowDown":
- event.preventDefault();
- this.setYear({ localizedYear, offset: -1 });
- break;
- case "ArrowUp":
- event.preventDefault();
- this.setYear({ localizedYear, offset: 1 });
- break;
- }
- };
- this.onYearChange = (event) => {
- this.setYear({
- localizedYear: this.parseCalendarYear(event.target.value)
- });
- };
- this.onYearInput = (event) => {
- this.setYear({
- localizedYear: this.parseCalendarYear(event.target.value),
- commit: false
- });
- };
- this.prevMonthClick = (event) => {
- this.handleArrowClick(event, this.prevMonthDate);
- };
- this.prevMonthKeydown = (event) => {
- if (key.isActivationKey(event.key)) {
- this.prevMonthClick(event);
- }
- };
- this.nextMonthClick = (event) => {
- this.handleArrowClick(event, this.nextMonthDate);
- };
- this.nextMonthKeydown = (event) => {
- if (key.isActivationKey(event.key)) {
- this.nextMonthClick(event);
- }
- };
- /*
- * Update active month on clicks of left/right arrows
- */
- this.handleArrowClick = (event, date) => {
- event.preventDefault();
- this.calciteDatePickerSelect.emit(date);
- };
- }
- //--------------------------------------------------------------------------
- //
- // Lifecycle
- //
- //--------------------------------------------------------------------------
- componentWillLoad() {
- this.parentDatePickerEl = dom.closestElementCrossShadowBoundary(this.el, "calcite-date-picker");
- }
- connectedCallback() {
- this.setNextPrevMonthDates();
- }
- render() {
- return index.h("div", { class: "header" }, this.renderContent());
- }
- renderContent() {
- var _a;
- if (!this.activeDate || !this.localeData) {
- return null;
- }
- if (this.parentDatePickerEl) {
- const { numberingSystem, lang: locale$1 } = this.parentDatePickerEl;
- locale.numberStringFormatter.numberFormatOptions = {
- useGrouping: false,
- ...(numberingSystem && { numberingSystem }),
- ...(locale$1 && { locale: locale$1 })
- };
- }
- const activeMonth = this.activeDate.getMonth();
- const { months, unitOrder } = this.localeData;
- const localizedMonth = (months.wide || months.narrow || months.abbreviated)[activeMonth];
- const localizedYear = this.formatCalendarYear(this.activeDate.getFullYear());
- 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}`, "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" }, suffix))), index.h("a", { "aria-disabled": `${this.nextMonthDate.getMonth() === activeMonth}`, "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);
- }
- formatCalendarYear(year) {
- const { localeData } = this;
- const buddhistCalendar = localeData["default-calendar"] === "buddhist";
- const yearOffset = buddhistCalendar ? BUDDHIST_CALENDAR_YEAR_OFFSET : 0;
- return locale.numberStringFormatter.localize(`${year + yearOffset}`);
- }
- parseCalendarYear(year) {
- const { localeData } = this;
- const buddhistCalendar = localeData["default-calendar"] === "buddhist";
- const yearOffset = buddhistCalendar ? BUDDHIST_CALENDAR_YEAR_OFFSET : 0;
- const parsedYear = Number(locale.numberStringFormatter.delocalize(year)) - yearOffset;
- return locale.numberStringFormatter.localize(`${parsedYear}`);
- }
- getInRangeDate({ localizedYear, offset = 0 }) {
- const { min, max, activeDate } = this;
- const parsedYear = Number(locale.numberStringFormatter.delocalize(localizedYear));
- 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
- *
- * @param root0
- * @param root0.localizedYear
- * @param root0.commit
- * @param root0.offset
- */
- setYear({ localizedYear, commit = true, offset = 0 }) {
- const { yearInput, activeDate } = 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 = this.formatCalendarYear((inRangeDate || activeDate).getFullYear());
- }
- }
- 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;
|