tyrell-components 1.0.0-RC14 → 1.0.0-RC16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/README.md +53 -53
  2. package/css/tyrell-theme.css +32 -4
  3. package/css/tyrell.css +10 -15
  4. package/dist/tyrell-colors-static.css +1 -316
  5. package/dist/tyrell-theme.css +1 -1443
  6. package/dist/tyrell.css +1 -1390
  7. package/dist/tyrell.js +1 -1
  8. package/lib/base/ty-component.d.ts +14 -0
  9. package/lib/base/ty-component.d.ts.map +1 -0
  10. package/lib/base/ty-component.js +223 -196
  11. package/lib/base/ty-component.js.map +1 -0
  12. package/lib/components/button.d.ts +1 -1
  13. package/lib/components/button.d.ts.map +1 -0
  14. package/lib/components/button.js +267 -259
  15. package/lib/components/button.js.map +1 -0
  16. package/lib/components/calendar-month.d.ts +2 -2
  17. package/lib/components/calendar-month.d.ts.map +1 -0
  18. package/lib/components/calendar-month.js +440 -416
  19. package/lib/components/calendar-month.js.map +1 -0
  20. package/lib/components/calendar-navigation.d.ts +11 -0
  21. package/lib/components/calendar-navigation.d.ts.map +1 -0
  22. package/lib/components/calendar-navigation.js +272 -261
  23. package/lib/components/calendar-navigation.js.map +1 -0
  24. package/lib/components/calendar.d.ts +31 -3
  25. package/lib/components/calendar.d.ts.map +1 -0
  26. package/lib/components/calendar.js +785 -603
  27. package/lib/components/calendar.js.map +1 -0
  28. package/lib/components/checkbox.d.ts +1 -1
  29. package/lib/components/checkbox.d.ts.map +1 -0
  30. package/lib/components/checkbox.js +273 -272
  31. package/lib/components/checkbox.js.map +1 -0
  32. package/lib/components/copy.d.ts +1 -1
  33. package/lib/components/copy.d.ts.map +1 -0
  34. package/lib/components/copy.js +287 -278
  35. package/lib/components/copy.js.map +1 -0
  36. package/lib/components/date-picker.d.ts +16 -10
  37. package/lib/components/date-picker.d.ts.map +1 -0
  38. package/lib/components/date-picker.js +1068 -1122
  39. package/lib/components/date-picker.js.map +1 -0
  40. package/lib/components/dropdown.d.ts +403 -0
  41. package/lib/components/dropdown.d.ts.map +1 -0
  42. package/lib/components/dropdown.js +1315 -0
  43. package/lib/components/dropdown.js.map +1 -0
  44. package/lib/components/file-upload.d.ts +4 -0
  45. package/lib/components/file-upload.js +418 -404
  46. package/lib/components/icon.d.ts.map +1 -0
  47. package/lib/components/icon.js +141 -141
  48. package/lib/components/icon.js.map +1 -0
  49. package/lib/components/input.d.ts +1 -1
  50. package/lib/components/input.d.ts.map +1 -0
  51. package/lib/components/input.js +593 -596
  52. package/lib/components/input.js.map +1 -0
  53. package/lib/components/modal.d.ts +2 -8
  54. package/lib/components/modal.d.ts.map +1 -0
  55. package/lib/components/modal.js +309 -319
  56. package/lib/components/modal.js.map +1 -0
  57. package/lib/components/multiselect.d.ts +389 -0
  58. package/lib/components/multiselect.d.ts.map +1 -0
  59. package/lib/components/multiselect.js +1301 -0
  60. package/lib/components/multiselect.js.map +1 -0
  61. package/lib/components/option.d.ts.map +1 -0
  62. package/lib/components/option.js +167 -167
  63. package/lib/components/option.js.map +1 -0
  64. package/lib/components/popup.d.ts.map +1 -0
  65. package/lib/components/popup.js +236 -233
  66. package/lib/components/popup.js.map +1 -0
  67. package/lib/components/radio.d.ts +17 -2
  68. package/lib/components/radio.js +437 -406
  69. package/lib/components/resize-observer.d.ts.map +1 -0
  70. package/lib/components/resize-observer.js +67 -67
  71. package/lib/components/resize-observer.js.map +1 -0
  72. package/lib/components/scroll-container.d.ts +3 -2
  73. package/lib/components/scroll-container.d.ts.map +1 -0
  74. package/lib/components/scroll-container.js +289 -294
  75. package/lib/components/scroll-container.js.map +1 -0
  76. package/lib/components/select.d.ts +85 -18
  77. package/lib/components/select.js +1647 -1529
  78. package/lib/components/selected-tags.d.ts +1 -1
  79. package/lib/components/selected-tags.js +188 -182
  80. package/lib/components/step.d.ts.map +1 -0
  81. package/lib/components/step.js +62 -62
  82. package/lib/components/step.js.map +1 -0
  83. package/lib/components/switch.d.ts +1 -1
  84. package/lib/components/switch.js +214 -213
  85. package/lib/components/tab.d.ts +49 -1
  86. package/lib/components/tab.d.ts.map +1 -0
  87. package/lib/components/tab.js +203 -62
  88. package/lib/components/tab.js.map +1 -0
  89. package/lib/components/tabs.d.ts +15 -2
  90. package/lib/components/tabs.d.ts.map +1 -0
  91. package/lib/components/tabs.js +576 -496
  92. package/lib/components/tabs.js.map +1 -0
  93. package/lib/components/tag.d.ts +5 -8
  94. package/lib/components/tag.d.ts.map +1 -0
  95. package/lib/components/tag.js +235 -235
  96. package/lib/components/tag.js.map +1 -0
  97. package/lib/components/textarea.d.ts +5 -4
  98. package/lib/components/textarea.d.ts.map +1 -0
  99. package/lib/components/textarea.js +458 -456
  100. package/lib/components/textarea.js.map +1 -0
  101. package/lib/components/tooltip.d.ts +4 -3
  102. package/lib/components/tooltip.d.ts.map +1 -0
  103. package/lib/components/tooltip.js +293 -283
  104. package/lib/components/tooltip.js.map +1 -0
  105. package/lib/components/wizard.d.ts +5 -4
  106. package/lib/components/wizard.d.ts.map +1 -0
  107. package/lib/components/wizard.js +359 -395
  108. package/lib/components/wizard.js.map +1 -0
  109. package/lib/icons/fontawesome/brands.d.ts.map +1 -0
  110. package/lib/icons/fontawesome/brands.js.map +1 -0
  111. package/lib/icons/fontawesome/regular.d.ts.map +1 -0
  112. package/lib/icons/fontawesome/regular.js.map +1 -0
  113. package/lib/icons/fontawesome/solid.d.ts.map +1 -0
  114. package/lib/icons/fontawesome/solid.js.map +1 -0
  115. package/lib/icons/heroicons/micro.d.ts.map +1 -0
  116. package/lib/icons/heroicons/micro.js +392 -392
  117. package/lib/icons/heroicons/micro.js.map +1 -0
  118. package/lib/icons/heroicons/mini.d.ts.map +1 -0
  119. package/lib/icons/heroicons/mini.js +382 -382
  120. package/lib/icons/heroicons/mini.js.map +1 -0
  121. package/lib/icons/heroicons/outline.d.ts.map +1 -0
  122. package/lib/icons/heroicons/outline.js +337 -337
  123. package/lib/icons/heroicons/outline.js.map +1 -0
  124. package/lib/icons/heroicons/solid.d.ts.map +1 -0
  125. package/lib/icons/heroicons/solid.js +407 -407
  126. package/lib/icons/heroicons/solid.js.map +1 -0
  127. package/lib/icons/lucide.d.ts.map +1 -0
  128. package/lib/icons/lucide.js +22843 -22843
  129. package/lib/icons/lucide.js.map +1 -0
  130. package/lib/icons/material/filled.d.ts.map +1 -0
  131. package/lib/icons/material/filled.js +9653 -9653
  132. package/lib/icons/material/filled.js.map +1 -0
  133. package/lib/icons/material/outlined.d.ts.map +1 -0
  134. package/lib/icons/material/outlined.js +10271 -10271
  135. package/lib/icons/material/outlined.js.map +1 -0
  136. package/lib/icons/material/round.d.ts.map +1 -0
  137. package/lib/icons/material/round.js +10495 -10495
  138. package/lib/icons/material/round.js.map +1 -0
  139. package/lib/icons/material/sharp.d.ts.map +1 -0
  140. package/lib/icons/material/sharp.js +9905 -9905
  141. package/lib/icons/material/sharp.js.map +1 -0
  142. package/lib/icons/material/two-tone.d.ts.map +1 -0
  143. package/lib/icons/material/two-tone.js +12792 -12792
  144. package/lib/icons/material/two-tone.js.map +1 -0
  145. package/lib/index.d.ts +1 -1
  146. package/lib/index.d.ts.map +1 -0
  147. package/lib/index.js +21 -21
  148. package/lib/index.js.map +1 -0
  149. package/lib/styles/button.d.ts.map +1 -0
  150. package/lib/styles/button.js +200 -302
  151. package/lib/styles/button.js.map +1 -0
  152. package/lib/styles/calendar-month.d.ts +3 -0
  153. package/lib/styles/calendar-month.d.ts.map +1 -0
  154. package/lib/styles/calendar-month.js +141 -185
  155. package/lib/styles/calendar-month.js.map +1 -0
  156. package/lib/styles/calendar-navigation.d.ts +1 -1
  157. package/lib/styles/calendar-navigation.d.ts.map +1 -0
  158. package/lib/styles/calendar-navigation.js +100 -86
  159. package/lib/styles/calendar-navigation.js.map +1 -0
  160. package/lib/styles/calendar.d.ts +3 -2
  161. package/lib/styles/calendar.d.ts.map +1 -0
  162. package/lib/styles/calendar.js +83 -9
  163. package/lib/styles/calendar.js.map +1 -0
  164. package/lib/styles/checkbox.js +62 -77
  165. package/lib/styles/copy.d.ts.map +1 -0
  166. package/lib/styles/copy.js +71 -91
  167. package/lib/styles/copy.js.map +1 -0
  168. package/lib/styles/custom-scrollbar.js +80 -100
  169. package/lib/styles/date-picker.d.ts.map +1 -0
  170. package/lib/styles/date-picker.js +295 -335
  171. package/lib/styles/date-picker.js.map +1 -0
  172. package/lib/styles/dropdown.d.ts +12 -0
  173. package/lib/styles/dropdown.d.ts.map +1 -0
  174. package/lib/styles/dropdown.js +725 -0
  175. package/lib/styles/dropdown.js.map +1 -0
  176. package/lib/styles/field-size.d.ts +6 -0
  177. package/lib/styles/field-size.js +91 -0
  178. package/lib/styles/file-upload.js +139 -169
  179. package/lib/styles/icon.d.ts.map +1 -0
  180. package/lib/styles/icon.js +92 -156
  181. package/lib/styles/icon.js.map +1 -0
  182. package/lib/styles/input.d.ts.map +1 -0
  183. package/lib/styles/input.js +125 -241
  184. package/lib/styles/input.js.map +1 -0
  185. package/lib/styles/modal.d.ts.map +1 -0
  186. package/lib/styles/modal.js +67 -102
  187. package/lib/styles/modal.js.map +1 -0
  188. package/lib/styles/multiselect.d.ts +6 -0
  189. package/lib/styles/multiselect.d.ts.map +1 -0
  190. package/lib/styles/multiselect.js +568 -0
  191. package/lib/styles/multiselect.js.map +1 -0
  192. package/lib/styles/option.d.ts +1 -1
  193. package/lib/styles/option.d.ts.map +1 -0
  194. package/lib/styles/option.js +47 -67
  195. package/lib/styles/option.js.map +1 -0
  196. package/lib/styles/popup.d.ts +1 -1
  197. package/lib/styles/popup.d.ts.map +1 -0
  198. package/lib/styles/popup.js +37 -65
  199. package/lib/styles/popup.js.map +1 -0
  200. package/lib/styles/radio.js +75 -96
  201. package/lib/styles/resize-observer.d.ts.map +1 -0
  202. package/lib/styles/resize-observer.js +2 -5
  203. package/lib/styles/resize-observer.js.map +1 -0
  204. package/lib/styles/scroll-container.d.ts +1 -1
  205. package/lib/styles/scroll-container.d.ts.map +1 -0
  206. package/lib/styles/scroll-container.js +101 -131
  207. package/lib/styles/scroll-container.js.map +1 -0
  208. package/lib/styles/select-base.js +596 -773
  209. package/lib/styles/select.d.ts +1 -1
  210. package/lib/styles/select.js +146 -228
  211. package/lib/styles/step.d.ts +1 -1
  212. package/lib/styles/step.d.ts.map +1 -0
  213. package/lib/styles/step.js +15 -30
  214. package/lib/styles/step.js.map +1 -0
  215. package/lib/styles/switch.js +37 -55
  216. package/lib/styles/tab.d.ts +1 -1
  217. package/lib/styles/tab.d.ts.map +1 -0
  218. package/lib/styles/tab.js +86 -29
  219. package/lib/styles/tab.js.map +1 -0
  220. package/lib/styles/tabs.d.ts +1 -1
  221. package/lib/styles/tabs.d.ts.map +1 -0
  222. package/lib/styles/tabs.js +190 -180
  223. package/lib/styles/tabs.js.map +1 -0
  224. package/lib/styles/tag.d.ts.map +1 -0
  225. package/lib/styles/tag.js +137 -191
  226. package/lib/styles/tag.js.map +1 -0
  227. package/lib/styles/textarea.d.ts +1 -1
  228. package/lib/styles/textarea.d.ts.map +1 -0
  229. package/lib/styles/textarea.js +205 -271
  230. package/lib/styles/textarea.js.map +1 -0
  231. package/lib/styles/tooltip.d.ts.map +1 -0
  232. package/lib/styles/tooltip.js +3 -3
  233. package/lib/styles/tooltip.js.map +1 -0
  234. package/lib/styles/wizard.d.ts +9 -5
  235. package/lib/styles/wizard.d.ts.map +1 -0
  236. package/lib/styles/wizard.js +301 -245
  237. package/lib/styles/wizard.js.map +1 -0
  238. package/lib/types/common.d.ts +4 -2
  239. package/lib/types/common.d.ts.map +1 -0
  240. package/lib/types/common.js +6 -5
  241. package/lib/types/common.js.map +1 -0
  242. package/lib/utils/calendar-utils.d.ts.map +1 -0
  243. package/lib/utils/calendar-utils.js +100 -100
  244. package/lib/utils/calendar-utils.js.map +1 -0
  245. package/lib/utils/custom-scrollbar.js +272 -272
  246. package/lib/utils/flavor-sheet.js +14 -14
  247. package/lib/utils/icon-registry.d.ts.map +1 -0
  248. package/lib/utils/icon-registry.js +127 -127
  249. package/lib/utils/icon-registry.js.map +1 -0
  250. package/lib/utils/loader-registry.js +3 -3
  251. package/lib/utils/locale.d.ts.map +1 -0
  252. package/lib/utils/locale.js +34 -34
  253. package/lib/utils/locale.js.map +1 -0
  254. package/lib/utils/mobile.js +1 -1
  255. package/lib/utils/number-format.d.ts.map +1 -0
  256. package/lib/utils/number-format.js +54 -54
  257. package/lib/utils/number-format.js.map +1 -0
  258. package/lib/utils/parse-boolean.d.ts +39 -0
  259. package/lib/utils/parse-boolean.d.ts.map +1 -0
  260. package/lib/utils/parse-boolean.js +23 -0
  261. package/lib/utils/parse-boolean.js.map +1 -0
  262. package/lib/utils/positioning.d.ts.map +1 -0
  263. package/lib/utils/positioning.js +212 -212
  264. package/lib/utils/positioning.js.map +1 -0
  265. package/lib/utils/property-capture.d.ts.map +1 -0
  266. package/lib/utils/property-capture.js +36 -36
  267. package/lib/utils/property-capture.js.map +1 -0
  268. package/lib/utils/property-manager.d.ts +1 -1
  269. package/lib/utils/property-manager.d.ts.map +1 -0
  270. package/lib/utils/property-manager.js +127 -125
  271. package/lib/utils/property-manager.js.map +1 -0
  272. package/lib/utils/resize-observer.d.ts.map +1 -0
  273. package/lib/utils/resize-observer.js +23 -23
  274. package/lib/utils/resize-observer.js.map +1 -0
  275. package/lib/utils/scroll-lock.d.ts.map +1 -0
  276. package/lib/utils/scroll-lock.js +57 -57
  277. package/lib/utils/scroll-lock.js.map +1 -0
  278. package/lib/utils/styles.d.ts.map +1 -0
  279. package/lib/utils/styles.js +17 -17
  280. package/lib/utils/styles.js.map +1 -0
  281. package/lib/utils/validity.d.ts +26 -0
  282. package/lib/utils/validity.js +53 -0
  283. package/lib/version.d.ts +1 -1
  284. package/lib/version.d.ts.map +1 -0
  285. package/lib/version.js +1 -1
  286. package/lib/version.js.map +1 -0
  287. package/package.json +28 -7
