date-picker-day.js 9.4 KB

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