calcite-date-picker_4.cjs.entry.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const resources = require('./resources-4c8610b1.js');
  10. const locale = require('./locale-678ce361.js');
  11. const dom = require('./dom-2ec8c9ed.js');
  12. const resources$1 = require('./resources-b5a5f8a7.js');
  13. const interactive = require('./interactive-32293bca.js');
  14. const key = require('./key-6a462411.js');
  15. const Heading = require('./Heading-1e87a15f.js');
  16. require('./observers-5706326b.js');
  17. require('./guid-f4f03a7a.js');
  18. 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}";
  19. const DatePicker = class {
  20. constructor(hostRef) {
  21. index.registerInstance(this, hostRef);
  22. this.calciteDatePickerChange = index.createEvent(this, "calciteDatePickerChange", 6);
  23. this.calciteDatePickerRangeChange = index.createEvent(this, "calciteDatePickerRangeChange", 6);
  24. /**
  25. * Localized string for "previous month" (used for aria label)
  26. *
  27. * @default "Previous month"
  28. */
  29. this.intlPrevMonth = resources.TEXT.prevMonth;
  30. /**
  31. * Localized string for "next month" (used for aria label)
  32. *
  33. * @default "Next month"
  34. */
  35. this.intlNextMonth = resources.TEXT.nextMonth;
  36. /**
  37. * Localized string for "year" (used for aria label)
  38. *
  39. * @default "Year"
  40. */
  41. this.intlYear = resources.TEXT.year;
  42. /** specify the scale of the date picker */
  43. this.scale = "m";
  44. /** Range mode activation */
  45. this.range = false;
  46. /** Disables the default behaviour on the third click of narrowing or extending the range and instead starts a new range. */
  47. this.proximitySelectionDisabled = false;
  48. this.globalAttributes = {};
  49. //--------------------------------------------------------------------------
  50. //
  51. // Private State/Props
  52. //
  53. //--------------------------------------------------------------------------
  54. this.effectiveLocale = "";
  55. //--------------------------------------------------------------------------
  56. //
  57. // Private Methods
  58. //
  59. //--------------------------------------------------------------------------
  60. this.keyDownHandler = (event) => {
  61. if (event.key === "Escape") {
  62. this.reset();
  63. }
  64. };
  65. this.monthHeaderSelectChange = (event) => {
  66. const date = new Date(event.detail);
  67. if (!this.range) {
  68. this.activeDate = date;
  69. }
  70. else {
  71. if (this.activeRange === "end") {
  72. this.activeEndDate = date;
  73. }
  74. else {
  75. this.activeStartDate = date;
  76. }
  77. this.mostRecentRangeValue = date;
  78. }
  79. };
  80. this.monthActiveDateChange = (event) => {
  81. const date = new Date(event.detail);
  82. if (!this.range) {
  83. this.activeDate = date;
  84. }
  85. else {
  86. if (this.activeRange === "end") {
  87. this.activeEndDate = date;
  88. }
  89. else {
  90. this.activeStartDate = date;
  91. }
  92. this.mostRecentRangeValue = date;
  93. }
  94. };
  95. this.monthHoverChange = (event) => {
  96. if (!this.startAsDate) {
  97. this.hoverRange = undefined;
  98. return;
  99. }
  100. const date = new Date(event.detail);
  101. this.hoverRange = {
  102. focused: this.activeRange || "start",
  103. start: this.startAsDate,
  104. end: this.endAsDate
  105. };
  106. if (!this.proximitySelectionDisabled) {
  107. if (this.endAsDate) {
  108. const startDiff = resources.getDaysDiff(date, this.startAsDate);
  109. const endDiff = resources.getDaysDiff(date, this.endAsDate);
  110. if (endDiff > 0) {
  111. this.hoverRange.end = date;
  112. this.hoverRange.focused = "end";
  113. }
  114. else if (startDiff < 0) {
  115. this.hoverRange.start = date;
  116. this.hoverRange.focused = "start";
  117. }
  118. else if (startDiff > endDiff) {
  119. this.hoverRange.start = date;
  120. this.hoverRange.focused = "start";
  121. }
  122. else {
  123. this.hoverRange.end = date;
  124. this.hoverRange.focused = "end";
  125. }
  126. }
  127. else {
  128. if (date < this.startAsDate) {
  129. this.hoverRange = {
  130. focused: "start",
  131. start: date,
  132. end: this.startAsDate
  133. };
  134. }
  135. else {
  136. this.hoverRange.end = date;
  137. this.hoverRange.focused = "end";
  138. }
  139. }
  140. }
  141. else {
  142. if (!this.endAsDate) {
  143. if (date < this.startAsDate) {
  144. this.hoverRange = {
  145. focused: "start",
  146. start: date,
  147. end: this.startAsDate
  148. };
  149. }
  150. else {
  151. this.hoverRange.end = date;
  152. this.hoverRange.focused = "end";
  153. }
  154. }
  155. else {
  156. this.hoverRange = undefined;
  157. }
  158. }
  159. event.stopPropagation();
  160. };
  161. this.monthMouseOutChange = () => {
  162. if (this.hoverRange) {
  163. this.hoverRange = undefined;
  164. }
  165. };
  166. /**
  167. * Reset active date and close
  168. */
  169. this.reset = () => {
  170. var _a, _b, _c, _d, _e, _f;
  171. if (!Array.isArray(this.valueAsDate) &&
  172. this.valueAsDate &&
  173. ((_a = this.valueAsDate) === null || _a === void 0 ? void 0 : _a.getTime()) !== ((_b = this.activeDate) === null || _b === void 0 ? void 0 : _b.getTime())) {
  174. this.activeDate = new Date(this.valueAsDate);
  175. }
  176. 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())) {
  177. this.activeStartDate = new Date(this.startAsDate);
  178. }
  179. 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())) {
  180. this.activeEndDate = new Date(this.endAsDate);
  181. }
  182. };
  183. /**
  184. * Event handler for when the selected date changes
  185. *
  186. * @param event
  187. */
  188. this.monthDateChange = (event) => {
  189. const date = new Date(event.detail);
  190. if (!this.range) {
  191. this.value = date ? resources.dateToISO(date) : "";
  192. this.valueAsDate = date || null;
  193. this.activeDate = date || null;
  194. this.calciteDatePickerChange.emit(date);
  195. return;
  196. }
  197. if (!this.startAsDate || (!this.endAsDate && date < this.startAsDate)) {
  198. if (this.startAsDate) {
  199. this.setEndDate(new Date(this.startAsDate));
  200. }
  201. if (this.activeRange == "end") {
  202. this.setEndDate(date);
  203. }
  204. else {
  205. this.setStartDate(date);
  206. }
  207. }
  208. else if (!this.endAsDate) {
  209. this.setEndDate(date);
  210. }
  211. else {
  212. if (!this.proximitySelectionDisabled) {
  213. if (this.activeRange) {
  214. if (this.activeRange == "end") {
  215. this.setEndDate(date);
  216. }
  217. else {
  218. this.setStartDate(date);
  219. }
  220. }
  221. else {
  222. const startDiff = resources.getDaysDiff(date, this.startAsDate);
  223. const endDiff = resources.getDaysDiff(date, this.endAsDate);
  224. if (endDiff === 0 || startDiff < 0) {
  225. this.setStartDate(date);
  226. }
  227. else if (startDiff === 0 || endDiff < 0) {
  228. this.setEndDate(date);
  229. }
  230. else if (startDiff < endDiff) {
  231. this.setStartDate(date);
  232. }
  233. else {
  234. this.setEndDate(date);
  235. }
  236. }
  237. }
  238. else {
  239. this.setStartDate(date);
  240. this.endAsDate = this.activeEndDate = this.end = undefined;
  241. }
  242. }
  243. this.calciteDatePickerChange.emit(date);
  244. };
  245. }
  246. handleValueAsDate(date) {
  247. if (!Array.isArray(date) && date && date !== this.activeDate) {
  248. this.activeDate = date;
  249. }
  250. }
  251. handleRangeChange() {
  252. const { startAsDate: startDate, endAsDate: endDate } = this;
  253. this.activeEndDate = endDate;
  254. this.activeStartDate = startDate;
  255. }
  256. onMinChanged(min) {
  257. if (min) {
  258. this.minAsDate = resources.dateFromISO(min);
  259. }
  260. }
  261. onMaxChanged(max) {
  262. if (max) {
  263. this.maxAsDate = resources.dateFromISO(max);
  264. }
  265. }
  266. // --------------------------------------------------------------------------
  267. //
  268. // Lifecycle
  269. //
  270. // --------------------------------------------------------------------------
  271. connectedCallback() {
  272. locale.connectLocalized(this);
  273. if (Array.isArray(this.value)) {
  274. this.valueAsDate = resources.getValueAsDateRange(this.value);
  275. this.start = this.value[0];
  276. this.end = this.value[1];
  277. }
  278. else if (this.value) {
  279. this.valueAsDate = resources.dateFromISO(this.value);
  280. }
  281. if (this.start) {
  282. this.setStartAsDate(resources.dateFromISO(this.start));
  283. }
  284. if (this.end) {
  285. this.setEndAsDate(resources.dateFromISO(this.end));
  286. }
  287. if (this.min) {
  288. this.minAsDate = resources.dateFromISO(this.min);
  289. }
  290. if (this.max) {
  291. this.maxAsDate = resources.dateFromISO(this.max);
  292. }
  293. }
  294. disconnectedCallback() {
  295. locale.disconnectLocalized(this);
  296. }
  297. async componentWillLoad() {
  298. await this.loadLocaleData();
  299. this.onMinChanged(this.min);
  300. this.onMaxChanged(this.max);
  301. }
  302. render() {
  303. var _a;
  304. const date = resources.dateFromRange(this.range ? this.startAsDate : this.valueAsDate, this.minAsDate, this.maxAsDate);
  305. const activeStartDate = this.range
  306. ? this.getActiveStartDate(date, this.minAsDate, this.maxAsDate)
  307. : this.getActiveDate(date, this.minAsDate, this.maxAsDate);
  308. let activeDate = activeStartDate;
  309. const endDate = this.range
  310. ? resources.dateFromRange(this.endAsDate, this.minAsDate, this.maxAsDate)
  311. : null;
  312. const activeEndDate = this.getActiveEndDate(endDate, this.minAsDate, this.maxAsDate);
  313. if ((this.activeRange === "end" ||
  314. (((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.focused) === "end" && (!this.proximitySelectionDisabled || endDate))) &&
  315. activeEndDate) {
  316. activeDate = activeEndDate;
  317. }
  318. if (this.range && this.mostRecentRangeValue) {
  319. activeDate = this.mostRecentRangeValue;
  320. }
  321. const minDate = this.range && this.activeRange
  322. ? this.activeRange === "start"
  323. ? this.minAsDate
  324. : date || this.minAsDate
  325. : this.minAsDate;
  326. const maxDate = this.range && this.activeRange
  327. ? this.activeRange === "start"
  328. ? endDate || this.maxAsDate
  329. : this.maxAsDate
  330. : this.maxAsDate;
  331. return (index.h(index.Host, { onBlur: this.reset, onKeyDown: this.keyDownHandler, role: "application" }, this.renderCalendar(activeDate, maxDate, minDate, date, endDate)));
  332. }
  333. valueHandler(value) {
  334. if (Array.isArray(value)) {
  335. this.valueAsDate = resources.getValueAsDateRange(value);
  336. this.start = value[0];
  337. this.end = value[1];
  338. }
  339. else if (value) {
  340. this.valueAsDate = resources.dateFromISO(value);
  341. this.start = "";
  342. this.end = "";
  343. }
  344. }
  345. startWatcher(start) {
  346. this.setStartAsDate(resources.dateFromISO(start));
  347. }
  348. endWatcher(end) {
  349. this.setEndAsDate(resources.dateFromISO(end));
  350. }
  351. async loadLocaleData() {
  352. locale.numberStringFormatter.numberFormatOptions = {
  353. numberingSystem: this.numberingSystem,
  354. locale: this.effectiveLocale,
  355. useGrouping: false
  356. };
  357. this.localeData = await resources.getLocaleData(this.effectiveLocale);
  358. }
  359. /**
  360. * Render calcite-date-picker-month-header and calcite-date-picker-month
  361. *
  362. * @param activeDate
  363. * @param maxDate
  364. * @param minDate
  365. * @param date
  366. * @param endDate
  367. */
  368. renderCalendar(activeDate, maxDate, minDate, date, endDate) {
  369. return (this.localeData && [
  370. 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() }),
  371. 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 })
  372. ]);
  373. }
  374. /**
  375. * Update date instance of start if valid
  376. *
  377. * @param startDate
  378. * @param emit
  379. */
  380. setStartAsDate(startDate, emit) {
  381. this.startAsDate = startDate;
  382. this.mostRecentRangeValue = this.startAsDate;
  383. if (emit) {
  384. this.calciteDatePickerRangeChange.emit({
  385. startDate,
  386. endDate: this.endAsDate
  387. });
  388. }
  389. }
  390. /**
  391. * Update date instance of end if valid
  392. *
  393. * @param endDate
  394. * @param emit
  395. */
  396. setEndAsDate(endDate, emit) {
  397. this.endAsDate = endDate ? resources.setEndOfDay(endDate) : endDate;
  398. this.mostRecentRangeValue = this.endAsDate;
  399. if (emit) {
  400. this.calciteDatePickerRangeChange.emit({
  401. startDate: this.startAsDate,
  402. endDate
  403. });
  404. }
  405. }
  406. setEndDate(date) {
  407. this.end = date ? resources.dateToISO(date) : "";
  408. this.setEndAsDate(date, true);
  409. this.activeEndDate = date || null;
  410. }
  411. setStartDate(date) {
  412. this.start = date ? resources.dateToISO(date) : "";
  413. this.setStartAsDate(date, true);
  414. this.activeStartDate = date || null;
  415. }
  416. /**
  417. * Get an active date using the value, or current date as default
  418. *
  419. * @param value
  420. * @param min
  421. * @param max
  422. */
  423. getActiveDate(value, min, max) {
  424. return resources.dateFromRange(this.activeDate, min, max) || value || resources.dateFromRange(new Date(), min, max);
  425. }
  426. getActiveStartDate(value, min, max) {
  427. return (resources.dateFromRange(this.activeStartDate, min, max) || value || resources.dateFromRange(new Date(), min, max));
  428. }
  429. getActiveEndDate(value, min, max) {
  430. return (resources.dateFromRange(this.activeEndDate, min, max) || value || resources.dateFromRange(new Date(), min, max));
  431. }
  432. static get assetsDirs() { return ["assets"]; }
  433. get el() { return index.getElement(this); }
  434. static get watchers() { return {
  435. "valueAsDate": ["handleValueAsDate"],
  436. "startAsDate": ["handleRangeChange"],
  437. "endAsDate": ["handleRangeChange"],
  438. "min": ["onMinChanged"],
  439. "max": ["onMaxChanged"],
  440. "value": ["valueHandler"],
  441. "start": ["startWatcher"],
  442. "end": ["endWatcher"],
  443. "effectiveLocale": ["loadLocaleData"]
  444. }; }
  445. };
  446. DatePicker.style = datePickerCss;
  447. 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}}";
  448. const DatePickerDay = class {
  449. constructor(hostRef) {
  450. index.registerInstance(this, hostRef);
  451. this.calciteDaySelect = index.createEvent(this, "calciteDaySelect", 6);
  452. this.calciteInternalDayHover = index.createEvent(this, "calciteInternalDayHover", 6);
  453. /** Date is outside of range and can't be selected */
  454. this.disabled = false;
  455. /** Date is in the current month. */
  456. this.currentMonth = false;
  457. /** Date is the current selected date of the picker */
  458. this.selected = false;
  459. /** Date is currently highlighted as part of the range */
  460. this.highlighted = false;
  461. /** Showing date range */
  462. this.range = false;
  463. /** Date is the start of date range */
  464. this.startOfRange = false;
  465. /** Date is the end of date range */
  466. this.endOfRange = false;
  467. /** Date is being hovered and within the set range */
  468. this.rangeHover = false;
  469. /** Date is actively in focus for keyboard navigation */
  470. this.active = false;
  471. //--------------------------------------------------------------------------
  472. //
  473. // Event Listeners
  474. //
  475. //--------------------------------------------------------------------------
  476. this.onClick = () => {
  477. !this.disabled && this.calciteDaySelect.emit();
  478. };
  479. this.keyDownHandler = (event) => {
  480. if (key.isActivationKey(event.key)) {
  481. !this.disabled && this.calciteDaySelect.emit();
  482. event.preventDefault();
  483. }
  484. };
  485. }
  486. mouseoverHandler() {
  487. this.calciteInternalDayHover.emit();
  488. }
  489. //--------------------------------------------------------------------------
  490. //
  491. // Lifecycle
  492. //
  493. //--------------------------------------------------------------------------
  494. componentWillLoad() {
  495. this.parentDatePickerEl = dom.closestElementCrossShadowBoundary(this.el, "calcite-date-picker");
  496. }
  497. render() {
  498. if (this.parentDatePickerEl) {
  499. const { numberingSystem, lang: locale$1 } = this.parentDatePickerEl;
  500. locale.numberStringFormatter.numberFormatOptions = {
  501. useGrouping: false,
  502. ...(numberingSystem && { numberingSystem }),
  503. ...(locale$1 && { locale: locale$1 })
  504. };
  505. }
  506. const formattedDay = locale.numberStringFormatter.localize(String(this.day));
  507. const dir = dom.getElementDir(this.el);
  508. 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))))));
  509. }
  510. componentDidRender() {
  511. interactive.updateHostInteraction(this, this.isTabbable);
  512. }
  513. isTabbable() {
  514. return this.active;
  515. }
  516. get el() { return index.getElement(this); }
  517. };
  518. DatePickerDay.style = datePickerDayCss;
  519. 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}";
  520. const DatePickerMonth = class {
  521. constructor(hostRef) {
  522. index.registerInstance(this, hostRef);
  523. this.calciteDatePickerSelect = index.createEvent(this, "calciteDatePickerSelect", 6);
  524. this.calciteInternalDatePickerHover = index.createEvent(this, "calciteInternalDatePickerHover", 6);
  525. this.calciteDatePickerActiveDateChange = index.createEvent(this, "calciteDatePickerActiveDateChange", 6);
  526. this.calciteInternalDatePickerMouseOut = index.createEvent(this, "calciteInternalDatePickerMouseOut", 6);
  527. /** Date currently active.*/
  528. this.activeDate = new Date();
  529. //--------------------------------------------------------------------------
  530. //
  531. // Event Listeners
  532. //
  533. //--------------------------------------------------------------------------
  534. this.keyDownHandler = (event) => {
  535. if (event.defaultPrevented) {
  536. return;
  537. }
  538. const isRTL = this.el.dir === "rtl";
  539. switch (event.key) {
  540. case "ArrowUp":
  541. event.preventDefault();
  542. this.addDays(-7);
  543. break;
  544. case "ArrowRight":
  545. event.preventDefault();
  546. this.addDays(isRTL ? -1 : 1);
  547. break;
  548. case "ArrowDown":
  549. event.preventDefault();
  550. this.addDays(7);
  551. break;
  552. case "ArrowLeft":
  553. event.preventDefault();
  554. this.addDays(isRTL ? 1 : -1);
  555. break;
  556. case "PageUp":
  557. event.preventDefault();
  558. this.addMonths(-1);
  559. break;
  560. case "PageDown":
  561. event.preventDefault();
  562. this.addMonths(1);
  563. break;
  564. case "Home":
  565. event.preventDefault();
  566. this.activeDate.setDate(1);
  567. this.addDays();
  568. break;
  569. case "End":
  570. event.preventDefault();
  571. this.activeDate.setDate(new Date(this.activeDate.getFullYear(), this.activeDate.getMonth() + 1, 0).getDate());
  572. this.addDays();
  573. break;
  574. case "Enter":
  575. case " ":
  576. event.preventDefault();
  577. break;
  578. case "Tab":
  579. this.activeFocus = false;
  580. }
  581. };
  582. /**
  583. * Once user is not interacting via keyboard,
  584. * disable auto focusing of active date
  585. */
  586. this.disableActiveFocus = () => {
  587. this.activeFocus = false;
  588. };
  589. this.dayHover = (event) => {
  590. const target = event.target;
  591. if (target.disabled) {
  592. this.calciteInternalDatePickerMouseOut.emit();
  593. }
  594. else {
  595. this.calciteInternalDatePickerHover.emit(target.value);
  596. }
  597. event.stopPropagation();
  598. };
  599. this.daySelect = (event) => {
  600. const target = event.target;
  601. this.calciteDatePickerSelect.emit(target.value);
  602. };
  603. }
  604. mouseoutHandler() {
  605. this.calciteInternalDatePickerMouseOut.emit();
  606. }
  607. //--------------------------------------------------------------------------
  608. //
  609. // Lifecycle
  610. //
  611. //--------------------------------------------------------------------------
  612. render() {
  613. const month = this.activeDate.getMonth();
  614. const year = this.activeDate.getFullYear();
  615. const startOfWeek = this.localeData.weekStart % 7;
  616. const { abbreviated, short, narrow } = this.localeData.days;
  617. const weekDays = this.scale === "s" ? narrow || short || abbreviated : short || abbreviated || narrow;
  618. const adjustedWeekDays = [...weekDays.slice(startOfWeek, 7), ...weekDays.slice(0, startOfWeek)];
  619. const curMonDays = this.getCurrentMonthDays(month, year);
  620. const prevMonDays = this.getPrevMonthdays(month, year, startOfWeek);
  621. const nextMonDays = this.getNextMonthDays(month, year, startOfWeek);
  622. const days = [
  623. ...prevMonDays.map((day) => {
  624. const date = new Date(year, month - 1, day);
  625. return this.renderDateDay(false, day, date);
  626. }),
  627. ...curMonDays.map((day) => {
  628. const date = new Date(year, month, day);
  629. const active = resources.sameDate(date, this.activeDate);
  630. return this.renderDateDay(active, day, date, true, true);
  631. }),
  632. ...nextMonDays.map((day) => {
  633. const date = new Date(year, month + 1, day);
  634. return this.renderDateDay(false, day, date);
  635. })
  636. ];
  637. const weeks = [];
  638. for (let i = 0; i < days.length; i += 7) {
  639. weeks.push(days.slice(i, i + 7));
  640. }
  641. 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))))));
  642. }
  643. //--------------------------------------------------------------------------
  644. //
  645. // Private Methods
  646. //
  647. //--------------------------------------------------------------------------
  648. /**
  649. * Add n months to the current month
  650. *
  651. * @param step
  652. */
  653. addMonths(step) {
  654. const nextDate = new Date(this.activeDate);
  655. nextDate.setMonth(this.activeDate.getMonth() + step);
  656. this.calciteDatePickerActiveDateChange.emit(resources.dateFromRange(nextDate, this.min, this.max));
  657. this.activeFocus = true;
  658. }
  659. /**
  660. * Add n days to the current date
  661. *
  662. * @param step
  663. */
  664. addDays(step = 0) {
  665. const nextDate = new Date(this.activeDate);
  666. nextDate.setDate(this.activeDate.getDate() + step);
  667. this.calciteDatePickerActiveDateChange.emit(resources.dateFromRange(nextDate, this.min, this.max));
  668. this.activeFocus = true;
  669. }
  670. /**
  671. * Get dates for last days of the previous month
  672. *
  673. * @param month
  674. * @param year
  675. * @param startOfWeek
  676. */
  677. getPrevMonthdays(month, year, startOfWeek) {
  678. const lastDate = new Date(year, month, 0);
  679. const date = lastDate.getDate();
  680. const day = lastDate.getDay();
  681. const days = [];
  682. if (day - 6 === startOfWeek) {
  683. return days;
  684. }
  685. for (let i = lastDate.getDay() - startOfWeek; i >= 0; i--) {
  686. days.push(date - i);
  687. }
  688. return days;
  689. }
  690. /**
  691. * Get dates for the current month
  692. *
  693. * @param month
  694. * @param year
  695. */
  696. getCurrentMonthDays(month, year) {
  697. const num = new Date(year, month + 1, 0).getDate();
  698. const days = [];
  699. for (let i = 0; i < num; i++) {
  700. days.push(i + 1);
  701. }
  702. return days;
  703. }
  704. /**
  705. * Get dates for first days of the next month
  706. *
  707. * @param month
  708. * @param year
  709. * @param startOfWeek
  710. */
  711. getNextMonthDays(month, year, startOfWeek) {
  712. const endDay = new Date(year, month + 1, 0).getDay();
  713. const days = [];
  714. if (endDay === (startOfWeek + 6) % 7) {
  715. return days;
  716. }
  717. for (let i = 0; i < (6 - (endDay - startOfWeek)) % 7; i++) {
  718. days.push(i + 1);
  719. }
  720. return days;
  721. }
  722. /**
  723. * Determine if the date is in between the start and end dates
  724. *
  725. * @param date
  726. */
  727. betweenSelectedRange(date) {
  728. return !!(this.startDate &&
  729. this.endDate &&
  730. date > this.startDate &&
  731. date < this.endDate &&
  732. !this.isRangeHover(date));
  733. }
  734. /**
  735. * Determine if the date should be in selected state
  736. *
  737. * @param date
  738. */
  739. isSelected(date) {
  740. return !!(resources.sameDate(date, this.selectedDate) ||
  741. (this.startDate && resources.sameDate(date, this.startDate)) ||
  742. (this.endDate && resources.sameDate(date, this.endDate)));
  743. }
  744. /**
  745. * Determine if the date is the start of the date range
  746. *
  747. * @param date
  748. */
  749. isStartOfRange(date) {
  750. return !!(this.startDate &&
  751. !resources.sameDate(this.startDate, this.endDate) &&
  752. resources.sameDate(this.startDate, date) &&
  753. !this.isEndOfRange(date));
  754. }
  755. isEndOfRange(date) {
  756. return !!((this.endDate && !resources.sameDate(this.startDate, this.endDate) && resources.sameDate(this.endDate, date)) ||
  757. (!this.endDate &&
  758. this.hoverRange &&
  759. resources.sameDate(this.startDate, this.hoverRange.end) &&
  760. resources.sameDate(date, this.hoverRange.end)));
  761. }
  762. /**
  763. * Render calcite-date-picker-day
  764. *
  765. * @param active
  766. * @param day
  767. * @param date
  768. * @param currentMonth
  769. * @param ref
  770. */
  771. renderDateDay(active, day, date, currentMonth, ref) {
  772. var _a;
  773. const isFocusedOnStart = this.isFocusedOnStart();
  774. const isHoverInRange = this.isHoverInRange() ||
  775. (!this.endDate && this.hoverRange && resources.sameDate((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.end, this.startDate));
  776. return (index.h("calcite-date-picker-day", { active: active, class: {
  777. "hover--inside-range": this.startDate && isHoverInRange,
  778. "hover--outside-range": this.startDate && !isHoverInRange,
  779. "focused--start": isFocusedOnStart,
  780. "focused--end": !isFocusedOnStart
  781. }, 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) => {
  782. // when moving via keyboard, focus must be updated on active date
  783. if (ref && active && this.activeFocus) {
  784. el === null || el === void 0 ? void 0 : el.focus();
  785. }
  786. }, scale: this.scale, selected: this.isSelected(date), startOfRange: this.isStartOfRange(date), value: date }));
  787. }
  788. isFocusedOnStart() {
  789. var _a;
  790. return ((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.focused) === "start";
  791. }
  792. isHoverInRange() {
  793. if (!this.hoverRange) {
  794. return false;
  795. }
  796. const { start, end } = this.hoverRange;
  797. return !!((!this.isFocusedOnStart() && this.startDate && (!this.endDate || end < this.endDate)) ||
  798. (this.isFocusedOnStart() && this.startDate && start > this.startDate));
  799. }
  800. isRangeHover(date) {
  801. if (!this.hoverRange) {
  802. return false;
  803. }
  804. const { start, end } = this.hoverRange;
  805. const isStart = this.isFocusedOnStart();
  806. const insideRange = this.isHoverInRange();
  807. const cond1 = insideRange &&
  808. ((!isStart && date > this.startDate && (date < end || resources.sameDate(date, end))) ||
  809. (isStart && date < this.endDate && (date > start || resources.sameDate(date, start))));
  810. const cond2 = !insideRange &&
  811. ((!isStart && date >= this.endDate && (date < end || resources.sameDate(date, end))) ||
  812. (isStart &&
  813. (date < this.startDate || (this.endDate && resources.sameDate(date, this.startDate))) &&
  814. (date > start || resources.sameDate(date, start))));
  815. return cond1 || cond2;
  816. }
  817. get el() { return index.getElement(this); }
  818. };
  819. DatePickerMonth.style = datePickerMonthCss;
  820. const BUDDHIST_CALENDAR_YEAR_OFFSET = 543;
  821. 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}";
  822. const DatePickerMonthHeader = class {
  823. constructor(hostRef) {
  824. index.registerInstance(this, hostRef);
  825. this.calciteDatePickerSelect = index.createEvent(this, "calciteDatePickerSelect", 6);
  826. //--------------------------------------------------------------------------
  827. //
  828. // Private State/Props
  829. //
  830. //--------------------------------------------------------------------------
  831. this.globalAttributes = {};
  832. //--------------------------------------------------------------------------
  833. //
  834. // Private Methods
  835. //
  836. //--------------------------------------------------------------------------
  837. /**
  838. * Increment year on UP/DOWN keys
  839. *
  840. * @param event
  841. */
  842. this.onYearKey = (event) => {
  843. const localizedYear = this.parseCalendarYear(event.target.value);
  844. switch (event.key) {
  845. case "ArrowDown":
  846. event.preventDefault();
  847. this.setYear({ localizedYear, offset: -1 });
  848. break;
  849. case "ArrowUp":
  850. event.preventDefault();
  851. this.setYear({ localizedYear, offset: 1 });
  852. break;
  853. }
  854. };
  855. this.onYearChange = (event) => {
  856. this.setYear({
  857. localizedYear: this.parseCalendarYear(event.target.value)
  858. });
  859. };
  860. this.onYearInput = (event) => {
  861. this.setYear({
  862. localizedYear: this.parseCalendarYear(event.target.value),
  863. commit: false
  864. });
  865. };
  866. this.prevMonthClick = (event) => {
  867. this.handleArrowClick(event, this.prevMonthDate);
  868. };
  869. this.prevMonthKeydown = (event) => {
  870. if (key.isActivationKey(event.key)) {
  871. this.prevMonthClick(event);
  872. }
  873. };
  874. this.nextMonthClick = (event) => {
  875. this.handleArrowClick(event, this.nextMonthDate);
  876. };
  877. this.nextMonthKeydown = (event) => {
  878. if (key.isActivationKey(event.key)) {
  879. this.nextMonthClick(event);
  880. }
  881. };
  882. /*
  883. * Update active month on clicks of left/right arrows
  884. */
  885. this.handleArrowClick = (event, date) => {
  886. event.preventDefault();
  887. this.calciteDatePickerSelect.emit(date);
  888. };
  889. }
  890. //--------------------------------------------------------------------------
  891. //
  892. // Lifecycle
  893. //
  894. //--------------------------------------------------------------------------
  895. componentWillLoad() {
  896. this.parentDatePickerEl = dom.closestElementCrossShadowBoundary(this.el, "calcite-date-picker");
  897. }
  898. connectedCallback() {
  899. this.setNextPrevMonthDates();
  900. }
  901. render() {
  902. return index.h("div", { class: "header" }, this.renderContent());
  903. }
  904. renderContent() {
  905. var _a;
  906. if (!this.activeDate || !this.localeData) {
  907. return null;
  908. }
  909. if (this.parentDatePickerEl) {
  910. const { numberingSystem, lang: locale$1 } = this.parentDatePickerEl;
  911. locale.numberStringFormatter.numberFormatOptions = {
  912. useGrouping: false,
  913. ...(numberingSystem && { numberingSystem }),
  914. ...(locale$1 && { locale: locale$1 })
  915. };
  916. }
  917. const activeMonth = this.activeDate.getMonth();
  918. const { months, unitOrder } = this.localeData;
  919. const localizedMonth = (months.wide || months.narrow || months.abbreviated)[activeMonth];
  920. const localizedYear = this.formatCalendarYear(this.activeDate.getFullYear());
  921. const iconScale = this.scale === "l" ? "m" : "s";
  922. const order = resources.getOrder(unitOrder);
  923. const reverse = order.indexOf("y") < order.indexOf("m");
  924. const suffix = (_a = this.localeData.year) === null || _a === void 0 ? void 0 : _a.suffix;
  925. 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: {
  926. year: true,
  927. "year--suffix": !!suffix
  928. }, 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 }))));
  929. }
  930. setNextPrevMonthDates() {
  931. if (!this.activeDate) {
  932. return;
  933. }
  934. this.nextMonthDate = resources.dateFromRange(resources.nextMonth(this.activeDate), this.min, this.max);
  935. this.prevMonthDate = resources.dateFromRange(resources.prevMonth(this.activeDate), this.min, this.max);
  936. }
  937. formatCalendarYear(year) {
  938. const { localeData } = this;
  939. const buddhistCalendar = localeData["default-calendar"] === "buddhist";
  940. const yearOffset = buddhistCalendar ? BUDDHIST_CALENDAR_YEAR_OFFSET : 0;
  941. return locale.numberStringFormatter.localize(`${year + yearOffset}`);
  942. }
  943. parseCalendarYear(year) {
  944. const { localeData } = this;
  945. const buddhistCalendar = localeData["default-calendar"] === "buddhist";
  946. const yearOffset = buddhistCalendar ? BUDDHIST_CALENDAR_YEAR_OFFSET : 0;
  947. const parsedYear = Number(locale.numberStringFormatter.delocalize(year)) - yearOffset;
  948. return locale.numberStringFormatter.localize(`${parsedYear}`);
  949. }
  950. getInRangeDate({ localizedYear, offset = 0 }) {
  951. const { min, max, activeDate } = this;
  952. const parsedYear = Number(locale.numberStringFormatter.delocalize(localizedYear));
  953. const length = parsedYear.toString().length;
  954. const year = isNaN(parsedYear) ? false : parsedYear + offset;
  955. const inRange = year && (!min || min.getFullYear() <= year) && (!max || max.getFullYear() >= year);
  956. // if you've supplied a year and it's in range
  957. if (year && inRange && length === localizedYear.length) {
  958. const nextDate = new Date(activeDate);
  959. nextDate.setFullYear(year);
  960. return resources.dateFromRange(nextDate, min, max);
  961. }
  962. }
  963. /**
  964. * Parse localized year string from input,
  965. * set to active if in range
  966. *
  967. * @param root0
  968. * @param root0.localizedYear
  969. * @param root0.commit
  970. * @param root0.offset
  971. */
  972. setYear({ localizedYear, commit = true, offset = 0 }) {
  973. const { yearInput, activeDate } = this;
  974. const inRangeDate = this.getInRangeDate({ localizedYear, offset });
  975. // if you've supplied a year and it's in range, update active date
  976. if (inRangeDate) {
  977. this.calciteDatePickerSelect.emit(inRangeDate);
  978. }
  979. if (commit) {
  980. yearInput.value = this.formatCalendarYear((inRangeDate || activeDate).getFullYear());
  981. }
  982. }
  983. get el() { return index.getElement(this); }
  984. static get watchers() { return {
  985. "min": ["setNextPrevMonthDates"],
  986. "max": ["setNextPrevMonthDates"],
  987. "activeDate": ["setNextPrevMonthDates"]
  988. }; }
  989. };
  990. DatePickerMonthHeader.style = datePickerMonthHeaderCss;
  991. exports.calcite_date_picker = DatePicker;
  992. exports.calcite_date_picker_day = DatePickerDay;
  993. exports.calcite_date_picker_month = DatePickerMonth;
  994. exports.calcite_date_picker_month_header = DatePickerMonthHeader;