@@ -6,1149 +6,1095 @@ import { computeAnchoredPosition, placementToAnchored } from '../utils/positioni
6
6
  import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
7
7
  import { isMobileTouch } from '../utils/mobile.js';
8
8
  import { TyComponent } from '../base/ty-component.js';
9
+ import { DEFAULT_SIZE } from '../types/common.js';
9
10
  const CALENDAR_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='16' height='16' xmlns='http://www.w3.org/2000/svg'><rect x='3' y='4' width='18' height='18' rx='2' ry='2'></rect><line x1='16' y1='2' x2='16' y2='6'></line><line x1='8' y1='2' x2='8' y2='6'></line><line x1='3' y1='10' x2='21' y2='10'></line></svg>`;
10
11
  const CLEAR_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='14' height='14' xmlns='http://www.w3.org/2000/svg'><line x1='18' y1='6' x2='6' y2='18'></line><line x1='6' y1='6' x2='18' y2='18'></line></svg>`;
11
12
  const SCHEDULE_ICON_SVG = `<svg stroke='currentColor' fill='none' stroke-width='2' viewBox='0 0 24 24' width='16' height='16' xmlns='http://www.w3.org/2000/svg'><circle cx='12' cy='12' r='10'></circle><polyline points='12,6 12,12 16,14'></polyline></svg>`;
12
13
  const elementIds = new WeakMap();
13
14
  let elementIdCounter = 0;
14
15
  function getElementHash(element) {
15
- let id = elementIds.get(element);
16
- if (id === undefined) {
17
- id = ++elementIdCounter;
18
- elementIds.set(element, id);
19
- }
20
- return id;
16
+ let id = elementIds.get(element);
17
+ if (id === undefined) {
18
+ id = ++elementIdCounter;
19
+ elementIds.set(element, id);
20
+ }
21
+ return id;
21
22
  }
22
23
  function parseValue(value, withTime) {
23
- if (!value)
24
- return null;
25
- let dateObj = null;
26
- if (typeof value === 'string') {
27
- if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
28
- const [yearStr, monthStr, dayStr] = value.split('-');
29
- const year = parseInt(yearStr, 10);
30
- const month = parseInt(monthStr, 10) - 1;
31
- const day = parseInt(dayStr, 10);
32
- dateObj = new Date(year, month, day, 0, 0, 0, 0);
33
- }
34
- else {
35
- dateObj = new Date(value);
36
- }
37
- }
38
- else if (typeof value === 'number') {
39
- dateObj = new Date(value);
40
- }
41
- if (!dateObj || isNaN(dateObj.getTime())) {
42
- return null;
43
- }
44
- const components = {
45
- year: dateObj.getFullYear(),
46
- month: dateObj.getMonth() + 1,
47
- day: dateObj.getDate(),
48
- hour: withTime ? dateObj.getHours() : 0,
49
- minute: withTime ? dateObj.getMinutes() : 0,
50
- };
51
- return components;
24
+ if (!value)
25
+ return null;
26
+ let dateObj = null;
27
+ if (typeof value === 'string') {
28
+ if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
29
+ const [yearStr, monthStr, dayStr] = value.split('-');
30
+ const year = parseInt(yearStr, 10);
31
+ const month = parseInt(monthStr, 10) - 1;
32
+ const day = parseInt(dayStr, 10);
33
+ dateObj = new Date(year, month, day, 0, 0, 0, 0);
34
+ }
35
+ else {
36
+ dateObj = new Date(value);
37
+ }
38
+ }
39
+ else if (typeof value === 'number') {
40
+ dateObj = new Date(value);
41
+ }
42
+ if (!dateObj || isNaN(dateObj.getTime())) {
43
+ return null;
44
+ }
45
+ const components = {
46
+ year: dateObj.getFullYear(),
47
+ month: dateObj.getMonth() + 1,
48
+ day: dateObj.getDate(),
49
+ hour: withTime ? dateObj.getHours() : 0,
50
+ minute: withTime ? dateObj.getMinutes() : 0,
51
+ };
52
+ return components;
52
53
  }
53
54
  function componentsToDateObject(components) {
54
- const { year, month, day, hour, minute } = components;
55
- if (!year || !month || !day)
56
- return null;
57
- return new Date(year, month - 1, day, hour || 0, minute || 0, 0, 0);
55
+ const { year, month, day, hour, minute } = components;
56
+ if (!year || !month || !day)
57
+ return null;
58
+ return new Date(year, month - 1, day, hour || 0, minute || 0, 0, 0);
58
59
  }
59
60
  function componentsToOutputValue(components) {
60
- if (!components.year || !components.month || !components.day) {
61
- return null;
62
- }
63
- const dateObj = componentsToDateObject(components);
64
- return dateObj ? dateObj.toISOString() : null;
61
+ if (!components.year || !components.month || !components.day) {
62
+ return null;
63
+ }
64
+ const dateObj = componentsToDateObject(components);
65
+ return dateObj ? dateObj.toISOString() : null;
65
66
  }
66
67
  function componentsToLocalValue(components, withTime) {
67
- if (!components.year || !components.month || !components.day) {
68
- return null;
69
- }
70
- const year = components.year.toString().padStart(4, '0');
71
- const month = components.month.toString().padStart(2, '0');
72
- const day = components.day.toString().padStart(2, '0');
73
- if (withTime) {
74
- const hour = (components.hour || 0).toString().padStart(2, '0');
75
- const minute = (components.minute || 0).toString().padStart(2, '0');
76
- return `${year}-${month}-${day}T${hour}:${minute}`;
77
- }
78
- else {
79
- return `${year}-${month}-${day}`;
80
- }
68
+ if (!components.year || !components.month || !components.day) {
69
+ return null;
70
+ }
71
+ const year = components.year.toString().padStart(4, '0');
72
+ const month = components.month.toString().padStart(2, '0');
73
+ const day = components.day.toString().padStart(2, '0');
74
+ if (withTime) {
75
+ const hour = (components.hour || 0).toString().padStart(2, '0');
76
+ const minute = (components.minute || 0).toString().padStart(2, '0');
77
+ return `${year}-${month}-${day}T${hour}:${minute}`;
78
+ }
79
+ else {
80
+ return `${year}-${month}-${day}`;
81
+ }
81
82
  }
