time-picker.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { Component, Element, h, Prop, Event, Watch, State, Listen, Method } from "@stencil/core";
  7. import { isActivationKey, numberKeys } from "../../utils/key";
  8. import { isValidNumber } from "../../utils/number";
  9. import { formatTimePart, maxTenthForMinuteAndSecond, getMeridiem, isValidTime, localizeTimeStringToParts, parseTimeString, localizeTimePart, getLocaleHourCycle, getTimeParts } from "../../utils/time";
  10. import { CSS, TEXT } from "./resources";
  11. function capitalize(str) {
  12. return str.charAt(0).toUpperCase() + str.slice(1);
  13. }
  14. export class TimePicker {
  15. constructor() {
  16. //--------------------------------------------------------------------------
  17. //
  18. // Properties
  19. //
  20. //--------------------------------------------------------------------------
  21. /** aria-label for the hour input
  22. * @default "Hour"
  23. */
  24. this.intlHour = TEXT.hour;
  25. /** aria-label for the hour down button
  26. * @default "Decrease hour"
  27. */
  28. this.intlHourDown = TEXT.hourDown;
  29. /** aria-label for the hour up button
  30. * @default "Increase hour"
  31. */
  32. this.intlHourUp = TEXT.hourUp;
  33. /** aria-label for the meridiem (am/pm) input
  34. * @default "AM/PM"
  35. */
  36. this.intlMeridiem = TEXT.meridiem;
  37. /** aria-label for the meridiem (am/pm) down button
  38. * @default "Decrease AM/PM"
  39. */
  40. this.intlMeridiemDown = TEXT.meridiemDown;
  41. /** aria-label for the meridiem (am/pm) up button
  42. * @default "Increase AM/PM"
  43. */
  44. this.intlMeridiemUp = TEXT.meridiemUp;
  45. /** aria-label for the minute input
  46. * @default "Minute"
  47. */
  48. this.intlMinute = TEXT.minute;
  49. /** aria-label for the minute down button
  50. * @default "Decrease minute"
  51. */
  52. this.intlMinuteDown = TEXT.minuteDown;
  53. /** aria-label for the minute up button
  54. * @default "Increase minute"
  55. */
  56. this.intlMinuteUp = TEXT.minuteUp;
  57. /** aria-label for the second input
  58. * @default "Second"
  59. */
  60. this.intlSecond = TEXT.second;
  61. /** aria-label for the second down button
  62. * @default "Decrease second"
  63. */
  64. this.intlSecondDown = TEXT.secondDown;
  65. /** aria-label for the second up button
  66. * @default "Increase second"
  67. */
  68. this.intlSecondUp = TEXT.secondUp;
  69. /**
  70. * BCP 47 language tag for desired language and country format
  71. * @internal
  72. */
  73. this.locale = document.documentElement.lang || navigator.language || "en";
  74. /** The scale (size) of the time picker */
  75. this.scale = "m";
  76. /** number (seconds) that specifies the granularity that the value must adhere to */
  77. this.step = 60;
  78. /** The selected time in UTC (always 24-hour format) */
  79. this.value = null;
  80. this.showSecond = this.step < 60;
  81. this.decrementHour = () => {
  82. const newHour = !this.hour ? 0 : this.hour === "00" ? 23 : parseInt(this.hour) - 1;
  83. this.setValuePart("hour", newHour);
  84. };
  85. this.decrementMeridiem = () => {
  86. const newMeridiem = this.meridiem === "PM" ? "AM" : "PM";
  87. this.setValuePart("meridiem", newMeridiem);
  88. };
  89. this.decrementMinuteOrSecond = (key) => {
  90. let newValue;
  91. if (isValidNumber(this[key])) {
  92. const valueAsNumber = parseInt(this[key]);
  93. newValue = valueAsNumber === 0 ? 59 : valueAsNumber - 1;
  94. }
  95. else {
  96. newValue = 59;
  97. }
  98. this.setValuePart(key, newValue);
  99. };
  100. this.decrementMinute = () => {
  101. this.decrementMinuteOrSecond("minute");
  102. };
  103. this.decrementSecond = () => {
  104. this.decrementMinuteOrSecond("second");
  105. };
  106. this.focusHandler = (event) => {
  107. this.activeEl = event.currentTarget;
  108. };
  109. this.hourDownButtonKeyDownHandler = (event) => {
  110. if (this.buttonActivated(event)) {
  111. this.decrementHour();
  112. }
  113. };
  114. this.hourKeyDownHandler = (event) => {
  115. const key = event.key;
  116. if (numberKeys.includes(key)) {
  117. const keyAsNumber = parseInt(key);
  118. let newHour;
  119. if (isValidNumber(this.hour)) {
  120. switch (this.hourCycle) {
  121. case "12":
  122. newHour =
  123. this.hour === "01" && keyAsNumber >= 0 && keyAsNumber <= 2
  124. ? `1${keyAsNumber}`
  125. : keyAsNumber;
  126. break;
  127. case "24":
  128. if (this.hour === "01") {
  129. newHour = `1${keyAsNumber}`;
  130. }
  131. else if (this.hour === "02" && keyAsNumber >= 0 && keyAsNumber <= 3) {
  132. newHour = `2${keyAsNumber}`;
  133. }
  134. else {
  135. newHour = keyAsNumber;
  136. }
  137. break;
  138. }
  139. }
  140. else {
  141. newHour = keyAsNumber;
  142. }
  143. this.setValuePart("hour", newHour);
  144. }
  145. else {
  146. switch (key) {
  147. case "Backspace":
  148. case "Delete":
  149. this.setValuePart("hour", null);
  150. break;
  151. case "ArrowDown":
  152. event.preventDefault();
  153. this.decrementHour();
  154. break;
  155. case "ArrowUp":
  156. event.preventDefault();
  157. this.incrementHour();
  158. break;
  159. case " ":
  160. case "Spacebar":
  161. event.preventDefault();
  162. break;
  163. }
  164. }
  165. };
  166. this.hourUpButtonKeyDownHandler = (event) => {
  167. if (this.buttonActivated(event)) {
  168. this.incrementHour();
  169. }
  170. };
  171. this.incrementMeridiem = () => {
  172. const newMeridiem = this.meridiem === "AM" ? "PM" : "AM";
  173. this.setValuePart("meridiem", newMeridiem);
  174. };
  175. this.incrementHour = () => {
  176. const newHour = isValidNumber(this.hour)
  177. ? this.hour === "23"
  178. ? 0
  179. : parseInt(this.hour) + 1
  180. : 1;
  181. this.setValuePart("hour", newHour);
  182. };
  183. this.incrementMinuteOrSecond = (key) => {
  184. const newValue = isValidNumber(this[key])
  185. ? this[key] === "59"
  186. ? 0
  187. : parseInt(this[key]) + 1
  188. : 0;
  189. this.setValuePart(key, newValue);
  190. };
  191. this.incrementMinute = () => {
  192. this.incrementMinuteOrSecond("minute");
  193. };
  194. this.incrementSecond = () => {
  195. this.incrementMinuteOrSecond("second");
  196. };
  197. this.meridiemDownButtonKeyDownHandler = (event) => {
  198. if (this.buttonActivated(event)) {
  199. this.decrementMeridiem();
  200. }
  201. };
  202. this.meridiemKeyDownHandler = (event) => {
  203. switch (event.key) {
  204. case "a":
  205. this.setValuePart("meridiem", "AM");
  206. break;
  207. case "p":
  208. this.setValuePart("meridiem", "PM");
  209. break;
  210. case "Backspace":
  211. case "Delete":
  212. this.setValuePart("meridiem", null);
  213. break;
  214. case "ArrowUp":
  215. event.preventDefault();
  216. this.incrementMeridiem();
  217. break;
  218. case "ArrowDown":
  219. event.preventDefault();
  220. this.decrementMeridiem();
  221. break;
  222. case " ":
  223. case "Spacebar":
  224. event.preventDefault();
  225. break;
  226. }
  227. };
  228. this.meridiemUpButtonKeyDownHandler = (event) => {
  229. if (this.buttonActivated(event)) {
  230. this.incrementMeridiem();
  231. }
  232. };
  233. this.minuteDownButtonKeyDownHandler = (event) => {
  234. if (this.buttonActivated(event)) {
  235. this.decrementMinute();
  236. }
  237. };
  238. this.minuteKeyDownHandler = (event) => {
  239. const key = event.key;
  240. if (numberKeys.includes(key)) {
  241. const keyAsNumber = parseInt(key);
  242. let newMinute;
  243. if (isValidNumber(this.minute) && this.minute.startsWith("0")) {
  244. const minuteAsNumber = parseInt(this.minute);
  245. newMinute =
  246. minuteAsNumber > maxTenthForMinuteAndSecond
  247. ? keyAsNumber
  248. : `${minuteAsNumber}${keyAsNumber}`;
  249. }
  250. else {
  251. newMinute = keyAsNumber;
  252. }
  253. this.setValuePart("minute", newMinute);
  254. }
  255. else {
  256. switch (key) {
  257. case "Backspace":
  258. case "Delete":
  259. this.setValuePart("minute", null);
  260. break;
  261. case "ArrowDown":
  262. event.preventDefault();
  263. this.decrementMinute();
  264. break;
  265. case "ArrowUp":
  266. event.preventDefault();
  267. this.incrementMinute();
  268. break;
  269. case " ":
  270. case "Spacebar":
  271. event.preventDefault();
  272. break;
  273. }
  274. }
  275. };
  276. this.minuteUpButtonKeyDownHandler = (event) => {
  277. if (this.buttonActivated(event)) {
  278. this.incrementMinute();
  279. }
  280. };
  281. this.secondDownButtonKeyDownHandler = (event) => {
  282. if (this.buttonActivated(event)) {
  283. this.decrementSecond();
  284. }
  285. };
  286. this.secondKeyDownHandler = (event) => {
  287. const key = event.key;
  288. if (numberKeys.includes(key)) {
  289. const keyAsNumber = parseInt(key);
  290. let newSecond;
  291. if (isValidNumber(this.second) && this.second.startsWith("0")) {
  292. const secondAsNumber = parseInt(this.second);
  293. newSecond =
  294. secondAsNumber > maxTenthForMinuteAndSecond
  295. ? keyAsNumber
  296. : `${secondAsNumber}${keyAsNumber}`;
  297. }
  298. else {
  299. newSecond = keyAsNumber;
  300. }
  301. this.setValuePart("second", newSecond);
  302. }
  303. else {
  304. switch (key) {
  305. case "Backspace":
  306. case "Delete":
  307. this.setValuePart("second", null);
  308. break;
  309. case "ArrowDown":
  310. event.preventDefault();
  311. this.decrementSecond();
  312. break;
  313. case "ArrowUp":
  314. event.preventDefault();
  315. this.incrementSecond();
  316. break;
  317. case " ":
  318. case "Spacebar":
  319. event.preventDefault();
  320. break;
  321. }
  322. }
  323. };
  324. this.secondUpButtonKeyDownHandler = (event) => {
  325. if (this.buttonActivated(event)) {
  326. this.incrementSecond();
  327. }
  328. };
  329. this.setHourEl = (el) => (this.hourEl = el);
  330. this.setMeridiemEl = (el) => (this.meridiemEl = el);
  331. this.setMinuteEl = (el) => (this.minuteEl = el);
  332. this.setSecondEl = (el) => (this.secondEl = el);
  333. this.setValue = (value, emit = true) => {
  334. if (isValidTime(value)) {
  335. const { hour, minute, second } = parseTimeString(value);
  336. const { localizedHour, localizedHourSuffix, localizedMinute, localizedMinuteSuffix, localizedSecond, localizedSecondSuffix, localizedMeridiem } = localizeTimeStringToParts(value, this.locale);
  337. this.localizedHour = localizedHour;
  338. this.localizedHourSuffix = localizedHourSuffix;
  339. this.localizedMinute = localizedMinute;
  340. this.localizedMinuteSuffix = localizedMinuteSuffix;
  341. this.localizedSecond = localizedSecond;
  342. this.localizedSecondSuffix = localizedSecondSuffix;
  343. this.hour = hour;
  344. this.minute = minute;
  345. this.second = second;
  346. if (localizedMeridiem) {
  347. this.localizedMeridiem = localizedMeridiem;
  348. this.meridiem = getMeridiem(this.hour);
  349. const formatParts = getTimeParts(value, this.locale);
  350. this.meridiemOrder = this.getMeridiemOrder(formatParts);
  351. }
  352. }
  353. else {
  354. this.hour = null;
  355. this.localizedHour = null;
  356. this.localizedHourSuffix = null;
  357. this.localizedMeridiem = null;
  358. this.localizedMinute = null;
  359. this.localizedMinuteSuffix = null;
  360. this.localizedSecond = null;
  361. this.localizedSecondSuffix = null;
  362. this.meridiem = null;
  363. this.minute = null;
  364. this.second = null;
  365. this.value = null;
  366. }
  367. if (emit) {
  368. this.calciteTimePickerChange.emit();
  369. }
  370. };
  371. this.setValuePart = (key, value, emit = true) => {
  372. var _a;
  373. if (key === "meridiem") {
  374. this.meridiem = value;
  375. if (isValidNumber(this.hour)) {
  376. const hourAsNumber = parseInt(this.hour);
  377. switch (value) {
  378. case "AM":
  379. if (hourAsNumber >= 12) {
  380. this.hour = formatTimePart(hourAsNumber - 12);
  381. }
  382. break;
  383. case "PM":
  384. if (hourAsNumber < 12) {
  385. this.hour = formatTimePart(hourAsNumber + 12);
  386. }
  387. break;
  388. }
  389. this.localizedHour = localizeTimePart(this.hour, "hour", this.locale);
  390. }
  391. }
  392. else {
  393. this[key] = typeof value === "number" ? formatTimePart(value) : value;
  394. this[`localized${capitalize(key)}`] = localizeTimePart(this[key], key, this.locale);
  395. }
  396. if (this.hour && this.minute) {
  397. const showSeconds = this.second && this.showSecond;
  398. this.value = `${this.hour}:${this.minute}:${showSeconds ? this.second : "00"}`;
  399. }
  400. else {
  401. this.value = null;
  402. }
  403. this.localizedMeridiem = this.value
  404. ? ((_a = localizeTimeStringToParts(this.value, this.locale)) === null || _a === void 0 ? void 0 : _a.localizedMeridiem) || null
  405. : localizeTimePart(this.meridiem, "meridiem", this.locale);
  406. if (emit) {
  407. this.calciteTimePickerChange.emit();
  408. }
  409. };
  410. }
  411. localeWatcher(newLocale) {
  412. this.hourCycle = getLocaleHourCycle(newLocale);
  413. this.setValue(this.value, false);
  414. }
  415. valueWatcher(newValue) {
  416. this.setValue(newValue, false);
  417. }
  418. //--------------------------------------------------------------------------
  419. //
  420. // Event Listeners
  421. //
  422. //--------------------------------------------------------------------------
  423. hostBlurHandler() {
  424. this.calciteTimePickerBlur.emit();
  425. }
  426. hostFocusHandler() {
  427. this.calciteTimePickerFocus.emit();
  428. }
  429. keyDownHandler(event) {
  430. const key = event.key;
  431. switch (this.activeEl) {
  432. case this.hourEl:
  433. if (key === "ArrowRight") {
  434. this.setFocus("minute");
  435. }
  436. break;
  437. case this.minuteEl:
  438. switch (key) {
  439. case "ArrowLeft":
  440. this.setFocus("hour");
  441. break;
  442. case "ArrowRight":
  443. if (this.step !== 60) {
  444. this.setFocus("second");
  445. }
  446. else if (this.hourCycle === "12") {
  447. this.setFocus("meridiem");
  448. }
  449. break;
  450. }
  451. break;
  452. case this.secondEl:
  453. switch (key) {
  454. case "ArrowLeft":
  455. this.setFocus("minute");
  456. break;
  457. case "ArrowRight":
  458. if (this.hourCycle === "12") {
  459. this.setFocus("meridiem");
  460. }
  461. break;
  462. }
  463. break;
  464. case this.meridiemEl:
  465. switch (key) {
  466. case "ArrowLeft":
  467. if (this.step !== 60) {
  468. this.setFocus("second");
  469. }
  470. else {
  471. this.setFocus("minute");
  472. }
  473. break;
  474. }
  475. break;
  476. }
  477. }
  478. //--------------------------------------------------------------------------
  479. //
  480. // Public Methods
  481. //
  482. //--------------------------------------------------------------------------
  483. /** Sets focus on the component. */
  484. async setFocus(target) {
  485. var _a;
  486. (_a = this[`${target || "hour"}El`]) === null || _a === void 0 ? void 0 : _a.focus();
  487. }
  488. // --------------------------------------------------------------------------
  489. //
  490. // Private Methods
  491. //
  492. // --------------------------------------------------------------------------
  493. buttonActivated(event) {
  494. const key = event.key;
  495. if (key === " ") {
  496. event.preventDefault();
  497. }
  498. return isActivationKey(key);
  499. }
  500. getMeridiemOrder(formatParts) {
  501. const isRTLKind = this.locale === "ar" || this.locale === "he";
  502. if (formatParts && !isRTLKind) {
  503. const index = formatParts.findIndex((parts) => {
  504. return parts.value === this.localizedMeridiem;
  505. });
  506. return index;
  507. }
  508. return 0;
  509. }
  510. // --------------------------------------------------------------------------
  511. //
  512. // Lifecycle
  513. //
  514. // --------------------------------------------------------------------------
  515. connectedCallback() {
  516. this.setValue(this.value, false);
  517. this.hourCycle = getLocaleHourCycle(this.locale);
  518. }
  519. // --------------------------------------------------------------------------
  520. //
  521. // Render Methods
  522. //
  523. // --------------------------------------------------------------------------
  524. render() {
  525. const hourIsNumber = isValidNumber(this.hour);
  526. const iconScale = this.scale === "s" || this.scale === "m" ? "s" : "m";
  527. const minuteIsNumber = isValidNumber(this.minute);
  528. const secondIsNumber = isValidNumber(this.second);
  529. const showMeridiem = this.hourCycle === "12";
  530. return (h("div", { class: {
  531. [CSS.timePicker]: true,
  532. [CSS.showMeridiem]: showMeridiem,
  533. [CSS.showSecond]: this.showSecond,
  534. [CSS[`scale-${this.scale}`]]: true
  535. }, dir: "ltr" },
  536. h("div", { class: CSS.column, role: "group" },
  537. h("span", { "aria-label": this.intlHourUp, class: {
  538. [CSS.button]: true,
  539. [CSS.buttonHourUp]: true,
  540. [CSS.buttonTopLeft]: true
  541. }, onClick: this.incrementHour, onKeyDown: this.hourUpButtonKeyDownHandler, role: "button", tabIndex: -1 },
  542. h("calcite-icon", { icon: "chevron-up", scale: iconScale })),
  543. h("span", { "aria-label": this.intlHour, "aria-valuemax": "23", "aria-valuemin": "1", "aria-valuenow": (hourIsNumber && parseInt(this.hour)) || "0", "aria-valuetext": this.hour, class: {
  544. [CSS.input]: true,
  545. [CSS.hour]: true
  546. }, onFocus: this.focusHandler, onKeyDown: this.hourKeyDownHandler, ref: this.setHourEl, role: "spinbutton", tabIndex: 0 }, this.localizedHour || "--"),
  547. h("span", { "aria-label": this.intlHourDown, class: {
  548. [CSS.button]: true,
  549. [CSS.buttonHourDown]: true,
  550. [CSS.buttonBottomLeft]: true
  551. }, onClick: this.decrementHour, onKeyDown: this.hourDownButtonKeyDownHandler, role: "button", tabIndex: -1 },
  552. h("calcite-icon", { icon: "chevron-down", scale: iconScale }))),
  553. h("span", { class: CSS.delimiter }, this.localizedHourSuffix),
  554. h("div", { class: CSS.column, role: "group" },
  555. h("span", { "aria-label": this.intlMinuteUp, class: {
  556. [CSS.button]: true,
  557. [CSS.buttonMinuteUp]: true
  558. }, onClick: this.incrementMinute, onKeyDown: this.minuteUpButtonKeyDownHandler, role: "button", tabIndex: -1 },
  559. h("calcite-icon", { icon: "chevron-up", scale: iconScale })),
  560. h("span", { "aria-label": this.intlMinute, "aria-valuemax": "12", "aria-valuemin": "1", "aria-valuenow": (minuteIsNumber && parseInt(this.minute)) || "0", "aria-valuetext": this.minute, class: {
  561. [CSS.input]: true,
  562. [CSS.minute]: true
  563. }, onFocus: this.focusHandler, onKeyDown: this.minuteKeyDownHandler, ref: this.setMinuteEl, role: "spinbutton", tabIndex: 0 }, this.localizedMinute || "--"),
  564. h("span", { "aria-label": this.intlMinuteDown, class: {
  565. [CSS.button]: true,
  566. [CSS.buttonMinuteDown]: true
  567. }, onClick: this.decrementMinute, onKeyDown: this.minuteDownButtonKeyDownHandler, role: "button", tabIndex: -1 },
  568. h("calcite-icon", { icon: "chevron-down", scale: iconScale }))),
  569. this.showSecond && h("span", { class: CSS.delimiter }, this.localizedMinuteSuffix),
  570. this.showSecond && (h("div", { class: CSS.column, role: "group" },
  571. h("span", { "aria-label": this.intlSecondUp, class: {
  572. [CSS.button]: true,
  573. [CSS.buttonSecondUp]: true
  574. }, onClick: this.incrementSecond, onKeyDown: this.secondUpButtonKeyDownHandler, role: "button", tabIndex: -1 },
  575. h("calcite-icon", { icon: "chevron-up", scale: iconScale })),
  576. h("span", { "aria-label": this.intlSecond, "aria-valuemax": "59", "aria-valuemin": "0", "aria-valuenow": (secondIsNumber && parseInt(this.second)) || "0", "aria-valuetext": this.second, class: {
  577. [CSS.input]: true,
  578. [CSS.second]: true
  579. }, onFocus: this.focusHandler, onKeyDown: this.secondKeyDownHandler, ref: this.setSecondEl, role: "spinbutton", tabIndex: 0 }, this.localizedSecond || "--"),
  580. h("span", { "aria-label": this.intlSecondDown, class: {
  581. [CSS.button]: true,
  582. [CSS.buttonSecondDown]: true
  583. }, onClick: this.decrementSecond, onKeyDown: this.secondDownButtonKeyDownHandler, role: "button", tabIndex: -1 },
  584. h("calcite-icon", { icon: "chevron-down", scale: iconScale })))),
  585. this.localizedSecondSuffix && (h("span", { class: CSS.delimiter }, this.localizedSecondSuffix)),
  586. showMeridiem && (h("div", { class: {
  587. [CSS.column]: true,
  588. [CSS.meridiemStart]: this.meridiemOrder === 0
  589. }, role: "group" },
  590. h("span", { "aria-label": this.intlMeridiemUp, class: {
  591. [CSS.button]: true,
  592. [CSS.buttonMeridiemUp]: true,
  593. [CSS.buttonTopRight]: true
  594. }, onClick: this.incrementMeridiem, onKeyDown: this.meridiemUpButtonKeyDownHandler, role: "button", tabIndex: -1 },
  595. h("calcite-icon", { icon: "chevron-up", scale: iconScale })),
  596. h("span", { "aria-label": this.intlMeridiem, "aria-valuemax": "2", "aria-valuemin": "1", "aria-valuenow": (this.meridiem === "PM" && "2") || "1", "aria-valuetext": this.meridiem, class: {
  597. [CSS.input]: true,
  598. [CSS.meridiem]: true
  599. }, onFocus: this.focusHandler, onKeyDown: this.meridiemKeyDownHandler, ref: this.setMeridiemEl, role: "spinbutton", tabIndex: 0 }, this.localizedMeridiem || "--"),
  600. h("span", { "aria-label": this.intlMeridiemDown, class: {
  601. [CSS.button]: true,
  602. [CSS.buttonMeridiemDown]: true,
  603. [CSS.buttonBottomRight]: true
  604. }, onClick: this.decrementMeridiem, onKeyDown: this.meridiemDownButtonKeyDownHandler, role: "button", tabIndex: -1 },
  605. h("calcite-icon", { icon: "chevron-down", scale: iconScale }))))));
  606. }
  607. static get is() { return "calcite-time-picker"; }
  608. static get encapsulation() { return "shadow"; }
  609. static get originalStyleUrls() { return {
  610. "$": ["time-picker.scss"]
  611. }; }
  612. static get styleUrls() { return {
  613. "$": ["time-picker.css"]
  614. }; }
  615. static get properties() { return {
  616. "intlHour": {
  617. "type": "string",
  618. "mutable": false,
  619. "complexType": {
  620. "original": "string",
  621. "resolved": "string",
  622. "references": {}
  623. },
  624. "required": false,
  625. "optional": false,
  626. "docs": {
  627. "tags": [{
  628. "name": "default",
  629. "text": "\"Hour\""
  630. }],
  631. "text": "aria-label for the hour input"
  632. },
  633. "attribute": "intl-hour",
  634. "reflect": false,
  635. "defaultValue": "TEXT.hour"
  636. },
  637. "intlHourDown": {
  638. "type": "string",
  639. "mutable": false,
  640. "complexType": {
  641. "original": "string",
  642. "resolved": "string",
  643. "references": {}
  644. },
  645. "required": false,
  646. "optional": false,
  647. "docs": {
  648. "tags": [{
  649. "name": "default",
  650. "text": "\"Decrease hour\""
  651. }],
  652. "text": "aria-label for the hour down button"
  653. },
  654. "attribute": "intl-hour-down",
  655. "reflect": false,
  656. "defaultValue": "TEXT.hourDown"
  657. },
  658. "intlHourUp": {
  659. "type": "string",
  660. "mutable": false,
  661. "complexType": {
  662. "original": "string",
  663. "resolved": "string",
  664. "references": {}
  665. },
  666. "required": false,
  667. "optional": false,
  668. "docs": {
  669. "tags": [{
  670. "name": "default",
  671. "text": "\"Increase hour\""
  672. }],
  673. "text": "aria-label for the hour up button"
  674. },
  675. "attribute": "intl-hour-up",
  676. "reflect": false,
  677. "defaultValue": "TEXT.hourUp"
  678. },
  679. "intlMeridiem": {
  680. "type": "string",
  681. "mutable": false,
  682. "complexType": {
  683. "original": "string",
  684. "resolved": "string",
  685. "references": {}
  686. },
  687. "required": false,
  688. "optional": false,
  689. "docs": {
  690. "tags": [{
  691. "name": "default",
  692. "text": "\"AM/PM\""
  693. }],
  694. "text": "aria-label for the meridiem (am/pm) input"
  695. },
  696. "attribute": "intl-meridiem",
  697. "reflect": false,
  698. "defaultValue": "TEXT.meridiem"
  699. },
  700. "intlMeridiemDown": {
  701. "type": "string",
  702. "mutable": false,
  703. "complexType": {
  704. "original": "string",
  705. "resolved": "string",
  706. "references": {}
  707. },
  708. "required": false,
  709. "optional": false,
  710. "docs": {
  711. "tags": [{
  712. "name": "default",
  713. "text": "\"Decrease AM/PM\""
  714. }],
  715. "text": "aria-label for the meridiem (am/pm) down button"
  716. },
  717. "attribute": "intl-meridiem-down",
  718. "reflect": false,
  719. "defaultValue": "TEXT.meridiemDown"
  720. },
  721. "intlMeridiemUp": {
  722. "type": "string",
  723. "mutable": false,
  724. "complexType": {
  725. "original": "string",
  726. "resolved": "string",
  727. "references": {}
  728. },
  729. "required": false,
  730. "optional": false,
  731. "docs": {
  732. "tags": [{
  733. "name": "default",
  734. "text": "\"Increase AM/PM\""
  735. }],
  736. "text": "aria-label for the meridiem (am/pm) up button"
  737. },
  738. "attribute": "intl-meridiem-up",
  739. "reflect": false,
  740. "defaultValue": "TEXT.meridiemUp"
  741. },
  742. "intlMinute": {
  743. "type": "string",
  744. "mutable": false,
  745. "complexType": {
  746. "original": "string",
  747. "resolved": "string",
  748. "references": {}
  749. },
  750. "required": false,
  751. "optional": false,
  752. "docs": {
  753. "tags": [{
  754. "name": "default",
  755. "text": "\"Minute\""
  756. }],
  757. "text": "aria-label for the minute input"
  758. },
  759. "attribute": "intl-minute",
  760. "reflect": false,
  761. "defaultValue": "TEXT.minute"
  762. },
  763. "intlMinuteDown": {
  764. "type": "string",
  765. "mutable": false,
  766. "complexType": {
  767. "original": "string",
  768. "resolved": "string",
  769. "references": {}
  770. },
  771. "required": false,
  772. "optional": false,
  773. "docs": {
  774. "tags": [{
  775. "name": "default",
  776. "text": "\"Decrease minute\""
  777. }],
  778. "text": "aria-label for the minute down button"
  779. },
  780. "attribute": "intl-minute-down",
  781. "reflect": false,
  782. "defaultValue": "TEXT.minuteDown"
  783. },
  784. "intlMinuteUp": {
  785. "type": "string",
  786. "mutable": false,
  787. "complexType": {
  788. "original": "string",
  789. "resolved": "string",
  790. "references": {}
  791. },
  792. "required": false,
  793. "optional": false,
  794. "docs": {
  795. "tags": [{
  796. "name": "default",
  797. "text": "\"Increase minute\""
  798. }],
  799. "text": "aria-label for the minute up button"
  800. },
  801. "attribute": "intl-minute-up",
  802. "reflect": false,
  803. "defaultValue": "TEXT.minuteUp"
  804. },
  805. "intlSecond": {
  806. "type": "string",
  807. "mutable": false,
  808. "complexType": {
  809. "original": "string",
  810. "resolved": "string",
  811. "references": {}
  812. },
  813. "required": false,
  814. "optional": false,
  815. "docs": {
  816. "tags": [{
  817. "name": "default",
  818. "text": "\"Second\""
  819. }],
  820. "text": "aria-label for the second input"
  821. },
  822. "attribute": "intl-second",
  823. "reflect": false,
  824. "defaultValue": "TEXT.second"
  825. },
  826. "intlSecondDown": {
  827. "type": "string",
  828. "mutable": false,
  829. "complexType": {
  830. "original": "string",
  831. "resolved": "string",
  832. "references": {}
  833. },
  834. "required": false,
  835. "optional": false,
  836. "docs": {
  837. "tags": [{
  838. "name": "default",
  839. "text": "\"Decrease second\""
  840. }],
  841. "text": "aria-label for the second down button"
  842. },
  843. "attribute": "intl-second-down",
  844. "reflect": false,
  845. "defaultValue": "TEXT.secondDown"
  846. },
  847. "intlSecondUp": {
  848. "type": "string",
  849. "mutable": false,
  850. "complexType": {
  851. "original": "string",
  852. "resolved": "string",
  853. "references": {}
  854. },
  855. "required": false,
  856. "optional": false,
  857. "docs": {
  858. "tags": [{
  859. "name": "default",
  860. "text": "\"Increase second\""
  861. }],
  862. "text": "aria-label for the second up button"
  863. },
  864. "attribute": "intl-second-up",
  865. "reflect": false,
  866. "defaultValue": "TEXT.secondUp"
  867. },
  868. "locale": {
  869. "type": "string",
  870. "mutable": true,
  871. "complexType": {
  872. "original": "string",
  873. "resolved": "string",
  874. "references": {}
  875. },
  876. "required": false,
  877. "optional": false,
  878. "docs": {
  879. "tags": [{
  880. "name": "internal",
  881. "text": undefined
  882. }],
  883. "text": "BCP 47 language tag for desired language and country format"
  884. },
  885. "attribute": "lang",
  886. "reflect": false,
  887. "defaultValue": "document.documentElement.lang || navigator.language || \"en\""
  888. },
  889. "scale": {
  890. "type": "string",
  891. "mutable": false,
  892. "complexType": {
  893. "original": "Scale",
  894. "resolved": "\"l\" | \"m\" | \"s\"",
  895. "references": {
  896. "Scale": {
  897. "location": "import",
  898. "path": "../interfaces"
  899. }
  900. }
  901. },
  902. "required": false,
  903. "optional": false,
  904. "docs": {
  905. "tags": [],
  906. "text": "The scale (size) of the time picker"
  907. },
  908. "attribute": "scale",
  909. "reflect": false,
  910. "defaultValue": "\"m\""
  911. },
  912. "step": {
  913. "type": "number",
  914. "mutable": false,
  915. "complexType": {
  916. "original": "number",
  917. "resolved": "number",
  918. "references": {}
  919. },
  920. "required": false,
  921. "optional": false,
  922. "docs": {
  923. "tags": [],
  924. "text": "number (seconds) that specifies the granularity that the value must adhere to"
  925. },
  926. "attribute": "step",
  927. "reflect": false,
  928. "defaultValue": "60"
  929. },
  930. "value": {
  931. "type": "string",
  932. "mutable": true,
  933. "complexType": {
  934. "original": "string",
  935. "resolved": "string",
  936. "references": {}
  937. },
  938. "required": false,
  939. "optional": false,
  940. "docs": {
  941. "tags": [],
  942. "text": "The selected time in UTC (always 24-hour format)"
  943. },
  944. "attribute": "value",
  945. "reflect": false,
  946. "defaultValue": "null"
  947. }
  948. }; }
  949. static get states() { return {
  950. "hour": {},
  951. "hourCycle": {},
  952. "localizedHour": {},
  953. "localizedHourSuffix": {},
  954. "localizedMeridiem": {},
  955. "localizedMinute": {},
  956. "localizedMinuteSuffix": {},
  957. "localizedSecond": {},
  958. "localizedSecondSuffix": {},
  959. "meridiem": {},
  960. "minute": {},
  961. "second": {},
  962. "showSecond": {}
  963. }; }
  964. static get events() { return [{
  965. "method": "calciteTimePickerBlur",
  966. "name": "calciteTimePickerBlur",
  967. "bubbles": true,
  968. "cancelable": true,
  969. "composed": true,
  970. "docs": {
  971. "tags": [{
  972. "name": "internal",
  973. "text": undefined
  974. }],
  975. "text": ""
  976. },
  977. "complexType": {
  978. "original": "void",
  979. "resolved": "void",
  980. "references": {}
  981. }
  982. }, {
  983. "method": "calciteTimePickerChange",
  984. "name": "calciteTimePickerChange",
  985. "bubbles": true,
  986. "cancelable": true,
  987. "composed": true,
  988. "docs": {
  989. "tags": [{
  990. "name": "internal",
  991. "text": undefined
  992. }],
  993. "text": ""
  994. },
  995. "complexType": {
  996. "original": "string",
  997. "resolved": "string",
  998. "references": {}
  999. }
  1000. }, {
  1001. "method": "calciteTimePickerFocus",
  1002. "name": "calciteTimePickerFocus",
  1003. "bubbles": true,
  1004. "cancelable": true,
  1005. "composed": true,
  1006. "docs": {
  1007. "tags": [{
  1008. "name": "internal",
  1009. "text": undefined
  1010. }],
  1011. "text": ""
  1012. },
  1013. "complexType": {
  1014. "original": "void",
  1015. "resolved": "void",
  1016. "references": {}
  1017. }
  1018. }]; }
  1019. static get methods() { return {
  1020. "setFocus": {
  1021. "complexType": {
  1022. "signature": "(target: TimePart) => Promise<void>",
  1023. "parameters": [{
  1024. "tags": [],
  1025. "text": ""
  1026. }],
  1027. "references": {
  1028. "Promise": {
  1029. "location": "global"
  1030. },
  1031. "TimePart": {
  1032. "location": "import",
  1033. "path": "../../utils/time"
  1034. }
  1035. },
  1036. "return": "Promise<void>"
  1037. },
  1038. "docs": {
  1039. "text": "Sets focus on the component.",
  1040. "tags": []
  1041. }
  1042. }
  1043. }; }
  1044. static get elementRef() { return "el"; }
  1045. static get watchers() { return [{
  1046. "propName": "locale",
  1047. "methodName": "localeWatcher"
  1048. }, {
  1049. "propName": "value",
  1050. "methodName": "valueWatcher"
  1051. }]; }
  1052. static get listeners() { return [{
  1053. "name": "blur",
  1054. "method": "hostBlurHandler",
  1055. "target": undefined,
  1056. "capture": false,
  1057. "passive": false
  1058. }, {
  1059. "name": "focus",
  1060. "method": "hostFocusHandler",
  1061. "target": undefined,
  1062. "capture": false,
  1063. "passive": false
  1064. }, {
  1065. "name": "keydown",
  1066. "method": "keyDownHandler",
  1067. "target": undefined,
  1068. "capture": false,
  1069. "passive": false
  1070. }]; }
  1071. }