calcite-date-picker_4.entry.js 56 KB

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