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

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