calcite-input-date-picker.cjs.entry.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.97
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-a0010f96.js');
  9. const resources = require('./resources-4c8610b1.js');
  10. const label = require('./label-28060b83.js');
  11. const form = require('./form-1d831023.js');
  12. const floatingUi = require('./floating-ui-b48c8256.js');
  13. const interactive = require('./interactive-32293bca.js');
  14. const dom = require('./dom-2ec8c9ed.js');
  15. const openCloseComponent = require('./openCloseComponent-178191c0.js');
  16. const locale = require('./locale-678ce361.js');
  17. const key = require('./key-6a462411.js');
  18. require('./debounce-2c8b61fb.js');
  19. require('./resources-b5a5f8a7.js');
  20. require('./guid-f4f03a7a.js');
  21. require('./observers-5706326b.js');
  22. const CSS = {
  23. menu: "menu-container",
  24. menuActive: "menu-container--active"
  25. };
  26. const inputDatePickerCss = "@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}}:host{--calcite-icon-size:1rem;--calcite-spacing-eighth:0.125rem;--calcite-spacing-quarter:0.25rem;--calcite-spacing-half:0.5rem;--calcite-spacing-three-quarters:0.75rem;--calcite-spacing:1rem;--calcite-spacing-plus-quarter:1.25rem;--calcite-spacing-plus-half:1.5rem;--calcite-spacing-double:2rem;--calcite-menu-min-width:10rem;--calcite-header-min-height:3rem;--calcite-footer-min-height:3rem}: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{position:relative;display:inline-block;inline-size:100%;overflow:visible;vertical-align:top;--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 .menu-container .calcite-floating-ui-anim{position:relative;transition:var(--calcite-floating-ui-transition);visibility:hidden;transition-property:transform, visibility, opacity;opacity:0;box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);z-index:1;border-radius:0.25rem}:host .menu-container[data-placement^=bottom] .calcite-floating-ui-anim{transform:translateY(-5px)}:host .menu-container[data-placement^=top] .calcite-floating-ui-anim{transform:translateY(5px)}:host .menu-container[data-placement^=left] .calcite-floating-ui-anim{transform:translateX(5px)}:host .menu-container[data-placement^=right] .calcite-floating-ui-anim{transform:translateX(-5px)}:host .menu-container[data-placement] .calcite-floating-ui-anim--active{opacity:1;visibility:visible;transform:translate(0)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.calendar-picker-wrapper{position:static;inline-size:100%;--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);transform:translate3d(0, 0, 0)}.input-wrapper{position:relative}:host([range]) .input-container{display:flex}:host([range]) .input-wrapper{flex:1 1 auto}:host([range]) .horizontal-arrow-container{display:flex;align-items:center;border-width:1px;border-inline-start-width:0px;border-inline-end-width:0px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-background);padding-block:0px;padding-inline:0.25rem}:host([range][layout=vertical]) .input-wrapper{inline-size:100%}:host([range][layout=vertical]) .input-container{flex-direction:column;align-items:flex-start}:host([range][layout=vertical]) .calendar-picker-wrapper--end{transform:translate3d(0, 0, 0)}:host([range][layout=vertical]) .vertical-arrow-container{inset-block-start:1.5rem;position:absolute;z-index:1;margin-inline:1px;background-color:var(--calcite-ui-foreground-1);padding-inline:0.625rem;inset-inline-start:0}:host([scale=s][range]:not([layout=vertical])) .calendar-picker-wrapper{inline-size:216px}:host([scale=m][range]:not([layout=vertical])) .calendar-picker-wrapper{inline-size:286px}:host([scale=l][range]:not([layout=vertical])) .calendar-picker-wrapper{inline-size:398px}.menu-container{display:block;position:absolute;z-index:900;inline-size:0;block-size:0;overflow:hidden;pointer-events:none;visibility:hidden}.menu-container .calcite-floating-ui-anim{position:relative;transition:var(--calcite-floating-ui-transition);visibility:hidden;transition-property:transform, visibility, opacity;opacity:0;box-shadow:0 0 16px 0 rgba(0, 0, 0, 0.16);z-index:1;border-radius:0.25rem}.menu-container[data-placement^=bottom] .calcite-floating-ui-anim{transform:translateY(-5px)}.menu-container[data-placement^=top] .calcite-floating-ui-anim{transform:translateY(5px)}.menu-container[data-placement^=left] .calcite-floating-ui-anim{transform:translateX(5px)}.menu-container[data-placement^=right] .calcite-floating-ui-anim{transform:translateX(-5px)}.menu-container[data-placement] .calcite-floating-ui-anim--active{opacity:1;visibility:visible;transform:translate(0)}:host([open]) .menu-container{pointer-events:initial;visibility:visible;inline-size:unset;block-size:unset;overflow:unset}.menu-container--active{pointer-events:initial;visibility:visible;inline-size:unset;block-size:unset;overflow:unset}.input .calcite-input__wrapper{margin-block-start:0px}:host([range][layout=vertical][scale=m]) .vertical-arrow-container{inset-block-start:1.5rem;padding-inline-start:0.75rem}:host([range][layout=vertical][scale=m]) .vertical-arrow-container calcite-icon{block-size:0.75rem;inline-size:0.75rem;min-inline-size:0px}:host([range][layout=vertical][scale=l]) .vertical-arrow-container{inset-block-start:2.25rem;padding-inline:0.875rem}:host([range][layout=vertical][open]) .vertical-arrow-container{display:none}::slotted(input[slot=hidden-form-input]){margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;inset:0 !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";
  27. const InputDatePicker = class {
  28. constructor(hostRef) {
  29. index.registerInstance(this, hostRef);
  30. this.calciteDatePickerChange = index.createEvent(this, "calciteDatePickerChange", 6);
  31. this.calciteDatePickerRangeChange = index.createEvent(this, "calciteDatePickerRangeChange", 6);
  32. this.calciteInputDatePickerChange = index.createEvent(this, "calciteInputDatePickerChange", 6);
  33. this.calciteInputDatePickerBeforeClose = index.createEvent(this, "calciteInputDatePickerBeforeClose", 6);
  34. this.calciteInputDatePickerClose = index.createEvent(this, "calciteInputDatePickerClose", 6);
  35. this.calciteInputDatePickerBeforeOpen = index.createEvent(this, "calciteInputDatePickerBeforeOpen", 6);
  36. this.calciteInputDatePickerOpen = index.createEvent(this, "calciteInputDatePickerOpen", 6);
  37. //--------------------------------------------------------------------------
  38. //
  39. // Public Properties
  40. //
  41. //--------------------------------------------------------------------------
  42. /**
  43. * When `true`, interaction is prevented and the component is displayed with lower opacity.
  44. */
  45. this.disabled = false;
  46. /**
  47. * When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
  48. *
  49. * @mdn [readOnly](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly)
  50. */
  51. this.readOnly = false;
  52. /**
  53. * When `true`, the component is active.
  54. *
  55. * @deprecated use `open` instead.
  56. */
  57. this.active = false;
  58. /** When `true`, displays the `calcite-date-picker` component. */
  59. this.open = false;
  60. /**
  61. * Accessible name for the component's previous month button.
  62. *
  63. * @default "Previous month"
  64. */
  65. this.intlPrevMonth = resources.TEXT.prevMonth;
  66. /**
  67. * Accessible name for the component's next month button.
  68. *
  69. * @default "Next month"
  70. */
  71. this.intlNextMonth = resources.TEXT.nextMonth;
  72. /**
  73. * Accessible name for the component's year input.
  74. *
  75. * @default "Year"
  76. */
  77. this.intlYear = resources.TEXT.year;
  78. /** Specifies the size of the component. */
  79. this.scale = "m";
  80. /**
  81. * Specifies the placement of the `calcite-date-picker` relative to the component.
  82. *
  83. * @default "bottom-start"
  84. */
  85. this.placement = floatingUi.defaultMenuPlacement;
  86. /** When `true`, activates a range for the component. */
  87. this.range = false;
  88. /**
  89. * When `true`, the component must have a value in order for the form to submit.
  90. *
  91. * @internal
  92. */
  93. this.required = false;
  94. /**
  95. * Determines the type of positioning to use for the overlaid content.
  96. *
  97. * Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.
  98. *
  99. * `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
  100. *
  101. */
  102. this.overlayPositioning = "absolute";
  103. /**
  104. * When `true`, disables the default behavior on the third click of narrowing or extending the range.
  105. * Instead starts a new range.
  106. */
  107. this.proximitySelectionDisabled = false;
  108. /** Defines the layout of the component. */
  109. this.layout = "horizontal";
  110. this.effectiveLocale = "";
  111. this.focusedInput = "start";
  112. this.globalAttributes = {};
  113. this.openTransitionProp = "opacity";
  114. //--------------------------------------------------------------------------
  115. //
  116. // Private Methods
  117. //
  118. //--------------------------------------------------------------------------
  119. this.setFilteredPlacements = () => {
  120. const { el, flipPlacements } = this;
  121. this.filteredFlipPlacements = flipPlacements
  122. ? floatingUi.filterComputedPlacements(flipPlacements, el)
  123. : null;
  124. };
  125. this.setTransitionEl = (el) => {
  126. this.transitionEl = el;
  127. openCloseComponent.connectOpenCloseComponent(this);
  128. };
  129. this.setStartInput = (el) => {
  130. this.startInput = el;
  131. };
  132. this.setEndInput = (el) => {
  133. this.endInput = el;
  134. };
  135. this.deactivate = () => {
  136. this.open = false;
  137. };
  138. this.keyDownHandler = (event) => {
  139. const { defaultPrevented, key } = event;
  140. if (key === "Enter" && !defaultPrevented) {
  141. if (form.submitForm(this)) {
  142. event.preventDefault();
  143. }
  144. }
  145. else if (key === "Escape" && !defaultPrevented) {
  146. this.active = false;
  147. this.open = false;
  148. event.preventDefault();
  149. }
  150. };
  151. this.inputBlur = (event) => {
  152. this.blur(event.currentTarget);
  153. };
  154. this.startInputFocus = () => {
  155. if (!this.readOnly) {
  156. this.open = true;
  157. }
  158. this.focusedInput = "start";
  159. };
  160. this.endInputFocus = () => {
  161. if (!this.readOnly) {
  162. this.open = true;
  163. }
  164. this.focusedInput = "end";
  165. };
  166. this.startInputInput = () => {
  167. const parsedValue = this.parseNumerals(this.startInput.value);
  168. const formattedValue = this.formatNumerals(parsedValue);
  169. this.startInput.value = formattedValue;
  170. this.input(parsedValue);
  171. };
  172. this.endInputInput = () => {
  173. const parsedValue = this.parseNumerals(this.endInput.value);
  174. const formattedValue = this.formatNumerals(parsedValue);
  175. this.endInput.value = formattedValue;
  176. this.input(parsedValue);
  177. };
  178. this.setFloatingEl = (el) => {
  179. if (el) {
  180. this.floatingEl = el;
  181. floatingUi.connectFloatingUI(this, this.referenceEl, this.floatingEl);
  182. }
  183. };
  184. this.setStartWrapper = (el) => {
  185. this.startWrapper = el;
  186. this.setReferenceEl();
  187. };
  188. this.setEndWrapper = (el) => {
  189. this.endWrapper = el;
  190. this.setReferenceEl();
  191. };
  192. /**
  193. * Event handler for when the selected date changes
  194. *
  195. * @param event
  196. */
  197. this.handleDateChange = (event) => {
  198. if (this.range) {
  199. return;
  200. }
  201. this.value = resources.dateToISO(event.detail);
  202. };
  203. this.handleDateRangeChange = (event) => {
  204. var _a, _b;
  205. if (!this.range || !event.detail) {
  206. return;
  207. }
  208. const { startDate, endDate } = event.detail;
  209. this.start = resources.dateToISO(startDate);
  210. this.end = resources.dateToISO(endDate);
  211. this.value = [this.start, this.end];
  212. if (this.shouldFocusRangeEnd()) {
  213. (_a = this.endInput) === null || _a === void 0 ? void 0 : _a.setFocus();
  214. }
  215. else if (this.shouldFocusRangeStart()) {
  216. (_b = this.startInput) === null || _b === void 0 ? void 0 : _b.setFocus();
  217. }
  218. };
  219. this.commonDateSeparators = [".", "-", "/"];
  220. this.formatNumerals = (value) => value
  221. ? value
  222. .split("")
  223. .map((char) =>
  224. // convert common separators to the locale's
  225. this.commonDateSeparators.includes(char)
  226. ? this.localeData.separator
  227. : key.numberKeys.includes(char)
  228. ? locale.numberStringFormatter.numberFormatter.format(Number(char))
  229. : char)
  230. .join("")
  231. : "";
  232. this.parseNumerals = (value) => value
  233. ? value
  234. .split("")
  235. .map((char) => key.numberKeys.includes(char) ? locale.numberStringFormatter.delocalize(char) : char)
  236. .join("")
  237. : "";
  238. }
  239. handleDisabledAndReadOnlyChange(value) {
  240. if (!value) {
  241. this.open = false;
  242. }
  243. }
  244. valueHandler(value) {
  245. if (Array.isArray(value)) {
  246. this.valueAsDate = resources.getValueAsDateRange(value);
  247. this.start = value[0];
  248. this.end = value[1];
  249. }
  250. else if (value) {
  251. this.valueAsDate = resources.dateFromISO(value);
  252. this.start = "";
  253. this.end = "";
  254. }
  255. else {
  256. this.valueAsDate = undefined;
  257. this.start = undefined;
  258. this.end = undefined;
  259. }
  260. }
  261. flipPlacementsHandler() {
  262. this.setFilteredPlacements();
  263. this.reposition(true);
  264. }
  265. onMinChanged(min) {
  266. if (min) {
  267. this.minAsDate = resources.dateFromISO(min);
  268. }
  269. }
  270. onMaxChanged(max) {
  271. if (max) {
  272. this.maxAsDate = resources.dateFromISO(max);
  273. }
  274. }
  275. activeHandler(value) {
  276. this.open = value;
  277. }
  278. openHandler(value) {
  279. this.active = value;
  280. if (this.disabled || this.readOnly) {
  281. if (!value) {
  282. floatingUi.updateAfterClose(this.floatingEl);
  283. }
  284. this.open = false;
  285. return;
  286. }
  287. if (value) {
  288. this.reposition(true);
  289. }
  290. else {
  291. floatingUi.updateAfterClose(this.floatingEl);
  292. }
  293. }
  294. overlayPositioningHandler() {
  295. this.reposition(true);
  296. }
  297. //--------------------------------------------------------------------------
  298. //
  299. // Event Listeners
  300. //
  301. //--------------------------------------------------------------------------
  302. handleDateOrRangeChange() {
  303. this.calciteInputDatePickerChange.emit();
  304. }
  305. calciteDaySelectHandler() {
  306. if (this.shouldFocusRangeStart() || this.shouldFocusRangeEnd()) {
  307. return;
  308. }
  309. this.open = false;
  310. }
  311. // --------------------------------------------------------------------------
  312. //
  313. // Public Methods
  314. //
  315. // --------------------------------------------------------------------------
  316. /** Sets focus on the component. */
  317. async setFocus() {
  318. var _a;
  319. (_a = this.startInput) === null || _a === void 0 ? void 0 : _a.setFocus();
  320. }
  321. /**
  322. * Updates the position of the component.
  323. *
  324. * @param delayed
  325. */
  326. async reposition(delayed = false) {
  327. const { floatingEl, referenceEl, placement, overlayPositioning, filteredFlipPlacements } = this;
  328. return floatingUi.reposition(this, {
  329. floatingEl,
  330. referenceEl,
  331. overlayPositioning,
  332. placement,
  333. flipPlacements: filteredFlipPlacements,
  334. type: "menu"
  335. }, delayed);
  336. }
  337. // --------------------------------------------------------------------------
  338. //
  339. // Lifecycle
  340. //
  341. // --------------------------------------------------------------------------
  342. connectedCallback() {
  343. locale.connectLocalized(this);
  344. const isOpen = this.active || this.open;
  345. isOpen && this.activeHandler(isOpen);
  346. isOpen && this.openHandler(isOpen);
  347. if (Array.isArray(this.value)) {
  348. this.valueAsDate = resources.getValueAsDateRange(this.value);
  349. this.start = this.value[0];
  350. this.end = this.value[1];
  351. }
  352. else if (this.value) {
  353. this.valueAsDate = resources.dateFromISO(this.value);
  354. this.start = "";
  355. this.end = "";
  356. }
  357. if (this.start) {
  358. this.startAsDate = resources.dateFromISO(this.start);
  359. }
  360. if (this.end) {
  361. this.endAsDate = resources.setEndOfDay(resources.dateFromISO(this.end));
  362. }
  363. if (this.min) {
  364. this.minAsDate = resources.dateFromISO(this.min);
  365. }
  366. if (this.max) {
  367. this.maxAsDate = resources.dateFromISO(this.max);
  368. }
  369. label.connectLabel(this);
  370. form.connectForm(this);
  371. openCloseComponent.connectOpenCloseComponent(this);
  372. this.setFilteredPlacements();
  373. this.reposition(true);
  374. locale.numberStringFormatter.numberFormatOptions = {
  375. numberingSystem: this.numberingSystem,
  376. locale: this.effectiveLocale,
  377. useGrouping: false
  378. };
  379. }
  380. async componentWillLoad() {
  381. await this.loadLocaleData();
  382. this.onMinChanged(this.min);
  383. this.onMaxChanged(this.max);
  384. }
  385. componentDidLoad() {
  386. this.reposition(true);
  387. }
  388. disconnectedCallback() {
  389. label.disconnectLabel(this);
  390. form.disconnectForm(this);
  391. floatingUi.disconnectFloatingUI(this, this.referenceEl, this.floatingEl);
  392. openCloseComponent.disconnectOpenCloseComponent(this);
  393. locale.disconnectLocalized(this);
  394. }
  395. componentDidRender() {
  396. interactive.updateHostInteraction(this);
  397. }
  398. render() {
  399. var _a, _b;
  400. const { disabled, readOnly, numberingSystem, effectiveLocale } = this;
  401. locale.numberStringFormatter.numberFormatOptions = {
  402. numberingSystem,
  403. locale: effectiveLocale,
  404. useGrouping: false
  405. };
  406. const date = resources.dateFromRange(this.range ? this.startAsDate : this.valueAsDate, this.minAsDate, this.maxAsDate);
  407. const endDate = this.range
  408. ? resources.dateFromRange(this.endAsDate, this.minAsDate, this.maxAsDate)
  409. : null;
  410. const formattedEndDate = endDate
  411. ? this.formatNumerals(endDate.toLocaleDateString(effectiveLocale))
  412. : "";
  413. const formattedDate = date ? this.formatNumerals(date.toLocaleDateString(effectiveLocale)) : "";
  414. return (index.h(index.Host, { onBlur: this.deactivate, onKeyDown: this.keyDownHandler, role: "application" }, this.localeData && (index.h("div", { "aria-expanded": dom.toAriaBoolean(this.open), class: "input-container", role: "application" }, index.h("div", { class: "input-wrapper", ref: this.setStartWrapper }, index.h("calcite-input", { class: `input ${this.layout === "vertical" && this.range ? `no-bottom-border` : ``}`, disabled: disabled, icon: "calendar", label: label.getLabelText(this), lang: effectiveLocale, "number-button-type": "none", numberingSystem: numberingSystem, onCalciteInputInput: this.startInputInput, onCalciteInternalInputBlur: this.inputBlur, onCalciteInternalInputFocus: this.startInputFocus, placeholder: (_a = this.localeData) === null || _a === void 0 ? void 0 : _a.placeholder, readOnly: readOnly, ref: this.setStartInput, scale: this.scale, type: "text", value: formattedDate })), index.h("div", { "aria-hidden": dom.toAriaBoolean(!this.open), class: {
  415. [CSS.menu]: true,
  416. [CSS.menuActive]: this.open
  417. }, ref: this.setFloatingEl }, index.h("div", { class: {
  418. ["calendar-picker-wrapper"]: true,
  419. ["calendar-picker-wrapper--end"]: this.focusedInput === "end",
  420. [floatingUi.FloatingCSS.animation]: true,
  421. [floatingUi.FloatingCSS.animationActive]: this.open
  422. }, ref: this.setTransitionEl }, index.h("calcite-date-picker", { activeRange: this.focusedInput, endAsDate: this.endAsDate, headingLevel: this.headingLevel, intlNextMonth: this.intlNextMonth, intlPrevMonth: this.intlPrevMonth, intlYear: this.intlYear, lang: effectiveLocale, max: this.max, maxAsDate: this.maxAsDate, min: this.min, minAsDate: this.minAsDate, numberingSystem: numberingSystem, onCalciteDatePickerChange: this.handleDateChange, onCalciteDatePickerRangeChange: this.handleDateRangeChange, proximitySelectionDisabled: this.proximitySelectionDisabled, range: this.range, scale: this.scale, startAsDate: this.startAsDate, tabIndex: 0, valueAsDate: this.valueAsDate }))), this.range && this.layout === "horizontal" && (index.h("div", { class: "horizontal-arrow-container" }, index.h("calcite-icon", { flipRtl: true, icon: "arrow-right", scale: "s" }))), this.range && this.layout === "vertical" && this.scale !== "s" && (index.h("div", { class: "vertical-arrow-container" }, index.h("calcite-icon", { icon: "arrow-down", scale: "s" }))), this.range && (index.h("div", { class: "input-wrapper", ref: this.setEndWrapper }, index.h("calcite-input", { class: {
  423. input: true,
  424. "border-top-color-one": this.layout === "vertical" && this.range
  425. }, disabled: disabled, icon: "calendar", lang: effectiveLocale, "number-button-type": "none", numberingSystem: numberingSystem, onCalciteInputInput: this.endInputInput, onCalciteInternalInputBlur: this.inputBlur, onCalciteInternalInputFocus: this.endInputFocus, placeholder: (_b = this.localeData) === null || _b === void 0 ? void 0 : _b.placeholder, readOnly: readOnly, ref: this.setEndInput, scale: this.scale, type: "text", value: formattedEndDate }))))), index.h(form.HiddenFormInputSlot, { component: this })));
  426. }
  427. setReferenceEl() {
  428. const { focusedInput, layout, endWrapper, startWrapper } = this;
  429. this.referenceEl =
  430. focusedInput === "end" || layout === "vertical"
  431. ? endWrapper || startWrapper
  432. : startWrapper || endWrapper;
  433. floatingUi.connectFloatingUI(this, this.referenceEl, this.floatingEl);
  434. }
  435. onLabelClick() {
  436. this.setFocus();
  437. }
  438. onBeforeOpen() {
  439. this.calciteInputDatePickerBeforeOpen.emit();
  440. }
  441. onOpen() {
  442. this.calciteInputDatePickerOpen.emit();
  443. }
  444. onBeforeClose() {
  445. this.calciteInputDatePickerBeforeClose.emit();
  446. }
  447. onClose() {
  448. this.calciteInputDatePickerClose.emit();
  449. }
  450. startWatcher(start) {
  451. this.startAsDate = resources.dateFromISO(start);
  452. }
  453. endWatcher(end) {
  454. this.endAsDate = end ? resources.setEndOfDay(resources.dateFromISO(end)) : resources.dateFromISO(end);
  455. }
  456. async loadLocaleData() {
  457. this.localeData = await resources.getLocaleData(this.effectiveLocale);
  458. }
  459. clearCurrentValue() {
  460. if (!this.range) {
  461. if (typeof this.value === "string" && this.value) {
  462. this.calciteDatePickerChange.emit();
  463. }
  464. this.value = "";
  465. return;
  466. }
  467. const { focusedInput } = this;
  468. if (focusedInput === "start") {
  469. if (this.start) {
  470. this.calciteDatePickerRangeChange.emit();
  471. }
  472. this.value = Array.isArray(this.value) ? ["", this.value[1] || ""] : [""];
  473. this.start = undefined;
  474. }
  475. else if (focusedInput === "end") {
  476. if (this.end) {
  477. this.calciteDatePickerRangeChange.emit();
  478. }
  479. this.value = Array.isArray(this.value) ? [this.value[0] || "", ""] : ["", ""];
  480. this.end = undefined;
  481. }
  482. }
  483. /**
  484. * If inputted string is a valid date, update value/active
  485. *
  486. * @param value
  487. */
  488. input(value) {
  489. const date = this.getDateFromInput(value);
  490. if (!date) {
  491. this.clearCurrentValue();
  492. return;
  493. }
  494. if (!this.range) {
  495. this.value = resources.dateToISO(date);
  496. this.calciteDatePickerChange.emit(date);
  497. return;
  498. }
  499. const { focusedInput } = this;
  500. if (focusedInput === "start") {
  501. if (!this.startAsDate || !resources.sameDate(date, this.startAsDate)) {
  502. const startDateISO = resources.dateToISO(date);
  503. this.value = Array.isArray(this.value)
  504. ? [startDateISO, this.value[1] || ""]
  505. : [startDateISO];
  506. this.start = startDateISO;
  507. this.calciteDatePickerRangeChange.emit({
  508. startDate: date,
  509. endDate: this.endAsDate
  510. });
  511. }
  512. }
  513. else if (focusedInput === "end") {
  514. if (!this.endAsDate || !resources.sameDate(date, this.endAsDate)) {
  515. const endDateISO = resources.dateToISO(date);
  516. this.value = Array.isArray(this.value)
  517. ? [this.value[0] || "", endDateISO]
  518. : ["", endDateISO];
  519. this.end = endDateISO;
  520. this.calciteDatePickerRangeChange.emit({
  521. startDate: this.startAsDate,
  522. endDate: resources.setEndOfDay(date)
  523. });
  524. }
  525. }
  526. }
  527. /**
  528. * Clean up invalid date from input on blur
  529. *
  530. * @param target
  531. */
  532. blur(target) {
  533. const { focusedInput, endAsDate, range, startAsDate, valueAsDate } = this;
  534. const locale = this.effectiveLocale;
  535. const date = this.getDateFromInput(target.value);
  536. if (!date) {
  537. if (!range && valueAsDate) {
  538. target.value = this.formatNumerals(Array.isArray(valueAsDate)
  539. ? valueAsDate[focusedInput === "end" ? 1 : 0].toLocaleDateString(locale)
  540. : valueAsDate.toLocaleDateString(locale));
  541. }
  542. else if (focusedInput === "start" && startAsDate) {
  543. target.value = this.formatNumerals(startAsDate.toLocaleDateString(locale));
  544. }
  545. else if (focusedInput === "end" && endAsDate) {
  546. target.value = this.formatNumerals(endAsDate.toLocaleDateString(locale));
  547. }
  548. }
  549. }
  550. shouldFocusRangeStart() {
  551. return !!(this.endAsDate &&
  552. !this.startAsDate &&
  553. this.focusedInput === "end" &&
  554. this.startInput);
  555. }
  556. shouldFocusRangeEnd() {
  557. return !!(this.startAsDate &&
  558. !this.endAsDate &&
  559. this.focusedInput === "start" &&
  560. this.endInput);
  561. }
  562. /**
  563. * Find a date from input string
  564. * return false if date is invalid, or out of range
  565. *
  566. * @param value
  567. */
  568. getDateFromInput(value) {
  569. if (!this.localeData) {
  570. return false;
  571. }
  572. const { separator } = this.localeData;
  573. const { day, month, year } = resources.parseDateString(value, this.localeData);
  574. const validDay = day > 0;
  575. const validMonth = month > -1;
  576. const date = new Date(year, month, day);
  577. date.setFullYear(year);
  578. const validDate = !isNaN(date.getTime());
  579. const validLength = value.split(separator).filter((c) => c).length > 2;
  580. const validYear = year.toString().length > 0;
  581. if (validDay &&
  582. validMonth &&
  583. validDate &&
  584. validLength &&
  585. validYear &&
  586. resources.inRange(date, this.min, this.max)) {
  587. return date;
  588. }
  589. return false;
  590. }
  591. get el() { return index.getElement(this); }
  592. static get watchers() { return {
  593. "disabled": ["handleDisabledAndReadOnlyChange"],
  594. "readOnly": ["handleDisabledAndReadOnlyChange"],
  595. "value": ["valueHandler"],
  596. "flipPlacements": ["flipPlacementsHandler"],
  597. "min": ["onMinChanged"],
  598. "max": ["onMaxChanged"],
  599. "active": ["activeHandler"],
  600. "open": ["openHandler"],
  601. "overlayPositioning": ["overlayPositioningHandler"],
  602. "layout": ["setReferenceEl"],
  603. "focusedInput": ["setReferenceEl"],
  604. "start": ["startWatcher"],
  605. "end": ["endWatcher"],
  606. "effectiveLocale": ["loadLocaleData"]
  607. }; }
  608. };
  609. InputDatePicker.style = inputDatePickerCss;
  610. exports.calcite_input_date_picker = InputDatePicker;