82
83
  function formatDisplayValue(components, formatType, locale, withTime) {
83
- if (!components.year || !components.month || !components.day) {
84
- return null;
85
- }
86
- const dateObj = componentsToDateObject(components);
87
- if (!dateObj)
88
- return null;
89
- const options = {
90
- dateStyle: formatType || 'long',
91
- };
92
- if (withTime) {
93
- options.timeStyle = 'short';
94
- }
95
- const formatter = new Intl.DateTimeFormat(locale, options);
96
- return formatter.format(dateObj);
97
- }
98
- function parseTimeComponents(rawDigits) {
99
- if (!rawDigits || rawDigits.length !== 4)
100
- return null;
101
- const hourStr = rawDigits.substring(0, 2);
102
- const minuteStr = rawDigits.substring(2, 4);
103
- const hour = parseInt(hourStr, 10);
104
- const minute = parseInt(minuteStr, 10);
105
- if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
106
- return null;
107
- }
108
- return { hour, minute };
109
- }
110
- function validateTimeDigit(digit, position, currentDigits) {
111
- switch (position) {
112
- case 0:
113
- return digit <= 2;
114
- case 1: {
115
- const firstHour = parseInt(currentDigits[0], 10);
116
- return firstHour === 2 ? digit <= 3 : true;
117
- }
118
- case 3:
119
- return digit <= 5;
120
- case 4:
121
- return true;
122
- default:
123
- return false;
124
- }
125
- }
126
- function formatTimeDisplay(hour, minute) {
127
- const hourStr = hour.toString().padStart(2, '0');
128
- const minuteStr = minute.toString().padStart(2, '0');
129
- return `${hourStr}:${minuteStr}`;
130
- }
131
- function findNextEditablePosition(currentPos) {
132
- switch (currentPos) {
133
- case 0: return 1;
134
- case 1: return 3;
135
- case 3: return 4;
136
- case 4: return 5;
137
- case 5: return 5;
138
- default: return currentPos;
139
- }
140
- }
141
- function findPrevEditablePosition(currentPos) {
142
- switch (currentPos) {
143
- case 5: return 4;
144
- case 4: return 3;
145
- case 3: return 1;
146
- case 1: return 0;
147
- case 0: return 0;
148
- default: return currentPos;
149
- }
150
- }
151
- function positionToRawDigitIndex(internalPos) {
152
- switch (internalPos) {
153
- case 0: return 0;
154
- case 1: return 1;
155
- case 3: return 2;
156
- case 4: return 3;
157
- default: return 0;
158
- }
159
- }
160
- class TimeInput {
161
- constructor(element, datePickerElement, hour = 0, minute = 0) {
162
- this.element = element;
163
- this.datePickerElement = datePickerElement;
164
- const display = formatTimeDisplay(hour, minute);
165
- const rawDigits = hour.toString().padStart(2, '0') + minute.toString().padStart(2, '0');
166
- this.state = {
167
- hour,
168
- minute,
169
- caretPosition: 0,
170
- displayValue: display,
171
- rawDigits,
172
- };
173
- this.element.value = display;
174
- this.setupEventListeners();
175
- }
176
- setupEventListeners() {
177
- this.element.addEventListener('keydown', (e) => this.handleKeyDown(e));
178
- this.element.addEventListener('input', (e) => this.handleInput(e));
179
- this.element.addEventListener('click', () => this.handleClick());
180
- this.element.addEventListener('focus', () => this.handleFocus());
181
- }
182
- handleKeyDown(event) {
183
- const key = event.key;
184
- switch (key) {
185
- case 'ArrowRight':
186
- this.handleArrowRight(event);
187
- break;
188
- case 'ArrowLeft':
189
- this.handleArrowLeft(event);
190
- break;
191
- case 'Backspace':
192
- this.handleBackspace(event);
193
- break;
194
- case 'Delete':
195
- this.handleDelete(event);
196
- break;
197
- case 'Home':
198
- event.preventDefault();
199
- this.updateState({ caretPosition: 0 });
200
- break;
201
- case 'End':
202
- event.preventDefault();
203
- this.updateState({ caretPosition: 5 });
204
- break;
205
- case 'Tab':
206
- break;
207
- default:
208
- if (/^\d$/.test(key)) {
209
- this.handleDigitInput(event, parseInt(key, 10));
210
- }
211
- break;
212
- }
213
- }
214
- handleInput(event) {
215
- event.preventDefault();
216
- }
217
- handleClick() {
218
- this.updateState({ caretPosition: 0 });
219
- }
220
- handleFocus() {
221
- this.updateState({ caretPosition: 0 });
222
- }
223
- handleArrowRight(event) {
224
- event.preventDefault();
225
- const nextPos = findNextEditablePosition(this.state.caretPosition);
226
- this.updateState({ caretPosition: nextPos });
227
- }
228
- handleArrowLeft(event) {
229
- event.preventDefault();
230
- const prevPos = findPrevEditablePosition(this.state.caretPosition);
231
- this.updateState({ caretPosition: prevPos });
232
- }
233
- handleDigitInput(event, digit) {
234
- event.preventDefault();
235
- const currentPos = this.state.caretPosition;
236
- if (![0, 1, 3, 4].includes(currentPos))
237
- return;
238
- if (!validateTimeDigit(digit, currentPos, this.state.rawDigits))
239
- return;
240
- const newState = this.replaceDigitAtPosition(currentPos, digit);
241
- if (!newState)
242
- return;
243
- const nextPos = findNextEditablePosition(currentPos);
244
- this.updateState({ ...newState, caretPosition: nextPos });
245
- this.notifyTimeChange();
246
- }
247
- handleBackspace(event) {
248
- event.preventDefault();
249
- const currentPos = this.state.caretPosition;
250
- if (currentPos === 0)
251
- return;
252
- const targetPos = currentPos === 1 ? 0 :
253
- currentPos === 3 ? 1 :
254
- currentPos === 4 ? 3 :
255
- currentPos === 5 ? 4 : 0;
256
- const newState = this.zeroDigitAtPosition(targetPos);
257
- if (!newState)
258
- return;
259
- this.updateState({ ...newState, caretPosition: targetPos });
260
- this.notifyTimeChange();
261
- }
262
- handleDelete(event) {
263
- event.preventDefault();
264
- const currentPos = this.state.caretPosition;
265
- if (![0, 1, 3, 4].includes(currentPos))
266
- return;
267
- const newState = this.zeroDigitAtPosition(currentPos);
268
- if (!newState)
269
- return;
270
- this.updateState({ ...newState, caretPosition: currentPos });
271
- this.notifyTimeChange();
272
- }
273
- replaceDigitAtPosition(position, newDigit) {
274
- const rawIndex = positionToRawDigitIndex(position);
275
- const digitsArray = this.state.rawDigits.split('');
276
- digitsArray[rawIndex] = newDigit.toString();
277
- const newDigits = digitsArray.join('');
278
- const parsed = parseTimeComponents(newDigits);
279
- if (!parsed)
280
- return null;
281
- return {
282
- rawDigits: newDigits,
283
- hour: parsed.hour,
284
- minute: parsed.minute,
285
- displayValue: formatTimeDisplay(parsed.hour, parsed.minute),
286
- };
287
- }
288
- zeroDigitAtPosition(position) {
289
- return this.replaceDigitAtPosition(position, 0);
290
- }
291
- updateState(updates) {
292
- this.state = { ...this.state, ...updates };
293
- this.element.value = this.state.displayValue;
294
- const caretPos = this.state.caretPosition;
295
- const actualPos = caretPos === 0 ? 0 :
296
- caretPos === 1 ? 1 :
297
- caretPos === 2 ? 3 :
298
- caretPos === 3 ? 3 :
299
- caretPos === 4 ? 4 :
300
- caretPos === 5 ? 5 : caretPos;
301
- this.element.setSelectionRange(actualPos, actualPos);
302
- }
303
- notifyTimeChange() {
304
- this.datePickerElement.handleTimeInputChange(this.state.hour, this.state.minute);
305
- }
306
- getTime() {
307
- return {
308
- hour: this.state.hour,
309
- minute: this.state.minute,
310
- };
311
- }
312
- setTime(hour, minute) {
313
- const display = formatTimeDisplay(hour, minute);
314
- const rawDigits = hour.toString().padStart(2, '0') + minute.toString().padStart(2, '0');
315
- this.state = {
316
- ...this.state,
317
- hour,
318
- minute,
319
- displayValue: display,
320
- rawDigits,
321
- };
322
- this.element.value = display;
323
- }
84
+ if (!components.year || !components.month || !components.day) {
85
+ return null;
86
+ }
87
+ const dateObj = componentsToDateObject(components);
88
+ if (!dateObj)
89
+ return null;
90
+ const options = {
91
+ dateStyle: formatType || 'long',
92
+ };
93
+ if (withTime) {
94
+ options.timeStyle = 'short';
95
+ }
96
+ const formatter = new Intl.DateTimeFormat(locale, options);
97
+ return formatter.format(dateObj);
98
+ }
99
+ class TimeFields {
100
+ constructor(hourEl, minuteEl, onChange, hour = 0, minute = 0) {
101
+ this.hourEl = hourEl;
102
+ this.minuteEl = minuteEl;
103
+ this.onChange = onChange;
104
+ this.typed = '';
105
+ this.hour = hour;
106
+ this.minute = minute;
107
+ this.paint();
108
+ this.wire(hourEl, 'hour');
109
+ this.wire(minuteEl, 'minute');
110
+ }
111
+ static pad(n) {
112
+ return n.toString().padStart(2, '0');
113
+ }
114
+ paint() {
115
+ this.hourEl.value = TimeFields.pad(this.hour);
116
+ this.minuteEl.value = TimeFields.pad(this.minute);
117
+ }
118
+ wire(el, part) {
119
+ const max = part === 'hour' ? 23 : 59;
120
+ const maxLead = part === 'hour' ? 2 : 5;
121
+ el.addEventListener('focus', () => {
122
+ this.typed = '';
123
+ el.select();
124
+ });
125
+ el.addEventListener('click', () => el.select());
126
+ el.addEventListener('blur', () => { this.typed = ''; });
127
+ el.addEventListener('input', () => this.paint());
128
+ el.addEventListener('keydown', (e) => {
129
+ const set = (v) => {
130
+ if (part === 'hour')
131
+ this.hour = v;
132
+ else
133
+ this.minute = v;
134
+ this.paint();
135
+ this.onChange(this.hour, this.minute);
136
+ };
137
+ const current = part === 'hour' ? this.hour : this.minute;
138
+ if (/^\d$/.test(e.key)) {
139
+ e.preventDefault();
140
+ const digit = Number(e.key);
141
+ const next = this.typed + e.key;
142
+ const complete = next.length === 2 || (next.length === 1 && digit > maxLead);
143
+ set(Math.min(Number(next), max));
144
+ if (complete) {
145
+ this.typed = '';
146
+ if (part === 'hour')
147
+ this.minuteEl.focus();
148
+ else
149
+ el.select();
150
+ }
151
+ else {
152
+ this.typed = next;
153
+ }
154
+ return;
155
+ }
156
+ switch (e.key) {
157
+ case 'ArrowUp':
158
+ case 'ArrowDown': {
159
+ e.preventDefault();
160
+ const delta = e.key === 'ArrowUp' ? 1 : -1;
161
+ this.typed = '';
162
+ set((current + delta + max + 1) % (max + 1));
163
+ el.select();
164
+ return;
165
+ }
166
+ case 'Backspace':
167
+ case 'Delete':
168
+ e.preventDefault();
169
+ if (part === 'minute' && this.typed === '' && e.key === 'Backspace' && current === 0) {
170
+ this.hourEl.focus();
171
+ return;
172
+ }
173
+ this.typed = '';
174
+ set(0);
175
+ el.select();
176
+ return;
177
+ case 'ArrowLeft':
178
+ if (part === 'minute') {
179
+ e.preventDefault();
180
+ this.hourEl.focus();
181
+ }
182
+ return;
183
+ case 'ArrowRight':
184
+ if (part === 'hour') {
185
+ e.preventDefault();
186
+ this.minuteEl.focus();
187
+ }
188
+ return;
189
+ case 'Tab':
190
+ case 'Escape':
191
+ case 'Enter':
192
+ return;
193
+ default:
194
+ if (e.key.length === 1 && !e.metaKey && !e.ctrlKey)
195
+ e.preventDefault();
196
+ }
197
+ });
198
+ }
199
+ getTime() {
200
+ return { hour: this.hour, minute: this.minute };
201
+ }
202
+ setTime(hour, minute) {
203
+ this.hour = hour;
204
+ this.minute = minute;
205
+ this.paint();
206
+ }
324
207
  }
