calcite-date-picker_4.entry.js 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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.82
  5. */
  6. import { r as registerInstance, c as createEvent, h, H as Host, g as getElement, F as Fragment } from './index-8ece2564.js';
  7. import { T as TEXT, c as getDaysDiff, d as dateToISO, a as dateFromISO, b as dateFromRange, g as getLocaleData, H as HEADING_LEVEL, s as sameDate, i as inRange, l as localizeNumber, e as getOrder, n as nextMonth, f as prevMonth, h as parseNumber } from './resources-f170fbe8.js';
  8. import { a as getElementDir, C as CSS_UTILITY } from './dom-da697a3f.js';
  9. import { u as updateHostInteraction } from './interactive-cb5bf285.js';
  10. import { H as Heading } from './Heading-8d613e81.js';
  11. import './locale-7ce850e5.js';
  12. import './number-237e74a9.js';
  13. import './guid-b4461004.js';
  14. const datePickerCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{position:relative;display:inline-block;width:100%;overflow:visible;border-radius:0px;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-2);background-color:var(--calcite-ui-foreground-1);vertical-align:top}:host([scale=s]){max-width:216px}:host([scale=m]){max-width:286px}:host([scale=l]){max-width:398px}";
  15. const DatePicker = class {
  16. constructor(hostRef) {
  17. registerInstance(this, hostRef);
  18. this.calciteDatePickerChange = createEvent(this, "calciteDatePickerChange", 7);
  19. this.calciteDatePickerRangeChange = createEvent(this, "calciteDatePickerRangeChange", 7);
  20. /** Localized string for "previous month" (used for aria label)
  21. * @default "Previous month"
  22. */
  23. this.intlPrevMonth = TEXT.prevMonth;
  24. /** Localized string for "next month" (used for aria label)
  25. * @default "Next month"
  26. */
  27. this.intlNextMonth = TEXT.nextMonth;
  28. /** Localized string for "year" (used for aria label)
  29. * @default "Year"
  30. */
  31. this.intlYear = TEXT.year;
  32. /** BCP 47 language tag for desired language and country format */
  33. this.locale = document.documentElement.lang || "en";
  34. /** specify the scale of the date picker */
  35. this.scale = "m";
  36. /** Range mode activation */
  37. this.range = false;
  38. /** Disables the default behaviour on the third click of narrowing or extending the range and instead starts a new range. */
  39. this.proximitySelectionDisabled = false;
  40. //--------------------------------------------------------------------------
  41. //
  42. // Private Methods
  43. //
  44. //--------------------------------------------------------------------------
  45. this.keyUpHandler = (e) => {
  46. if (e.key === "Escape") {
  47. this.reset();
  48. }
  49. };
  50. this.monthHeaderSelectChange = (e) => {
  51. const date = new Date(e.detail);
  52. if (!this.range) {
  53. this.activeDate = date;
  54. }
  55. else {
  56. if (this.activeRange === "end") {
  57. this.activeEndDate = date;
  58. }
  59. else {
  60. this.activeStartDate = date;
  61. }
  62. this.mostRecentRangeValue = date;
  63. }
  64. };
  65. this.monthActiveDateChange = (e) => {
  66. const date = new Date(e.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.monthHoverChange = (e) => {
  81. if (!this.startAsDate) {
  82. this.hoverRange = undefined;
  83. return;
  84. }
  85. const date = new Date(e.detail);
  86. this.hoverRange = {
  87. focused: this.activeRange || "start",
  88. start: this.startAsDate,
  89. end: this.endAsDate
  90. };
  91. if (!this.proximitySelectionDisabled) {
  92. if (this.endAsDate) {
  93. const startDiff = getDaysDiff(date, this.startAsDate);
  94. const endDiff = getDaysDiff(date, this.endAsDate);
  95. if (endDiff > 0) {
  96. this.hoverRange.end = date;
  97. this.hoverRange.focused = "end";
  98. }
  99. else if (startDiff < 0) {
  100. this.hoverRange.start = date;
  101. this.hoverRange.focused = "start";
  102. }
  103. else if (startDiff > endDiff) {
  104. this.hoverRange.start = date;
  105. this.hoverRange.focused = "start";
  106. }
  107. else {
  108. this.hoverRange.end = date;
  109. this.hoverRange.focused = "end";
  110. }
  111. }
  112. else {
  113. if (date < this.startAsDate) {
  114. this.hoverRange = {
  115. focused: "start",
  116. start: date,
  117. end: this.startAsDate
  118. };
  119. }
  120. else {
  121. this.hoverRange.end = date;
  122. this.hoverRange.focused = "end";
  123. }
  124. }
  125. }
  126. else {
  127. if (!this.endAsDate) {
  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. else {
  141. this.hoverRange = undefined;
  142. }
  143. }
  144. };
  145. this.monthMouseOutChange = () => {
  146. if (this.hoverRange) {
  147. this.hoverRange = undefined;
  148. }
  149. };
  150. /**
  151. * Reset active date and close
  152. */
  153. this.reset = () => {
  154. var _a, _b, _c, _d, _e, _f;
  155. if (!Array.isArray(this.valueAsDate) &&
  156. this.valueAsDate &&
  157. ((_a = this.valueAsDate) === null || _a === void 0 ? void 0 : _a.getTime()) !== ((_b = this.activeDate) === null || _b === void 0 ? void 0 : _b.getTime())) {
  158. this.activeDate = new Date(this.valueAsDate);
  159. }
  160. 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())) {
  161. this.activeStartDate = new Date(this.startAsDate);
  162. }
  163. 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())) {
  164. this.activeEndDate = new Date(this.endAsDate);
  165. }
  166. };
  167. /**
  168. * Event handler for when the selected date changes
  169. */
  170. this.monthDateChange = (e) => {
  171. const date = new Date(e.detail);
  172. if (!this.range) {
  173. this.value = date ? dateToISO(date) : "";
  174. this.valueAsDate = date || null;
  175. this.activeDate = date || null;
  176. this.calciteDatePickerChange.emit(date);
  177. return;
  178. }
  179. if (!this.startAsDate || (!this.endAsDate && date < this.startAsDate)) {
  180. if (this.startAsDate) {
  181. this.setEndDate(new Date(this.startAsDate));
  182. }
  183. if (this.activeRange == "end") {
  184. this.setEndDate(date);
  185. }
  186. else {
  187. this.setStartDate(date);
  188. }
  189. }
  190. else if (!this.endAsDate) {
  191. this.setEndDate(date);
  192. }
  193. else {
  194. if (!this.proximitySelectionDisabled) {
  195. if (this.activeRange) {
  196. if (this.activeRange == "end") {
  197. this.setEndDate(date);
  198. }
  199. else {
  200. this.setStartDate(date);
  201. }
  202. }
  203. else {
  204. const startDiff = getDaysDiff(date, this.startAsDate);
  205. const endDiff = getDaysDiff(date, this.endAsDate);
  206. if (endDiff === 0 || startDiff < 0) {
  207. this.setStartDate(date);
  208. }
  209. else if (startDiff === 0 || endDiff < 0) {
  210. this.setEndDate(date);
  211. }
  212. else if (startDiff < endDiff) {
  213. this.setStartDate(date);
  214. }
  215. else {
  216. this.setEndDate(date);
  217. }
  218. }
  219. }
  220. else {
  221. this.setStartDate(date);
  222. this.endAsDate = this.activeEndDate = this.end = undefined;
  223. }
  224. }
  225. this.calciteDatePickerChange.emit(date);
  226. };
  227. }
  228. handleValueAsDate(date) {
  229. if (!Array.isArray(date) && date && date !== this.activeDate) {
  230. this.activeDate = date;
  231. }
  232. }
  233. handleRangeChange() {
  234. const { startAsDate: startDate, endAsDate: endDate } = this;
  235. this.activeEndDate = endDate;
  236. this.activeStartDate = startDate;
  237. }
  238. onMinChanged(min) {
  239. if (min) {
  240. this.minAsDate = dateFromISO(min);
  241. }
  242. }
  243. onMaxChanged(max) {
  244. if (max) {
  245. this.maxAsDate = dateFromISO(max);
  246. }
  247. }
  248. // --------------------------------------------------------------------------
  249. //
  250. // Lifecycle
  251. //
  252. // --------------------------------------------------------------------------
  253. connectedCallback() {
  254. if (Array.isArray(this.value)) {
  255. this.valueAsDate = this.value.map((v) => dateFromISO(v));
  256. this.start = this.value[0];
  257. this.end = this.value[1];
  258. }
  259. else if (this.value) {
  260. this.valueAsDate = dateFromISO(this.value);
  261. }
  262. if (this.start) {
  263. this.setStartAsDate(dateFromISO(this.start));
  264. }
  265. if (this.end) {
  266. this.setEndAsDate(dateFromISO(this.end));
  267. }
  268. if (this.min) {
  269. this.minAsDate = dateFromISO(this.min);
  270. }
  271. if (this.max) {
  272. this.maxAsDate = dateFromISO(this.max);
  273. }
  274. }
  275. async componentWillLoad() {
  276. await this.loadLocaleData();
  277. this.onMinChanged(this.min);
  278. this.onMaxChanged(this.max);
  279. }
  280. render() {
  281. var _a;
  282. const date = dateFromRange(this.range ? this.startAsDate : this.valueAsDate, this.minAsDate, this.maxAsDate);
  283. const activeStartDate = this.range
  284. ? this.getActiveStartDate(date, this.minAsDate, this.maxAsDate)
  285. : this.getActiveDate(date, this.minAsDate, this.maxAsDate);
  286. let activeDate = activeStartDate;
  287. const endDate = this.range
  288. ? dateFromRange(this.endAsDate, this.minAsDate, this.maxAsDate)
  289. : null;
  290. const activeEndDate = this.getActiveEndDate(endDate, this.minAsDate, this.maxAsDate);
  291. if ((this.activeRange === "end" ||
  292. (((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.focused) === "end" && (!this.proximitySelectionDisabled || endDate))) &&
  293. activeEndDate) {
  294. activeDate = activeEndDate;
  295. }
  296. if (this.range && this.mostRecentRangeValue) {
  297. activeDate = this.mostRecentRangeValue;
  298. }
  299. const minDate = this.range && this.activeRange
  300. ? this.activeRange === "start"
  301. ? this.minAsDate
  302. : date || this.minAsDate
  303. : this.minAsDate;
  304. const maxDate = this.range && this.activeRange
  305. ? this.activeRange === "start"
  306. ? endDate || this.maxAsDate
  307. : this.maxAsDate
  308. : this.maxAsDate;
  309. return (h(Host, { onBlur: this.reset, onKeyUp: this.keyUpHandler, role: "application" }, this.renderCalendar(activeDate, maxDate, minDate, date, endDate)));
  310. }
  311. valueHandler(value) {
  312. if (Array.isArray(value)) {
  313. this.valueAsDate = value.map((v) => dateFromISO(v));
  314. this.start = value[0];
  315. this.end = value[1];
  316. }
  317. else if (value) {
  318. this.valueAsDate = dateFromISO(value);
  319. this.start = "";
  320. this.end = "";
  321. }
  322. }
  323. startWatcher(start) {
  324. this.setStartAsDate(dateFromISO(start));
  325. }
  326. endWatcher(end) {
  327. this.setEndAsDate(dateFromISO(end));
  328. }
  329. async loadLocaleData() {
  330. const { locale } = this;
  331. this.localeData = await getLocaleData(locale);
  332. }
  333. /**
  334. * Render calcite-date-picker-month-header and calcite-date-picker-month
  335. */
  336. renderCalendar(activeDate, maxDate, minDate, date, endDate) {
  337. return (this.localeData && [
  338. 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() }),
  339. h("calcite-date-picker-month", { activeDate: activeDate, endDate: this.range ? endDate : undefined, hoverRange: this.hoverRange, localeData: this.localeData, max: maxDate, min: minDate, onCalciteDatePickerActiveDateChange: this.monthActiveDateChange, onCalciteDatePickerHover: this.monthHoverChange, onCalciteDatePickerMouseOut: this.monthMouseOutChange, onCalciteDatePickerSelect: this.monthDateChange, scale: this.scale, selectedDate: this.activeRange === "end" ? endDate : date, startDate: this.range ? date : undefined })
  340. ]);
  341. }
  342. /**
  343. * Update date instance of start if valid
  344. */
  345. setStartAsDate(startDate, emit) {
  346. this.startAsDate = startDate;
  347. this.mostRecentRangeValue = this.startAsDate;
  348. if (emit) {
  349. this.calciteDatePickerRangeChange.emit({
  350. startDate,
  351. endDate: this.endAsDate
  352. });
  353. }
  354. }
  355. /**
  356. * Update date instance of end if valid
  357. */
  358. setEndAsDate(endDate, emit) {
  359. this.endAsDate = endDate;
  360. this.mostRecentRangeValue = this.endAsDate;
  361. if (emit) {
  362. this.calciteDatePickerRangeChange.emit({
  363. startDate: this.startAsDate,
  364. endDate
  365. });
  366. }
  367. }
  368. setEndDate(date) {
  369. this.end = date ? dateToISO(date) : "";
  370. this.setEndAsDate(date, true);
  371. this.activeEndDate = date || null;
  372. }
  373. setStartDate(date) {
  374. this.start = date ? dateToISO(date) : "";
  375. this.setStartAsDate(date, true);
  376. this.activeStartDate = date || null;
  377. }
  378. /**
  379. * Get an active date using the value, or current date as default
  380. */
  381. getActiveDate(value, min, max) {
  382. return dateFromRange(this.activeDate, min, max) || value || dateFromRange(new Date(), min, max);
  383. }
  384. getActiveStartDate(value, min, max) {
  385. return (dateFromRange(this.activeStartDate, min, max) || value || dateFromRange(new Date(), min, max));
  386. }
  387. getActiveEndDate(value, min, max) {
  388. return (dateFromRange(this.activeEndDate, min, max) || value || dateFromRange(new Date(), min, max));
  389. }
  390. static get assetsDirs() { return ["assets"]; }
  391. get el() { return getElement(this); }
  392. static get watchers() { return {
  393. "valueAsDate": ["handleValueAsDate"],
  394. "startAsDate": ["handleRangeChange"],
  395. "endAsDate": ["handleRangeChange"],
  396. "min": ["onMinChanged"],
  397. "max": ["onMaxChanged"],
  398. "value": ["valueHandler"],
  399. "start": ["startWatcher"],
  400. "end": ["endWatcher"],
  401. "locale": ["loadLocaleData"]
  402. }; }
  403. };
  404. DatePicker.style = datePickerCss;
  405. const datePickerDayCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:-ms-flexbox;display:flex;min-width:0px;cursor:pointer;-ms-flex-pack:center;justify-content:center;color:var(--calcite-ui-text-3);width:14.2857142857%}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.day-v-wrapper{-ms-flex:1 1 auto;flex:1 1 auto}.day-wrapper{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center}.day{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-radius:9999px;font-size:var(--calcite-font-size--2);line-height:1rem;line-height:1;color:var(--calcite-ui-text-3);opacity:var(--calcite-ui-opacity-disabled);-webkit-transition-property:all;transition-property:all;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-duration:150ms;transition-duration:150ms;background:none;-webkit-box-shadow:0 0 0 2px transparent, 0 0 0 0px transparent;box-shadow:0 0 0 2px transparent, 0 0 0 0px transparent}.text{margin-top:1px;margin-right:0px;margin-bottom:0px;margin-left:1px}:host([scale=s]) .day-v-wrapper{padding-top:0.125rem;padding-bottom:0.125rem}:host([scale=s]) .day-wrapper{padding:0px}:host([scale=s]) .day{height:27px;width:27px;font-size:var(--calcite-font-size--2)}:host([scale=m]) .day-v-wrapper{padding-top:0.25rem;padding-bottom:0.25rem}:host([scale=m]) .day-wrapper{padding-left:0.25rem;padding-right:0.25rem}:host([scale=m]) .day{height:33px;width:33px;font-size:var(--calcite-font-size--1)}:host([scale=l]) .day-v-wrapper{padding-top:0.25rem;padding-bottom:0.25rem}:host([scale=l]) .day-wrapper{padding-left:0.25rem;padding-right:0.25rem}:host([scale=l]) .day{height:43px;width:43px;font-size:var(--calcite-font-size-0)}:host([current-month]) .day{opacity:1}:host(:hover:not([disabled])) .day,:host([active]:not([range])) .day{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}:host(:focus),:host([active]){outline:2px solid transparent;outline-offset:2px;z-index:1}:host(:focus:not([disabled])) .day{-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1), 0 0 0 4px var(--calcite-ui-brand);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1), 0 0 0 4px var(--calcite-ui-brand)}:host([selected]) .day{font-weight:var(--calcite-font-weight-medium);background-color:var(--calcite-ui-brand) !important;color:var(--calcite-ui-foreground-1) !important;z-index:1}:host([range][selected]) .day-wrapper{background-color:var(--calcite-ui-foreground-current)}:host([start-of-range]) .day-wrapper{border-start-start-radius:40%;border-end-start-radius:40%}:host([end-of-range]) .day-wrapper{border-start-end-radius:40%;border-end-end-radius:40%}:host([start-of-range]) :not(.calcite--rtl) .day-wrapper,:host([end-of-range]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 4px 0 var(--calcite-ui-foreground-1);box-shadow:inset 4px 0 var(--calcite-ui-foreground-1)}:host([start-of-range]) :not(.calcite--rtl) .day,:host([end-of-range]) .calcite--rtl .day{opacity:1}:host([start-of-range]:not(:focus)) :not(.calcite--rtl) .day,:host([end-of-range]:not(:focus)) .calcite--rtl .day{-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([end-of-range]) :not(.calcite--rtl) .day-wrapper,:host([start-of-range]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -4px 0 var(--calcite-ui-foreground-1);box-shadow:inset -4px 0 var(--calcite-ui-foreground-1)}:host([end-of-range]) :not(.calcite--rtl) .day,:host([start-of-range]) .calcite--rtl .day{opacity:1}:host([end-of-range]:not(:focus)) :not(.calcite--rtl) .day,:host([start-of-range]:not(:focus)) .calcite--rtl .day{-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host([end-of-range][scale=l]) :not(.calcite--rtl) .day-wrapper,:host([start-of-range][scale=l]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -8px 0 var(--calcite-ui-foreground-1);box-shadow:inset -8px 0 var(--calcite-ui-foreground-1)}:host([start-of-range][scale=l]) :not(.calcite--rtl) .day-wrapper,:host([end-of-range][scale=l]) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 8px 0 var(--calcite-ui-foreground-1);box-shadow:inset 8px 0 var(--calcite-ui-foreground-1)}:host([highlighted]) .day-wrapper{background-color:var(--calcite-ui-foreground-current)}:host([highlighted]) .day-wrapper .day{color:var(--calcite-ui-text-1)}:host([highlighted]:not([active]:focus)) .day{border-radius:0px;color:var(--calcite-ui-text-1)}:host([range-hover]:not([selected])) .day-wrapper{background-color:var(--calcite-ui-foreground-2)}:host([range-hover]:not([selected])) .day{border-radius:0px}:host([end-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host([start-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host([start-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host([end-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, right top, left top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to left, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host(:hover[end-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host(:hover[start-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-1)), to(var(--calcite-ui-foreground-1)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host(:hover[start-of-range][range-hover]) :not(.calcite--rtl) .day-wrapper,:host(:hover[end-of-range][range-hover]) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, right top, left top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-1)), to(var(--calcite-ui-foreground-1)));background-image:linear-gradient(to left, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1));border-radius:0px;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;-webkit-box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)}:host(:hover[range-hover]:not([selected]).focused--end) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--start) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-current)), to(var(--calcite-ui-foreground-current)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current))}:host(:hover[range-hover]:not([selected]).focused--end) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--start) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--start) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--end) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-current)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-current), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2))}:host(:hover[range-hover]:not([selected]).focused--start) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--end) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-1)), color-stop(var(--calcite-ui-foreground-1)), color-stop(var(--calcite-ui-foreground-2)), to(var(--calcite-ui-foreground-2)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2))}:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) :not(.calcite--rtl) .day-wrapper,:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) .calcite--rtl .day-wrapper{background-image:-webkit-gradient(linear, left top, right top, from(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-2)), color-stop(var(--calcite-ui-foreground-1)), to(var(--calcite-ui-foreground-1)));background-image:linear-gradient(to right, var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-2), var(--calcite-ui-foreground-1), var(--calcite-ui-foreground-1))}:host(:hover[range-hover]:not([selected]).focused--end.hover--outside-range) :not(.calcite--rtl) .day,:host(:hover[range-hover]:not([selected]).focused--start.hover--outside-range) .calcite--rtl .day{border-radius:9999px;opacity:1;-webkit-box-shadow:0 0 0 2px var(--calcite-ui-foreground-1);box-shadow:0 0 0 2px var(--calcite-ui-foreground-1)}:host(:hover[start-of-range].hover--inside-range.focused--end) .day-wrapper,:host(:hover[end-of-range].hover--inside-range.focused--start) .day-wrapper{background-image:none}:host([start-of-range].hover--inside-range.focused--end) .day-wrapper,:host([end-of-range].hover--inside-range.focused--start) .day-wrapper{background-color:var(--calcite-ui-foreground-2)}:host([highlighted]:last-child) :not(.calcite--rtl) .day-wrapper,:host([range-hover]:last-child) :not(.calcite--rtl) .day-wrapper,:host([highlighted]:first-child) .calcite--rtl .day-wrapper,:host([range-hover]:first-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -4px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset -4px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([highlighted]:first-child) :not(.calcite--rtl) .day-wrapper,:host([range-hover]:first-child) :not(.calcite--rtl) .day-wrapper,:host([highlighted]:last-child) .calcite--rtl .day-wrapper,:host([range-hover]:last-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 4px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset 4px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=s][highlighted]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][range-hover]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][highlighted]:first-child) .calcite--rtl .day-wrapper,:host([scale=s][range-hover]:first-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -1px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset -1px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=s][highlighted]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][range-hover]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=s][highlighted]:last-child) .calcite--rtl .day-wrapper,:host([scale=s][range-hover]:last-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 1px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset 1px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([scale=l][highlighted]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][range-hover]:first-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][highlighted]:last-child) .calcite--rtl .day-wrapper,:host([scale=l][range-hover]:last-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset 6px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset 6px 0px 0px 0px var(--calcite-ui-foreground-1)}:host([highlighted]:first-child) .day-wrapper,:host([range-hover]:first-child) .day-wrapper{border-start-start-radius:45%;border-end-start-radius:45%}:host([highlighted]:last-child) .day-wrapper,:host([range-hover]:last-child) .day-wrapper{border-start-end-radius:45%;border-end-end-radius:45%}:host([scale=l][highlighted]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][range-hover]:last-child) :not(.calcite--rtl) .day-wrapper,:host([scale=l][highlighted]:first-child) .calcite--rtl .day-wrapper,:host([scale=l][range-hover]:first-child) .calcite--rtl .day-wrapper{-webkit-box-shadow:inset -6px 0px 0px 0px var(--calcite-ui-foreground-1);box-shadow:inset -6px 0px 0px 0px var(--calcite-ui-foreground-1)}@media (forced-colors: active){:host(:hover:not([disabled])) .day,:host([active]:not([range])) .day{border-radius:0px}:host([selected]){outline:2px solid canvasText;z-index:1}:host([selected]) .day{border-radius:0px;background-color:highlight}:host([range][selected]) .day-wrapper,:host([highlighted]) .day-wrapper,:host([range-hover]:not([selected])) .day-wrapper{background-color:highlight}:host([range][selected][start-of-range]) .day-wrapper,:host([range][selected][end-of-range]) .day-wrapper{background-color:canvas}}";
  406. const DatePickerDay = class {
  407. constructor(hostRef) {
  408. registerInstance(this, hostRef);
  409. this.calciteDaySelect = createEvent(this, "calciteDaySelect", 7);
  410. this.calciteDayHover = createEvent(this, "calciteDayHover", 7);
  411. /** Date is outside of range and can't be selected */
  412. this.disabled = false;
  413. /** Date is in the current month. */
  414. this.currentMonth = false;
  415. /** Date is the current selected date of the picker */
  416. this.selected = false;
  417. /** Date is currently highlighted as part of the range */
  418. this.highlighted = false;
  419. /** Showing date range */
  420. this.range = false;
  421. /** Date is the start of date range */
  422. this.startOfRange = false;
  423. /** Date is the end of date range */
  424. this.endOfRange = false;
  425. /** Date is being hovered and within the set range */
  426. this.rangeHover = false;
  427. /** Date is actively in focus for keyboard navigation */
  428. this.active = false;
  429. //--------------------------------------------------------------------------
  430. //
  431. // Event Listeners
  432. //
  433. //--------------------------------------------------------------------------
  434. this.onClick = () => {
  435. !this.disabled && this.calciteDaySelect.emit();
  436. };
  437. this.keyDownHandler = (e) => {
  438. const key = e.key;
  439. if (key === " " || key === "Enter") {
  440. !this.disabled && this.calciteDaySelect.emit();
  441. }
  442. };
  443. }
  444. mouseoverHandler() {
  445. this.calciteDayHover.emit({
  446. disabled: this.disabled
  447. });
  448. }
  449. //--------------------------------------------------------------------------
  450. //
  451. // Lifecycle
  452. //
  453. //--------------------------------------------------------------------------
  454. render() {
  455. const formattedDay = String(this.day)
  456. .split("")
  457. .map((i) => this.localeData.numerals[i])
  458. .join("");
  459. const dir = getElementDir(this.el);
  460. 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))))));
  461. }
  462. componentDidRender() {
  463. updateHostInteraction(this, this.isTabbable);
  464. }
  465. isTabbable() {
  466. return this.active;
  467. }
  468. get el() { return getElement(this); }
  469. };
  470. DatePickerDay.style = datePickerDayCss;
  471. const datePickerMonthCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}.calender{margin-bottom:0.25rem}.week-headers{display:-ms-flexbox;display:flex;border-width:0px;border-top-width:1px;border-style:solid;border-color:var(--calcite-ui-border-3);padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem}.week-header{text-align:center;font-weight:var(--calcite-font-weight-bold);color:var(--calcite-ui-text-3);width:14.2857142857%}:host([scale=s]) .week-header{padding-left:0px;padding-right:0px;padding-top:0.5rem;padding-bottom:0.75rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=m]) .week-header{padding-left:0px;padding-right:0px;padding-top:0.75rem;padding-bottom:1rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=l]) .week-header{padding-left:0px;padding-right:0px;padding-top:1rem;padding-bottom:1.25rem;font-size:var(--calcite-font-size--1);line-height:1rem}.week-days{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;padding-top:0px;padding-bottom:0px;padding-left:6px;padding-right:6px}.week-days:focus{outline:2px solid transparent;outline-offset:2px}";
  472. const DatePickerMonth = class {
  473. constructor(hostRef) {
  474. registerInstance(this, hostRef);
  475. this.calciteDatePickerSelect = createEvent(this, "calciteDatePickerSelect", 7);
  476. this.calciteDatePickerHover = createEvent(this, "calciteDatePickerHover", 7);
  477. this.calciteDatePickerActiveDateChange = createEvent(this, "calciteDatePickerActiveDateChange", 7);
  478. this.calciteDatePickerMouseOut = createEvent(this, "calciteDatePickerMouseOut", 7);
  479. /** Date currently active.*/
  480. this.activeDate = new Date();
  481. //--------------------------------------------------------------------------
  482. //
  483. // Event Listeners
  484. //
  485. //--------------------------------------------------------------------------
  486. this.keyDownHandler = (e) => {
  487. const isRTL = this.el.dir === "rtl";
  488. switch (e.key) {
  489. case "ArrowUp":
  490. e.preventDefault();
  491. this.addDays(-7);
  492. break;
  493. case "ArrowRight":
  494. e.preventDefault();
  495. this.addDays(isRTL ? -1 : 1);
  496. break;
  497. case "ArrowDown":
  498. e.preventDefault();
  499. this.addDays(7);
  500. break;
  501. case "ArrowLeft":
  502. e.preventDefault();
  503. this.addDays(isRTL ? 1 : -1);
  504. break;
  505. case "PageUp":
  506. e.preventDefault();
  507. this.addMonths(-1);
  508. break;
  509. case "PageDown":
  510. e.preventDefault();
  511. this.addMonths(1);
  512. break;
  513. case "Home":
  514. e.preventDefault();
  515. this.activeDate.setDate(1);
  516. this.addDays();
  517. break;
  518. case "End":
  519. e.preventDefault();
  520. this.activeDate.setDate(new Date(this.activeDate.getFullYear(), this.activeDate.getMonth() + 1, 0).getDate());
  521. this.addDays();
  522. break;
  523. case "Enter":
  524. case " ":
  525. e.preventDefault();
  526. break;
  527. case "Tab":
  528. this.activeFocus = false;
  529. }
  530. };
  531. /**
  532. * Once user is not interacting via keyboard,
  533. * disable auto focusing of active date
  534. */
  535. this.disableActiveFocus = () => {
  536. this.activeFocus = false;
  537. };
  538. this.dayHover = (e) => {
  539. const target = e.target;
  540. if (e.detail.disabled) {
  541. this.calciteDatePickerMouseOut.emit();
  542. }
  543. else {
  544. this.calciteDatePickerHover.emit(target.value);
  545. }
  546. };
  547. this.daySelect = (e) => {
  548. const target = e.target;
  549. this.calciteDatePickerSelect.emit(target.value);
  550. };
  551. }
  552. mouseoutHandler() {
  553. this.calciteDatePickerMouseOut.emit();
  554. }
  555. //--------------------------------------------------------------------------
  556. //
  557. // Lifecycle
  558. //
  559. //--------------------------------------------------------------------------
  560. render() {
  561. const month = this.activeDate.getMonth();
  562. const year = this.activeDate.getFullYear();
  563. const startOfWeek = this.localeData.weekStart % 7;
  564. const { abbreviated, short, narrow } = this.localeData.days;
  565. const weekDays = this.scale === "s" ? narrow || short || abbreviated : short || abbreviated || narrow;
  566. const adjustedWeekDays = [...weekDays.slice(startOfWeek, 7), ...weekDays.slice(0, startOfWeek)];
  567. const curMonDays = this.getCurrentMonthDays(month, year);
  568. const prevMonDays = this.getPrevMonthdays(month, year, startOfWeek);
  569. const nextMonDays = this.getNextMonthDays(month, year, startOfWeek);
  570. const days = [
  571. ...prevMonDays.map((day) => {
  572. const date = new Date(year, month - 1, day);
  573. return this.renderDateDay(false, day, date);
  574. }),
  575. ...curMonDays.map((day) => {
  576. const date = new Date(year, month, day);
  577. const active = sameDate(date, this.activeDate);
  578. return this.renderDateDay(active, day, date, true, true);
  579. }),
  580. ...nextMonDays.map((day) => {
  581. const date = new Date(year, month + 1, day);
  582. return this.renderDateDay(false, day, date);
  583. })
  584. ];
  585. const weeks = [];
  586. for (let i = 0; i < days.length; i += 7) {
  587. weeks.push(days.slice(i, i + 7));
  588. }
  589. 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))))));
  590. }
  591. //--------------------------------------------------------------------------
  592. //
  593. // Private Methods
  594. //
  595. //--------------------------------------------------------------------------
  596. /**
  597. * Add n months to the current month
  598. */
  599. addMonths(step) {
  600. const nextDate = new Date(this.activeDate);
  601. nextDate.setMonth(this.activeDate.getMonth() + step);
  602. this.calciteDatePickerActiveDateChange.emit(dateFromRange(nextDate, this.min, this.max));
  603. this.activeFocus = true;
  604. }
  605. /**
  606. * Add n days to the current date
  607. */
  608. addDays(step = 0) {
  609. const nextDate = new Date(this.activeDate);
  610. nextDate.setDate(this.activeDate.getDate() + step);
  611. this.calciteDatePickerActiveDateChange.emit(dateFromRange(nextDate, this.min, this.max));
  612. this.activeFocus = true;
  613. }
  614. /**
  615. * Get dates for last days of the previous month
  616. */
  617. getPrevMonthdays(month, year, startOfWeek) {
  618. const lastDate = new Date(year, month, 0);
  619. const date = lastDate.getDate();
  620. const day = lastDate.getDay();
  621. const days = [];
  622. if (day - 6 === startOfWeek) {
  623. return days;
  624. }
  625. for (let i = Math.abs(lastDate.getDay() - startOfWeek); i >= 0; i--) {
  626. days.push(date - i);
  627. }
  628. return days;
  629. }
  630. /**
  631. * Get dates for the current month
  632. */
  633. getCurrentMonthDays(month, year) {
  634. const num = new Date(year, month + 1, 0).getDate();
  635. const days = [];
  636. for (let i = 0; i < num; i++) {
  637. days.push(i + 1);
  638. }
  639. return days;
  640. }
  641. /**
  642. * Get dates for first days of the next month
  643. */
  644. getNextMonthDays(month, year, startOfWeek) {
  645. const endDay = new Date(year, month + 1, 0).getDay();
  646. const days = [];
  647. if (endDay === (startOfWeek + 6) % 7) {
  648. return days;
  649. }
  650. for (let i = 0; i < (6 - (endDay - startOfWeek)) % 7; i++) {
  651. days.push(i + 1);
  652. }
  653. return days;
  654. }
  655. /**
  656. * Determine if the date is in between the start and end dates
  657. */
  658. betweenSelectedRange(date) {
  659. return !!(this.startDate &&
  660. this.endDate &&
  661. date > this.startDate &&
  662. date < this.endDate &&
  663. !this.isRangeHover(date));
  664. }
  665. /**
  666. * Determine if the date should be in selected state
  667. */
  668. isSelected(date) {
  669. return !!(sameDate(date, this.selectedDate) ||
  670. (this.startDate && sameDate(date, this.startDate)) ||
  671. (this.endDate && sameDate(date, this.endDate)));
  672. }
  673. /**
  674. * Determine if the date is the start of the date range
  675. */
  676. isStartOfRange(date) {
  677. return !!(this.startDate &&
  678. !sameDate(this.startDate, this.endDate) &&
  679. sameDate(this.startDate, date) &&
  680. !this.isEndOfRange(date));
  681. }
  682. isEndOfRange(date) {
  683. return !!((this.endDate && !sameDate(this.startDate, this.endDate) && sameDate(this.endDate, date)) ||
  684. (!this.endDate &&
  685. this.hoverRange &&
  686. sameDate(this.startDate, this.hoverRange.end) &&
  687. sameDate(date, this.hoverRange.end)));
  688. }
  689. /**
  690. * Render calcite-date-picker-day
  691. */
  692. renderDateDay(active, day, date, currentMonth, ref) {
  693. var _a;
  694. const isFocusedOnStart = this.isFocusedOnStart();
  695. const isHoverInRange = this.isHoverInRange() ||
  696. (!this.endDate && this.hoverRange && sameDate((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.end, this.startDate));
  697. return (h("calcite-date-picker-day", { active: active, class: {
  698. "hover--inside-range": this.startDate && isHoverInRange,
  699. "hover--outside-range": this.startDate && !isHoverInRange,
  700. "focused--start": isFocusedOnStart,
  701. "focused--end": !isFocusedOnStart
  702. }, currentMonth: currentMonth, day: day, disabled: !inRange(date, this.min, this.max), endOfRange: this.isEndOfRange(date), highlighted: this.betweenSelectedRange(date), key: date.toDateString(), localeData: this.localeData, onCalciteDayHover: this.dayHover, onCalciteDaySelect: this.daySelect, range: !!this.startDate && !!this.endDate && !sameDate(this.startDate, this.endDate), rangeHover: this.isRangeHover(date), ref: (el) => {
  703. // when moving via keyboard, focus must be updated on active date
  704. if (ref && active && this.activeFocus) {
  705. el === null || el === void 0 ? void 0 : el.focus();
  706. }
  707. }, scale: this.scale, selected: this.isSelected(date), startOfRange: this.isStartOfRange(date), value: date }));
  708. }
  709. isFocusedOnStart() {
  710. var _a;
  711. return ((_a = this.hoverRange) === null || _a === void 0 ? void 0 : _a.focused) === "start";
  712. }
  713. isHoverInRange() {
  714. if (!this.hoverRange) {
  715. return false;
  716. }
  717. const { start, end } = this.hoverRange;
  718. return !!((!this.isFocusedOnStart() && this.startDate && (!this.endDate || end < this.endDate)) ||
  719. (this.isFocusedOnStart() && this.startDate && start > this.startDate));
  720. }
  721. isRangeHover(date) {
  722. if (!this.hoverRange) {
  723. return false;
  724. }
  725. const { start, end } = this.hoverRange;
  726. const isStart = this.isFocusedOnStart();
  727. const insideRange = this.isHoverInRange();
  728. const cond1 = insideRange &&
  729. ((!isStart && date > this.startDate && (date < end || sameDate(date, end))) ||
  730. (isStart && date < this.endDate && (date > start || sameDate(date, start))));
  731. const cond2 = !insideRange &&
  732. ((!isStart && date >= this.endDate && (date < end || sameDate(date, end))) ||
  733. (isStart &&
  734. (date < this.startDate || (this.endDate && sameDate(date, this.startDate))) &&
  735. (date > start || sameDate(date, start))));
  736. return cond1 || cond2;
  737. }
  738. get el() { return getElement(this); }
  739. };
  740. DatePickerMonth.style = datePickerMonthCss;
  741. const datePickerMonthHeaderCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:block}.header{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;padding-top:0px;padding-bottom:0px;padding-left:0.25rem;padding-right:0.25rem}:host([scale=s]) .text{margin-top:0.5rem;margin-bottom:0.5rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=s]) .chevron{height:2.25rem}:host([scale=m]) .text{margin-top:0.75rem;margin-bottom:0.75rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([scale=m]) .chevron{height:3rem}:host([scale=l]) .text{margin-top:1rem;margin-bottom:1rem;font-size:var(--calcite-font-size-1);line-height:1.5rem}:host([scale=l]) .chevron{height:3.5rem}.chevron{margin-left:-0.25rem;margin-right:-0.25rem;-webkit-box-sizing:content-box;box-sizing:content-box;display:-ms-flexbox;display:flex;-ms-flex-positive:0;flex-grow:0;cursor:pointer;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;border-style:none;background-color:var(--calcite-ui-foreground-1);padding-left:0.25rem;padding-right:0.25rem;color:var(--calcite-ui-text-3);outline:2px solid transparent;outline-offset:2px;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;width:14.2857142857%}.chevron:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.chevron:hover,.chevron:focus{background-color:var(--calcite-ui-foreground-2);fill:var(--calcite-ui-text-1);color:var(--calcite-ui-text-1)}.chevron:active{background-color:var(--calcite-ui-foreground-3)}.chevron[aria-disabled=true]{pointer-events:none;opacity:0}.text{margin-top:auto;margin-bottom:auto;width:100%;-ms-flex:1 1 auto;flex:1 1 auto;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;text-align:center;line-height:1}.text-nreverse{-ms-flex-direction:row-reverse;flex-direction:row-reverse}.month,.year,.suffix{margin-left:0.25rem;margin-right:0.25rem;margin-top:auto;margin-bottom:auto;display:inline-block;background-color:var(--calcite-ui-foreground-1);font-weight:var(--calcite-font-weight-medium);line-height:1.25;color:var(--calcite-ui-text-1);font-size:inherit}.year{position:relative;width:3rem;border-style:none;background-color:transparent;text-align:center;font-family:inherit;outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;z-index:2}.year:hover{-webkit-transition-duration:100ms;transition-duration:100ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);-webkit-transition-property:outline-color;transition-property:outline-color;outline:2px solid var(--calcite-ui-border-2);outline-offset:2px}.year:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:2px}.year--suffix{width:4rem;text-align:left}.year-wrap{position:relative}.suffix{position:absolute;top:0px;left:0px;width:4rem;white-space:nowrap;text-align:left}.suffix__invisible{visibility:hidden}";
  742. const DatePickerMonthHeader = class {
  743. constructor(hostRef) {
  744. registerInstance(this, hostRef);
  745. this.calciteDatePickerSelect = createEvent(this, "calciteDatePickerSelect", 7);
  746. //--------------------------------------------------------------------------
  747. //
  748. // Private Methods
  749. //
  750. //--------------------------------------------------------------------------
  751. /**
  752. * Increment year on UP/DOWN keys
  753. */
  754. this.onYearKey = (e) => {
  755. const localizedYear = e.target.value;
  756. switch (e.key) {
  757. case "ArrowDown":
  758. e.preventDefault();
  759. this.setYear({ localizedYear, offset: -1 });
  760. break;
  761. case "ArrowUp":
  762. e.preventDefault();
  763. this.setYear({ localizedYear, offset: 1 });
  764. break;
  765. }
  766. };
  767. this.onYearChange = (event) => {
  768. this.setYear({ localizedYear: event.target.value });
  769. };
  770. this.onYearInput = (event) => {
  771. this.setYear({ localizedYear: event.target.value, commit: false });
  772. };
  773. this.prevMonthClick = (e) => {
  774. this.handleArrowClick(e, this.prevMonthDate);
  775. };
  776. this.prevMonthKeydown = (e) => {
  777. const key = e.key;
  778. if (key === " " || key === "Enter") {
  779. this.prevMonthClick(e);
  780. }
  781. };
  782. this.nextMonthClick = (e) => {
  783. this.handleArrowClick(e, this.nextMonthDate);
  784. };
  785. this.nextMonthKeydown = (e) => {
  786. const key = e.key;
  787. if (key === " " || key === "Enter") {
  788. this.nextMonthClick(e);
  789. }
  790. };
  791. /*
  792. * Update active month on clicks of left/right arrows
  793. */
  794. this.handleArrowClick = (e, date) => {
  795. e === null || e === void 0 ? void 0 : e.preventDefault();
  796. e.stopPropagation();
  797. this.calciteDatePickerSelect.emit(date);
  798. };
  799. }
  800. //--------------------------------------------------------------------------
  801. //
  802. // Lifecycle
  803. //
  804. //--------------------------------------------------------------------------
  805. connectedCallback() {
  806. this.setNextPrevMonthDates();
  807. }
  808. render() {
  809. return h("div", { class: "header" }, this.renderContent());
  810. }
  811. renderContent() {
  812. var _a;
  813. if (!this.activeDate || !this.localeData) {
  814. return null;
  815. }
  816. const activeMonth = this.activeDate.getMonth();
  817. const { months, unitOrder } = this.localeData;
  818. const localizedMonth = (months.wide || months.narrow || months.abbreviated)[activeMonth];
  819. const localizedYear = localizeNumber(this.activeDate.getFullYear(), this.localeData);
  820. const iconScale = this.scale === "l" ? "m" : "s";
  821. const order = getOrder(unitOrder);
  822. const reverse = order.indexOf("y") < order.indexOf("m");
  823. const suffix = (_a = this.localeData.year) === null || _a === void 0 ? void 0 : _a.suffix;
  824. return (h(Fragment, null, h("a", { "aria-disabled": (this.prevMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlPrevMonth, class: "chevron", href: "#", onClick: this.prevMonthClick, onKeyDown: this.prevMonthKeydown, role: "button", tabindex: this.prevMonthDate.getMonth() === activeMonth ? -1 : 0 }, 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: {
  825. year: true,
  826. "year--suffix": !!suffix
  827. }, 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" }, h("span", { "aria-hidden": "true", class: "suffix__invisible" }, localizedYear), " " + suffix)))), h("a", { "aria-disabled": (this.nextMonthDate.getMonth() === activeMonth).toString(), "aria-label": this.intlNextMonth, class: "chevron", href: "#", onClick: this.nextMonthClick, onKeyDown: this.nextMonthKeydown, role: "button", tabindex: this.nextMonthDate.getMonth() === activeMonth ? -1 : 0 }, h("calcite-icon", { "flip-rtl": true, icon: "chevron-right", scale: iconScale }))));
  828. }
  829. setNextPrevMonthDates() {
  830. if (!this.activeDate) {
  831. return;
  832. }
  833. this.nextMonthDate = dateFromRange(nextMonth(this.activeDate), this.min, this.max);
  834. this.prevMonthDate = dateFromRange(prevMonth(this.activeDate), this.min, this.max);
  835. }
  836. getInRangeDate({ localizedYear, offset = 0 }) {
  837. const { min, max, activeDate, localeData } = this;
  838. const parsedYear = parseNumber(localizedYear, localeData);
  839. const length = parsedYear.toString().length;
  840. const year = isNaN(parsedYear) ? false : parsedYear + offset;
  841. const inRange = year && (!min || min.getFullYear() <= year) && (!max || max.getFullYear() >= year);
  842. // if you've supplied a year and it's in range
  843. if (year && inRange && length === localizedYear.length) {
  844. const nextDate = new Date(activeDate);
  845. nextDate.setFullYear(year);
  846. return dateFromRange(nextDate, min, max);
  847. }
  848. }
  849. /**
  850. * Parse localized year string from input,
  851. * set to active if in range
  852. */
  853. setYear({ localizedYear, commit = true, offset = 0 }) {
  854. const { yearInput, activeDate, localeData } = this;
  855. const inRangeDate = this.getInRangeDate({ localizedYear, offset });
  856. // if you've supplied a year and it's in range, update active date
  857. if (inRangeDate) {
  858. this.calciteDatePickerSelect.emit(inRangeDate);
  859. }
  860. if (commit) {
  861. yearInput.value = localizeNumber((inRangeDate || activeDate).getFullYear(), localeData);
  862. }
  863. }
  864. get el() { return getElement(this); }
  865. static get watchers() { return {
  866. "min": ["setNextPrevMonthDates"],
  867. "max": ["setNextPrevMonthDates"],
  868. "activeDate": ["setNextPrevMonthDates"]
  869. }; }
  870. };
  871. DatePickerMonthHeader.style = datePickerMonthHeaderCss;
  872. 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 };