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
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_SIZE } from '../types/common.js';
1
2
  import { TyComponent } from '../base/ty-component.js';
2
3
  import { ensureStyles } from '../utils/styles.js';
3
4
  import { syncCustomFlavorSheet } from '../utils/flavor-sheet.js';
@@ -8,605 +9,601 @@ import { REQUIRED_ICON_SVG } from '../utils/icons.js';
8
9
  const EYE_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>`;
9
10
  const EYE_OFF_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"/><path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"/><path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"/><path d="m2 2 20 20"/></svg>`;
10
11
  export class TyInput extends TyComponent {
11
- constructor() {
12
- super();
13
- this._shadowValue = null;
14
- this._isFocused = false;
15
- this._listenersSetup = false;
16
- this._errorAutoDanger = false;
17
- this._customFlavorSheet = null;
18
- this._inputHandler = null;
19
- this._changeHandler = null;
20
- this._focusHandler = null;
21
- this._blurHandler = null;
22
- this._inputDebounceTimer = null;
23
- this._changeDebounceTimer = null;
24
- const shadow = this.shadowRoot;
25
- ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
26
- }
27
- onConnect() {
28
- this.initializeShadowValue();
29
- this._localeObserver = observeLocaleChanges(this, () => {
30
- this.render();
31
- });
32
- this._syncCustomFlavor();
33
- }
34
- _syncCustomFlavor() {
35
- this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => inputCustomFlavorCss(base));
36
- }
37
- onDisconnect() {
38
- this.removeEventListeners();
39
- if (this._localeObserver) {
40
- this._localeObserver();
41
- this._localeObserver = undefined;
42
- }
43
- if (this._inputDebounceTimer !== null) {
44
- clearTimeout(this._inputDebounceTimer);
45
- this._inputDebounceTimer = null;
46
- }
47
- if (this._changeDebounceTimer !== null) {
48
- clearTimeout(this._changeDebounceTimer);
49
- this._changeDebounceTimer = null;
50
- }
51
- }
52
- onPropertiesChanged(changes) {
53
- for (const { name, newValue } of changes) {
54
- switch (name) {
55
- case 'flavor':
56
- this._syncCustomFlavor();
57
- break;
58
- case 'value':
59
- this._shadowValue = this.parseShadowValue(newValue || '');
60
- break;
61
- case 'type':
62
- const currentValue = this.getProperty('value') || '';
63
- this._shadowValue = this.parseShadowValue(currentValue);
64
- break;
65
- case 'error':
66
- if (newValue) {
67
- if (this.getProperty('flavor') === 'neutral') {
68
- this.setProperty('flavor', 'danger');
69
- this._errorAutoDanger = true;
70
- }
71
- }
72
- else if (this._errorAutoDanger) {
73
- if (this.getProperty('flavor') === 'danger') {
74
- this.setProperty('flavor', 'neutral');
75
- }
76
- this._errorAutoDanger = false;
77
- }
78
- break;
79
- }
80
- }
81
- }
82
- onFormReset() {
83
- this._shadowValue = null;
84
- this.initializeShadowValue();
85
- this._isFocused = false;
86
- if (this._inputDebounceTimer !== null) {
87
- clearTimeout(this._inputDebounceTimer);
88
- this._inputDebounceTimer = null;
89
- }
90
- if (this._changeDebounceTimer !== null) {
91
- clearTimeout(this._changeDebounceTimer);
92
- this._changeDebounceTimer = null;
93
- }
94
- this.render();
95
- }
96
- getFormValue() {
97
- const formValue = this._shadowValue !== null ? String(this._shadowValue) : null;
98
- return formValue;
99
- }
100
- initializeShadowValue() {
101
- const currentValue = this.getProperty('value');
102
- if (currentValue) {
103
- this._shadowValue = this.parseShadowValue(currentValue);
104
- this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
105
- }
106
- }
107
- parseShadowValue(value) {
108
- if (!value || typeof value !== 'string' || value.trim() === '')
109
- return null;
110
- if (shouldFormatType(this.type)) {
111
- const parsed = parseNumericValue(value);
112
- if (parsed !== null && this.precision === 0) {
113
- return Math.round(parsed);
114
- }
115
- return parsed;
116
- }
117
- return value;
118
- }
119
- shouldFormat() {
120
- return shouldFormatType(this.type) &&
121
- !this._isFocused &&
122
- this._shadowValue !== null &&
123
- typeof this._shadowValue === 'number';
124
- }
125
- getFormatConfig() {
126
- return {
127
- type: this.type,
128
- locale: this.locale,
129
- currency: this.currency,
130
- precision: this.precision
131
- };
132
- }
133
- getDisplayValue() {
134
- if (this.shouldFormat()) {
135
- let valueToFormat = this._shadowValue;
136
- if (this.type === 'percent') {
137
- valueToFormat = valueToFormat / 100;
138
- }
139
- return formatNumber(valueToFormat, this.getFormatConfig());
140
- }
141
- return this._shadowValue !== null ? String(this._shadowValue) : '';
142
- }
143
- get type() { return this.getProperty('type'); }
144
- set type(v) { this.setProperty('type', v); }
145
- get value() {
146
- return this._shadowValue !== null ? String(this._shadowValue) : '';
147
- }
148
- set value(v) { this.setProperty('value', v); }
149
- get name() { return this.getProperty('name'); }
150
- set name(v) { this.setProperty('name', v); }
151
- get placeholder() { return this.getProperty('placeholder'); }
152
- set placeholder(v) { this.setProperty('placeholder', v); }
153
- get label() { return this.getProperty('label'); }
154
- set label(v) { this.setProperty('label', v); }
155
- get disabled() { return this.getProperty('disabled'); }
156
- set disabled(v) { this.setProperty('disabled', v); }
157
- get required() { return this.getProperty('required'); }
158
- set required(v) { this.setProperty('required', v); }
159
- get error() { return this.getProperty('error'); }
160
- set error(v) { this.setProperty('error', v); }
161
- get size() { return this.getProperty('size'); }
162
- set size(v) { this.setProperty('size', v); }
163
- get flavor() { return this.getProperty('flavor'); }
164
- set flavor(v) { this.setProperty('flavor', v); }
165
- get currency() { return this.getProperty('currency'); }
166
- set currency(v) { this.setProperty('currency', v); }
167
- get locale() {
168
- return getEffectiveLocale(this, this.getProperty('locale'));
169
- }
170
- set locale(v) { this.setProperty('locale', v); }
171
- get precision() { return this.getProperty('precision'); }
172
- set precision(v) { this.setProperty('precision', v); }
173
- get debounce() { return this.getProperty('debounce'); }
174
- set debounce(v) { this.setProperty('debounce', v); }
175
- get form() {
176
- return this._internals.form;
177
- }
178
- buildClassList() {
179
- const classes = [this.size];
180
- if (this.disabled)
181
- classes.push('disabled');
182
- if (this.required)
183
- classes.push('required');
184
- if (this.error)
185
- classes.push('error');
186
- return classes.join(' ');
187
- }
188
- dispatchInputEvent(rawValue, originalEvent) {
189
- this.dispatchEvent(new CustomEvent('input', {
190
- detail: {
191
- value: this._shadowValue,
192
- formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
193
- rawValue: rawValue,
194
- originalEvent: originalEvent
195
- },
196
- bubbles: true,
197
- composed: true
198
- }));
199
- }
200
- dispatchChangeEvent(rawValue, originalEvent) {
201
- this.dispatchEvent(new CustomEvent('change', {
202
- detail: {
203
- value: this._shadowValue,
204
- formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
205
- rawValue: rawValue,
206
- originalEvent: originalEvent
207
- },
208
- bubbles: true,
209
- composed: true
210
- }));
211
- }
212
- removeEventListeners() {
213
- if (!this._listenersSetup)
214
- return;
215
- const shadow = this.shadowRoot;
216
- if (!shadow)
217
- return;
218
- const inputEl = shadow.querySelector('input');
219
- if (!inputEl)
220
- return;
221
- if (this._inputHandler) {
222
- inputEl.removeEventListener('input', this._inputHandler);
223
- this._inputHandler = null;
224
- }
225
- if (this._changeHandler) {
226
- inputEl.removeEventListener('change', this._changeHandler);
227
- this._changeHandler = null;
228
- }
229
- if (this._focusHandler) {
230
- inputEl.removeEventListener('focus', this._focusHandler);
231
- this._focusHandler = null;
232
- }
233
- if (this._blurHandler) {
234
- inputEl.removeEventListener('blur', this._blurHandler);
235
- this._blurHandler = null;
236
- }
237
- this._listenersSetup = false;
238
- }
239
- setupEventListeners() {
240
- if (this._listenersSetup) {
241
- return;
242
- }
243
- const shadow = this.shadowRoot;
244
- const inputEl = shadow.querySelector('input');
245
- const wrapperEl = shadow.querySelector('.input-wrapper');
246
- if (!inputEl || !wrapperEl) {
247
- console.warn('[TyInput.setupEventListeners] ⚠️ Input element not found!');
248
- return;
249
- }
250
- this._inputHandler = (e) => {
251
- e.stopPropagation();
252
- e.stopImmediatePropagation();
253
- const target = e.target;
254
- const rawValue = target.value;
255
- this._shadowValue = this.parseShadowValue(rawValue);
256
- this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
257
- this.updateValidity();
258
- if (this._inputDebounceTimer !== null) {
259
- clearTimeout(this._inputDebounceTimer);
260
- }
261
- if (this.debounce > 0) {
262
- this._inputDebounceTimer = window.setTimeout(() => {
263
- this.dispatchInputEvent(inputEl.value, e);
264
- this._inputDebounceTimer = null;
265
- }, this.debounce);
266
- }
267
- else {
268
- this.dispatchInputEvent(rawValue, e);
269
- }
270
- };
271
- this._changeHandler = (e) => {
272
- e.stopPropagation();
273
- e.stopImmediatePropagation();
274
- const target = e.target;
275
- const rawValue = target.value;
276
- this._shadowValue = this.parseShadowValue(rawValue);
277
- this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
278
- this.updateValidity();
279
- if (this._changeDebounceTimer !== null) {
280
- clearTimeout(this._changeDebounceTimer);
281
- }
282
- if (this.debounce > 0) {
283
- this._changeDebounceTimer = window.setTimeout(() => {
284
- this.dispatchChangeEvent(inputEl.value, e);
285
- this._changeDebounceTimer = null;
286
- }, this.debounce);
287
- }
288
- else {
289
- this.dispatchChangeEvent(rawValue, e);
290
- }
291
- };
292
- this._focusHandler = (e) => {
293
- this._isFocused = true;
294
- wrapperEl.classList.add('focused');
295
- if (shouldFormatType(this.type) && this._shadowValue !== null) {
296
- inputEl.value = String(this._shadowValue);
297
- }
298
- this.dispatchEvent(new CustomEvent('focus', {
299
- detail: { originalEvent: e },
300
- bubbles: true,
301
- composed: true
302
- }));
303
- };
304
- this._blurHandler = (e) => {
305
- const target = e.target;
306
- const rawValue = target.value;
307
- if (this._inputDebounceTimer !== null) {
308
- clearTimeout(this._inputDebounceTimer);
309
- this._inputDebounceTimer = null;
310
- this.dispatchInputEvent(rawValue, e);
311
- }
312
- if (this._changeDebounceTimer !== null) {
313
- clearTimeout(this._changeDebounceTimer);
314
- this._changeDebounceTimer = null;
315
- this.dispatchChangeEvent(rawValue, e);
316
- }
317
- this._isFocused = false;
318
- wrapperEl.classList.remove('focused');
319
- if (this.shouldFormat()) {
320
- inputEl.value = this.getDisplayValue();
321
- }
322
- this.dispatchEvent(new CustomEvent('blur', {
323
- detail: { originalEvent: e },
324
- bubbles: true,
325
- composed: true
326
- }));
327
- };
328
- inputEl.addEventListener('input', this._inputHandler);
329
- inputEl.addEventListener('change', this._changeHandler);
330
- inputEl.addEventListener('focus', this._focusHandler);
331
- inputEl.addEventListener('blur', this._blurHandler);
332
- this._listenersSetup = true;
333
- }
334
- render() {
335
- const shadow = this.shadowRoot;
336
- const existingInput = shadow.querySelector('input');
337
- const existingWrapper = shadow.querySelector('.input-wrapper');
338
- const existingLabel = shadow.querySelector('.ty-field-label');
339
- const existingError = shadow.querySelector('.error-message');
340
- const classes = this.buildClassList();
341
- const inputType = ['password', 'email', 'tel', 'url'].includes(this.type)
342
- ? this.type
343
- : 'text';
344
- const inputMode = shouldFormatType(this.type) ? 'decimal'
345
- : this.type === 'email' ? 'email'
346
- : this.type === 'tel' ? 'tel'
347
- : this.type === 'url' ? 'url'
348
- : undefined;
349
- const displayValue = this.getDisplayValue();
350
- if (existingInput && existingWrapper) {
351
- existingInput.type = inputType;
352
- existingInput.value = displayValue;
353
- existingInput.placeholder = this.placeholder;
354
- existingInput.name = this.name;
355
- if (inputMode)
356
- existingInput.inputMode = inputMode;
357
- else
358
- existingInput.removeAttribute('inputmode');
359
- existingWrapper.className = `input-wrapper ${classes}`;
360
- existingInput.disabled = this.disabled;
361
- if (this.disabled) {
362
- existingInput.setAttribute('disabled', '');
363
- }
364
- else {
365
- existingInput.removeAttribute('disabled');
366
- }
367
- existingInput.required = this.required;
368
- if (this.required) {
369
- existingInput.setAttribute('required', '');
370
- }
371
- else {
372
- existingInput.removeAttribute('required');
373
- }
374
- if (this.label)
375
- existingInput.setAttribute('aria-label', this.label);
376
- else
377
- existingInput.removeAttribute('aria-label');
378
- if (this.label) {
379
- if (existingLabel) {
380
- existingLabel.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
381
- existingLabel.style.display = 'flex';
382
- }
383
- else {
384
- const labelEl = document.createElement('label');
385
- labelEl.className = 'ty-field-label';
386
- labelEl.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
387
- const container = shadow.querySelector('.input-container');
388
- if (container) {
389
- container.insertBefore(labelEl, existingWrapper);
390
- }
391
- }
392
- }
393
- else if (existingLabel) {
394
- ;
395
- existingLabel.style.display = 'none';
396
- }
397
- if (this.error) {
398
- if (existingError) {
399
- existingError.textContent = this.error;
400
- }
401
- else {
402
- const errorEl = document.createElement('div');
403
- errorEl.className = 'error-message';
404
- errorEl.textContent = this.error;
405
- shadow.querySelector('.input-container')?.appendChild(errorEl);
406
- }
407
- }
408
- else if (existingError) {
409
- existingError.remove();
410
- }
411
- }
412
- else {
413
- const labelHtml = this.label ? `
414
- <label class="ty-field-label">
415
- ${this.label}
416
- ${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}
417
- </label>
418
- ` : '';
419
- const errorHtml = this.error ? `
420
- <div class="error-message">${this.error}</div>
421
- ` : '';
422
- shadow.innerHTML = `
423
- <div class="input-container">
424
- ${labelHtml}
425
- <div class="input-wrapper ${classes}">
426
- <slot name="start"></slot>
427
- <input
428
- type="${inputType}"
429
- value="${displayValue}"
430
- placeholder="${this.placeholder}"
431
- name="${this.name}"
432
- ${inputMode ? `inputmode="${inputMode}"` : ''}
433
- />
434
- <slot name="end"></slot>
435
- ${inputType === 'password' ? `
436
- <button class="password-toggle" type="button"
437
- aria-label="Show password" aria-pressed="false">
438
- ${EYE_ICON_SVG}
439
- </button>` : ''}
440
- </div>
441
- ${errorHtml}
442
- </div>
443
- `;
444
- const inputEl = shadow.querySelector('input');
445
- inputEl.disabled = this.disabled;
446
- inputEl.required = this.required;
447
- if (this.label)
448
- inputEl.setAttribute('aria-label', this.label);
449
- this.setupPasswordToggle();
450
- this.setupEventListeners();
451
- }
452
- this.updateValidity();
453
- }
454
- setupPasswordToggle() {
455
- const shadow = this.shadowRoot;
456
- const toggle = shadow.querySelector('.password-toggle');
457
- const inputEl = shadow.querySelector('input');
458
- if (!toggle || !inputEl)
459
- return;
460
- toggle.addEventListener('mousedown', (e) => e.preventDefault());
461
- toggle.addEventListener('click', () => {
462
- const reveal = inputEl.type === 'password';
463
- inputEl.type = reveal ? 'text' : 'password';
464
- toggle.innerHTML = reveal ? EYE_OFF_ICON_SVG : EYE_ICON_SVG;
465
- toggle.setAttribute('aria-label', reveal ? 'Hide password' : 'Show password');
466
- toggle.setAttribute('aria-pressed', String(reveal));
467
- });
468
- }
469
- updateValidity() {
470
- const inputEl = this.shadowRoot?.querySelector('input');
471
- if (this.disabled) {
472
- this._internals.setValidity({});
473
- return;
474
- }
475
- const current = inputEl ? inputEl.value : String(this.getProperty('value') ?? '');
476
- if (this.required && current.trim() === '') {
477
- this._internals.setValidity({ valueMissing: true }, 'Please fill out this field', inputEl ?? undefined);
478
- }
479
- else {
480
- this._internals.setValidity({});
481
- }
482
- }
12
+ constructor() {
13
+ super();
14
+ this._shadowValue = null;
15
+ this._isFocused = false;
16
+ this._listenersSetup = false;
17
+ this._errorAutoDanger = false;
18
+ this._customFlavorSheet = null;
19
+ this._inputHandler = null;
20
+ this._changeHandler = null;
21
+ this._focusHandler = null;
22
+ this._blurHandler = null;
23
+ this._inputDebounceTimer = null;
24
+ this._changeDebounceTimer = null;
25
+ const shadow = this.shadowRoot;
26
+ ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
27
+ }
28
+ onConnect() {
29
+ this.initializeShadowValue();
30
+ this._localeObserver = observeLocaleChanges(this, () => {
31
+ this.render();
32
+ });
33
+ this._syncCustomFlavor();
34
+ }
35
+ _syncCustomFlavor() {
36
+ this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => inputCustomFlavorCss(base));
37
+ }
38
+ onDisconnect() {
39
+ this.removeEventListeners();
40
+ if (this._localeObserver) {
41
+ this._localeObserver();
42
+ this._localeObserver = undefined;
43
+ }
44
+ if (this._inputDebounceTimer !== null) {
45
+ clearTimeout(this._inputDebounceTimer);
46
+ this._inputDebounceTimer = null;
47
+ }
48
+ if (this._changeDebounceTimer !== null) {
49
+ clearTimeout(this._changeDebounceTimer);
50
+ this._changeDebounceTimer = null;
51
+ }
52
+ }
53
+ onPropertiesChanged(changes) {
54
+ for (const { name, newValue } of changes) {
55
+ switch (name) {
56
+ case 'flavor':
57
+ this._syncCustomFlavor();
58
+ break;
59
+ case 'value':
60
+ this._shadowValue = this.parseShadowValue(newValue || '');
61
+ break;
62
+ case 'type':
63
+ const currentValue = this.getProperty('value') || '';
64
+ this._shadowValue = this.parseShadowValue(currentValue);
65
+ break;
66
+ case 'error':
67
+ if (newValue) {
68
+ if (this.getProperty('flavor') === 'neutral') {
69
+ this.setProperty('flavor', 'danger');
70
+ this._errorAutoDanger = true;
71
+ }
72
+ }
73
+ else if (this._errorAutoDanger) {
74
+ if (this.getProperty('flavor') === 'danger') {
75
+ this.setProperty('flavor', 'neutral');
76
+ }
77
+ this._errorAutoDanger = false;
78
+ }
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ onFormReset() {
84
+ this._shadowValue = null;
85
+ this.initializeShadowValue();
86
+ this._isFocused = false;
87
+ if (this._inputDebounceTimer !== null) {
88
+ clearTimeout(this._inputDebounceTimer);
89
+ this._inputDebounceTimer = null;
90
+ }
91
+ if (this._changeDebounceTimer !== null) {
92
+ clearTimeout(this._changeDebounceTimer);
93
+ this._changeDebounceTimer = null;
94
+ }
95
+ this.render();
96
+ }
97
+ getFormValue() {
98
+ const formValue = this._shadowValue !== null ? String(this._shadowValue) : null;
99
+ return formValue;
100
+ }
101
+ initializeShadowValue() {
102
+ const currentValue = this.getProperty('value');
103
+ if (currentValue) {
104
+ this._shadowValue = this.parseShadowValue(currentValue);
105
+ this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
106
+ }
107
+ }
108
+ parseShadowValue(value) {
109
+ if (!value || typeof value !== 'string' || value.trim() === '')
110
+ return null;
111
+ if (shouldFormatType(this.type)) {
112
+ const parsed = parseNumericValue(value);
113
+ if (parsed !== null && this.precision === 0) {
114
+ return Math.round(parsed);
115
+ }
116
+ return parsed;
117
+ }
118
+ return value;
119
+ }
120
+ shouldFormat() {
121
+ return shouldFormatType(this.type) &&
122
+ !this._isFocused &&
123
+ this._shadowValue !== null &&
124
+ typeof this._shadowValue === 'number';
125
+ }
126
+ getFormatConfig() {
127
+ return {
128
+ type: this.type,
129
+ locale: this.locale,
130
+ currency: this.currency,
131
+ precision: this.precision
132
+ };
133
+ }
134
+ getDisplayValue() {
135
+ if (this.shouldFormat()) {
136
+ let valueToFormat = this._shadowValue;
137
+ if (this.type === 'percent') {
138
+ valueToFormat = valueToFormat / 100;
139
+ }
140
+ return formatNumber(valueToFormat, this.getFormatConfig());
141
+ }
142
+ return this._shadowValue !== null ? String(this._shadowValue) : '';
143
+ }
144
+ get type() { return this.getProperty('type'); }
145
+ set type(v) { this.setProperty('type', v); }
146
+ get value() {
147
+ return this._shadowValue !== null ? String(this._shadowValue) : '';
148
+ }
149
+ set value(v) { this.setProperty('value', v); }
150
+ get name() { return this.getProperty('name'); }
151
+ set name(v) { this.setProperty('name', v); }
152
+ get placeholder() { return this.getProperty('placeholder'); }
153
+ set placeholder(v) { this.setProperty('placeholder', v); }
154
+ get label() { return this.getProperty('label'); }
155
+ set label(v) { this.setProperty('label', v); }
156
+ get disabled() { return this.getProperty('disabled'); }
157
+ set disabled(v) { this.setProperty('disabled', v); }
158
+ get required() { return this.getProperty('required'); }
159
+ set required(v) { this.setProperty('required', v); }
160
+ get error() { return this.getProperty('error'); }
161
+ set error(v) { this.setProperty('error', v); }
162
+ get size() { return this.getProperty('size'); }
163
+ set size(v) { this.setProperty('size', v); }
164
+ get flavor() { return this.getProperty('flavor'); }
165
+ set flavor(v) { this.setProperty('flavor', v); }
166
+ get currency() { return this.getProperty('currency'); }
167
+ set currency(v) { this.setProperty('currency', v); }
168
+ get locale() {
169
+ return getEffectiveLocale(this, this.getProperty('locale'));
170
+ }
171
+ set locale(v) { this.setProperty('locale', v); }
172
+ get precision() { return this.getProperty('precision'); }
173
+ set precision(v) { this.setProperty('precision', v); }
174
+ get debounce() { return this.getProperty('debounce'); }
175
+ set debounce(v) { this.setProperty('debounce', v); }
176
+ get form() {
177
+ return this._internals.form;
178
+ }
179
+ buildClassList() {
180
+ const classes = [];
181
+ if (this.disabled)
182
+ classes.push('disabled');
183
+ if (this.required)
184
+ classes.push('required');
185
+ if (this.error)
186
+ classes.push('error');
187
+ return classes.join(' ');
188
+ }
189
+ dispatchInputEvent(rawValue, originalEvent) {
190
+ this.dispatchEvent(new CustomEvent('input', {
191
+ detail: {
192
+ value: this._shadowValue,
193
+ formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
194
+ rawValue: rawValue,
195
+ originalEvent: originalEvent
196
+ },
197
+ bubbles: true,
198
+ composed: true
199
+ }));
200
+ }
201
+ dispatchChangeEvent(rawValue, originalEvent) {
202
+ this.dispatchEvent(new CustomEvent('change', {
203
+ detail: {
204
+ value: this._shadowValue,
205
+ formattedValue: this.shouldFormat() ? this.getDisplayValue() : null,
206
+ rawValue: rawValue,
207
+ originalEvent: originalEvent
208
+ },
209
+ bubbles: true,
210
+ composed: true
211
+ }));
212
+ }
213
+ removeEventListeners() {
214
+ if (!this._listenersSetup)
215
+ return;
216
+ const shadow = this.shadowRoot;
217
+ if (!shadow)
218
+ return;
219
+ const inputEl = shadow.querySelector('input');
220
+ if (!inputEl)
221
+ return;
222
+ if (this._inputHandler) {
223
+ inputEl.removeEventListener('input', this._inputHandler);
224
+ this._inputHandler = null;
225
+ }
226
+ if (this._changeHandler) {
227
+ inputEl.removeEventListener('change', this._changeHandler);
228
+ this._changeHandler = null;
229
+ }
230
+ if (this._focusHandler) {
231
+ inputEl.removeEventListener('focus', this._focusHandler);
232
+ this._focusHandler = null;
233
+ }
234
+ if (this._blurHandler) {
235
+ inputEl.removeEventListener('blur', this._blurHandler);
236
+ this._blurHandler = null;
237
+ }
238
+ this._listenersSetup = false;
239
+ }
240
+ setupEventListeners() {
241
+ if (this._listenersSetup) {
242
+ return;
243
+ }
244
+ const shadow = this.shadowRoot;
245
+ const inputEl = shadow.querySelector('input');
246
+ const wrapperEl = shadow.querySelector('.input-wrapper');
247
+ if (!inputEl || !wrapperEl) {
248
+ console.warn('[TyInput.setupEventListeners] ⚠️ Input element not found!');
249
+ return;
250
+ }
251
+ this._inputHandler = (e) => {
252
+ e.stopPropagation();
253
+ e.stopImmediatePropagation();
254
+ const target = e.target;
255
+ const rawValue = target.value;
256
+ this._shadowValue = this.parseShadowValue(rawValue);
257
+ this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
258
+ this.updateValidity();
259
+ if (this._inputDebounceTimer !== null) {
260
+ clearTimeout(this._inputDebounceTimer);
261
+ }
262
+ if (this.debounce > 0) {
263
+ this._inputDebounceTimer = window.setTimeout(() => {
264
+ this.dispatchInputEvent(inputEl.value, e);
265
+ this._inputDebounceTimer = null;
266
+ }, this.debounce);
267
+ }
268
+ else {
269
+ this.dispatchInputEvent(rawValue, e);
270
+ }
271
+ };
272
+ this._changeHandler = (e) => {
273
+ e.stopPropagation();
274
+ e.stopImmediatePropagation();
275
+ const target = e.target;
276
+ const rawValue = target.value;
277
+ this._shadowValue = this.parseShadowValue(rawValue);
278
+ this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : null);
279
+ this.updateValidity();
280
+ if (this._changeDebounceTimer !== null) {
281
+ clearTimeout(this._changeDebounceTimer);
282
+ }
283
+ if (this.debounce > 0) {
284
+ this._changeDebounceTimer = window.setTimeout(() => {
285
+ this.dispatchChangeEvent(inputEl.value, e);
286
+ this._changeDebounceTimer = null;
287
+ }, this.debounce);
288
+ }
289
+ else {
290
+ this.dispatchChangeEvent(rawValue, e);
291
+ }
292
+ };
293
+ this._focusHandler = (e) => {
294
+ this._isFocused = true;
295
+ wrapperEl.classList.add('focused');
296
+ if (shouldFormatType(this.type) && this._shadowValue !== null) {
297
+ inputEl.value = String(this._shadowValue);
298
+ }
299
+ this.dispatchEvent(new CustomEvent('focus', {
300
+ detail: { originalEvent: e },
301
+ bubbles: true,
302
+ composed: true
303
+ }));
304
+ };
305
+ this._blurHandler = (e) => {
306
+ const target = e.target;
307
+ const rawValue = target.value;
308
+ if (this._inputDebounceTimer !== null) {
309
+ clearTimeout(this._inputDebounceTimer);
310
+ this._inputDebounceTimer = null;
311
+ this.dispatchInputEvent(rawValue, e);
312
+ }
313
+ if (this._changeDebounceTimer !== null) {
314
+ clearTimeout(this._changeDebounceTimer);
315
+ this._changeDebounceTimer = null;
316
+ this.dispatchChangeEvent(rawValue, e);
317
+ }
318
+ this._isFocused = false;
319
+ wrapperEl.classList.remove('focused');
320
+ if (this.shouldFormat()) {
321
+ inputEl.value = this.getDisplayValue();
322
+ }
323
+ this.dispatchEvent(new CustomEvent('blur', {
324
+ detail: { originalEvent: e },
325
+ bubbles: true,
326
+ composed: true
327
+ }));
328
+ };
329
+ inputEl.addEventListener('input', this._inputHandler);
330
+ inputEl.addEventListener('change', this._changeHandler);
331
+ inputEl.addEventListener('focus', this._focusHandler);
332
+ inputEl.addEventListener('blur', this._blurHandler);
333
+ this._listenersSetup = true;
334
+ }
335
+ render() {
336
+ const shadow = this.shadowRoot;
337
+ const existingInput = shadow.querySelector('input');
338
+ const existingWrapper = shadow.querySelector('.input-wrapper');
339
+ const existingLabel = shadow.querySelector('.ty-field-label');
340
+ const existingError = shadow.querySelector('.error-message');
341
+ const classes = this.buildClassList();
342
+ const inputType = ['password', 'email', 'tel', 'url'].includes(this.type)
343
+ ? this.type
344
+ : 'text';
345
+ const inputMode = shouldFormatType(this.type) ? 'decimal'
346
+ : this.type === 'email' ? 'email'
347
+ : this.type === 'tel' ? 'tel'
348
+ : this.type === 'url' ? 'url'
349
+ : undefined;
350
+ const displayValue = this.getDisplayValue();
351
+ if (existingInput && existingWrapper) {
352
+ existingInput.type = inputType;
353
+ existingInput.value = displayValue;
354
+ existingInput.placeholder = this.placeholder;
355
+ existingInput.name = this.name;
356
+ if (inputMode)
357
+ existingInput.inputMode = inputMode;
358
+ else
359
+ existingInput.removeAttribute('inputmode');
360
+ existingWrapper.className = `input-wrapper ${classes}`;
361
+ existingInput.disabled = this.disabled;
362
+ if (this.disabled) {
363
+ existingInput.setAttribute('disabled', '');
364
+ }
365
+ else {
366
+ existingInput.removeAttribute('disabled');
367
+ }
368
+ existingInput.required = this.required;
369
+ if (this.required) {
370
+ existingInput.setAttribute('required', '');
371
+ }
372
+ else {
373
+ existingInput.removeAttribute('required');
374
+ }
375
+ if (this.label)
376
+ existingInput.setAttribute('aria-label', this.label);
377
+ else
378
+ existingInput.removeAttribute('aria-label');
379
+ if (this.label) {
380
+ if (existingLabel) {
381
+ existingLabel.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
382
+ existingLabel.style.display = 'flex';
383
+ }
384
+ else {
385
+ const labelEl = document.createElement('label');
386
+ labelEl.className = 'ty-field-label';
387
+ labelEl.innerHTML = `${this.label}${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}`;
388
+ const container = shadow.querySelector('.input-container');
389
+ if (container) {
390
+ container.insertBefore(labelEl, existingWrapper);
391
+ }
392
+ }
393
+ }
394
+ else if (existingLabel) {
395
+ ;
396
+ existingLabel.style.display = 'none';
397
+ }
398
+ if (this.error) {
399
+ if (existingError) {
400
+ existingError.textContent = this.error;
401
+ }
402
+ else {
403
+ const errorEl = document.createElement('div');
404
+ errorEl.className = 'error-message';
405
+ errorEl.textContent = this.error;
406
+ shadow.querySelector('.input-container')?.appendChild(errorEl);
407
+ }
408
+ }
409
+ else if (existingError) {
410
+ existingError.remove();
411
+ }
412
+ }
413
+ else {
414
+ const labelHtml = this.label ? `
415
+ <label class="ty-field-label">
416
+ ${this.label}
417
+ ${this.required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ''}
418
+ </label>
419
+ ` : '';
420
+ const errorHtml = this.error ? `
421
+ <div class="error-message">${this.error}</div>
422
+ ` : '';
423
+ shadow.innerHTML = `
424
+ <div class="input-container">
425
+ ${labelHtml}
426
+ <div class="input-wrapper ${classes}">
427
+ <slot name="start"></slot>
428
+ <input
429
+ type="${inputType}"
430
+ value="${displayValue}"
431
+ placeholder="${this.placeholder}"
432
+ name="${this.name}"
433
+ ${inputMode ? `inputmode="${inputMode}"` : ''}
434
+ />
435
+ <slot name="end"></slot>
436
+ ${inputType === 'password' ? `
437
+ <button class="password-toggle" type="button"
438
+ aria-label="Show password" aria-pressed="false">
439
+ ${EYE_ICON_SVG}
440
+ </button>` : ''}
441
+ </div>
442
+ ${errorHtml}
443
+ </div>
444
+ `;
445
+ const inputEl = shadow.querySelector('input');
446
+ inputEl.disabled = this.disabled;
447
+ inputEl.required = this.required;
448
+ if (this.label)
449
+ inputEl.setAttribute('aria-label', this.label);
450
+ this.setupPasswordToggle();
451
+ this.setupEventListeners();
452
+ }
453
+ this.updateValidity();
454
+ }
455
+ setupPasswordToggle() {
456
+ const shadow = this.shadowRoot;
457
+ const toggle = shadow.querySelector('.password-toggle');
458
+ const inputEl = shadow.querySelector('input');
459
+ if (!toggle || !inputEl)
460
+ return;
461
+ toggle.addEventListener('mousedown', (e) => e.preventDefault());
462
+ toggle.addEventListener('click', () => {
463
+ const reveal = inputEl.type === 'password';
464
+ inputEl.type = reveal ? 'text' : 'password';
465
+ toggle.innerHTML = reveal ? EYE_OFF_ICON_SVG : EYE_ICON_SVG;
466
+ toggle.setAttribute('aria-label', reveal ? 'Hide password' : 'Show password');
467
+ toggle.setAttribute('aria-pressed', String(reveal));
468
+ });
469
+ }
470
+ updateValidity() {
471
+ const inputEl = this.shadowRoot?.querySelector('input');
472
+ if (this.disabled) {
473
+ this.applyValidity({});
474
+ return;
475
+ }
476
+ const current = inputEl ? inputEl.value : String(this.getProperty('value') ?? '');
477
+ if (this.required && current.trim() === '') {
478
+ this.applyValidity({ valueMissing: true }, 'Please fill out this field', inputEl ?? undefined);
479
+ }
480
+ else {
481
+ this.applyValidity({});
482
+ }
483
+ }
483
484
  }
484
485
  TyInput.formAssociated = true;
485
486
  TyInput.properties = {
486
- type: {
487
- type: 'string',
488
- visual: true,
489
- default: 'text',
490
- validate: (v) => {
491
- const validTypes = [
492
- 'text', 'email', 'password', 'number', 'tel', 'url',
493
- 'currency', 'percent', 'compact'
494
- ];
495
- return validTypes.includes(v);
496
- },
497
- coerce: (v) => {
498
- const validTypes = [
499
- 'text', 'email', 'password', 'number', 'tel', 'url',
500
- 'currency', 'percent', 'compact'
501
- ];
502
- if (!validTypes.includes(v)) {
503
- console.warn(`[ty-input] Invalid type '${v}'. Using 'text'.`);
504
- return 'text';
505
- }
506
- return v;
507
- }
508
- },
509
- value: {
510
- type: 'string',
511
- visual: true,
512
- formValue: true,
513
- emitChange: true,
514
- default: ''
515
- },
516
- name: {
517
- type: 'string',
518
- default: ''
519
- },
520
- placeholder: {
521
- type: 'string',
522
- visual: true,
523
- default: ''
524
- },
525
- label: {
526
- type: 'string',
527
- visual: true,
528
- default: ''
529
- },
530
- disabled: {
531
- type: 'boolean',
532
- visual: true,
533
- default: false
534
- },
535
- required: {
536
- type: 'boolean',
537
- visual: true,
538
- default: false
539
- },
540
- error: {
541
- type: 'string',
542
- visual: true,
543
- default: ''
544
- },
545
- size: {
546
- type: 'string',
547
- visual: true,
548
- default: 'md',
549
- validate: (v) => ['sm', 'md', 'lg'].includes(v),
550
- coerce: (v) => {
551
- if (v === 'xs')
552
- return 'sm';
553
- if (v === 'xl')
554
- return 'lg';
555
- if (!['sm', 'md', 'lg'].includes(v)) {
556
- console.warn(`[ty-input] Invalid size '${v}'. Using 'md'.`);
557
- return 'md';
558
- }
559
- return v;
560
- }
561
- },
562
- flavor: {
563
- type: 'string',
564
- visual: true,
565
- default: 'neutral'
566
- },
567
- currency: {
568
- type: 'string',
569
- visual: true,
570
- default: 'USD'
571
- },
572
- locale: {
573
- type: 'string',
574
- visual: true,
575
- default: 'en-US'
576
- },
577
- precision: {
578
- type: 'number',
579
- visual: true,
580
- default: undefined,
581
- validate: (v) => {
582
- if (v === undefined || v === null)
583
- return true;
584
- return typeof v === 'number' && v >= 0 && v <= 10;
585
- },
586
- coerce: (v) => {
587
- if (v === undefined || v === null)
588
- return undefined;
589
- const num = Number(v);
590
- if (isNaN(num))
591
- return undefined;
592
- return Math.max(0, Math.min(10, Math.floor(num)));
593
- }
594
- },
595
- debounce: {
596
- type: 'number',
597
- default: 0,
598
- validate: (v) => {
599
- const num = Number(v);
600
- return !isNaN(num) && num >= 0 && num <= 5000;
601
- },
602
- coerce: (v) => {
603
- const num = Number(v);
604
- if (isNaN(num))
605
- return 0;
606
- return Math.max(0, Math.min(5000, Math.floor(num)));
607
- }
608
- }
487
+ type: {
488
+ type: 'string',
489
+ visual: true,
490
+ default: 'text',
491
+ validate: (v) => {
492
+ const validTypes = [
493
+ 'text', 'email', 'password', 'number', 'tel', 'url',
494
+ 'currency', 'percent', 'compact'
495
+ ];
496
+ return validTypes.includes(v);
497
+ },
498
+ coerce: (v) => {
499
+ const validTypes = [
500
+ 'text', 'email', 'password', 'number', 'tel', 'url',
501
+ 'currency', 'percent', 'compact'
502
+ ];
503
+ if (!validTypes.includes(v)) {
504
+ console.warn(`[ty-input] Invalid type '${v}'. Using 'text'.`);
505
+ return 'text';
506
+ }
507
+ return v;
508
+ }
509
+ },
510
+ value: {
511
+ type: 'string',
512
+ visual: true,
513
+ formValue: true,
514
+ emitChange: true,
515
+ default: ''
516
+ },
517
+ name: {
518
+ type: 'string',
519
+ default: ''
520
+ },
521
+ placeholder: {
522
+ type: 'string',
523
+ visual: true,
524
+ default: ''
525
+ },
526
+ label: {
527
+ type: 'string',
528
+ visual: true,
529
+ default: ''
530
+ },
531
+ disabled: {
532
+ type: 'boolean',
533
+ visual: true,
534
+ default: false
535
+ },
536
+ required: {
537
+ type: 'boolean',
538
+ visual: true,
539
+ default: false
540
+ },
541
+ error: {
542
+ type: 'string',
543
+ visual: true,
544
+ default: ''
545
+ },
546
+ size: {
547
+ type: 'string',
548
+ visual: true,
549
+ default: DEFAULT_SIZE,
550
+ validate: (v) => ["xs", "sm", "md", "lg", "xl"].includes(v),
551
+ coerce: (v) => {
552
+ if (!["xs", "sm", "md", "lg", "xl"].includes(v)) {
553
+ console.warn(`[ty-input] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
554
+ return DEFAULT_SIZE;
555
+ }
556
+ return v;
557
+ }
558
+ },
559
+ flavor: {
560
+ type: 'string',
561
+ visual: true,
562
+ default: 'neutral'
563
+ },
564
+ currency: {
565
+ type: 'string',
566
+ visual: true,
567
+ default: 'USD'
568
+ },
569
+ locale: {
570
+ type: 'string',
571
+ visual: true,
572
+ default: 'en-US'
573
+ },
574
+ precision: {
575
+ type: 'number',
576
+ visual: true,
577
+ default: undefined,
578
+ validate: (v) => {
579
+ if (v === undefined || v === null)
580
+ return true;
581
+ return typeof v === 'number' && v >= 0 && v <= 10;
582
+ },
583
+ coerce: (v) => {
584
+ if (v === undefined || v === null)
585
+ return undefined;
586
+ const num = Number(v);
587
+ if (isNaN(num))
588
+ return undefined;
589
+ return Math.max(0, Math.min(10, Math.floor(num)));
590
+ }
591
+ },
592
+ debounce: {
593
+ type: 'number',
594
+ default: 0,
595
+ validate: (v) => {
596
+ const num = Number(v);
597
+ return !isNaN(num) && num >= 0 && num <= 5000;
598
+ },
599
+ coerce: (v) => {
600
+ const num = Number(v);
601
+ if (isNaN(num))
602
+ return 0;
603
+ return Math.max(0, Math.min(5000, Math.floor(num)));
604
+ }
605
+ }
609
606
  };
610
607
  if (!customElements.get('ty-input')) {
611
- customElements.define('ty-input', TyInput);
608
+ customElements.define('ty-input', TyInput);
612
609
  }