325
208
  export class TyDatePicker extends TyComponent {
326
- constructor() {
327
- super();
328
- this._state = {
329
- withTime: false,
330
- open: false,
331
- };
332
- this._closeTimestamp = 0;
333
- this._customFlavorSheet = null;
334
- const shadow = this.shadowRoot;
335
- ensureStyles(shadow, { css: datePickerStyles, id: 'ty-date-picker' });
336
- }
337
- onConnect() {
338
- this.initializeState();
339
- this.render();
340
- this._localeObserver = observeLocaleChanges(this, () => {
341
- this.render();
342
- });
343
- this._syncCustomFlavor();
344
- }
345
- _syncCustomFlavor() {
346
- const flavor = this.flavor === 'default' ? 'neutral' : this.flavor;
347
- this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, flavor, ({ base }) => datePickerCustomFlavorCss(base));
348
- }
349
- onDisconnect() {
350
- if (this._localeObserver) {
351
- this._localeObserver();
352
- this._localeObserver = undefined;
353
- }
354
- this.cleanup();
355
- }
356
- onPropertiesChanged(changes) {
357
- for (const { name, newValue } of changes) {
358
- switch (name) {
359
- case 'flavor':
360
- this._syncCustomFlavor();
361
- break;
362
- case 'size':
363
- case 'label':
364
- case 'placeholder':
365
- case 'required':
366
- case 'disabled':
367
- case 'clearable':
368
- case 'format':
369
- case 'locale':
370
- break;
371
- case 'value': {
372
- const newComponents = parseValue(newValue, this._state.withTime);
373
- if (newComponents === null) {
374
- const hasDate = this._state.year !== undefined ||
375
- this._state.month !== undefined ||
376
- this._state.day !== undefined;
377
- if (hasDate) {
378
- this._state = {
379
- withTime: this._state.withTime,
380
- open: this._state.open,
381
- };
382
- }
383
- break;
384
- }
385
- const currentComponents = {
386
- year: this._state.year,
387
- month: this._state.month,
388
- day: this._state.day,
389
- hour: this._state.hour,
390
- minute: this._state.minute,
391
- };
392
- const changed = newComponents?.year !== currentComponents.year ||
393
- newComponents?.month !== currentComponents.month ||
394
- newComponents?.day !== currentComponents.day ||
395
- newComponents?.hour !== currentComponents.hour ||
396
- newComponents?.minute !== currentComponents.minute;
397
- if (changed) {
398
- this._state = {
399
- ...this._state,
400
- ...newComponents,
401
- };
402
- }
403
- break;
404
- }
405
- case 'with-time': {
406
- const newWithTime = newValue;
407
- const oldWithTime = this._state.withTime;
408
- if (newWithTime !== oldWithTime) {
409
- this._state.withTime = newWithTime;
410
- const hasDate = this._state.year !== undefined &&
411
- this._state.month !== undefined &&
412
- this._state.day !== undefined;
413
- if (hasDate) {
414
- this.syncFormValue();
415
- }
416
- }
417
- break;
418
- }
419
- }
420
- }
421
- }
422
- getFormValue() {
423
- return componentsToOutputValue(this.getComponents());
424
- }
425
- getComponents() {
426
- return {
427
- year: this._state.year,
428
- month: this._state.month,
429
- day: this._state.day,
430
- hour: this._state.hour,
431
- minute: this._state.minute,
432
- };
433
- }
434
- hasDate() {
435
- return !!(this._state.year && this._state.month && this._state.day);
436
- }
437
- getFormattedValue(components) {
438
- const c = components || this.getComponents();
439
- if (!c.year || !c.month || !c.day)
440
- return null;
441
- return formatDisplayValue(c, this.getProperty('format') || 'long', getEffectiveLocale(this, this.getProperty('locale')), this._state.withTime);
442
- }
443
- initializeState() {
444
- const valueAttr = this.getProperty('value');
445
- const withTime = this.getProperty('with-time');
446
- const components = parseValue(valueAttr, withTime);
447
- if (components === null) {
448
- this._state = {
449
- withTime,
450
- open: false,
451
- };
452
- }
453
- else {
454
- this._state = {
455
- ...components,
456
- withTime,
457
- open: false,
458
- };
459
- }
460
- this.syncFormValue();
461
- }
462
- updateState(updates, forceSync = false) {
463
- this._state = { ...this._state, ...updates };
464
- const shouldSync = forceSync || !this._state.open || !this._state.withTime;
465
- if (shouldSync) {
466
- this.syncFormValue();
467
- }
468
- }
469
- syncFormValue() {
470
- const utcValue = this.getFormValue();
471
- const currentValue = this.getProperty('value');
472
- if (utcValue !== currentValue) {
473
- if (utcValue) {
474
- this.setProperty('value', utcValue);
475
- }
476
- else {
477
- this.setProperty('value', null);
478
- }
479
- }
480
- }
481
- handleTimeInputChange(hour, minute) {
482
- if (!this.hasDate())
483
- return;
484
- const components = { ...this.getComponents(), hour, minute };
485
- this.updateState(components, true);
486
- this.emitChangeEvent(components, 'time-change');
487
- }
488
- emitChangeEvent(components, source) {
489
- const utcValue = components ? componentsToOutputValue(components) : null;
490
- const localValue = components ? componentsToLocalValue(components, this._state.withTime) : null;
491
- const milliseconds = components ? componentsToDateObject(components)?.getTime() ?? null : null;
492
- const formatted = components ? this.getFormattedValue(components) : null;
493
- const detail = {
494
- value: utcValue,
495
- localValue,
496
- milliseconds,
497
- formatted,
498
- source,
499
- };
500
- const event = new CustomEvent('change', {
501
- detail,
502
- bubbles: true,
503
- cancelable: true,
504
- });
505
- this.dispatchEvent(event);
506
- }
507
- get size() { return this.getProperty('size'); }
508
- set size(v) { this.setProperty('size', v); }
509
- get placement() { return this.getProperty('placement'); }
510
- set placement(v) { this.setProperty('placement', v); }
511
- get flavor() { return this.getProperty('flavor'); }
512
- set flavor(v) { this.setProperty('flavor', v); }
513
- get label() { return this.getProperty('label'); }
514
- set label(v) { this.setProperty('label', v); }
515
- get placeholder() { return this.getProperty('placeholder'); }
516
- set placeholder(v) { this.setProperty('placeholder', v); }
517
- get name() { return this.getProperty('name'); }
518
- set name(v) { this.setProperty('name', v); }
519
- get format() { return this.getProperty('format'); }
520
- set format(v) { this.setProperty('format', v); }
521
- get locale() { return this.getProperty('locale'); }
522
- set locale(v) { this.setProperty('locale', v); }
523
- get required() { return this.getProperty('required'); }
524
- set required(v) { this.setProperty('required', v); }
525
- get disabled() { return this.getProperty('disabled'); }
526
- set disabled(v) { this.setProperty('disabled', v); }
527
- get clearable() { return this.getProperty('clearable'); }
528
- set clearable(v) { this.setProperty('clearable', v); }
529
- get min() { return this.getProperty('min'); }
530
- set min(v) { this.setProperty('min', v ?? ''); }
531
- get max() { return this.getProperty('max'); }
532
- set max(v) { this.setProperty('max', v ?? ''); }
533
- get withTime() { return this.getProperty('with-time'); }
534
- set withTime(v) { this.setProperty('with-time', v); }
535
- get value() {
536
- return this.getProperty('value') || null;
537
- }
538
- set value(val) {
539
- if (val === null || val === undefined || val === '') {
540
- this.setProperty('value', null);
541
- }
542
- else {
543
- const strValue = val instanceof Date ? val.toISOString() : val;
544
- this.setProperty('value', strValue);
545
- }
546
- }
547
- clear() {
548
- this.clearValue();
549
- }
550
- buildStubClasses() {
551
- const classes = ['date-picker-stub'];
552
- const size = this.getProperty('size') || 'md';
553
- classes.push(size);
554
- if (this.getProperty('disabled'))
555
- classes.push('disabled');
556
- if (this.getProperty('required'))
557
- classes.push('required');
558
- if (this._state.open)
559
- classes.push('open');
560
- return classes.join(' ');
561
- }
562
- renderStub() {
563
- const stub = document.createElement('div');
564
- stub.className = this.buildStubClasses();
565
- const isDisabled = this.getProperty('disabled');
566
- if (isDisabled) {
567
- stub.setAttribute('disabled', 'true');
568
- }
569
- stub.setAttribute('role', 'button');
570
- stub.setAttribute('aria-haspopup', 'dialog');
571
- stub.setAttribute('aria-expanded', String(this._state.open));
572
- stub.setAttribute('tabindex', isDisabled ? '-1' : '0');
573
- if (isDisabled)
574
- stub.setAttribute('aria-disabled', 'true');
575
- if (this.getProperty('label')) {
576
- stub.setAttribute('aria-labelledby', `date-picker-label-${getElementHash(this)}`);
577
- }
578
- stub.addEventListener('keydown', (e) => {
579
- const ke = e;
580
- if (this._state.open)
581
- return;
582
- if (ke.key === 'Enter' || ke.key === ' ') {
583
- ke.preventDefault();
584
- this.handleStubClick(e);
585
- }
586
- });
587
- const startSlot = document.createElement('slot');
588
- startSlot.name = 'start';
589
- const displayText = document.createElement('span');
590
- displayText.className = 'stub-text';
591
- const formattedValue = this.getFormattedValue();
592
- const placeholder = this.getProperty('placeholder') || 'Select date...';
593
- displayText.textContent = formattedValue || placeholder;
594
- if (!formattedValue) {
595
- displayText.classList.add('placeholder');
596
- }
597
- const iconContainer = document.createElement('div');
598
- iconContainer.className = 'stub-icons';
599
- const clearable = this.getProperty('clearable');
600
- if (clearable && formattedValue && !isDisabled) {
601
- const clearButton = document.createElement('button');
602
- clearButton.className = 'stub-clear';
603
- clearButton.type = 'button';
604
- clearButton.innerHTML = CLEAR_ICON_SVG;
605
- clearButton.addEventListener('click', (e) => this.handleClearClick(e));
606
- iconContainer.appendChild(clearButton);
607
- }
608
- const calendarIcon = document.createElement('span');
609
- calendarIcon.className = 'stub-arrow';
610
- calendarIcon.innerHTML = CALENDAR_ICON_SVG;
611
- iconContainer.appendChild(calendarIcon);
612
- stub.addEventListener('click', (e) => this.handleStubClick(e));
613
- stub.appendChild(startSlot);
614
- stub.appendChild(displayText);
615
- stub.appendChild(iconContainer);
616
- return stub;
617
- }
618
- createTimeInputElement() {
619
- const input = document.createElement('input');
620
- input.type = 'text';
621
- input.className = 'time-input';
622
- input.placeholder = 'HH:mm';
623
- input.autocomplete = 'off';
624
- input.maxLength = 5;
625
- return input;
626
- }
627
- renderTimeSection() {
628
- const timeSection = document.createElement('div');
629
- timeSection.className = 'time-section';
630
- const timeLabel = document.createElement('label');
631
- timeLabel.className = 'time-label';
632
- timeLabel.textContent = 'Time:';
633
- const timeInputElement = this.createTimeInputElement();
634
- const hour = this._state.hour || 0;
635
- const minute = this._state.minute || 0;
636
- this._timeInput = new TimeInput(timeInputElement, this, hour, minute);
637
- const timeIcon = document.createElement('span');
638
- timeIcon.className = 'time-icon';
639
- timeIcon.innerHTML = SCHEDULE_ICON_SVG;
640
- timeSection.appendChild(timeLabel);
641
- timeSection.appendChild(timeInputElement);
642
- timeSection.appendChild(timeIcon);
643
- return timeSection;
644
- }
645
- renderCalendarDropdown() {
646
- const dialog = document.createElement('dialog');
647
- dialog.className = 'calendar-dialog';
648
- const contentWrapper = document.createElement('div');
649
- contentWrapper.className = 'calendar-content';
650
- const calendar = document.createElement('ty-calendar');
651
- if (this._state.year && this._state.month && this._state.day) {
652
- calendar.setAttribute('year', this._state.year.toString());
653
- calendar.setAttribute('month', this._state.month.toString());
654
- calendar.setAttribute('day', this._state.day.toString());
655
- }
656
- const locale = getEffectiveLocale(this, this.getProperty('locale'));
657
- if (locale) {
658
- calendar.setAttribute('locale', locale);
659
- }
660
- const min = this.getProperty('min');
661
- const max = this.getProperty('max');
662
- if (min)
663
- calendar.setAttribute('min', min);
664
- if (max)
665
- calendar.setAttribute('max', max);
666
- const flavor = this.getProperty('flavor');
667
- if (flavor && flavor !== 'default')
668
- calendar.setAttribute('flavor', flavor);
669
- calendar.addEventListener('change', (e) => this.handleCalendarChange(e));
670
- contentWrapper.appendChild(calendar);
671
- if (this._state.withTime) {
672
- contentWrapper.appendChild(this.renderTimeSection());
673
- }
674
- dialog.appendChild(contentWrapper);
675
- dialog.addEventListener('close', () => {
676
- this.updateState({ open: false });
677
- });
678
- return dialog;
679
- }
680
- renderNativeInput() {
681
- const wrapper = document.createElement('div');
682
- wrapper.className = 'dropdown-wrapper';
683
- const stub = document.createElement('div');
684
- stub.className = this.buildStubClasses();
685
- const isDisabled = this.getProperty('disabled');
686
- if (isDisabled) {
687
- stub.setAttribute('disabled', 'true');
688
- }
689
- const input = document.createElement('input');
690
- input.className = 'native-date-input';
691
- input.type = this._state.withTime ? 'datetime-local' : 'date';
692
- if (isDisabled)
693
- input.disabled = true;
694
- if (this.getProperty('required'))
695
- input.required = true;
696
- const minBound = this.getProperty('min');
697
- const maxBound = this.getProperty('max');
698
- if (minBound)
699
- input.min = this._state.withTime ? `${minBound}T00:00` : minBound;
700
- if (maxBound)
701
- input.max = this._state.withTime ? `${maxBound}T23:59` : maxBound;
702
- const localValue = componentsToLocalValue(this.getComponents(), this._state.withTime);
703
- if (localValue) {
704
- input.value = localValue;
705
- }
706
- const placeholder = this.getProperty('placeholder') || 'Select date...';
707
- const formattedValue = this.getFormattedValue();
708
- const placeholderEl = document.createElement('span');
709
- placeholderEl.className = 'stub-text' + (formattedValue ? '' : ' placeholder');
710
- placeholderEl.textContent = formattedValue || placeholder;
711
- input.addEventListener('change', () => {
712
- if (!input.value) {
713
- this.clearValue();
714
- return;
715
- }
716
- const parsed = parseValue(input.value, this._state.withTime);
717
- if (parsed) {
718
- this.updateState(parsed, true);
719
- this.emitChangeEvent(parsed, 'selection');
720
- }
721
- });
722
- const startSlot = document.createElement('slot');
723
- startSlot.name = 'start';
724
- stub.appendChild(startSlot);
725
- stub.appendChild(input);
726
- stub.appendChild(placeholderEl);
727
- const iconContainer = document.createElement('div');
728
- iconContainer.className = 'stub-icons';
729
- const clearable = this.getProperty('clearable');
730
- if (clearable && localValue && !isDisabled) {
731
- const clearButton = document.createElement('button');
732
- clearButton.className = 'stub-clear';
733
- clearButton.type = 'button';
734
- clearButton.innerHTML = CLEAR_ICON_SVG;
735
- clearButton.addEventListener('click', (e) => this.handleClearClick(e));
736
- iconContainer.appendChild(clearButton);
737
- }
738
- const calendarIcon = document.createElement('span');
739
- calendarIcon.className = 'stub-arrow';
740
- calendarIcon.innerHTML = CALENDAR_ICON_SVG;
741
- iconContainer.appendChild(calendarIcon);
742
- stub.appendChild(iconContainer);
743
- wrapper.appendChild(stub);
744
- return wrapper;
745
- }
746
- calculateCalendarPosition() {
747
- if (!this.shadowRoot)
748
- return;
749
- if (isMobileTouch())
750
- return;
751
- const stub = this.shadowRoot.querySelector('.date-picker-stub');
752
- const dialog = this.shadowRoot.querySelector('.calendar-dialog');
753
- if (!stub || !dialog)
754
- return;
755
- const stubRect = stub.getBoundingClientRect();
756
- const dialogRect = dialog.getBoundingClientRect();
757
- const estimatedHeight = dialogRect.height || 400;
758
- const popupWidth = dialogRect.width || 320;
759
- const wrapPadding = 8;
760
- const anchored = placementToAnchored(this.getProperty('placement'));
761
- const pos = computeAnchoredPosition({
762
- anchorRect: stubRect,
763
- popupWidth,
764
- popupHeight: estimatedHeight,
765
- gap: 0,
766
- align: anchored.align,
767
- side: anchored.side,
768
- });
769
- const positionBelow = pos.below;
770
- const x = pos.x - wrapPadding;
771
- const y = positionBelow ? pos.topY : pos.bottomY;
772
- this.style.setProperty('--calendar-x', `${x}px`);
773
- this.style.setProperty('--calendar-y', `${y}px`);
774
- this.style.setProperty('--calendar-offset-x', '0px');
775
- this.style.setProperty('--calendar-offset-y', '0px');
776
- if (positionBelow) {
777
- dialog.classList.add('position-below');
778
- dialog.classList.remove('position-above');
779
- }
780
- else {
781
- dialog.classList.add('position-above');
782
- dialog.classList.remove('position-below');
783
- }
784
- }
785
- renderContainer() {
786
- const container = document.createElement('div');
787
- container.className = 'dropdown-container';
788
- const label = this.getProperty('label');
789
- if (label) {
790
- const labelEl = document.createElement('label');
791
- labelEl.className = 'ty-field-label';
792
- labelEl.id = `date-picker-label-${getElementHash(this)}`;
793
- labelEl.innerHTML = label + (this.getProperty('required') ? '<span class="required-icon">*</span>' : '');
794
- container.appendChild(labelEl);
795
- }
796
- return container;
797
- }
798
- render() {
799
- if (!this.shadowRoot)
800
- return;
801
- ensureStyles(this.shadowRoot, { css: datePickerStyles, id: 'ty-date-picker' });
802
- if (isMobileTouch()) {
803
- const existingNativeInput = this.shadowRoot.querySelector('.native-date-input');
804
- if (existingNativeInput) {
805
- this.updateDisplay();
806
- return;
807
- }
808
- this.shadowRoot.innerHTML = '';
809
- const container = this.renderContainer();
810
- container.appendChild(this.renderNativeInput());
811
- this.shadowRoot.appendChild(container);
812
- return;
813
- }
814
- const existingDialog = this.shadowRoot.querySelector('.calendar-dialog');
815
- const isDialogOpen = existingDialog && existingDialog.open;
816
- if (isDialogOpen && this._state.open) {
817
- this.updateDisplay();
818
- this.calculateCalendarPosition();
819
- return;
820
- }
821
- this.shadowRoot.innerHTML = '';
822
- const container = this.renderContainer();
823
- const wrapper = document.createElement('div');
824
- wrapper.className = 'dropdown-wrapper';
825
- wrapper.appendChild(this.renderStub());
826
- wrapper.appendChild(this.renderCalendarDropdown());
827
- container.appendChild(wrapper);
828
- this.shadowRoot.appendChild(container);
829
- this.setupEventListeners();
830
- }
831
- updateDisplay() {
832
- if (!this.shadowRoot)
833
- return;
834
- const formattedValue = this.getFormattedValue();
835
- const placeholder = this.getProperty('placeholder') || 'Select date...';
836
- const hasValue = this.hasDate();
837
- const clearable = this.getProperty('clearable');
838
- const isDisabled = this.getProperty('disabled');
839
- const stubText = this.shadowRoot.querySelector('.stub-text');
840
- if (stubText) {
841
- stubText.textContent = formattedValue || placeholder;
842
- stubText.classList.toggle('placeholder', !formattedValue);
843
- }
844
- const clearButton = this.shadowRoot.querySelector('.stub-clear');
845
- if (clearButton) {
846
- clearButton.style.display = (clearable && hasValue && !isDisabled) ? '' : 'none';
847
- }
848
- if (isMobileTouch()) {
849
- const nativeInput = this.shadowRoot.querySelector('.native-date-input');
850
- if (nativeInput) {
851
- const localValue = componentsToLocalValue(this.getComponents(), this._state.withTime);
852
- nativeInput.value = localValue || '';
853
- }
854
- return;
855
- }
856
- const calendar = this.shadowRoot.querySelector('ty-calendar');
857
- if (calendar && hasValue) {
858
- calendar.setAttribute('year', this._state.year.toString());
859
- calendar.setAttribute('month', this._state.month.toString());
860
- calendar.setAttribute('day', this._state.day.toString());
861
- }
862
- if (calendar) {
863
- const flavor = this.getProperty('flavor');
864
- if (flavor && flavor !== 'default')
865
- calendar.setAttribute('flavor', flavor);
866
- else
867
- calendar.removeAttribute('flavor');
868
- }
869
- if (this._timeInput && this._state.hour !== undefined && this._state.minute !== undefined) {
870
- this._timeInput.setTime(this._state.hour, this._state.minute);
871
- }
872
- }
873
- setupEventListeners() {
874
- if (this._clickListener) {
875
- document.removeEventListener('click', this._clickListener);
876
- }
877
- if (this._keydownListener) {
878
- document.removeEventListener('keydown', this._keydownListener);
879
- }
880
- this._clickListener = (e) => this.handleOutsideClick(e);
881
- this._keydownListener = (e) => this.handleEscapeKey(e);
882
- document.addEventListener('click', this._clickListener);
883
- document.addEventListener('keydown', this._keydownListener);
884
- const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
885
- if (dialog) {
886
- this._dialogClickListener = (e) => this.handleDialogClick(e);
887
- dialog.addEventListener('click', this._dialogClickListener);
888
- }
889
- }
890
- handleStubClick(event) {
891
- event.preventDefault();
892
- const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
893
- if (this._state.open && (!dialog || !dialog.open)) {
894
- this.updateState({ open: false }, true);
895
- unlockScroll(`date-picker-${this.id || this.toString()}`);
896
- }
897
- const disabled = this.getProperty('disabled');
898
- if (!disabled && Date.now() - this._closeTimestamp > 300) {
899
- this.openDropdown();
900
- }
901
- }
902
- clearValue() {
903
- this.updateState({
904
- year: undefined,
905
- month: undefined,
906
- day: undefined,
907
- hour: undefined,
908
- minute: undefined,
909
- }, true);
910
- this.value = null;
911
- this.emitChangeEvent(null, 'clear');
912
- this.render();
913
- }
914
- handleClearClick(event) {
915
- event.preventDefault();
916
- event.stopPropagation();
917
- this.clearValue();
918
- }
919
- handleCalendarChange(event) {
920
- event.preventDefault();
921
- event.stopPropagation();
922
- const customEvent = event;
923
- const detail = customEvent.detail;
924
- const dayContext = detail.dayContext;
925
- if (!dayContext)
926
- return;
927
- const newComponents = {
928
- year: dayContext.year,
929
- month: dayContext.month,
930
- day: dayContext.dayInMonth,
931
- hour: this._state.hour,
932
- minute: this._state.minute,
933
- };
934
- this.updateState(newComponents, true);
935
- this.emitChangeEvent(newComponents, 'selection');
936
- if (!this._state.withTime) {
937
- this.closeDropdown();
938
- }
939
- else {
940
- requestAnimationFrame(() => {
941
- if (!this.shadowRoot)
942
- return;
943
- const timeInput = this.shadowRoot.querySelector('.time-input');
944
- if (timeInput) {
945
- timeInput.focus();
946
- }
947
- });
948
- }
949
- }
950
- handleDialogClick(event) {
951
- if (!this.shadowRoot)
952
- return;
953
- const dialog = this.shadowRoot.querySelector('.calendar-dialog');
954
- const content = this.shadowRoot.querySelector('.calendar-content');
955
- if (event.target === dialog && this._state.open && content && !content.contains(event.target)) {
956
- event.preventDefault();
957
- event.stopPropagation();
958
- this.closeDropdown();
959
- }
960
- }
961
- handleOutsideClick(event) {
962
- if (!this.shadowRoot)
963
- return;
964
- const target = event.target;
965
- const dialog = this.shadowRoot.querySelector('.calendar-dialog');
966
- if (this._state.open && dialog && !this.contains(target) && !dialog.contains(target)) {
967
- this.closeDropdown();
968
- }
969
- }
970
- handleEscapeKey(event) {
971
- const keyboardEvent = event;
972
- if (keyboardEvent.key === 'Escape' && this._state.open) {
973
- keyboardEvent.preventDefault();
974
- this.closeDropdown();
975
- }
976
- }
977
- openDropdown() {
978
- if (this._state.open)
979
- return;
980
- if (isMobileTouch())
981
- return;
982
- this.updateState({ open: true });
983
- this.dispatchEvent(new CustomEvent('open'));
984
- this.render();
985
- requestAnimationFrame(() => {
986
- if (!this.shadowRoot)
987
- return;
988
- const dialog = this.shadowRoot.querySelector('.calendar-dialog');
989
- if (dialog) {
990
- const pickerId = `date-picker-${this.id || this.toString()}`;
991
- lockScroll(pickerId);
992
- dialog.showModal();
993
- this.calculateCalendarPosition();
994
- dialog.classList.add('open');
995
- const stubEl = this.shadowRoot.querySelector('.date-picker-stub');
996
- if (stubEl)
997
- stubEl.setAttribute('aria-expanded', 'true');
998
- const focusedElement = this.shadowRoot.activeElement;
999
- if (focusedElement) {
1000
- focusedElement.blur();
1001
- }
1002
- }
1003
- });
1004
- }
1005
- closeDropdown() {
1006
- if (!this._state.open)
1007
- return;
1008
- this._closeTimestamp = Date.now();
1009
- const pickerId = `date-picker-${this.id || this.toString()}`;
1010
- this.updateState({ open: false }, true);
1011
- unlockScroll(pickerId);
1012
- if (this.shadowRoot) {
1013
- const dialog = this.shadowRoot.querySelector('.calendar-dialog');
1014
- if (dialog) {
1015
- dialog.classList.remove('position-above', 'position-below', 'open');
1016
- dialog.close();
1017
- }
1018
- const stubEl = this.shadowRoot.querySelector('.date-picker-stub');
1019
- if (stubEl)
1020
- stubEl.setAttribute('aria-expanded', 'false');
1021
- }
1022
- this.dispatchEvent(new CustomEvent('close'));
1023
- this.render();
1024
- }
1025
- cleanup() {
1026
- if (this._clickListener) {
1027
- document.removeEventListener('click', this._clickListener);
1028
- }
1029
- if (this._keydownListener) {
1030
- document.removeEventListener('keydown', this._keydownListener);
1031
- }
1032
- if (this._dialogClickListener && this.shadowRoot) {
1033
- const dialog = this.shadowRoot.querySelector('.calendar-dialog');
1034
- if (dialog) {
1035
- dialog.removeEventListener('click', this._dialogClickListener);
1036
- }
1037
- }
1038
- if (this._state.open) {
1039
- const pickerId = `date-picker-${this.id || this.toString()}`;
1040
- unlockScroll(pickerId);
1041
- }
1042
- this._clickListener = undefined;
1043
- this._keydownListener = undefined;
1044
- this._dialogClickListener = undefined;
1045
- this._timeInput = undefined;
1046
- }
209
+ constructor() {
210
+ super();
211
+ this._state = {
212
+ withTime: false,
213
+ open: false,
214
+ };
215
+ this._closeTimestamp = 0;
216
+ this._customFlavorSheet = null;
217
+ const shadow = this.shadowRoot;
218
+ ensureStyles(shadow, { css: datePickerStyles, id: 'ty-date-picker' });
219
+ }
220
+ onConnect() {
221
+ this.initializeState();
222
+ this.render();
223
+ this.updateValidity();
224
+ this._localeObserver = observeLocaleChanges(this, () => {
225
+ this.render();
226
+ });
227
+ this._syncCustomFlavor();
228
+ }
229
+ _syncCustomFlavor() {
230
+ const flavor = this.flavor === 'default' ? 'neutral' : this.flavor;
231
+ this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, flavor, ({ base }) => datePickerCustomFlavorCss(base));
232
+ }
233
+ onDisconnect() {
234
+ if (this._localeObserver) {
235
+ this._localeObserver();
236
+ this._localeObserver = undefined;
237
+ }
238
+ this.cleanup();
239
+ }
240
+ onPropertiesChanged(changes) {
241
+ for (const { name, newValue } of changes) {
242
+ switch (name) {
243
+ case 'flavor':
244
+ this._syncCustomFlavor();
245
+ break;
246
+ case 'size':
247
+ case 'label':
248
+ case 'placeholder':
249
+ case 'required':
250
+ case 'disabled':
251
+ this.updateValidity();
252
+ break;
253
+ case 'noClear':
254
+ case 'format':
255
+ case 'locale':
256
+ break;
257
+ case 'value': {
258
+ const newComponents = parseValue(newValue, this._state.withTime);
259
+ if (newComponents === null) {
260
+ const hasDate = this._state.year !== undefined ||
261
+ this._state.month !== undefined ||
262
+ this._state.day !== undefined;
263
+ if (hasDate) {
264
+ this._state = {
265
+ withTime: this._state.withTime,
266
+ open: this._state.open,
267
+ };
268
+ }
269
+ this.syncFormValue();
270
+ break;
271
+ }
272
+ const currentComponents = {
273
+ year: this._state.year,
274
+ month: this._state.month,
275
+ day: this._state.day,
276
+ hour: this._state.hour,
277
+ minute: this._state.minute,
278
+ };
279
+ const changed = newComponents?.year !== currentComponents.year ||
280
+ newComponents?.month !== currentComponents.month ||
281
+ newComponents?.day !== currentComponents.day ||
282
+ newComponents?.hour !== currentComponents.hour ||
283
+ newComponents?.minute !== currentComponents.minute;
284
+ if (changed) {
285
+ this._state = {
286
+ ...this._state,
287
+ ...newComponents,
288
+ };
289
+ this.syncFormValue();
290
+ }
291
+ break;
292
+ }
293
+ case 'with-time': {
294
+ const newWithTime = newValue;
295
+ const oldWithTime = this._state.withTime;
296
+ if (newWithTime !== oldWithTime) {
297
+ this._state.withTime = newWithTime;
298
+ const hasDate = this._state.year !== undefined &&
299
+ this._state.month !== undefined &&
300
+ this._state.day !== undefined;
301
+ if (hasDate) {
302
+ this.syncFormValue();
303
+ }
304
+ }
305
+ break;
306
+ }
307
+ }
308
+ }
309
+ }
310
+ getFormValue() {
311
+ return componentsToOutputValue(this.getComponents());
312
+ }
313
+ updateFormValue() {
314
+ super.updateFormValue();
315
+ this.updateValidity();
316
+ }
317
+ updateValidity() {
318
+ if (this.getProperty('disabled') || !this.getProperty('required') || this.getFormValue()) {
319
+ this.applyValidity({});
320
+ return;
321
+ }
322
+ const anchor = this.shadowRoot?.querySelector('.date-picker-stub, .native-date-input');
323
+ this.applyValidity({ valueMissing: true }, 'Please select a date', anchor ?? undefined);
324
+ }
325
+ getComponents() {
326
+ return {
327
+ year: this._state.year,
328
+ month: this._state.month,
329
+ day: this._state.day,
330
+ hour: this._state.hour,
331
+ minute: this._state.minute,
332
+ };
333
+ }
334
+ hasDate() {
335
+ return !!(this._state.year && this._state.month && this._state.day);
336
+ }
337
+ getFormattedValue(components) {
338
+ const c = components || this.getComponents();
339
+ if (!c.year || !c.month || !c.day)
340
+ return null;
341
+ return formatDisplayValue(c, this.getProperty('format') || 'long', getEffectiveLocale(this, this.getProperty('locale')), this._state.withTime);
342
+ }
343
+ initializeState() {
344
+ const valueAttr = this.getProperty('value');
345
+ const withTime = this.getProperty('with-time');
346
+ const components = parseValue(valueAttr, withTime);
347
+ if (components === null) {
348
+ this._state = {
349
+ withTime,
350
+ open: false,
351
+ };
352
+ }
353
+ else {
354
+ this._state = {
355
+ ...components,
356
+ withTime,
357
+ open: false,
358
+ };
359
+ }
360
+ this.syncFormValue();
361
+ }
362
+ updateState(updates, forceSync = false) {
363
+ this._state = { ...this._state, ...updates };
364
+ const shouldSync = forceSync || !this._state.open || !this._state.withTime;
365
+ if (shouldSync) {
366
+ this.syncFormValue();
367
+ }
368
+ }
369
+ syncFormValue() {
370
+ const utcValue = this.getFormValue();
371
+ const currentValue = this.getProperty('value');
372
+ if (utcValue !== currentValue) {
373
+ if (utcValue) {
374
+ this.setProperty('value', utcValue);
375
+ }
376
+ else {
377
+ this.setProperty('value', null);
378
+ }
379
+ }
380
+ }
381
+ handleTimeInputChange(hour, minute) {
382
+ if (!this.hasDate())
383
+ return;
384
+ const components = { ...this.getComponents(), hour, minute };
385
+ this.updateState(components, true);
386
+ this.emitChangeEvent(components, 'time-change');
387
+ this.updateTimeSummary();
388
+ }
389
+ updateTimeSummary(summary = this.shadowRoot?.querySelector('.time-summary')) {
390
+ if (!summary)
391
+ return;
392
+ const c = this.getComponents();
393
+ const text = summary.querySelector('.time-summary-date');
394
+ const iso = summary.querySelector('.time-summary-iso');
395
+ if (!c.year || !c.month || !c.day) {
396
+ text.textContent = 'Pick a day';
397
+ iso.textContent = '';
398
+ return;
399
+ }
400
+ const locale = getEffectiveLocale(this, this.getProperty('locale')) || undefined;
401
+ const date = new Date(c.year, c.month - 1, c.day, c.hour ?? 0, c.minute ?? 0);
402
+ const day = new Intl.DateTimeFormat(locale, { weekday: 'short', month: 'short', day: 'numeric' }).format(date);
403
+ const time = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }).format(date);
404
+ text.textContent = `${day} · ${time}`;
405
+ iso.textContent = componentsToLocalValue(c, true) ?? '';
406
+ }
407
+ emitChangeEvent(components, source) {
408
+ const utcValue = components ? componentsToOutputValue(components) : null;
409
+ const localValue = components ? componentsToLocalValue(components, this._state.withTime) : null;
410
+ const milliseconds = components ? componentsToDateObject(components)?.getTime() ?? null : null;
411
+ const formatted = components ? this.getFormattedValue(components) : null;
412
+ const detail = {
413
+ value: utcValue,
414
+ localValue,
415
+ milliseconds,
416
+ formatted,
417
+ source,
418
+ };
419
+ const event = new CustomEvent('change', {
420
+ detail,
421
+ bubbles: true,
422
+ cancelable: true,
423
+ });
424
+ this.dispatchEvent(event);
425
+ }
426
+ get size() { return this.getProperty('size'); }
427
+ set size(v) { this.setProperty('size', v); }
428
+ get placement() { return this.getProperty('placement'); }
429
+ set placement(v) { this.setProperty('placement', v); }
430
+ get flavor() { return this.getProperty('flavor'); }
431
+ set flavor(v) { this.setProperty('flavor', v); }
432
+ get label() { return this.getProperty('label'); }
433
+ set label(v) { this.setProperty('label', v); }
434
+ get placeholder() { return this.getProperty('placeholder'); }
435
+ set placeholder(v) { this.setProperty('placeholder', v); }
436
+ get name() { return this.getProperty('name'); }
437
+ set name(v) { this.setProperty('name', v); }
438
+ get format() { return this.getProperty('format'); }
439
+ set format(v) { this.setProperty('format', v); }
440
+ get locale() { return this.getProperty('locale'); }
441
+ set locale(v) { this.setProperty('locale', v); }
442
+ get required() { return this.getProperty('required'); }
443
+ set required(v) { this.setProperty('required', v); }
444
+ get disabled() { return this.getProperty('disabled'); }
445
+ set disabled(v) { this.setProperty('disabled', v); }
446
+ get noClear() { return this.getProperty('noClear'); }
447
+ set noClear(v) { this.setProperty('noClear', v); }
448
+ get min() { return this.getProperty('min'); }
449
+ set min(v) { this.setProperty('min', v ?? ''); }
450
+ get max() { return this.getProperty('max'); }
451
+ set max(v) { this.setProperty('max', v ?? ''); }
452
+ get withTime() { return this.getProperty('with-time'); }
453
+ set withTime(v) { this.setProperty('with-time', v); }
454
+ get value() {
455
+ return this.getProperty('value') || null;
456
+ }
457
+ set value(val) {
458
+ if (val === null || val === undefined || val === '') {
459
+ this.setProperty('value', null);
460
+ }
461
+ else {
462
+ const strValue = val instanceof Date ? val.toISOString() : val;
463
+ this.setProperty('value', strValue);
464
+ }
465
+ }
466
+ clear() {
467
+ this.clearValue();
468
+ }
469
+ buildStubClasses() {
470
+ const classes = ['date-picker-stub'];
471
+ if (this.getProperty('disabled'))
472
+ classes.push('disabled');
473
+ if (this.getProperty('required'))
474
+ classes.push('required');
475
+ if (this._state.open)
476
+ classes.push('open');
477
+ return classes.join(' ');
478
+ }
479
+ renderStub() {
480
+ const stub = document.createElement('div');
481
+ stub.className = this.buildStubClasses();
482
+ const isDisabled = this.getProperty('disabled');
483
+ if (isDisabled) {
484
+ stub.setAttribute('disabled', 'true');
485
+ }
486
+ stub.setAttribute('role', 'button');
487
+ stub.setAttribute('aria-haspopup', 'dialog');
488
+ stub.setAttribute('aria-expanded', String(this._state.open));
489
+ stub.setAttribute('tabindex', isDisabled ? '-1' : '0');
490
+ if (isDisabled)
491
+ stub.setAttribute('aria-disabled', 'true');
492
+ if (this.getProperty('label')) {
493
+ stub.setAttribute('aria-labelledby', `date-picker-label-${getElementHash(this)}`);
494
+ }
495
+ stub.addEventListener('keydown', (e) => {
496
+ const ke = e;
497
+ if (this._state.open)
498
+ return;
499
+ if (ke.key === 'Enter' || ke.key === ' ') {
500
+ ke.preventDefault();
501
+ this.handleStubClick(e);
502
+ }
503
+ });
504
+ const startSlot = document.createElement('slot');
505
+ startSlot.name = 'start';
506
+ const displayText = document.createElement('span');
507
+ displayText.className = 'stub-text';
508
+ const formattedValue = this.getFormattedValue();
509
+ const placeholder = this.getProperty('placeholder') || 'Select date...';
510
+ displayText.textContent = formattedValue || placeholder;
511
+ if (!formattedValue) {
512
+ displayText.classList.add('placeholder');
513
+ }
514
+ const iconContainer = document.createElement('div');
515
+ iconContainer.className = 'stub-icons';
516
+ const clearable = !this.getProperty('noClear');
517
+ if (clearable && formattedValue && !isDisabled) {
518
+ const clearButton = document.createElement('button');
519
+ clearButton.className = 'stub-clear';
520
+ clearButton.type = 'button';
521
+ clearButton.innerHTML = CLEAR_ICON_SVG;
522
+ clearButton.addEventListener('click', (e) => this.handleClearClick(e));
523
+ iconContainer.appendChild(clearButton);
524
+ }
525
+ const calendarIcon = document.createElement('span');
526
+ calendarIcon.className = 'stub-arrow';
527
+ calendarIcon.innerHTML = CALENDAR_ICON_SVG;
528
+ iconContainer.appendChild(calendarIcon);
529
+ stub.addEventListener('click', (e) => this.handleStubClick(e));
530
+ stub.appendChild(startSlot);
531
+ stub.appendChild(displayText);
532
+ stub.appendChild(iconContainer);
533
+ return stub;
534
+ }
535
+ createTimeField(part) {
536
+ const input = document.createElement('input');
537
+ input.type = 'text';
538
+ input.className = `time-input time-${part}`;
539
+ input.inputMode = 'numeric';
540
+ input.autocomplete = 'off';
541
+ input.maxLength = 2;
542
+ input.setAttribute('aria-label', part === 'hour' ? 'Hours' : 'Minutes');
543
+ return input;
544
+ }
545
+ renderTimeSection() {
546
+ const timeSection = document.createElement('div');
547
+ timeSection.className = 'time-section';
548
+ timeSection.setAttribute('role', 'group');
549
+ timeSection.setAttribute('aria-label', 'Time');
550
+ const row = document.createElement('div');
551
+ row.className = 'time-row';
552
+ const label = document.createElement('span');
553
+ label.className = 'time-label';
554
+ const icon = document.createElement('span');
555
+ icon.className = 'time-icon';
556
+ icon.innerHTML = SCHEDULE_ICON_SVG;
557
+ label.appendChild(icon);
558
+ label.appendChild(document.createTextNode('Time'));
559
+ const fields = document.createElement('div');
560
+ fields.className = 'time-fields';
561
+ const hourEl = this.createTimeField('hour');
562
+ const minuteEl = this.createTimeField('minute');
563
+ const colon = document.createElement('span');
564
+ colon.className = 'time-colon';
565
+ colon.textContent = ':';
566
+ fields.appendChild(hourEl);
567
+ fields.appendChild(colon);
568
+ fields.appendChild(minuteEl);
569
+ this._timeInput = new TimeFields(hourEl, minuteEl, (hour, minute) => this.handleTimeInputChange(hour, minute), this._state.hour || 0, this._state.minute || 0);
570
+ row.appendChild(label);
571
+ row.appendChild(fields);
572
+ const summary = document.createElement('div');
573
+ summary.className = 'time-summary';
574
+ summary.setAttribute('aria-live', 'polite');
575
+ const summaryDate = document.createElement('span');
576
+ summaryDate.className = 'time-summary-date';
577
+ const summaryIso = document.createElement('span');
578
+ summaryIso.className = 'time-summary-iso';
579
+ summary.appendChild(summaryDate);
580
+ summary.appendChild(summaryIso);
581
+ this.updateTimeSummary(summary);
582
+ timeSection.appendChild(row);
583
+ timeSection.appendChild(summary);
584
+ return timeSection;
585
+ }
586
+ renderCalendarDropdown() {
587
+ const dialog = document.createElement('dialog');
588
+ dialog.className = 'calendar-dialog';
589
+ const contentWrapper = document.createElement('div');
590
+ contentWrapper.className = 'calendar-content';
591
+ const calendar = document.createElement('ty-calendar');
592
+ if (this._state.year && this._state.month && this._state.day) {
593
+ calendar.setAttribute('year', this._state.year.toString());
594
+ calendar.setAttribute('month', this._state.month.toString());
595
+ calendar.setAttribute('day', this._state.day.toString());
596
+ }
597
+ const locale = getEffectiveLocale(this, this.getProperty('locale'));
598
+ if (locale) {
599
+ calendar.setAttribute('locale', locale);
600
+ }
601
+ const min = this.getProperty('min');
602
+ const max = this.getProperty('max');
603
+ if (min)
604
+ calendar.setAttribute('min', min);
605
+ if (max)
606
+ calendar.setAttribute('max', max);
607
+ const flavor = this.getProperty('flavor');
608
+ if (flavor && flavor !== 'default')
609
+ calendar.setAttribute('flavor', flavor);
610
+ calendar.addEventListener('change', (e) => this.handleCalendarChange(e));
611
+ contentWrapper.appendChild(calendar);
612
+ if (this._state.withTime) {
613
+ contentWrapper.appendChild(this.renderTimeSection());
614
+ }
615
+ dialog.appendChild(contentWrapper);
616
+ dialog.addEventListener('close', () => {
617
+ this.updateState({ open: false });
618
+ });
619
+ return dialog;
620
+ }
621
+ renderNativeInput() {
622
+ const wrapper = document.createElement('div');
623
+ wrapper.className = 'dropdown-wrapper';
624
+ const stub = document.createElement('div');
625
+ stub.className = this.buildStubClasses();
626
+ const isDisabled = this.getProperty('disabled');
627
+ if (isDisabled) {
628
+ stub.setAttribute('disabled', 'true');
629
+ }
630
+ const input = document.createElement('input');
631
+ input.className = 'native-date-input';
632
+ input.type = this._state.withTime ? 'datetime-local' : 'date';
633
+ if (isDisabled)
634
+ input.disabled = true;
635
+ if (this.getProperty('required'))
636
+ input.required = true;
637
+ const minBound = this.getProperty('min');
638
+ const maxBound = this.getProperty('max');
639
+ if (minBound)
640
+ input.min = this._state.withTime ? `${minBound}T00:00` : minBound;
641
+ if (maxBound)
642
+ input.max = this._state.withTime ? `${maxBound}T23:59` : maxBound;
643
+ const localValue = componentsToLocalValue(this.getComponents(), this._state.withTime);
644
+ if (localValue) {
645
+ input.value = localValue;
646
+ }
647
+ const placeholder = this.getProperty('placeholder') || 'Select date...';
648
+ const formattedValue = this.getFormattedValue();
649
+ const placeholderEl = document.createElement('span');
650
+ placeholderEl.className = 'stub-text' + (formattedValue ? '' : ' placeholder');
651
+ placeholderEl.textContent = formattedValue || placeholder;
652
+ input.addEventListener('change', () => {
653
+ if (!input.value) {
654
+ this.clearValue();
655
+ return;
656
+ }
657
+ const parsed = parseValue(input.value, this._state.withTime);
658
+ if (parsed) {
659
+ this.updateState(parsed, true);
660
+ this.emitChangeEvent(parsed, 'selection');
661
+ }
662
+ });
663
+ const startSlot = document.createElement('slot');
664
+ startSlot.name = 'start';
665
+ stub.appendChild(startSlot);
666
+ stub.appendChild(input);
667
+ stub.appendChild(placeholderEl);
668
+ const iconContainer = document.createElement('div');
669
+ iconContainer.className = 'stub-icons';
670
+ const clearable = !this.getProperty('noClear');
671
+ if (clearable && localValue && !isDisabled) {
672
+ const clearButton = document.createElement('button');
673
+ clearButton.className = 'stub-clear';
674
+ clearButton.type = 'button';
675
+ clearButton.innerHTML = CLEAR_ICON_SVG;
676
+ clearButton.addEventListener('click', (e) => this.handleClearClick(e));
677
+ iconContainer.appendChild(clearButton);
678
+ }
679
+ const calendarIcon = document.createElement('span');
680
+ calendarIcon.className = 'stub-arrow';
681
+ calendarIcon.innerHTML = CALENDAR_ICON_SVG;
682
+ iconContainer.appendChild(calendarIcon);
683
+ stub.appendChild(iconContainer);
684
+ wrapper.appendChild(stub);
685
+ return wrapper;
686
+ }
687
+ calculateCalendarPosition() {
688
+ if (!this.shadowRoot)
689
+ return;
690
+ if (isMobileTouch())
691
+ return;
692
+ const stub = this.shadowRoot.querySelector('.date-picker-stub');
693
+ const dialog = this.shadowRoot.querySelector('.calendar-dialog');
694
+ if (!stub || !dialog)
695
+ return;
696
+ const stubRect = stub.getBoundingClientRect();
697
+ const dialogRect = dialog.getBoundingClientRect();
698
+ const estimatedHeight = dialogRect.height || 400;
699
+ const popupWidth = dialogRect.width || 320;
700
+ const wrapPadding = 8;
701
+ const anchored = placementToAnchored(this.getProperty('placement'));
702
+ const pos = computeAnchoredPosition({
703
+ anchorRect: stubRect,
704
+ popupWidth,
705
+ popupHeight: estimatedHeight,
706
+ gap: 0,
707
+ align: anchored.align,
708
+ side: anchored.side,
709
+ });
710
+ const positionBelow = pos.below;
711
+ const x = pos.x - wrapPadding;
712
+ const y = positionBelow ? pos.topY : pos.bottomY;
713
+ this.style.setProperty('--calendar-x', `${x}px`);
714
+ this.style.setProperty('--calendar-y', `${y}px`);
715
+ this.style.setProperty('--calendar-offset-x', '0px');
716
+ this.style.setProperty('--calendar-offset-y', '0px');
717
+ if (positionBelow) {
718
+ dialog.classList.add('position-below');
719
+ dialog.classList.remove('position-above');
720
+ }
721
+ else {
722
+ dialog.classList.add('position-above');
723
+ dialog.classList.remove('position-below');
724
+ }
725
+ }
726
+ renderContainer() {
727
+ const container = document.createElement('div');
728
+ container.className = 'dropdown-container';
729
+ const label = this.getProperty('label');
730
+ if (label) {
731
+ const labelEl = document.createElement('label');
732
+ labelEl.className = 'ty-field-label';
733
+ labelEl.id = `date-picker-label-${getElementHash(this)}`;
734
+ labelEl.innerHTML = label + (this.getProperty('required') ? '<span class="required-icon">*</span>' : '');
735
+ container.appendChild(labelEl);
736
+ }
737
+ return container;
738
+ }
739
+ render() {
740
+ if (!this.shadowRoot)
741
+ return;
742
+ ensureStyles(this.shadowRoot, { css: datePickerStyles, id: 'ty-date-picker' });
743
+ if (isMobileTouch()) {
744
+ const existingNativeInput = this.shadowRoot.querySelector('.native-date-input');
745
+ if (existingNativeInput) {
746
+ this.updateDisplay();
747
+ return;
748
+ }
749
+ this.shadowRoot.innerHTML = '';
750
+ const container = this.renderContainer();
751
+ container.appendChild(this.renderNativeInput());
752
+ this.shadowRoot.appendChild(container);
753
+ return;
754
+ }
755
+ const existingDialog = this.shadowRoot.querySelector('.calendar-dialog');
756
+ const isDialogOpen = existingDialog && existingDialog.open;
757
+ if (isDialogOpen && this._state.open) {
758
+ this.updateDisplay();
759
+ this.calculateCalendarPosition();
760
+ return;
761
+ }
762
+ this.shadowRoot.innerHTML = '';
763
+ const container = this.renderContainer();
764
+ const wrapper = document.createElement('div');
765
+ wrapper.className = 'dropdown-wrapper';
766
+ wrapper.appendChild(this.renderStub());
767
+ wrapper.appendChild(this.renderCalendarDropdown());
768
+ container.appendChild(wrapper);
769
+ this.shadowRoot.appendChild(container);
770
+ this.setupEventListeners();
771
+ }
772
+ updateDisplay() {
773
+ if (!this.shadowRoot)
774
+ return;
775
+ const formattedValue = this.getFormattedValue();
776
+ const placeholder = this.getProperty('placeholder') || 'Select date...';
777
+ const hasValue = this.hasDate();
778
+ const clearable = !this.getProperty('noClear');
779
+ const isDisabled = this.getProperty('disabled');
780
+ const stubText = this.shadowRoot.querySelector('.stub-text');
781
+ if (stubText) {
782
+ stubText.textContent = formattedValue || placeholder;
783
+ stubText.classList.toggle('placeholder', !formattedValue);
784
+ }
785
+ const clearButton = this.shadowRoot.querySelector('.stub-clear');
786
+ if (clearButton) {
787
+ clearButton.style.display = (clearable && hasValue && !isDisabled) ? '' : 'none';
788
+ }
789
+ if (isMobileTouch()) {
790
+ const nativeInput = this.shadowRoot.querySelector('.native-date-input');
791
+ if (nativeInput) {
792
+ const localValue = componentsToLocalValue(this.getComponents(), this._state.withTime);
793
+ nativeInput.value = localValue || '';
794
+ }
795
+ return;
796
+ }
797
+ const calendar = this.shadowRoot.querySelector('ty-calendar');
798
+ if (calendar && hasValue) {
799
+ calendar.setAttribute('year', this._state.year.toString());
800
+ calendar.setAttribute('month', this._state.month.toString());
801
+ calendar.setAttribute('day', this._state.day.toString());
802
+ }
803
+ if (calendar) {
804
+ const flavor = this.getProperty('flavor');
805
+ if (flavor && flavor !== 'default')
806
+ calendar.setAttribute('flavor', flavor);
807
+ else
808
+ calendar.removeAttribute('flavor');
809
+ const min = this.getProperty('min');
810
+ const max = this.getProperty('max');
811
+ if (min)
812
+ calendar.setAttribute('min', min);
813
+ else
814
+ calendar.removeAttribute('min');
815
+ if (max)
816
+ calendar.setAttribute('max', max);
817
+ else
818
+ calendar.removeAttribute('max');
819
+ }
820
+ if (this._timeInput && this._state.hour !== undefined && this._state.minute !== undefined) {
821
+ this._timeInput.setTime(this._state.hour, this._state.minute);
822
+ }
823
+ this.updateTimeSummary();
824
+ }
825
+ setupEventListeners() {
826
+ if (this._clickListener) {
827
+ document.removeEventListener('click', this._clickListener);
828
+ }
829
+ if (this._keydownListener) {
830
+ document.removeEventListener('keydown', this._keydownListener);
831
+ }
832
+ this._clickListener = (e) => this.handleOutsideClick(e);
833
+ this._keydownListener = (e) => this.handleEscapeKey(e);
834
+ document.addEventListener('click', this._clickListener);
835
+ document.addEventListener('keydown', this._keydownListener);
836
+ const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
837
+ if (dialog) {
838
+ this._dialogClickListener = (e) => this.handleDialogClick(e);
839
+ dialog.addEventListener('click', this._dialogClickListener);
840
+ }
841
+ }
842
+ handleStubClick(event) {
843
+ event.preventDefault();
844
+ const dialog = this.shadowRoot?.querySelector('.calendar-dialog');
845
+ if (this._state.open && (!dialog || !dialog.open)) {
846
+ this.updateState({ open: false }, true);
847
+ unlockScroll(`date-picker-${this.id || this.toString()}`);
848
+ }
849
+ const disabled = this.getProperty('disabled');
850
+ if (!disabled && Date.now() - this._closeTimestamp > 300) {
851
+ this.openDropdown();
852
+ }
853
+ }
854
+ clearValue() {
855
+ this.updateState({
856
+ year: undefined,
857
+ month: undefined,
858
+ day: undefined,
859
+ hour: undefined,
860
+ minute: undefined,
861
+ }, true);
862
+ this.value = null;
863
+ this.emitChangeEvent(null, 'clear');
864
+ this.render();
865
+ }
866
+ handleClearClick(event) {
867
+ event.preventDefault();
868
+ event.stopPropagation();
869
+ this.clearValue();
870
+ }
871
+ handleCalendarChange(event) {
872
+ event.preventDefault();
873
+ event.stopPropagation();
874
+ const customEvent = event;
875
+ const detail = customEvent.detail;
876
+ const dayContext = detail.dayContext;
877
+ if (!dayContext)
878
+ return;
879
+ const newComponents = {
880
+ year: dayContext.year,
881
+ month: dayContext.month,
882
+ day: dayContext.dayInMonth,
883
+ hour: this._state.hour,
884
+ minute: this._state.minute,
885
+ };
886
+ this.updateState(newComponents, true);
887
+ this.emitChangeEvent(newComponents, 'selection');
888
+ if (!this._state.withTime) {
889
+ this.closeDropdown();
890
+ }
891
+ else {
892
+ requestAnimationFrame(() => {
893
+ if (!this.shadowRoot)
894
+ return;
895
+ this.updateTimeSummary();
896
+ const timeInput = this.shadowRoot.querySelector('.time-hour');
897
+ if (timeInput) {
898
+ timeInput.focus();
899
+ }
900
+ });
901
+ }
902
+ }
903
+ handleDialogClick(event) {
904
+ if (!this.shadowRoot)
905
+ return;
906
+ const dialog = this.shadowRoot.querySelector('.calendar-dialog');
907
+ const content = this.shadowRoot.querySelector('.calendar-content');
908
+ if (event.target === dialog && this._state.open && content && !content.contains(event.target)) {
909
+ event.preventDefault();
910
+ event.stopPropagation();
911
+ this.closeDropdown();
912
+ }
913
+ }
914
+ handleOutsideClick(event) {
915
+ if (!this.shadowRoot)
916
+ return;
917
+ const target = event.target;
918
+ const dialog = this.shadowRoot.querySelector('.calendar-dialog');
919
+ if (this._state.open && dialog && !this.contains(target) && !dialog.contains(target)) {
920
+ this.closeDropdown();
921
+ }
922
+ }
923
+ handleEscapeKey(event) {
924
+ const keyboardEvent = event;
925
+ if (keyboardEvent.key === 'Escape' && this._state.open) {
926
+ keyboardEvent.preventDefault();
927
+ this.closeDropdown();
928
+ }
929
+ }
930
+ openDropdown() {
931
+ if (this._state.open)
932
+ return;
933
+ if (isMobileTouch())
934
+ return;
935
+ this.updateState({ open: true });
936
+ this.dispatchEvent(new CustomEvent('open'));
937
+ this.render();
938
+ requestAnimationFrame(() => {
939
+ if (!this.shadowRoot)
940
+ return;
941
+ const dialog = this.shadowRoot.querySelector('.calendar-dialog');
942
+ if (dialog) {
943
+ const pickerId = `date-picker-${this.id || this.toString()}`;
944
+ lockScroll(pickerId);
945
+ dialog.showModal();
946
+ this.calculateCalendarPosition();
947
+ dialog.classList.add('open');
948
+ const stubEl = this.shadowRoot.querySelector('.date-picker-stub');
949
+ if (stubEl)
950
+ stubEl.setAttribute('aria-expanded', 'true');
951
+ const focusedElement = this.shadowRoot.activeElement;
952
+ if (focusedElement) {
953
+ focusedElement.blur();
954
+ }
955
+ }
956
+ });
957
+ }
958
+ closeDropdown() {
959
+ if (!this._state.open)
960
+ return;
961
+ this._closeTimestamp = Date.now();
962
+ const pickerId = `date-picker-${this.id || this.toString()}`;
963
+ this.updateState({ open: false }, true);
964
+ unlockScroll(pickerId);
965
+ if (this.shadowRoot) {
966
+ const dialog = this.shadowRoot.querySelector('.calendar-dialog');
967
+ if (dialog) {
968
+ dialog.classList.remove('position-above', 'position-below', 'open');
969
+ dialog.close();
970
+ }
971
+ const stubEl = this.shadowRoot.querySelector('.date-picker-stub');
972
+ if (stubEl)
973
+ stubEl.setAttribute('aria-expanded', 'false');
974
+ }
975
+ this.dispatchEvent(new CustomEvent('close'));
976
+ this.render();
977
+ }
978
+ cleanup() {
979
+ if (this._clickListener) {
980
+ document.removeEventListener('click', this._clickListener);
981
+ }
982
+ if (this._keydownListener) {
983
+ document.removeEventListener('keydown', this._keydownListener);
984
+ }
985
+ if (this._dialogClickListener && this.shadowRoot) {
986
+ const dialog = this.shadowRoot.querySelector('.calendar-dialog');
987
+ if (dialog) {
988
+ dialog.removeEventListener('click', this._dialogClickListener);
989
+ }
990
+ }
991
+ if (this._state.open) {
992
+ const pickerId = `date-picker-${this.id || this.toString()}`;
993
+ unlockScroll(pickerId);
994
+ }
995
+ this._clickListener = undefined;
996
+ this._keydownListener = undefined;
997
+ this._dialogClickListener = undefined;
998
+ this._timeInput = undefined;
999
+ }
1047
1000
  }
