date-picker-day.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. import { Host, h } from "@stencil/core";
  7. import { closestElementCrossShadowBoundary, getElementDir } from "../../utils/dom";
  8. import { CSS_UTILITY } from "../../utils/resources";
  9. import { updateHostInteraction } from "../../utils/interactive";
  10. import { isActivationKey } from "../../utils/key";
  11. import { numberStringFormatter } from "../../utils/locale";
  12. export class DatePickerDay {
  13. constructor() {
  14. /** Date is outside of range and can't be selected */
  15. this.disabled = false;
  16. /** Date is in the current month. */
  17. this.currentMonth = false;
  18. /** Date is the current selected date of the picker */
  19. this.selected = false;
  20. /** Date is currently highlighted as part of the range */
  21. this.highlighted = false;
  22. /** Showing date range */
  23. this.range = false;
  24. /** Date is the start of date range */
  25. this.startOfRange = false;
  26. /** Date is the end of date range */
  27. this.endOfRange = false;
  28. /** Date is being hovered and within the set range */
  29. this.rangeHover = false;
  30. /** Date is actively in focus for keyboard navigation */
  31. this.active = false;
  32. //--------------------------------------------------------------------------
  33. //
  34. // Event Listeners
  35. //
  36. //--------------------------------------------------------------------------
  37. this.onClick = () => {
  38. !this.disabled && this.calciteDaySelect.emit();
  39. };
  40. this.keyDownHandler = (event) => {
  41. if (isActivationKey(event.key)) {
  42. !this.disabled && this.calciteDaySelect.emit();
  43. event.preventDefault();
  44. }
  45. };
  46. }
  47. mouseoverHandler() {
  48. this.calciteInternalDayHover.emit();
  49. }
  50. //--------------------------------------------------------------------------
  51. //
  52. // Lifecycle
  53. //
  54. //--------------------------------------------------------------------------
  55. componentWillLoad() {
  56. this.parentDatePickerEl = closestElementCrossShadowBoundary(this.el, "calcite-date-picker");
  57. }
  58. render() {
  59. if (this.parentDatePickerEl) {
  60. const { numberingSystem, lang: locale } = this.parentDatePickerEl;
  61. numberStringFormatter.numberFormatOptions = {
  62. useGrouping: false,
  63. ...(numberingSystem && { numberingSystem }),
  64. ...(locale && { locale })
  65. };
  66. }
  67. const formattedDay = numberStringFormatter.localize(String(this.day));
  68. const dir = getElementDir(this.el);
  69. return (h(Host, { onClick: this.onClick, onKeyDown: this.keyDownHandler, role: "gridcell" }, h("div", { class: { "day-v-wrapper": true, [CSS_UTILITY.rtl]: dir === "rtl" } }, h("div", { class: "day-wrapper" }, h("span", { class: "day" }, h("span", { class: "text" }, formattedDay))))));
  70. }
  71. componentDidRender() {
  72. updateHostInteraction(this, this.isTabbable);
  73. }
  74. isTabbable() {
  75. return this.active;
  76. }
  77. static get is() { return "calcite-date-picker-day"; }
  78. static get encapsulation() { return "shadow"; }
  79. static get originalStyleUrls() {
  80. return {
  81. "$": ["date-picker-day.scss"]
  82. };
  83. }
  84. static get styleUrls() {
  85. return {
  86. "$": ["date-picker-day.css"]
  87. };
  88. }
  89. static get properties() {
  90. return {
  91. "day": {
  92. "type": "number",
  93. "mutable": false,
  94. "complexType": {
  95. "original": "number",
  96. "resolved": "number",
  97. "references": {}
  98. },
  99. "required": true,
  100. "optional": false,
  101. "docs": {
  102. "tags": [],
  103. "text": "Day of the month to be shown."
  104. },
  105. "attribute": "day",
  106. "reflect": false
  107. },
  108. "disabled": {
  109. "type": "boolean",
  110. "mutable": false,
  111. "complexType": {
  112. "original": "boolean",
  113. "resolved": "boolean",
  114. "references": {}
  115. },
  116. "required": false,
  117. "optional": false,
  118. "docs": {
  119. "tags": [],
  120. "text": "Date is outside of range and can't be selected"
  121. },
  122. "attribute": "disabled",
  123. "reflect": true,
  124. "defaultValue": "false"
  125. },
  126. "currentMonth": {
  127. "type": "boolean",
  128. "mutable": false,
  129. "complexType": {
  130. "original": "boolean",
  131. "resolved": "boolean",
  132. "references": {}
  133. },
  134. "required": false,
  135. "optional": false,
  136. "docs": {
  137. "tags": [],
  138. "text": "Date is in the current month."
  139. },
  140. "attribute": "current-month",
  141. "reflect": true,
  142. "defaultValue": "false"
  143. },
  144. "selected": {
  145. "type": "boolean",
  146. "mutable": false,
  147. "complexType": {
  148. "original": "boolean",
  149. "resolved": "boolean",
  150. "references": {}
  151. },
  152. "required": false,
  153. "optional": false,
  154. "docs": {
  155. "tags": [],
  156. "text": "Date is the current selected date of the picker"
  157. },
  158. "attribute": "selected",
  159. "reflect": true,
  160. "defaultValue": "false"
  161. },
  162. "highlighted": {
  163. "type": "boolean",
  164. "mutable": false,
  165. "complexType": {
  166. "original": "boolean",
  167. "resolved": "boolean",
  168. "references": {}
  169. },
  170. "required": false,
  171. "optional": false,
  172. "docs": {
  173. "tags": [],
  174. "text": "Date is currently highlighted as part of the range"
  175. },
  176. "attribute": "highlighted",
  177. "reflect": true,
  178. "defaultValue": "false"
  179. },
  180. "range": {
  181. "type": "boolean",
  182. "mutable": false,
  183. "complexType": {
  184. "original": "boolean",
  185. "resolved": "boolean",
  186. "references": {}
  187. },
  188. "required": false,
  189. "optional": false,
  190. "docs": {
  191. "tags": [],
  192. "text": "Showing date range"
  193. },
  194. "attribute": "range",
  195. "reflect": true,
  196. "defaultValue": "false"
  197. },
  198. "startOfRange": {
  199. "type": "boolean",
  200. "mutable": false,
  201. "complexType": {
  202. "original": "boolean",
  203. "resolved": "boolean",
  204. "references": {}
  205. },
  206. "required": false,
  207. "optional": false,
  208. "docs": {
  209. "tags": [],
  210. "text": "Date is the start of date range"
  211. },
  212. "attribute": "start-of-range",
  213. "reflect": true,
  214. "defaultValue": "false"
  215. },
  216. "endOfRange": {
  217. "type": "boolean",
  218. "mutable": false,
  219. "complexType": {
  220. "original": "boolean",
  221. "resolved": "boolean",
  222. "references": {}
  223. },
  224. "required": false,
  225. "optional": false,
  226. "docs": {
  227. "tags": [],
  228. "text": "Date is the end of date range"
  229. },
  230. "attribute": "end-of-range",
  231. "reflect": true,
  232. "defaultValue": "false"
  233. },
  234. "rangeHover": {
  235. "type": "boolean",
  236. "mutable": false,
  237. "complexType": {
  238. "original": "boolean",
  239. "resolved": "boolean",
  240. "references": {}
  241. },
  242. "required": false,
  243. "optional": false,
  244. "docs": {
  245. "tags": [],
  246. "text": "Date is being hovered and within the set range"
  247. },
  248. "attribute": "range-hover",
  249. "reflect": true,
  250. "defaultValue": "false"
  251. },
  252. "active": {
  253. "type": "boolean",
  254. "mutable": false,
  255. "complexType": {
  256. "original": "boolean",
  257. "resolved": "boolean",
  258. "references": {}
  259. },
  260. "required": false,
  261. "optional": false,
  262. "docs": {
  263. "tags": [],
  264. "text": "Date is actively in focus for keyboard navigation"
  265. },
  266. "attribute": "active",
  267. "reflect": true,
  268. "defaultValue": "false"
  269. },
  270. "scale": {
  271. "type": "string",
  272. "mutable": false,
  273. "complexType": {
  274. "original": "Scale",
  275. "resolved": "\"l\" | \"m\" | \"s\"",
  276. "references": {
  277. "Scale": {
  278. "location": "import",
  279. "path": "../interfaces"
  280. }
  281. }
  282. },
  283. "required": false,
  284. "optional": false,
  285. "docs": {
  286. "tags": [],
  287. "text": "specify the scale of the date picker"
  288. },
  289. "attribute": "scale",
  290. "reflect": true
  291. },
  292. "value": {
  293. "type": "unknown",
  294. "mutable": false,
  295. "complexType": {
  296. "original": "Date",
  297. "resolved": "Date",
  298. "references": {
  299. "Date": {
  300. "location": "global"
  301. }
  302. }
  303. },
  304. "required": false,
  305. "optional": false,
  306. "docs": {
  307. "tags": [],
  308. "text": "Date value for the day."
  309. }
  310. }
  311. };
  312. }
  313. static get events() {
  314. return [{
  315. "method": "calciteDaySelect",
  316. "name": "calciteDaySelect",
  317. "bubbles": true,
  318. "cancelable": false,
  319. "composed": true,
  320. "docs": {
  321. "tags": [],
  322. "text": "Emitted when user selects day"
  323. },
  324. "complexType": {
  325. "original": "void",
  326. "resolved": "void",
  327. "references": {}
  328. }
  329. }, {
  330. "method": "calciteInternalDayHover",
  331. "name": "calciteInternalDayHover",
  332. "bubbles": true,
  333. "cancelable": false,
  334. "composed": true,
  335. "docs": {
  336. "tags": [{
  337. "name": "internal",
  338. "text": undefined
  339. }],
  340. "text": "Emitted when user hovers over a day"
  341. },
  342. "complexType": {
  343. "original": "void",
  344. "resolved": "void",
  345. "references": {}
  346. }
  347. }];
  348. }
  349. static get elementRef() { return "el"; }
  350. static get listeners() {
  351. return [{
  352. "name": "pointerover",
  353. "method": "mouseoverHandler",
  354. "target": undefined,
  355. "capture": false,
  356. "passive": true
  357. }];
  358. }
  359. }