tyrell-components 1.0.0-TC52 → 1.0.0-TC53
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.
- package/css/tyrell-theme.css +25 -2
- package/css/tyrell.css +4 -0
- package/dist/tyrell-colors-static.css +1 -316
- package/dist/tyrell-theme.css +1 -1443
- package/dist/tyrell.css +1 -1390
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.js +196 -196
- package/lib/components/button.d.ts +1 -1
- package/lib/components/button.js +260 -259
- package/lib/components/calendar-month.d.ts +2 -2
- package/lib/components/calendar-month.js +426 -416
- package/lib/components/calendar-navigation.js +238 -238
- package/lib/components/calendar.js +605 -602
- package/lib/components/checkbox.d.ts +1 -1
- package/lib/components/checkbox.js +273 -272
- package/lib/components/copy.d.ts +1 -1
- package/lib/components/copy.js +279 -278
- package/lib/components/date-picker.d.ts +1 -1
- package/lib/components/date-picker.js +1103 -1108
- package/lib/components/file-upload.js +404 -404
- package/lib/components/icon.js +141 -141
- package/lib/components/input.d.ts +1 -1
- package/lib/components/input.js +593 -596
- package/lib/components/modal.js +319 -319
- package/lib/components/option.js +167 -167
- package/lib/components/popup.js +233 -233
- package/lib/components/radio.d.ts +2 -2
- package/lib/components/radio.js +407 -406
- package/lib/components/resize-observer.js +67 -67
- package/lib/components/scroll-container.js +294 -294
- package/lib/components/select.d.ts +1 -1
- package/lib/components/select.js +1524 -1532
- package/lib/components/selected-tags.js +184 -184
- package/lib/components/step.js +62 -62
- package/lib/components/switch.d.ts +1 -1
- package/lib/components/switch.js +214 -213
- package/lib/components/tab.js +62 -62
- package/lib/components/tabs.js +507 -507
- package/lib/components/tag.d.ts +1 -1
- package/lib/components/tag.js +236 -235
- package/lib/components/textarea.d.ts +1 -1
- package/lib/components/textarea.js +457 -456
- package/lib/components/tooltip.js +283 -283
- package/lib/components/wizard.js +384 -384
- package/lib/icons/heroicons/micro.js +392 -392
- package/lib/icons/heroicons/mini.js +382 -382
- package/lib/icons/heroicons/outline.js +337 -337
- package/lib/icons/heroicons/solid.js +407 -407
- package/lib/icons/lucide.js +22843 -22843
- package/lib/icons/material/filled.js +9653 -9653
- package/lib/icons/material/outlined.js +10271 -10271
- package/lib/icons/material/round.js +10495 -10495
- package/lib/icons/material/sharp.js +9905 -9905
- package/lib/icons/material/two-tone.js +12792 -12792
- package/lib/index.js +21 -21
- package/lib/styles/button.js +176 -288
- package/lib/styles/calendar-month.js +123 -183
- package/lib/styles/calendar-navigation.js +60 -79
- package/lib/styles/calendar.js +8 -9
- package/lib/styles/checkbox.js +45 -72
- package/lib/styles/copy.js +67 -91
- package/lib/styles/custom-scrollbar.js +80 -100
- package/lib/styles/date-picker.js +261 -331
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.js +139 -169
- package/lib/styles/icon.js +92 -156
- package/lib/styles/input.js +125 -241
- package/lib/styles/modal.js +67 -102
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +47 -67
- package/lib/styles/popup.js +34 -65
- package/lib/styles/radio.js +69 -96
- package/lib/styles/resize-observer.js +2 -5
- package/lib/styles/scroll-container.js +100 -130
- package/lib/styles/select-base.js +525 -778
- package/lib/styles/select.js +140 -228
- package/lib/styles/step.js +22 -29
- package/lib/styles/switch.js +34 -55
- package/lib/styles/tab.js +22 -29
- package/lib/styles/tabs.js +171 -252
- package/lib/styles/tag.js +135 -188
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +205 -271
- package/lib/styles/tooltip.js +3 -3
- package/lib/styles/wizard.js +170 -226
- package/lib/types/common.d.ts +2 -0
- package/lib/types/common.js +6 -5
- package/lib/utils/calendar-utils.js +100 -100
- package/lib/utils/custom-scrollbar.js +272 -272
- package/lib/utils/flavor-sheet.js +14 -14
- package/lib/utils/icon-registry.js +127 -127
- package/lib/utils/loader-registry.js +3 -3
- package/lib/utils/locale.js +34 -34
- package/lib/utils/mobile.js +1 -1
- package/lib/utils/number-format.js +54 -54
- package/lib/utils/positioning.js +212 -212
- package/lib/utils/property-capture.js +36 -36
- package/lib/utils/property-manager.js +125 -125
- package/lib/utils/resize-observer.js +23 -23
- package/lib/utils/scroll-lock.js +57 -57
- package/lib/utils/styles.js +17 -17
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +4 -4
|
@@ -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 { textareaStyles } from '../styles/textarea.js';
|
|
@@ -5,465 +6,465 @@ import { CustomScrollbar, isCustomScrollbarEnabled } from '../utils/custom-scrol
|
|
|
5
6
|
import { customScrollbarStyles } from '../styles/custom-scrollbar.js';
|
|
6
7
|
const REQUIRED_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg>`;
|
|
7
8
|
export class TyTextarea extends TyComponent {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._textareaEl = null;
|
|
12
|
+
this._dummyEl = null;
|
|
13
|
+
this._scrollbar = null;
|
|
14
|
+
this._isFocused = false;
|
|
15
|
+
this.handleInputEvent = (e) => {
|
|
16
|
+
const target = e.target;
|
|
17
|
+
const newValue = target.value;
|
|
18
|
+
this.value = newValue;
|
|
19
|
+
if (this._textareaEl && this._dummyEl) {
|
|
20
|
+
this.resizeTextarea(this._textareaEl, this._dummyEl);
|
|
21
|
+
}
|
|
22
|
+
this.emitValueEvents(e);
|
|
23
|
+
};
|
|
24
|
+
this.handleFocusEvent = () => {
|
|
25
|
+
this._isFocused = true;
|
|
26
|
+
};
|
|
27
|
+
this.handleBlurEvent = () => {
|
|
28
|
+
this._isFocused = false;
|
|
29
|
+
};
|
|
30
|
+
const shadow = this.shadowRoot;
|
|
31
|
+
ensureStyles(shadow, { css: textareaStyles, id: 'ty-textarea' });
|
|
32
|
+
if (isCustomScrollbarEnabled()) {
|
|
33
|
+
ensureStyles(shadow, { css: customScrollbarStyles, id: 'ty-custom-scrollbar' });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
onConnect() {
|
|
37
|
+
}
|
|
38
|
+
onDisconnect() {
|
|
39
|
+
this._destroyScrollbar();
|
|
40
|
+
if (this._textareaEl) {
|
|
41
|
+
const newTextarea = this._textareaEl.cloneNode(true);
|
|
42
|
+
this._textareaEl.parentNode?.replaceChild(newTextarea, this._textareaEl);
|
|
43
|
+
this._textareaEl = null;
|
|
44
|
+
}
|
|
45
|
+
this._dummyEl = null;
|
|
46
|
+
}
|
|
47
|
+
onPropertiesChanged(changes) {
|
|
48
|
+
}
|
|
49
|
+
getFormValue() {
|
|
50
|
+
return this.getProperty('value') || null;
|
|
51
|
+
}
|
|
52
|
+
get value() { return this.getProperty('value'); }
|
|
53
|
+
set value(v) { this.setProperty('value', v); }
|
|
54
|
+
get name() { return this.getProperty('name'); }
|
|
55
|
+
set name(v) { this.setProperty('name', v); }
|
|
56
|
+
get placeholder() { return this.getProperty('placeholder'); }
|
|
57
|
+
set placeholder(v) { this.setProperty('placeholder', v); }
|
|
58
|
+
get label() { return this.getProperty('label'); }
|
|
59
|
+
set label(v) { this.setProperty('label', v); }
|
|
60
|
+
get disabled() { return this.getProperty('disabled'); }
|
|
61
|
+
set disabled(v) { this.setProperty('disabled', v); }
|
|
62
|
+
get required() { return this.getProperty('required'); }
|
|
63
|
+
set required(v) { this.setProperty('required', v); }
|
|
64
|
+
get error() { return this.getProperty('error'); }
|
|
65
|
+
set error(v) { this.setProperty('error', v); }
|
|
66
|
+
get size() {
|
|
67
|
+
return this.getProperty('size');
|
|
68
|
+
}
|
|
69
|
+
set size(v) {
|
|
70
|
+
this.setProperty('size', v);
|
|
71
|
+
}
|
|
72
|
+
get rows() { return this.getProperty('rows'); }
|
|
73
|
+
set rows(v) { this.setProperty('rows', v); }
|
|
74
|
+
get cols() { return this.getProperty('cols'); }
|
|
75
|
+
set cols(v) { this.setProperty('cols', v); }
|
|
76
|
+
get resize() {
|
|
77
|
+
return this.getProperty('resize');
|
|
78
|
+
}
|
|
79
|
+
set resize(v) {
|
|
80
|
+
this.setProperty('resize', v);
|
|
81
|
+
}
|
|
82
|
+
get minHeight() { return this.getProperty('minHeight'); }
|
|
83
|
+
set minHeight(v) { this.setProperty('minHeight', v); }
|
|
84
|
+
get maxHeight() { return this.getProperty('maxHeight'); }
|
|
85
|
+
set maxHeight(v) { this.setProperty('maxHeight', v); }
|
|
86
|
+
getFontStyle(el) {
|
|
87
|
+
const computedStyle = window.getComputedStyle(el);
|
|
88
|
+
return {
|
|
89
|
+
fontFamily: computedStyle.fontFamily,
|
|
90
|
+
fontSize: computedStyle.fontSize,
|
|
91
|
+
fontWeight: computedStyle.fontWeight,
|
|
92
|
+
lineHeight: computedStyle.lineHeight,
|
|
93
|
+
letterSpacing: computedStyle.letterSpacing,
|
|
94
|
+
fontStyle: computedStyle.fontStyle
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
getSpacingStyle(el) {
|
|
98
|
+
const computedStyle = window.getComputedStyle(el);
|
|
99
|
+
return {
|
|
100
|
+
padding: computedStyle.padding,
|
|
101
|
+
paddingTop: computedStyle.paddingTop,
|
|
102
|
+
paddingRight: computedStyle.paddingRight,
|
|
103
|
+
paddingBottom: computedStyle.paddingBottom,
|
|
104
|
+
paddingLeft: computedStyle.paddingLeft,
|
|
105
|
+
margin: computedStyle.margin,
|
|
106
|
+
borderWidth: computedStyle.borderWidth
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
setupDummyElement(textareaEl) {
|
|
110
|
+
const root = this.shadowRoot;
|
|
111
|
+
const existingDummy = root.querySelector('.textarea-dummy');
|
|
112
|
+
if (existingDummy) {
|
|
113
|
+
existingDummy.remove();
|
|
114
|
+
}
|
|
115
|
+
const dummyEl = document.createElement('pre');
|
|
116
|
+
const fontStyle = this.getFontStyle(textareaEl);
|
|
117
|
+
const spacingStyle = this.getSpacingStyle(textareaEl);
|
|
118
|
+
dummyEl.className = 'textarea-dummy';
|
|
119
|
+
const style = dummyEl.style;
|
|
120
|
+
style.position = 'absolute';
|
|
121
|
+
style.top = '0';
|
|
122
|
+
style.left = '0';
|
|
123
|
+
style.visibility = 'hidden';
|
|
124
|
+
style.whiteSpace = 'pre-wrap';
|
|
125
|
+
style.wordBreak = 'break-word';
|
|
126
|
+
style.boxSizing = 'border-box';
|
|
127
|
+
style.overflow = 'hidden';
|
|
128
|
+
style.pointerEvents = 'none';
|
|
129
|
+
Object.entries(fontStyle).forEach(([prop, value]) => {
|
|
130
|
+
;
|
|
131
|
+
style[prop] = value;
|
|
132
|
+
});
|
|
133
|
+
Object.entries(spacingStyle).forEach(([prop, value]) => {
|
|
134
|
+
;
|
|
135
|
+
style[prop] = value;
|
|
136
|
+
});
|
|
137
|
+
root.appendChild(dummyEl);
|
|
138
|
+
this._dummyEl = dummyEl;
|
|
139
|
+
return dummyEl;
|
|
140
|
+
}
|
|
141
|
+
resizeTextarea(textareaEl, dummyEl) {
|
|
142
|
+
if (!textareaEl || !dummyEl)
|
|
143
|
+
return;
|
|
144
|
+
const value = this.value;
|
|
145
|
+
const placeholder = this.placeholder;
|
|
146
|
+
const content = (value === '' && placeholder) ? placeholder : value + ' ';
|
|
147
|
+
const currentHeight = textareaEl.clientHeight;
|
|
148
|
+
dummyEl.textContent = content;
|
|
149
|
+
dummyEl.style.width = `${textareaEl.clientWidth}px`;
|
|
150
|
+
const measuredHeight = dummyEl.scrollHeight;
|
|
151
|
+
const minHeight = this.minHeight ? parseInt(this.minHeight.replace('px', ''), 10) : null;
|
|
152
|
+
const maxHeight = this.maxHeight ? parseInt(this.maxHeight.replace('px', ''), 10) : null;
|
|
153
|
+
let constrainedHeight = measuredHeight;
|
|
154
|
+
if (minHeight !== null)
|
|
155
|
+
constrainedHeight = Math.max(constrainedHeight, minHeight);
|
|
156
|
+
if (maxHeight !== null)
|
|
157
|
+
constrainedHeight = Math.min(constrainedHeight, maxHeight);
|
|
158
|
+
if (Math.abs(constrainedHeight - currentHeight) > 2) {
|
|
159
|
+
textareaEl.style.height = `${constrainedHeight}px`;
|
|
160
|
+
const needsScroll = maxHeight !== null && measuredHeight >= maxHeight;
|
|
161
|
+
if (needsScroll) {
|
|
162
|
+
textareaEl.style.overflowY = 'auto';
|
|
163
|
+
this._setupScrollbar(textareaEl);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
textareaEl.style.overflowY = 'hidden';
|
|
167
|
+
this._destroyScrollbar();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
this._scrollbar?.update();
|
|
171
|
+
}
|
|
172
|
+
_setupScrollbar(textareaEl) {
|
|
173
|
+
if (this._scrollbar || !isCustomScrollbarEnabled())
|
|
174
|
+
return;
|
|
175
|
+
textareaEl.style.scrollbarWidth = 'none';
|
|
176
|
+
this.setAttribute('data-custom-scroll', '');
|
|
177
|
+
this._scrollbar = new CustomScrollbar(textareaEl, {
|
|
178
|
+
vertical: true,
|
|
179
|
+
horizontal: false
|
|
180
|
+
});
|
|
181
|
+
const scroll = this.shadowRoot.querySelector('.textarea-scroll');
|
|
182
|
+
if (scroll && this._scrollbar.trackY) {
|
|
183
|
+
scroll.appendChild(this._scrollbar.trackY);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
_destroyScrollbar() {
|
|
187
|
+
if (!this._scrollbar)
|
|
188
|
+
return;
|
|
189
|
+
this._scrollbar.trackY?.remove();
|
|
190
|
+
this._scrollbar.destroy();
|
|
191
|
+
this._scrollbar = null;
|
|
192
|
+
this.removeAttribute('data-custom-scroll');
|
|
193
|
+
if (this._textareaEl) {
|
|
194
|
+
this._textareaEl.style.scrollbarWidth = '';
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
emitValueEvents(originalEvent) {
|
|
198
|
+
const value = this.value;
|
|
199
|
+
this._internals.setFormValue(value || '');
|
|
200
|
+
this.updateValidity();
|
|
201
|
+
const data = {
|
|
202
|
+
bubbles: true,
|
|
203
|
+
composed: true,
|
|
204
|
+
detail: {
|
|
205
|
+
value,
|
|
206
|
+
originalEvent
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
this.dispatchEvent(new CustomEvent('input', data));
|
|
211
|
+
this.dispatchEvent(new CustomEvent('change', data));
|
|
212
|
+
}, 0);
|
|
213
|
+
}
|
|
214
|
+
buildClassList() {
|
|
215
|
+
const classes = [this.size];
|
|
216
|
+
if (this.disabled)
|
|
217
|
+
classes.push('disabled');
|
|
218
|
+
if (this.required)
|
|
219
|
+
classes.push('required');
|
|
220
|
+
if (this.error)
|
|
221
|
+
classes.push('error');
|
|
222
|
+
if (this.resize !== 'none')
|
|
223
|
+
classes.push(`resize-${this.resize}`);
|
|
224
|
+
const customClass = this.getAttribute('class');
|
|
225
|
+
if (customClass)
|
|
226
|
+
classes.push(customClass);
|
|
227
|
+
return classes.join(' ');
|
|
228
|
+
}
|
|
229
|
+
applyHeightConstraints(textareaEl) {
|
|
230
|
+
if (this.minHeight) {
|
|
231
|
+
textareaEl.style.minHeight = this.minHeight;
|
|
232
|
+
}
|
|
233
|
+
if (this.maxHeight) {
|
|
234
|
+
textareaEl.style.maxHeight = this.maxHeight;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
setupTextareaEvents(textareaEl) {
|
|
238
|
+
textareaEl.addEventListener('input', this.handleInputEvent);
|
|
239
|
+
textareaEl.addEventListener('change', this.handleInputEvent);
|
|
240
|
+
textareaEl.addEventListener('focus', this.handleFocusEvent);
|
|
241
|
+
textareaEl.addEventListener('blur', this.handleBlurEvent);
|
|
242
|
+
}
|
|
243
|
+
render() {
|
|
244
|
+
const root = this.shadowRoot;
|
|
245
|
+
const existingContainer = root.querySelector('.textarea-container');
|
|
246
|
+
const existingLabel = root.querySelector('label');
|
|
247
|
+
const existingTextarea = root.querySelector('textarea');
|
|
248
|
+
const existingError = root.querySelector('.error-message');
|
|
249
|
+
if (existingContainer && existingTextarea) {
|
|
250
|
+
if (this.label) {
|
|
251
|
+
if (existingLabel) {
|
|
252
|
+
existingLabel.innerHTML = this.label +
|
|
253
|
+
(this.required ? ` <span class="required-icon">${REQUIRED_ICON}</span>` : '');
|
|
254
|
+
existingLabel.style.display = 'block';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else if (existingLabel) {
|
|
258
|
+
existingLabel.style.display = 'none';
|
|
259
|
+
}
|
|
260
|
+
existingTextarea.value = this.value || '';
|
|
261
|
+
existingTextarea.placeholder = this.placeholder || '';
|
|
262
|
+
existingTextarea.disabled = this.disabled;
|
|
263
|
+
existingTextarea.required = this.required;
|
|
264
|
+
existingTextarea.className = this.buildClassList();
|
|
265
|
+
if (this.label)
|
|
266
|
+
existingTextarea.setAttribute('aria-label', this.label);
|
|
267
|
+
else
|
|
268
|
+
existingTextarea.removeAttribute('aria-label');
|
|
269
|
+
if (this.name) {
|
|
270
|
+
existingTextarea.setAttribute('name', this.name);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
existingTextarea.removeAttribute('name');
|
|
274
|
+
}
|
|
275
|
+
if (this.rows)
|
|
276
|
+
existingTextarea.setAttribute('rows', this.rows);
|
|
277
|
+
if (this.cols)
|
|
278
|
+
existingTextarea.setAttribute('cols', this.cols);
|
|
279
|
+
this.applyHeightConstraints(existingTextarea);
|
|
280
|
+
if (this.error) {
|
|
281
|
+
if (!existingError) {
|
|
282
|
+
const errorEl = document.createElement('div');
|
|
283
|
+
errorEl.className = 'error-message';
|
|
284
|
+
existingContainer.appendChild(errorEl);
|
|
285
|
+
}
|
|
286
|
+
const errorEl = root.querySelector('.error-message');
|
|
287
|
+
if (errorEl)
|
|
288
|
+
errorEl.textContent = this.error;
|
|
289
|
+
}
|
|
290
|
+
else if (existingError) {
|
|
291
|
+
existingError.remove();
|
|
292
|
+
}
|
|
293
|
+
const dummyEl = this.setupDummyElement(existingTextarea);
|
|
294
|
+
setTimeout(() => this.resizeTextarea(existingTextarea, dummyEl), 0);
|
|
295
|
+
this._textareaEl = existingTextarea;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const container = document.createElement('div');
|
|
299
|
+
container.className = 'textarea-container';
|
|
300
|
+
const labelEl = document.createElement('label');
|
|
301
|
+
labelEl.className = 'ty-field-label';
|
|
302
|
+
if (this.label) {
|
|
303
|
+
labelEl.innerHTML = this.label +
|
|
304
|
+
(this.required ? ` <span class="required-icon">${REQUIRED_ICON}</span>` : '');
|
|
305
|
+
labelEl.style.display = 'block';
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
labelEl.style.display = 'none';
|
|
309
|
+
}
|
|
310
|
+
const textareaEl = document.createElement('textarea');
|
|
311
|
+
textareaEl.value = this.value || '';
|
|
312
|
+
textareaEl.placeholder = this.placeholder || '';
|
|
313
|
+
textareaEl.disabled = this.disabled;
|
|
314
|
+
textareaEl.required = this.required;
|
|
315
|
+
textareaEl.className = this.buildClassList();
|
|
316
|
+
if (this.label)
|
|
317
|
+
textareaEl.setAttribute('aria-label', this.label);
|
|
318
|
+
if (this.name) {
|
|
319
|
+
textareaEl.setAttribute('name', this.name);
|
|
320
|
+
}
|
|
321
|
+
textareaEl.setAttribute('rows', this.rows || '3');
|
|
322
|
+
if (this.cols)
|
|
323
|
+
textareaEl.setAttribute('cols', this.cols);
|
|
324
|
+
this.applyHeightConstraints(textareaEl);
|
|
325
|
+
this.setupTextareaEvents(textareaEl);
|
|
326
|
+
const wrapperEl = document.createElement('div');
|
|
327
|
+
wrapperEl.className = 'textarea-wrapper';
|
|
328
|
+
const headerEl = document.createElement('div');
|
|
329
|
+
headerEl.className = 'textarea-header';
|
|
330
|
+
const headerSlot = document.createElement('slot');
|
|
331
|
+
headerSlot.setAttribute('name', 'header');
|
|
332
|
+
headerEl.appendChild(headerSlot);
|
|
333
|
+
const scrollEl = document.createElement('div');
|
|
334
|
+
scrollEl.className = 'textarea-scroll';
|
|
335
|
+
scrollEl.appendChild(textareaEl);
|
|
336
|
+
const footerEl = document.createElement('div');
|
|
337
|
+
footerEl.className = 'textarea-footer';
|
|
338
|
+
const footerSlot = document.createElement('slot');
|
|
339
|
+
footerSlot.setAttribute('name', 'footer');
|
|
340
|
+
footerEl.appendChild(footerSlot);
|
|
341
|
+
wrapperEl.appendChild(headerEl);
|
|
342
|
+
wrapperEl.appendChild(scrollEl);
|
|
343
|
+
wrapperEl.appendChild(footerEl);
|
|
344
|
+
const syncSlot = (slot, region) => {
|
|
345
|
+
const update = () => region.classList.toggle('has-content', slot.assignedNodes({ flatten: true }).length > 0);
|
|
346
|
+
slot.addEventListener('slotchange', update);
|
|
347
|
+
update();
|
|
348
|
+
};
|
|
349
|
+
syncSlot(headerSlot, headerEl);
|
|
350
|
+
syncSlot(footerSlot, footerEl);
|
|
351
|
+
container.appendChild(labelEl);
|
|
352
|
+
container.appendChild(wrapperEl);
|
|
353
|
+
if (this.error) {
|
|
354
|
+
const errorEl = document.createElement('div');
|
|
355
|
+
errorEl.className = 'error-message';
|
|
356
|
+
errorEl.textContent = this.error;
|
|
357
|
+
container.appendChild(errorEl);
|
|
358
|
+
}
|
|
359
|
+
root.appendChild(container);
|
|
360
|
+
const dummyEl = this.setupDummyElement(textareaEl);
|
|
361
|
+
setTimeout(() => this.resizeTextarea(textareaEl, dummyEl), 0);
|
|
362
|
+
this._textareaEl = textareaEl;
|
|
363
|
+
}
|
|
364
|
+
this.updateValidity();
|
|
365
|
+
}
|
|
366
|
+
updateValidity() {
|
|
367
|
+
const ta = this.shadowRoot?.querySelector('textarea');
|
|
368
|
+
if (this.disabled) {
|
|
369
|
+
this._internals.setValidity({});
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const current = ta ? ta.value : String(this.value ?? '');
|
|
373
|
+
if (this.required && current.trim() === '') {
|
|
374
|
+
this._internals.setValidity({ valueMissing: true }, 'Please fill out this field', ta ?? undefined);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
this._internals.setValidity({});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
379
380
|
}
|
|
380
381
|
TyTextarea.formAssociated = true;
|
|
381
382
|
TyTextarea.properties = {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
383
|
+
value: {
|
|
384
|
+
type: 'string',
|
|
385
|
+
visual: true,
|
|
386
|
+
formValue: true,
|
|
387
|
+
emitChange: true,
|
|
388
|
+
default: ''
|
|
389
|
+
},
|
|
390
|
+
name: {
|
|
391
|
+
type: 'string',
|
|
392
|
+
default: ''
|
|
393
|
+
},
|
|
394
|
+
placeholder: {
|
|
395
|
+
type: 'string',
|
|
396
|
+
visual: true,
|
|
397
|
+
default: ''
|
|
398
|
+
},
|
|
399
|
+
label: {
|
|
400
|
+
type: 'string',
|
|
401
|
+
visual: true,
|
|
402
|
+
default: ''
|
|
403
|
+
},
|
|
404
|
+
disabled: {
|
|
405
|
+
type: 'boolean',
|
|
406
|
+
visual: true,
|
|
407
|
+
default: false
|
|
408
|
+
},
|
|
409
|
+
required: {
|
|
410
|
+
type: 'boolean',
|
|
411
|
+
visual: true,
|
|
412
|
+
default: false
|
|
413
|
+
},
|
|
414
|
+
error: {
|
|
415
|
+
type: 'string',
|
|
416
|
+
visual: true,
|
|
417
|
+
default: ''
|
|
418
|
+
},
|
|
419
|
+
size: {
|
|
420
|
+
type: 'string',
|
|
421
|
+
visual: true,
|
|
422
|
+
default: DEFAULT_SIZE,
|
|
423
|
+
validate: (v) => ['xs', 'sm', 'md', 'lg', 'xl'].includes(v),
|
|
424
|
+
coerce: (v) => {
|
|
425
|
+
if (!['xs', 'sm', 'md', 'lg', 'xl'].includes(v)) {
|
|
426
|
+
console.warn(`[ty-textarea] Invalid size '${v}'. Using '${DEFAULT_SIZE}'.`);
|
|
427
|
+
return DEFAULT_SIZE;
|
|
428
|
+
}
|
|
429
|
+
return v;
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
rows: {
|
|
433
|
+
type: 'string',
|
|
434
|
+
visual: true,
|
|
435
|
+
default: '3',
|
|
436
|
+
coerce: (v) => String(v)
|
|
437
|
+
},
|
|
438
|
+
cols: {
|
|
439
|
+
type: 'string',
|
|
440
|
+
visual: true,
|
|
441
|
+
default: '',
|
|
442
|
+
coerce: (v) => v ? String(v) : ''
|
|
443
|
+
},
|
|
444
|
+
resize: {
|
|
445
|
+
type: 'string',
|
|
446
|
+
visual: true,
|
|
447
|
+
default: 'none',
|
|
448
|
+
validate: (v) => ['none', 'both', 'horizontal', 'vertical'].includes(v),
|
|
449
|
+
coerce: (v) => {
|
|
450
|
+
if (!['none', 'both', 'horizontal', 'vertical'].includes(v)) {
|
|
451
|
+
console.warn(`[ty-textarea] Invalid resize '${v}'. Using 'none'.`);
|
|
452
|
+
return 'none';
|
|
453
|
+
}
|
|
454
|
+
return v;
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
minHeight: {
|
|
458
|
+
type: 'string',
|
|
459
|
+
visual: true,
|
|
460
|
+
default: ''
|
|
461
|
+
},
|
|
462
|
+
maxHeight: {
|
|
463
|
+
type: 'string',
|
|
464
|
+
visual: true,
|
|
465
|
+
default: ''
|
|
466
|
+
}
|
|
466
467
|
};
|
|
467
468
|
if (!customElements.get('ty-textarea')) {
|
|
468
|
-
|
|
469
|
+
customElements.define('ty-textarea', TyTextarea);
|
|
469
470
|
}
|