1048
1001
  TyDatePicker.properties = {
1049
- placement: {
1050
- type: 'string',
1051
- visual: true,
1052
- default: '',
1053
- },
1054
- size: {
1055
- type: 'string',
1056
- visual: true,
1057
- default: 'md',
1058
- validate: (v) => ['sm', 'md', 'lg'].includes(v),
1059
- coerce: (v) => {
1060
- if (v === 'xs')
1061
- return 'sm';
1062
- if (v === 'xl')
1063
- return 'lg';
1064
- if (!['sm', 'md', 'lg'].includes(v)) {
1065
- console.warn(`[ty-date-picker] Invalid size '${v}'. Using 'md'.`);
1066
- return 'md';
1067
- }
1068
- return v;
1069
- }
1070
- },
1071
- flavor: {
1072
- type: 'string',
1073
- visual: true,
1074
- default: 'default'
1075
- },
1076
- label: {
1077
- type: 'string',
1078
- visual: true,
1079
- default: ''
1080
- },
1081
- placeholder: {
1082
- type: 'string',
1083
- visual: true,
1084
- default: 'Select date...'
1085
- },
1086
- name: {
1087
- type: 'string',
1088
- visual: false,
1089
- default: ''
1090
- },
1091
- min: {
1092
- type: 'string',
1093
- visual: true,
1094
- default: ''
1095
- },
1096
- max: {
1097
- type: 'string',
1098
- visual: true,
1099
- default: ''
1100
- },
1101
- required: {
1102
- type: 'boolean',
1103
- visual: true,
1104
- default: false
1105
- },
1106
- disabled: {
1107
- type: 'boolean',
1108
- visual: true,
1109
- default: false
1110
- },
1111
- clearable: {
1112
- type: 'boolean',
1113
- visual: true,
1114
- default: true,
1115
- aliases: {
1116
- 'not-clearable': false
1117
- }
1118
- },
1119
- format: {
1120
- type: 'string',
1121
- visual: true,
1122
- default: 'long',
1123
- validate: (v) => ['short', 'medium', 'long', 'full'].includes(v),
1124
- coerce: (v) => {
1125
- const validFormats = ['short', 'medium', 'long', 'full'];
1126
- if (!validFormats.includes(v)) {
1127
- console.warn(`[ty-date-picker] Invalid format '${v}'. Using 'long'.`);
1128
- return 'long';
1129
- }
1130
- return v;
1131
- }
1132
- },
1133
- locale: {
1134
- type: 'string',
1135
- visual: true,
1136
- default: ''
1137
- },
1138
- value: {
1139
- type: 'string',
1140
- visual: true,
1141
- formValue: true,
1142
- emitChange: false,
1143
- default: null
1144
- },
1145
- 'with-time': {
1146
- type: 'boolean',
1147
- visual: true,
1148
- default: false
1149
- }
1002
+ placement: {
1003
+ type: 'string',
1004
+ visual: true,
1005
+ default: '',
1006
+ },
1007
+ size: {
1008
+ type: 'string',
1009
+ visual: true,
1010
+ default: DEFAULT_SIZE,
1011
+ validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
1012
+ coerce: (v) => {
1013
+ if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
1014
+ console.warn(`[ty-date-picker] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
1015
+ return DEFAULT_SIZE;
1016
+ }
1017
+ return v;
1018
+ }
1019
+ },
1020
+ flavor: {
1021
+ type: 'string',
1022
+ visual: true,
1023
+ default: 'default'
1024
+ },
1025
+ label: {
1026
+ type: 'string',
1027
+ visual: true,
1028
+ default: ''
1029
+ },
1030
+ placeholder: {
1031
+ type: 'string',
1032
+ visual: true,
1033
+ default: 'Select date...'
1034
+ },
1035
+ name: {
1036
+ type: 'string',
1037
+ visual: false,
1038
+ default: ''
1039
+ },
1040
+ min: {
1041
+ type: 'string',
1042
+ visual: true,
1043
+ default: ''
1044
+ },
1045
+ max: {
1046
+ type: 'string',
1047
+ visual: true,
1048
+ default: ''
1049
+ },
1050
+ required: {
1051
+ type: 'boolean',
1052
+ visual: true,
1053
+ default: false
1054
+ },
1055
+ disabled: {
1056
+ type: 'boolean',
1057
+ visual: true,
1058
+ default: false
1059
+ },
1060
+ noClear: {
1061
+ type: 'boolean',
1062
+ visual: true,
1063
+ default: false
1064
+ },
1065
+ format: {
1066
+ type: 'string',
1067
+ visual: true,
1068
+ default: 'long',
1069
+ validate: (v) => ['short', 'medium', 'long', 'full'].includes(v),
1070
+ coerce: (v) => {
1071
+ const validFormats = ['short', 'medium', 'long', 'full'];
1072
+ if (!validFormats.includes(v)) {
1073
+ console.warn(`[ty-date-picker] Invalid format '${v}'. Using 'long'.`);
1074
+ return 'long';
1075
+ }
1076
+ return v;
1077
+ }
1078
+ },
1079
+ locale: {
1080
+ type: 'string',
1081
+ visual: true,
1082
+ default: ''
1083
+ },
1084
+ value: {
1085
+ type: 'string',
1086
+ visual: true,
1087
+ formValue: true,
1088
+ emitChange: false,
1089
+ default: null
1090
+ },
1091
+ 'with-time': {
1092
+ type: 'boolean',
1093
+ visual: true,
1094
+ default: false
1095
+ }
1150
1096
  };
1151
1097
  TyDatePicker.formAssociated = true;
1152
1098
  if (!customElements.get('ty-date-picker')) {
1153
- customElements.define('ty-date-picker', TyDatePicker);
1099
+ customElements.define('ty-date-picker', TyDatePicker);
1154
1100
  }