calcite-input-time-picker_2.cjs.entry.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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 guid = require('./guid-f4f03a7a.js');
  10. const locale = require('./locale-678ce361.js');
  11. const label = require('./label-28060b83.js');
  12. const form = require('./form-1d831023.js');
  13. const interactive = require('./interactive-32293bca.js');
  14. const key = require('./key-6a462411.js');
  15. require('./observers-5706326b.js');
  16. require('./dom-2ec8c9ed.js');
  17. require('./resources-b5a5f8a7.js');
  18. const maxTenthForMinuteAndSecond = 5;
  19. function createLocaleDateTimeFormatter(locale$1, numberingSystem, includeSeconds = true) {
  20. try {
  21. const options = {
  22. hour: "2-digit",
  23. minute: "2-digit",
  24. timeZone: "UTC",
  25. numberingSystem: locale.getSupportedNumberingSystem(numberingSystem)
  26. };
  27. if (includeSeconds) {
  28. options.second = "2-digit";
  29. }
  30. return new Intl.DateTimeFormat(locale.getSupportedLocale(locale$1), options);
  31. }
  32. catch (error) {
  33. throw new Error(`Invalid locale supplied while attempting to create a DateTime formatter: ${locale$1}`);
  34. }
  35. }
  36. function formatTimePart(number) {
  37. const numberAsString = number.toString();
  38. return number >= 0 && number <= 9 ? numberAsString.padStart(2, "0") : numberAsString;
  39. }
  40. function formatTimeString(value) {
  41. if (!isValidTime(value)) {
  42. return null;
  43. }
  44. const [hourString, minuteString, secondString] = value.split(":");
  45. const hour = formatTimePart(parseInt(hourString));
  46. const minute = formatTimePart(parseInt(minuteString));
  47. if (secondString) {
  48. const second = formatTimePart(parseInt(secondString));
  49. return `${hour}:${minute}:${second}`;
  50. }
  51. return `${hour}:${minute}`;
  52. }
  53. function getLocaleHourCycle(locale, numberingSystem) {
  54. const formatter = createLocaleDateTimeFormatter(locale, numberingSystem);
  55. const parts = formatter.formatToParts(new Date(Date.UTC(0, 0, 0, 0, 0, 0)));
  56. return getLocalizedTimePart("meridiem", parts) ? "12" : "24";
  57. }
  58. function getLocalizedTimePart(part, parts) {
  59. var _a, _b, _c, _d;
  60. if (!part || !parts) {
  61. return null;
  62. }
  63. if (part === "hourSuffix") {
  64. const hourIndex = parts.indexOf(parts.find(({ type }) => type === "hour"));
  65. const minuteIndex = parts.indexOf(parts.find(({ type }) => type === "minute"));
  66. const hourSuffix = parts[hourIndex + 1];
  67. return hourSuffix && hourSuffix.type === "literal" && minuteIndex - hourIndex === 2
  68. ? ((_a = hourSuffix.value) === null || _a === void 0 ? void 0 : _a.trim()) || null
  69. : null;
  70. }
  71. if (part === "minuteSuffix") {
  72. const minuteIndex = parts.indexOf(parts.find(({ type }) => type === "minute"));
  73. const secondIndex = parts.indexOf(parts.find(({ type }) => type === "second"));
  74. const minuteSuffix = parts[minuteIndex + 1];
  75. return minuteSuffix && minuteSuffix.type === "literal" && secondIndex - minuteIndex === 2
  76. ? ((_b = minuteSuffix.value) === null || _b === void 0 ? void 0 : _b.trim()) || null
  77. : null;
  78. }
  79. if (part === "secondSuffix") {
  80. const secondIndex = parts.indexOf(parts.find(({ type }) => type === "second"));
  81. const secondSuffix = parts[secondIndex + 1];
  82. return secondSuffix && secondSuffix.type === "literal" ? ((_c = secondSuffix.value) === null || _c === void 0 ? void 0 : _c.trim()) || null : null;
  83. }
  84. return ((_d = parts.find(({ type }) => (part == "meridiem" ? type === "dayPeriod" : type === part))) === null || _d === void 0 ? void 0 : _d.value) || null;
  85. }
  86. function getMeridiem(hour) {
  87. if (!locale.isValidNumber(hour)) {
  88. return null;
  89. }
  90. const hourAsNumber = parseInt(hour);
  91. return hourAsNumber >= 0 && hourAsNumber <= 11 ? "AM" : "PM";
  92. }
  93. function isValidTime(value) {
  94. if (!value || value.startsWith(":") || value.endsWith(":")) {
  95. return false;
  96. }
  97. const splitValue = value.split(":");
  98. const validLength = splitValue.length > 1 && splitValue.length < 4;
  99. if (!validLength) {
  100. return false;
  101. }
  102. const [hour, minute, second] = splitValue;
  103. const hourAsNumber = parseInt(splitValue[0]);
  104. const minuteAsNumber = parseInt(splitValue[1]);
  105. const secondAsNumber = parseInt(splitValue[2]);
  106. const hourValid = locale.isValidNumber(hour) && hourAsNumber >= 0 && hourAsNumber < 24;
  107. const minuteValid = locale.isValidNumber(minute) && minuteAsNumber >= 0 && minuteAsNumber < 60;
  108. const secondValid = locale.isValidNumber(second) && secondAsNumber >= 0 && secondAsNumber < 60;
  109. if ((hourValid && minuteValid && !second) || (hourValid && minuteValid && secondValid)) {
  110. return true;
  111. }
  112. }
  113. function isValidTimePart(value, part) {
  114. if (part === "meridiem") {
  115. return value === "AM" || value === "PM";
  116. }
  117. if (!locale.isValidNumber(value)) {
  118. return false;
  119. }
  120. const valueAsNumber = Number(value);
  121. return part === "hour" ? valueAsNumber >= 0 && valueAsNumber < 24 : valueAsNumber >= 0 && valueAsNumber < 60;
  122. }
  123. function localizeTimePart({ value, part, locale, numberingSystem }) {
  124. if (!isValidTimePart(value, part)) {
  125. return;
  126. }
  127. const valueAsNumber = parseInt(value);
  128. const date = new Date(Date.UTC(0, 0, 0, part === "hour" ? valueAsNumber : part === "meridiem" ? (value === "AM" ? 0 : 12) : 0, part === "minute" ? valueAsNumber : 0, part === "second" ? valueAsNumber : 0));
  129. if (!date) {
  130. return;
  131. }
  132. const formatter = createLocaleDateTimeFormatter(locale, numberingSystem);
  133. const parts = formatter.formatToParts(date);
  134. return getLocalizedTimePart(part, parts);
  135. }
  136. function localizeTimeString({ value, locale, numberingSystem, includeSeconds = true }) {
  137. if (!isValidTime(value)) {
  138. return null;
  139. }
  140. const { hour, minute, second = "0" } = parseTimeString(value);
  141. const dateFromTimeString = new Date(Date.UTC(0, 0, 0, parseInt(hour), parseInt(minute), parseInt(second)));
  142. const formatter = createLocaleDateTimeFormatter(locale, numberingSystem, includeSeconds);
  143. return (formatter === null || formatter === void 0 ? void 0 : formatter.format(dateFromTimeString)) || null;
  144. }
  145. function localizeTimeStringToParts({ value, locale, numberingSystem }) {
  146. if (!isValidTime(value)) {
  147. return null;
  148. }
  149. const { hour, minute, second = "0" } = parseTimeString(value);
  150. const dateFromTimeString = new Date(Date.UTC(0, 0, 0, parseInt(hour), parseInt(minute), parseInt(second)));
  151. if (dateFromTimeString) {
  152. const formatter = createLocaleDateTimeFormatter(locale, numberingSystem);
  153. const parts = formatter.formatToParts(dateFromTimeString);
  154. return {
  155. localizedHour: getLocalizedTimePart("hour", parts),
  156. localizedHourSuffix: getLocalizedTimePart("hourSuffix", parts),
  157. localizedMinute: getLocalizedTimePart("minute", parts),
  158. localizedMinuteSuffix: getLocalizedTimePart("minuteSuffix", parts),
  159. localizedSecond: getLocalizedTimePart("second", parts),
  160. localizedSecondSuffix: getLocalizedTimePart("secondSuffix", parts),
  161. localizedMeridiem: getLocalizedTimePart("meridiem", parts)
  162. };
  163. }
  164. return null;
  165. }
  166. function getTimeParts({ value, locale, numberingSystem }) {
  167. if (!isValidTime(value)) {
  168. return null;
  169. }
  170. const { hour, minute, second = "0" } = parseTimeString(value);
  171. const dateFromTimeString = new Date(Date.UTC(0, 0, 0, parseInt(hour), parseInt(minute), parseInt(second)));
  172. if (dateFromTimeString) {
  173. const formatter = createLocaleDateTimeFormatter(locale, numberingSystem);
  174. const parts = formatter.formatToParts(dateFromTimeString);
  175. return parts;
  176. }
  177. return null;
  178. }
  179. function parseTimeString(value) {
  180. if (isValidTime(value)) {
  181. const [hour, minute, second] = value.split(":");
  182. return {
  183. hour,
  184. minute,
  185. second
  186. };
  187. }
  188. return {
  189. hour: null,
  190. minute: null,
  191. second: null
  192. };
  193. }
  194. const inputTimePickerCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:inline-block;-webkit-user-select:none;user-select:none}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}::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}";
  195. const InputTimePicker = class {
  196. constructor(hostRef) {
  197. index.registerInstance(this, hostRef);
  198. this.calciteInputTimePickerChange = index.createEvent(this, "calciteInputTimePickerChange", 7);
  199. //--------------------------------------------------------------------------
  200. //
  201. // Properties
  202. //
  203. //--------------------------------------------------------------------------
  204. /**
  205. * When `true`, the component is active.
  206. *
  207. * @deprecated Use `open` instead.
  208. */
  209. this.active = false;
  210. /** When `true`, displays the `calcite-time-picker` component. */
  211. this.open = false;
  212. /** When `true`, interaction is prevented and the component is displayed with lower opacity. */
  213. this.disabled = false;
  214. /**
  215. * When `true`, the component's value can be read, but controls are not accessible and the value cannot be modified.
  216. *
  217. * @mdn [readOnly](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly)
  218. */
  219. this.readOnly = false;
  220. /**
  221. * When `true`, the component must have a value in order for the form to submit.
  222. *
  223. * @internal
  224. */
  225. this.required = false;
  226. /** Specifies the size of the component. */
  227. this.scale = "m";
  228. /**
  229. * Determines the type of positioning to use for the overlaid content.
  230. *
  231. * Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.
  232. *
  233. * `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
  234. *
  235. */
  236. this.overlayPositioning = "absolute";
  237. /**
  238. * Determines where the popover will be positioned relative to the input.
  239. *
  240. * @see [LogicalPlacement](https://github.com/Esri/calcite-components/blob/master/src/utils/floating-ui.ts#L25)
  241. */
  242. this.placement = "auto";
  243. /** Specifies the granularity the component's `value` must adhere to (in seconds). */
  244. this.step = 60;
  245. /** The component's value in UTC (always 24-hour format). */
  246. this.value = null;
  247. /** whether the value of the input was changed as a result of user typing or not */
  248. this.internalValueChange = false;
  249. this.previousValidValue = null;
  250. this.referenceElementId = `input-time-picker-${guid.guid()}`;
  251. //--------------------------------------------------------------------------
  252. //
  253. // State
  254. //
  255. //--------------------------------------------------------------------------
  256. this.effectiveLocale = "";
  257. //--------------------------------------------------------------------------
  258. //
  259. // Event Listeners
  260. //
  261. //--------------------------------------------------------------------------
  262. this.calciteInternalInputBlurHandler = () => {
  263. this.open = false;
  264. const shouldIncludeSeconds = this.shouldIncludeSeconds();
  265. const { effectiveLocale: locale$1, numberingSystem, value, calciteInputEl } = this;
  266. locale.numberStringFormatter.numberFormatOptions = {
  267. locale: locale$1,
  268. numberingSystem,
  269. useGrouping: false
  270. };
  271. const delocalizedValue = locale.numberStringFormatter.delocalize(calciteInputEl.value);
  272. const localizedInputValue = localizeTimeString({
  273. value: delocalizedValue,
  274. includeSeconds: shouldIncludeSeconds,
  275. locale: locale$1,
  276. numberingSystem
  277. });
  278. this.setInputValue(localizedInputValue ||
  279. localizeTimeString({ value, locale: locale$1, numberingSystem, includeSeconds: shouldIncludeSeconds }));
  280. };
  281. this.calciteInternalInputFocusHandler = (event) => {
  282. if (!this.readOnly) {
  283. this.open = true;
  284. event.stopPropagation();
  285. }
  286. };
  287. this.calciteInputInputHandler = (event) => {
  288. const target = event.target;
  289. locale.numberStringFormatter.numberFormatOptions = {
  290. locale: this.effectiveLocale,
  291. numberingSystem: this.numberingSystem,
  292. useGrouping: false
  293. };
  294. const delocalizedValue = locale.numberStringFormatter.delocalize(target.value);
  295. this.setValue({ value: delocalizedValue });
  296. // only translate the numerals until blur
  297. const localizedValue = delocalizedValue
  298. .split("")
  299. .map((char) => key.numberKeys.includes(char)
  300. ? locale.numberStringFormatter.numberFormatter.format(Number(char))
  301. : char)
  302. .join("");
  303. this.setInputValue(localizedValue);
  304. };
  305. this.timePickerChangeHandler = (event) => {
  306. event.stopPropagation();
  307. const target = event.target;
  308. const value = target.value;
  309. this.setValue({ value, origin: "time-picker" });
  310. };
  311. // --------------------------------------------------------------------------
  312. //
  313. // Private Methods
  314. //
  315. // --------------------------------------------------------------------------
  316. this.keyDownHandler = (event) => {
  317. const { defaultPrevented, key } = event;
  318. if (defaultPrevented) {
  319. return;
  320. }
  321. if (key === "Enter") {
  322. if (form.submitForm(this)) {
  323. event.preventDefault();
  324. }
  325. }
  326. if (key === "Escape" && this.open) {
  327. this.open = false;
  328. event.preventDefault();
  329. }
  330. };
  331. this.setCalcitePopoverEl = (el) => {
  332. this.popoverEl = el;
  333. };
  334. this.setCalciteInputEl = (el) => {
  335. this.calciteInputEl = el;
  336. };
  337. this.setCalciteTimePickerEl = (el) => {
  338. this.calciteTimePickerEl = el;
  339. };
  340. this.setInputValue = (newInputValue) => {
  341. if (!this.calciteInputEl) {
  342. return;
  343. }
  344. this.calciteInputEl.value = newInputValue;
  345. };
  346. this.setValue = ({ value, origin = "input" }) => {
  347. const previousValue = this.value;
  348. const newValue = formatTimeString(value);
  349. const newLocalizedValue = localizeTimeString({
  350. value: newValue,
  351. locale: this.effectiveLocale,
  352. numberingSystem: this.numberingSystem,
  353. includeSeconds: this.shouldIncludeSeconds()
  354. });
  355. this.internalValueChange = origin !== "external" && origin !== "loading";
  356. const shouldEmit = origin !== "loading" &&
  357. origin !== "external" &&
  358. ((value !== this.previousValidValue && !value) ||
  359. !!(!this.previousValidValue && newValue) ||
  360. (newValue !== this.previousValidValue && newValue));
  361. if (value) {
  362. if (shouldEmit) {
  363. this.previousValidValue = newValue;
  364. }
  365. if (newValue && newValue !== this.value) {
  366. this.value = newValue;
  367. }
  368. this.localizedValue = newLocalizedValue;
  369. }
  370. else {
  371. this.value = value;
  372. this.localizedValue = null;
  373. }
  374. if (origin === "time-picker" || origin === "external") {
  375. this.setInputValue(newLocalizedValue);
  376. }
  377. if (shouldEmit) {
  378. const changeEvent = this.calciteInputTimePickerChange.emit();
  379. if (changeEvent.defaultPrevented) {
  380. this.internalValueChange = false;
  381. this.value = previousValue;
  382. this.setInputValue(previousValue);
  383. this.previousValidValue = previousValue;
  384. }
  385. else {
  386. this.previousValidValue = newValue;
  387. }
  388. }
  389. };
  390. }
  391. activeHandler(value) {
  392. this.open = value;
  393. }
  394. openHandler(value) {
  395. this.active = value;
  396. if (this.disabled || this.readOnly) {
  397. this.open = false;
  398. return;
  399. }
  400. if (value) {
  401. this.reposition(true);
  402. }
  403. }
  404. handleDisabledAndReadOnlyChange(value) {
  405. if (!value) {
  406. this.open = false;
  407. }
  408. }
  409. localeChanged() {
  410. locale.updateEffectiveLocale(this);
  411. }
  412. valueWatcher(newValue) {
  413. if (!this.internalValueChange) {
  414. this.setValue({ value: newValue, origin: "external" });
  415. }
  416. this.internalValueChange = false;
  417. }
  418. effectiveLocaleWatcher() {
  419. this.setInputValue(localizeTimeString({
  420. value: this.value,
  421. locale: this.effectiveLocale,
  422. numberingSystem: this.numberingSystem,
  423. includeSeconds: this.shouldIncludeSeconds()
  424. }));
  425. }
  426. clickHandler(event) {
  427. if (event.composedPath().includes(this.calciteTimePickerEl)) {
  428. return;
  429. }
  430. this.setFocus();
  431. }
  432. timePickerBlurHandler(event) {
  433. event.preventDefault();
  434. event.stopPropagation();
  435. this.open = false;
  436. }
  437. timePickerFocusHandler(event) {
  438. event.preventDefault();
  439. event.stopPropagation();
  440. if (!this.readOnly) {
  441. this.open = true;
  442. }
  443. }
  444. // --------------------------------------------------------------------------
  445. //
  446. // Public Methods
  447. //
  448. // --------------------------------------------------------------------------
  449. /** Sets focus on the component. */
  450. async setFocus() {
  451. var _a;
  452. (_a = this.calciteInputEl) === null || _a === void 0 ? void 0 : _a.setFocus();
  453. }
  454. /**
  455. * Updates the position of the component.
  456. *
  457. * @param delayed
  458. */
  459. async reposition(delayed = false) {
  460. var _a;
  461. (_a = this.popoverEl) === null || _a === void 0 ? void 0 : _a.reposition(delayed);
  462. }
  463. onLabelClick() {
  464. this.setFocus();
  465. }
  466. shouldIncludeSeconds() {
  467. return this.step < 60;
  468. }
  469. //--------------------------------------------------------------------------
  470. //
  471. // Lifecycle
  472. //
  473. //--------------------------------------------------------------------------
  474. connectedCallback() {
  475. locale.connectLocalized(this);
  476. const { active, open } = this;
  477. if (this.value) {
  478. this.setValue({ value: isValidTime(this.value) ? this.value : undefined, origin: "loading" });
  479. }
  480. label.connectLabel(this);
  481. form.connectForm(this);
  482. if (open) {
  483. this.active = open;
  484. }
  485. else if (active) {
  486. this.open = active;
  487. }
  488. }
  489. componentDidLoad() {
  490. this.setInputValue(this.localizedValue);
  491. }
  492. disconnectedCallback() {
  493. label.disconnectLabel(this);
  494. form.disconnectForm(this);
  495. locale.disconnectLocalized(this);
  496. }
  497. componentDidRender() {
  498. interactive.updateHostInteraction(this);
  499. }
  500. // --------------------------------------------------------------------------
  501. //
  502. // Render Methods
  503. //
  504. // --------------------------------------------------------------------------
  505. render() {
  506. const popoverId = `${this.referenceElementId}-popover`;
  507. return (index.h(index.Host, { onKeyDown: this.keyDownHandler }, index.h("div", { "aria-controls": popoverId, "aria-haspopup": "dialog", "aria-label": this.name, "aria-owns": popoverId, id: this.referenceElementId, role: "combobox" }, index.h("calcite-input", { disabled: this.disabled, icon: "clock", label: label.getLabelText(this), onCalciteInputInput: this.calciteInputInputHandler, onCalciteInternalInputBlur: this.calciteInternalInputBlurHandler, onCalciteInternalInputFocus: this.calciteInternalInputFocusHandler, readOnly: this.readOnly, ref: this.setCalciteInputEl, scale: this.scale, step: this.step })), index.h("calcite-popover", { id: popoverId, label: "Time Picker", open: this.open, overlayPositioning: this.overlayPositioning, placement: this.placement, ref: this.setCalcitePopoverEl, referenceElement: this.referenceElementId, triggerDisabled: true }, index.h("calcite-time-picker", { intlHour: this.intlHour, intlHourDown: this.intlHourDown, intlHourUp: this.intlHourUp, intlMeridiem: this.intlMeridiem, intlMeridiemDown: this.intlMeridiemDown, intlMeridiemUp: this.intlMeridiemUp, intlMinute: this.intlMinute, intlMinuteDown: this.intlMinuteDown, intlMinuteUp: this.intlMinuteUp, intlSecond: this.intlSecond, intlSecondDown: this.intlSecondDown, intlSecondUp: this.intlSecondUp, lang: this.effectiveLocale, numberingSystem: this.numberingSystem, onCalciteInternalTimePickerChange: this.timePickerChangeHandler, ref: this.setCalciteTimePickerEl, scale: this.scale, step: this.step, value: this.value })), index.h(form.HiddenFormInputSlot, { component: this })));
  508. }
  509. get el() { return index.getElement(this); }
  510. static get watchers() { return {
  511. "active": ["activeHandler"],
  512. "open": ["openHandler"],
  513. "disabled": ["handleDisabledAndReadOnlyChange"],
  514. "readOnly": ["handleDisabledAndReadOnlyChange"],
  515. "locale": ["localeChanged"],
  516. "value": ["valueWatcher"],
  517. "effectiveLocale": ["effectiveLocaleWatcher"]
  518. }; }
  519. };
  520. InputTimePicker.style = inputTimePickerCss;
  521. const CSS = {
  522. button: "button",
  523. buttonBottomLeft: "button--bottom-left",
  524. buttonBottomRight: "button--bottom-right",
  525. buttonHourDown: "button--hour-down",
  526. buttonHourUp: "button--hour-up",
  527. buttonMeridiemDown: "button--meridiem-down",
  528. buttonMeridiemUp: "button--meridiem-up",
  529. buttonMinuteDown: "button--minute-down",
  530. buttonMinuteUp: "button--minute-up",
  531. buttonSecondDown: "button--second-down",
  532. buttonSecondUp: "button--second-up",
  533. buttonTopLeft: "button--top-left",
  534. buttonTopRight: "button--top-right",
  535. column: "column",
  536. delimiter: "delimiter",
  537. hour: "hour",
  538. input: "input",
  539. meridiem: "meridiem",
  540. minute: "minute",
  541. second: "second",
  542. showMeridiem: "show-meridiem",
  543. showSecond: "show-second",
  544. "scale-s": "scale-s",
  545. "scale-m": "scale-m",
  546. "scale-l": "scale-l",
  547. timePicker: "time-picker",
  548. meridiemStart: "meridiem--start"
  549. };
  550. const TEXT = {
  551. hour: "Hour",
  552. hourDown: "Decrease hour",
  553. hourUp: "Increase hour",
  554. meridiem: "AM/PM",
  555. meridiemDown: "Decrease AM/PM",
  556. meridiemUp: "Increase AM/PM",
  557. minute: "Minute",
  558. minuteDown: "Decrease minute",
  559. minuteUp: "Increase minute",
  560. second: "Second",
  561. secondDown: "Decrease second",
  562. secondUp: "Increase second"
  563. };
  564. const timePickerCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:inline-block}.time-picker{display:flex;-webkit-user-select:none;user-select:none;align-items:center;background-color:var(--calcite-ui-foreground-1);font-weight:var(--calcite-font-weight-medium);color:var(--calcite-ui-text-1);--tw-shadow:0 6px 20px -4px rgba(0, 0, 0, 0.1), 0 4px 12px -2px rgba(0, 0, 0, 0.08);--tw-shadow-colored:0 6px 20px -4px var(--tw-shadow-color), 0 4px 12px -2px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);border-radius:var(--calcite-border-radius)}.time-picker .column{display:flex;flex-direction:column}.time-picker .meridiem--start{order:-1}.time-picker .button{display:inline-flex;cursor:pointer;align-items:center;justify-content:center;background-color:var(--calcite-ui-foreground-1)}.time-picker .button:hover,.time-picker .button:focus{background-color:var(--calcite-ui-foreground-2);outline:2px solid transparent;outline-offset:2px}.time-picker .button:active{background-color:var(--calcite-ui-foreground-3)}.time-picker .button.top-left{border-start-start-radius:var(--calcite-border-radius)}.time-picker .button.bottom-left{border-end-start-radius:var(--calcite-border-radius)}.time-picker .button.top-right{border-start-end-radius:var(--calcite-border-radius)}.time-picker .button.bottom-right{border-end-end-radius:var(--calcite-border-radius)}.time-picker .button calcite-icon{color:var(--calcite-ui-text-3)}.time-picker .input{display:inline-flex;cursor:pointer;align-items:center;justify-content:center;background-color:var(--calcite-ui-foreground-1);font-weight:var(--calcite-font-weight-medium)}.time-picker .input:hover{box-shadow:inset 0 0 0 2px var(--calcite-ui-foreground-2)}.time-picker .input:focus,.time-picker .input:hover:focus{outline:2px solid transparent;outline-offset:2px;box-shadow:inset 0 0 0 2px var(--calcite-ui-brand)}.time-picker.scale-s{font-size:var(--calcite-font-size--1)}.time-picker.scale-s .button,.time-picker.scale-s .input{padding-inline:0.75rem;padding-block:0.25rem}.time-picker.scale-s:not(.show-meridiem) .delimiter:last-child{padding-inline-end:0.75rem}.time-picker.scale-m{font-size:var(--calcite-font-size-0)}.time-picker.scale-m .button,.time-picker.scale-m .input{padding-inline:1rem;padding-block:0.5rem}.time-picker.scale-m:not(.show-meridiem) .delimiter:last-child{padding-inline-end:1rem}.time-picker.scale-l{font-size:var(--calcite-font-size-1)}.time-picker.scale-l .button,.time-picker.scale-l .input{padding-inline:1.25rem;padding-block:0.75rem}.time-picker.scale-l:not(.show-meridiem) .delimiter:last-child{padding-inline-end:1.25rem}";
  565. function capitalize(str) {
  566. return str.charAt(0).toUpperCase() + str.slice(1);
  567. }
  568. const TimePicker = class {
  569. constructor(hostRef) {
  570. index.registerInstance(this, hostRef);
  571. this.calciteInternalTimePickerBlur = index.createEvent(this, "calciteInternalTimePickerBlur", 6);
  572. this.calciteInternalTimePickerChange = index.createEvent(this, "calciteInternalTimePickerChange", 6);
  573. this.calciteInternalTimePickerFocus = index.createEvent(this, "calciteInternalTimePickerFocus", 6);
  574. //--------------------------------------------------------------------------
  575. //
  576. // Properties
  577. //
  578. //--------------------------------------------------------------------------
  579. /**
  580. * Accessible name for the component's hour input.
  581. *
  582. * @default "Hour"
  583. */
  584. this.intlHour = TEXT.hour;
  585. /**
  586. * Accessible name for the component's hour down button.
  587. *
  588. * @default "Decrease hour"
  589. */
  590. this.intlHourDown = TEXT.hourDown;
  591. /**
  592. * Accessible name for the component's hour up button.
  593. *
  594. * @default "Increase hour"
  595. */
  596. this.intlHourUp = TEXT.hourUp;
  597. /**
  598. * Accessible name for the component's meridiem (AM/PM) input.
  599. *
  600. * @default "AM/PM"
  601. */
  602. this.intlMeridiem = TEXT.meridiem;
  603. /**
  604. * Accessible name for the component's meridiem (AM/PM) down button.
  605. *
  606. * @default "Decrease AM/PM"
  607. */
  608. this.intlMeridiemDown = TEXT.meridiemDown;
  609. /**
  610. * Accessible name for the component's meridiem (AM/PM) up button.
  611. *
  612. * @default "Increase AM/PM"
  613. */
  614. this.intlMeridiemUp = TEXT.meridiemUp;
  615. /**
  616. * Accessible name for the component's minute input.
  617. *
  618. * @default "Minute"
  619. */
  620. this.intlMinute = TEXT.minute;
  621. /**
  622. * Accessible name for the component's minute down button.
  623. *
  624. * @default "Decrease minute"
  625. */
  626. this.intlMinuteDown = TEXT.minuteDown;
  627. /**
  628. * Accessible name for the component's minute up button.
  629. *
  630. * @default "Increase minute"
  631. */
  632. this.intlMinuteUp = TEXT.minuteUp;
  633. /**
  634. * Accessible name for the component's second input.
  635. *
  636. * @default "Second"
  637. */
  638. this.intlSecond = TEXT.second;
  639. /**
  640. * Accessible name for the component's second down button.
  641. *
  642. * @default "Decrease second"
  643. */
  644. this.intlSecondDown = TEXT.secondDown;
  645. /**
  646. * Accessible name for the component's second up button.
  647. *
  648. * @default "Increase second"
  649. */
  650. this.intlSecondUp = TEXT.secondUp;
  651. /** Specifies the size of the component. */
  652. this.scale = "m";
  653. /** Specifies the granularity the `value` must adhere to (in seconds). */
  654. this.step = 60;
  655. /** The component's value in UTC (always 24-hour format). */
  656. this.value = null;
  657. // --------------------------------------------------------------------------
  658. //
  659. // State
  660. //
  661. // --------------------------------------------------------------------------
  662. this.effectiveLocale = "";
  663. this.showSecond = this.step < 60;
  664. this.decrementHour = () => {
  665. const newHour = !this.hour ? 0 : this.hour === "00" ? 23 : parseInt(this.hour) - 1;
  666. this.setValuePart("hour", newHour);
  667. };
  668. this.decrementMeridiem = () => {
  669. const newMeridiem = this.meridiem === "PM" ? "AM" : "PM";
  670. this.setValuePart("meridiem", newMeridiem);
  671. };
  672. this.decrementMinuteOrSecond = (key) => {
  673. let newValue;
  674. if (locale.isValidNumber(this[key])) {
  675. const valueAsNumber = parseInt(this[key]);
  676. newValue = valueAsNumber === 0 ? 59 : valueAsNumber - 1;
  677. }
  678. else {
  679. newValue = 59;
  680. }
  681. this.setValuePart(key, newValue);
  682. };
  683. this.decrementMinute = () => {
  684. this.decrementMinuteOrSecond("minute");
  685. };
  686. this.decrementSecond = () => {
  687. this.decrementMinuteOrSecond("second");
  688. };
  689. this.focusHandler = (event) => {
  690. this.activeEl = event.currentTarget;
  691. };
  692. this.hourDownButtonKeyDownHandler = (event) => {
  693. if (this.buttonActivated(event)) {
  694. this.decrementHour();
  695. }
  696. };
  697. this.hourKeyDownHandler = (event) => {
  698. const { key: key$1 } = event;
  699. if (key.numberKeys.includes(key$1)) {
  700. const keyAsNumber = parseInt(key$1);
  701. let newHour;
  702. if (locale.isValidNumber(this.hour)) {
  703. switch (this.hourCycle) {
  704. case "12":
  705. newHour =
  706. this.hour === "01" && keyAsNumber >= 0 && keyAsNumber <= 2
  707. ? `1${keyAsNumber}`
  708. : keyAsNumber;
  709. break;
  710. case "24":
  711. if (this.hour === "01") {
  712. newHour = `1${keyAsNumber}`;
  713. }
  714. else if (this.hour === "02" && keyAsNumber >= 0 && keyAsNumber <= 3) {
  715. newHour = `2${keyAsNumber}`;
  716. }
  717. else {
  718. newHour = keyAsNumber;
  719. }
  720. break;
  721. }
  722. }
  723. else {
  724. newHour = keyAsNumber;
  725. }
  726. this.setValuePart("hour", newHour);
  727. }
  728. else {
  729. switch (key$1) {
  730. case "Backspace":
  731. case "Delete":
  732. this.setValuePart("hour", null);
  733. break;
  734. case "ArrowDown":
  735. event.preventDefault();
  736. this.decrementHour();
  737. break;
  738. case "ArrowUp":
  739. event.preventDefault();
  740. this.incrementHour();
  741. break;
  742. case " ":
  743. event.preventDefault();
  744. break;
  745. }
  746. }
  747. };
  748. this.hourUpButtonKeyDownHandler = (event) => {
  749. if (this.buttonActivated(event)) {
  750. this.incrementHour();
  751. }
  752. };
  753. this.incrementMeridiem = () => {
  754. const newMeridiem = this.meridiem === "AM" ? "PM" : "AM";
  755. this.setValuePart("meridiem", newMeridiem);
  756. };
  757. this.incrementHour = () => {
  758. const newHour = locale.isValidNumber(this.hour)
  759. ? this.hour === "23"
  760. ? 0
  761. : parseInt(this.hour) + 1
  762. : 1;
  763. this.setValuePart("hour", newHour);
  764. };
  765. this.incrementMinuteOrSecond = (key) => {
  766. const newValue = locale.isValidNumber(this[key])
  767. ? this[key] === "59"
  768. ? 0
  769. : parseInt(this[key]) + 1
  770. : 0;
  771. this.setValuePart(key, newValue);
  772. };
  773. this.incrementMinute = () => {
  774. this.incrementMinuteOrSecond("minute");
  775. };
  776. this.incrementSecond = () => {
  777. this.incrementMinuteOrSecond("second");
  778. };
  779. this.meridiemDownButtonKeyDownHandler = (event) => {
  780. if (this.buttonActivated(event)) {
  781. this.decrementMeridiem();
  782. }
  783. };
  784. this.meridiemKeyDownHandler = (event) => {
  785. switch (event.key) {
  786. case "a":
  787. this.setValuePart("meridiem", "AM");
  788. break;
  789. case "p":
  790. this.setValuePart("meridiem", "PM");
  791. break;
  792. case "Backspace":
  793. case "Delete":
  794. this.setValuePart("meridiem", null);
  795. break;
  796. case "ArrowUp":
  797. event.preventDefault();
  798. this.incrementMeridiem();
  799. break;
  800. case "ArrowDown":
  801. event.preventDefault();
  802. this.decrementMeridiem();
  803. break;
  804. case " ":
  805. event.preventDefault();
  806. break;
  807. }
  808. };
  809. this.meridiemUpButtonKeyDownHandler = (event) => {
  810. if (this.buttonActivated(event)) {
  811. this.incrementMeridiem();
  812. }
  813. };
  814. this.minuteDownButtonKeyDownHandler = (event) => {
  815. if (this.buttonActivated(event)) {
  816. this.decrementMinute();
  817. }
  818. };
  819. this.minuteKeyDownHandler = (event) => {
  820. const { key: key$1 } = event;
  821. if (key.numberKeys.includes(key$1)) {
  822. const keyAsNumber = parseInt(key$1);
  823. let newMinute;
  824. if (locale.isValidNumber(this.minute) && this.minute.startsWith("0")) {
  825. const minuteAsNumber = parseInt(this.minute);
  826. newMinute =
  827. minuteAsNumber > maxTenthForMinuteAndSecond
  828. ? keyAsNumber
  829. : `${minuteAsNumber}${keyAsNumber}`;
  830. }
  831. else {
  832. newMinute = keyAsNumber;
  833. }
  834. this.setValuePart("minute", newMinute);
  835. }
  836. else {
  837. switch (key$1) {
  838. case "Backspace":
  839. case "Delete":
  840. this.setValuePart("minute", null);
  841. break;
  842. case "ArrowDown":
  843. event.preventDefault();
  844. this.decrementMinute();
  845. break;
  846. case "ArrowUp":
  847. event.preventDefault();
  848. this.incrementMinute();
  849. break;
  850. case " ":
  851. event.preventDefault();
  852. break;
  853. }
  854. }
  855. };
  856. this.minuteUpButtonKeyDownHandler = (event) => {
  857. if (this.buttonActivated(event)) {
  858. this.incrementMinute();
  859. }
  860. };
  861. this.secondDownButtonKeyDownHandler = (event) => {
  862. if (this.buttonActivated(event)) {
  863. this.decrementSecond();
  864. }
  865. };
  866. this.secondKeyDownHandler = (event) => {
  867. const { key: key$1 } = event;
  868. if (key.numberKeys.includes(key$1)) {
  869. const keyAsNumber = parseInt(key$1);
  870. let newSecond;
  871. if (locale.isValidNumber(this.second) && this.second.startsWith("0")) {
  872. const secondAsNumber = parseInt(this.second);
  873. newSecond =
  874. secondAsNumber > maxTenthForMinuteAndSecond
  875. ? keyAsNumber
  876. : `${secondAsNumber}${keyAsNumber}`;
  877. }
  878. else {
  879. newSecond = keyAsNumber;
  880. }
  881. this.setValuePart("second", newSecond);
  882. }
  883. else {
  884. switch (key$1) {
  885. case "Backspace":
  886. case "Delete":
  887. this.setValuePart("second", null);
  888. break;
  889. case "ArrowDown":
  890. event.preventDefault();
  891. this.decrementSecond();
  892. break;
  893. case "ArrowUp":
  894. event.preventDefault();
  895. this.incrementSecond();
  896. break;
  897. case " ":
  898. event.preventDefault();
  899. break;
  900. }
  901. }
  902. };
  903. this.secondUpButtonKeyDownHandler = (event) => {
  904. if (this.buttonActivated(event)) {
  905. this.incrementSecond();
  906. }
  907. };
  908. this.setHourEl = (el) => (this.hourEl = el);
  909. this.setMeridiemEl = (el) => (this.meridiemEl = el);
  910. this.setMinuteEl = (el) => (this.minuteEl = el);
  911. this.setSecondEl = (el) => (this.secondEl = el);
  912. this.setValue = (value, emit = true) => {
  913. if (isValidTime(value)) {
  914. const { hour, minute, second } = parseTimeString(value);
  915. const { effectiveLocale: locale, numberingSystem } = this;
  916. const { localizedHour, localizedHourSuffix, localizedMinute, localizedMinuteSuffix, localizedSecond, localizedSecondSuffix, localizedMeridiem } = localizeTimeStringToParts({ value, locale, numberingSystem });
  917. this.localizedHour = localizedHour;
  918. this.localizedHourSuffix = localizedHourSuffix;
  919. this.localizedMinute = localizedMinute;
  920. this.localizedMinuteSuffix = localizedMinuteSuffix;
  921. this.localizedSecond = localizedSecond;
  922. this.localizedSecondSuffix = localizedSecondSuffix;
  923. this.hour = hour;
  924. this.minute = minute;
  925. this.second = second;
  926. if (localizedMeridiem) {
  927. this.localizedMeridiem = localizedMeridiem;
  928. this.meridiem = getMeridiem(this.hour);
  929. const formatParts = getTimeParts({ value, locale, numberingSystem });
  930. this.meridiemOrder = this.getMeridiemOrder(formatParts);
  931. }
  932. }
  933. else {
  934. this.hour = null;
  935. this.localizedHour = null;
  936. this.localizedHourSuffix = null;
  937. this.localizedMeridiem = null;
  938. this.localizedMinute = null;
  939. this.localizedMinuteSuffix = null;
  940. this.localizedSecond = null;
  941. this.localizedSecondSuffix = null;
  942. this.meridiem = null;
  943. this.minute = null;
  944. this.second = null;
  945. this.value = null;
  946. }
  947. if (emit) {
  948. this.calciteInternalTimePickerChange.emit();
  949. }
  950. };
  951. this.setValuePart = (key, value, emit = true) => {
  952. var _a;
  953. const { effectiveLocale: locale$1, numberingSystem } = this;
  954. if (key === "meridiem") {
  955. this.meridiem = value;
  956. if (locale.isValidNumber(this.hour)) {
  957. const hourAsNumber = parseInt(this.hour);
  958. switch (value) {
  959. case "AM":
  960. if (hourAsNumber >= 12) {
  961. this.hour = formatTimePart(hourAsNumber - 12);
  962. }
  963. break;
  964. case "PM":
  965. if (hourAsNumber < 12) {
  966. this.hour = formatTimePart(hourAsNumber + 12);
  967. }
  968. break;
  969. }
  970. this.localizedHour = localizeTimePart({
  971. value: this.hour,
  972. part: "hour",
  973. locale: locale$1,
  974. numberingSystem
  975. });
  976. }
  977. }
  978. else {
  979. this[key] = typeof value === "number" ? formatTimePart(value) : value;
  980. this[`localized${capitalize(key)}`] = localizeTimePart({
  981. value: this[key],
  982. part: key,
  983. locale: locale$1,
  984. numberingSystem
  985. });
  986. }
  987. if (this.hour && this.minute) {
  988. const showSeconds = this.second && this.showSecond;
  989. this.value = `${this.hour}:${this.minute}:${showSeconds ? this.second : "00"}`;
  990. }
  991. else {
  992. this.value = null;
  993. }
  994. this.localizedMeridiem = this.value
  995. ? ((_a = localizeTimeStringToParts({ value: this.value, locale: locale$1, numberingSystem })) === null || _a === void 0 ? void 0 : _a.localizedMeridiem) || null
  996. : localizeTimePart({ value: this.meridiem, part: "meridiem", locale: locale$1, numberingSystem });
  997. if (emit) {
  998. this.calciteInternalTimePickerChange.emit();
  999. }
  1000. };
  1001. }
  1002. localeChanged() {
  1003. locale.updateEffectiveLocale(this);
  1004. }
  1005. valueWatcher(newValue) {
  1006. this.setValue(newValue, false);
  1007. }
  1008. effectiveLocaleWatcher() {
  1009. this.updateLocale();
  1010. }
  1011. //--------------------------------------------------------------------------
  1012. //
  1013. // Event Listeners
  1014. //
  1015. //--------------------------------------------------------------------------
  1016. hostBlurHandler() {
  1017. this.calciteInternalTimePickerBlur.emit();
  1018. }
  1019. hostFocusHandler() {
  1020. this.calciteInternalTimePickerFocus.emit();
  1021. }
  1022. keyDownHandler(event) {
  1023. const { defaultPrevented, key } = event;
  1024. if (defaultPrevented) {
  1025. return;
  1026. }
  1027. switch (this.activeEl) {
  1028. case this.hourEl:
  1029. if (key === "ArrowRight") {
  1030. this.setFocus("minute");
  1031. event.preventDefault();
  1032. }
  1033. break;
  1034. case this.minuteEl:
  1035. switch (key) {
  1036. case "ArrowLeft":
  1037. this.setFocus("hour");
  1038. event.preventDefault();
  1039. break;
  1040. case "ArrowRight":
  1041. if (this.step !== 60) {
  1042. this.setFocus("second");
  1043. event.preventDefault();
  1044. }
  1045. else if (this.hourCycle === "12") {
  1046. this.setFocus("meridiem");
  1047. event.preventDefault();
  1048. }
  1049. break;
  1050. }
  1051. break;
  1052. case this.secondEl:
  1053. switch (key) {
  1054. case "ArrowLeft":
  1055. this.setFocus("minute");
  1056. event.preventDefault();
  1057. break;
  1058. case "ArrowRight":
  1059. if (this.hourCycle === "12") {
  1060. this.setFocus("meridiem");
  1061. event.preventDefault();
  1062. }
  1063. break;
  1064. }
  1065. break;
  1066. case this.meridiemEl:
  1067. switch (key) {
  1068. case "ArrowLeft":
  1069. if (this.step !== 60) {
  1070. this.setFocus("second");
  1071. event.preventDefault();
  1072. }
  1073. else {
  1074. this.setFocus("minute");
  1075. event.preventDefault();
  1076. }
  1077. break;
  1078. }
  1079. break;
  1080. }
  1081. }
  1082. //--------------------------------------------------------------------------
  1083. //
  1084. // Public Methods
  1085. //
  1086. //--------------------------------------------------------------------------
  1087. /**
  1088. * Sets focus on the component.
  1089. *
  1090. * @param target
  1091. */
  1092. async setFocus(target) {
  1093. var _a;
  1094. (_a = this[`${target || "hour"}El`]) === null || _a === void 0 ? void 0 : _a.focus();
  1095. }
  1096. // --------------------------------------------------------------------------
  1097. //
  1098. // Private Methods
  1099. //
  1100. // --------------------------------------------------------------------------
  1101. buttonActivated(event) {
  1102. const { key: key$1 } = event;
  1103. if (key$1 === " ") {
  1104. event.preventDefault();
  1105. }
  1106. return key.isActivationKey(key$1);
  1107. }
  1108. getMeridiemOrder(formatParts) {
  1109. const locale = this.effectiveLocale;
  1110. const isRTLKind = locale === "ar" || locale === "he";
  1111. if (formatParts && !isRTLKind) {
  1112. const index = formatParts.findIndex((parts) => {
  1113. return parts.value === this.localizedMeridiem;
  1114. });
  1115. return index;
  1116. }
  1117. return 0;
  1118. }
  1119. updateLocale() {
  1120. this.hourCycle = getLocaleHourCycle(this.effectiveLocale, this.numberingSystem);
  1121. this.setValue(this.value, false);
  1122. }
  1123. // --------------------------------------------------------------------------
  1124. //
  1125. // Lifecycle
  1126. //
  1127. // --------------------------------------------------------------------------
  1128. connectedCallback() {
  1129. locale.connectLocalized(this);
  1130. this.updateLocale();
  1131. this.meridiemOrder = this.getMeridiemOrder(getTimeParts({
  1132. value: "0:00:00",
  1133. locale: this.effectiveLocale,
  1134. numberingSystem: this.numberingSystem
  1135. }));
  1136. }
  1137. disconnectedCallback() {
  1138. locale.disconnectLocalized(this);
  1139. }
  1140. // --------------------------------------------------------------------------
  1141. //
  1142. // Render Methods
  1143. //
  1144. // --------------------------------------------------------------------------
  1145. render() {
  1146. const hourIsNumber = locale.isValidNumber(this.hour);
  1147. const iconScale = this.scale === "s" || this.scale === "m" ? "s" : "m";
  1148. const minuteIsNumber = locale.isValidNumber(this.minute);
  1149. const secondIsNumber = locale.isValidNumber(this.second);
  1150. const showMeridiem = this.hourCycle === "12";
  1151. return (index.h("div", { class: {
  1152. [CSS.timePicker]: true,
  1153. [CSS.showMeridiem]: showMeridiem,
  1154. [CSS.showSecond]: this.showSecond,
  1155. [CSS[`scale-${this.scale}`]]: true
  1156. }, dir: "ltr" }, index.h("div", { class: CSS.column, role: "group" }, index.h("span", { "aria-label": this.intlHourUp, class: {
  1157. [CSS.button]: true,
  1158. [CSS.buttonHourUp]: true,
  1159. [CSS.buttonTopLeft]: true
  1160. }, onClick: this.incrementHour, onKeyDown: this.hourUpButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-up", scale: iconScale })), index.h("span", { "aria-label": this.intlHour, "aria-valuemax": "23", "aria-valuemin": "1", "aria-valuenow": (hourIsNumber && parseInt(this.hour)) || "0", "aria-valuetext": this.hour, class: {
  1161. [CSS.input]: true,
  1162. [CSS.hour]: true
  1163. }, onFocus: this.focusHandler, onKeyDown: this.hourKeyDownHandler, ref: this.setHourEl, role: "spinbutton", tabIndex: 0 }, this.localizedHour || "--"), index.h("span", { "aria-label": this.intlHourDown, class: {
  1164. [CSS.button]: true,
  1165. [CSS.buttonHourDown]: true,
  1166. [CSS.buttonBottomLeft]: true
  1167. }, onClick: this.decrementHour, onKeyDown: this.hourDownButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-down", scale: iconScale }))), index.h("span", { class: CSS.delimiter }, this.localizedHourSuffix), index.h("div", { class: CSS.column, role: "group" }, index.h("span", { "aria-label": this.intlMinuteUp, class: {
  1168. [CSS.button]: true,
  1169. [CSS.buttonMinuteUp]: true
  1170. }, onClick: this.incrementMinute, onKeyDown: this.minuteUpButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-up", scale: iconScale })), index.h("span", { "aria-label": this.intlMinute, "aria-valuemax": "12", "aria-valuemin": "1", "aria-valuenow": (minuteIsNumber && parseInt(this.minute)) || "0", "aria-valuetext": this.minute, class: {
  1171. [CSS.input]: true,
  1172. [CSS.minute]: true
  1173. }, onFocus: this.focusHandler, onKeyDown: this.minuteKeyDownHandler, ref: this.setMinuteEl, role: "spinbutton", tabIndex: 0 }, this.localizedMinute || "--"), index.h("span", { "aria-label": this.intlMinuteDown, class: {
  1174. [CSS.button]: true,
  1175. [CSS.buttonMinuteDown]: true
  1176. }, onClick: this.decrementMinute, onKeyDown: this.minuteDownButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-down", scale: iconScale }))), this.showSecond && index.h("span", { class: CSS.delimiter }, this.localizedMinuteSuffix), this.showSecond && (index.h("div", { class: CSS.column, role: "group" }, index.h("span", { "aria-label": this.intlSecondUp, class: {
  1177. [CSS.button]: true,
  1178. [CSS.buttonSecondUp]: true
  1179. }, onClick: this.incrementSecond, onKeyDown: this.secondUpButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-up", scale: iconScale })), index.h("span", { "aria-label": this.intlSecond, "aria-valuemax": "59", "aria-valuemin": "0", "aria-valuenow": (secondIsNumber && parseInt(this.second)) || "0", "aria-valuetext": this.second, class: {
  1180. [CSS.input]: true,
  1181. [CSS.second]: true
  1182. }, onFocus: this.focusHandler, onKeyDown: this.secondKeyDownHandler, ref: this.setSecondEl, role: "spinbutton", tabIndex: 0 }, this.localizedSecond || "--"), index.h("span", { "aria-label": this.intlSecondDown, class: {
  1183. [CSS.button]: true,
  1184. [CSS.buttonSecondDown]: true
  1185. }, onClick: this.decrementSecond, onKeyDown: this.secondDownButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-down", scale: iconScale })))), this.localizedSecondSuffix && (index.h("span", { class: CSS.delimiter }, this.localizedSecondSuffix)), showMeridiem && (index.h("div", { class: {
  1186. [CSS.column]: true,
  1187. [CSS.meridiemStart]: this.meridiemOrder === 0
  1188. }, role: "group" }, index.h("span", { "aria-label": this.intlMeridiemUp, class: {
  1189. [CSS.button]: true,
  1190. [CSS.buttonMeridiemUp]: true,
  1191. [CSS.buttonTopRight]: true
  1192. }, onClick: this.incrementMeridiem, onKeyDown: this.meridiemUpButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-up", scale: iconScale })), index.h("span", { "aria-label": this.intlMeridiem, "aria-valuemax": "2", "aria-valuemin": "1", "aria-valuenow": (this.meridiem === "PM" && "2") || "1", "aria-valuetext": this.meridiem, class: {
  1193. [CSS.input]: true,
  1194. [CSS.meridiem]: true
  1195. }, onFocus: this.focusHandler, onKeyDown: this.meridiemKeyDownHandler, ref: this.setMeridiemEl, role: "spinbutton", tabIndex: 0 }, this.localizedMeridiem || "--"), index.h("span", { "aria-label": this.intlMeridiemDown, class: {
  1196. [CSS.button]: true,
  1197. [CSS.buttonMeridiemDown]: true,
  1198. [CSS.buttonBottomRight]: true
  1199. }, onClick: this.decrementMeridiem, onKeyDown: this.meridiemDownButtonKeyDownHandler, role: "button", tabIndex: -1 }, index.h("calcite-icon", { icon: "chevron-down", scale: iconScale }))))));
  1200. }
  1201. get el() { return index.getElement(this); }
  1202. static get watchers() { return {
  1203. "locale": ["localeChanged"],
  1204. "value": ["valueWatcher"],
  1205. "effectiveLocale": ["effectiveLocaleWatcher"]
  1206. }; }
  1207. };
  1208. TimePicker.style = timePickerCss;
  1209. exports.calcite_input_time_picker = InputTimePicker;
  1210. exports.calcite_time_picker = TimePicker;