shirkasoft-ui-components 1.14.0 → 2.0.0

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 (92) hide show
  1. package/README.md +4 -8
  2. package/fesm2022/shirkasoft-ui-components-breadcrumb.mjs +189 -100
  3. package/fesm2022/shirkasoft-ui-components-breadcrumb.mjs.map +1 -1
  4. package/fesm2022/shirkasoft-ui-components-button.mjs +363 -69
  5. package/fesm2022/shirkasoft-ui-components-button.mjs.map +1 -1
  6. package/fesm2022/shirkasoft-ui-components-chart.mjs +206 -142
  7. package/fesm2022/shirkasoft-ui-components-chart.mjs.map +1 -1
  8. package/fesm2022/shirkasoft-ui-components-config.mjs +905 -843
  9. package/fesm2022/shirkasoft-ui-components-config.mjs.map +1 -1
  10. package/fesm2022/shirkasoft-ui-components-confirm-dialog.mjs +307 -142
  11. package/fesm2022/shirkasoft-ui-components-confirm-dialog.mjs.map +1 -1
  12. package/fesm2022/shirkasoft-ui-components-date-picker.mjs +1624 -1440
  13. package/fesm2022/shirkasoft-ui-components-date-picker.mjs.map +1 -1
  14. package/fesm2022/shirkasoft-ui-components-fieldset.mjs +347 -92
  15. package/fesm2022/shirkasoft-ui-components-fieldset.mjs.map +1 -1
  16. package/fesm2022/shirkasoft-ui-components-file-upload.mjs +484 -300
  17. package/fesm2022/shirkasoft-ui-components-file-upload.mjs.map +1 -1
  18. package/fesm2022/shirkasoft-ui-components-icons.mjs +1028 -533
  19. package/fesm2022/shirkasoft-ui-components-icons.mjs.map +1 -1
  20. package/fesm2022/shirkasoft-ui-components-knob.mjs +389 -201
  21. package/fesm2022/shirkasoft-ui-components-knob.mjs.map +1 -1
  22. package/fesm2022/shirkasoft-ui-components-loading.mjs +505 -128
  23. package/fesm2022/shirkasoft-ui-components-loading.mjs.map +1 -1
  24. package/fesm2022/shirkasoft-ui-components-modal.mjs +311 -314
  25. package/fesm2022/shirkasoft-ui-components-modal.mjs.map +1 -1
  26. package/fesm2022/shirkasoft-ui-components-notification.mjs +188 -142
  27. package/fesm2022/shirkasoft-ui-components-notification.mjs.map +1 -1
  28. package/fesm2022/shirkasoft-ui-components-price-input.mjs +517 -327
  29. package/fesm2022/shirkasoft-ui-components-price-input.mjs.map +1 -1
  30. package/fesm2022/shirkasoft-ui-components-rail-sidebar.mjs +669 -289
  31. package/fesm2022/shirkasoft-ui-components-rail-sidebar.mjs.map +1 -1
  32. package/fesm2022/shirkasoft-ui-components-select.mjs +1014 -819
  33. package/fesm2022/shirkasoft-ui-components-select.mjs.map +1 -1
  34. package/fesm2022/shirkasoft-ui-components-sidebar.mjs +508 -184
  35. package/fesm2022/shirkasoft-ui-components-sidebar.mjs.map +1 -1
  36. package/fesm2022/shirkasoft-ui-components-skeleton.mjs +197 -57
  37. package/fesm2022/shirkasoft-ui-components-skeleton.mjs.map +1 -1
  38. package/fesm2022/shirkasoft-ui-components-table.mjs +1916 -1698
  39. package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
  40. package/fesm2022/shirkasoft-ui-components-tabs.mjs +419 -175
  41. package/fesm2022/shirkasoft-ui-components-tabs.mjs.map +1 -1
  42. package/fesm2022/shirkasoft-ui-components-tag.mjs +175 -49
  43. package/fesm2022/shirkasoft-ui-components-tag.mjs.map +1 -1
  44. package/fesm2022/shirkasoft-ui-components-text-field.mjs +687 -402
  45. package/fesm2022/shirkasoft-ui-components-text-field.mjs.map +1 -1
  46. package/fesm2022/shirkasoft-ui-components-theme-picker.mjs +310 -124
  47. package/fesm2022/shirkasoft-ui-components-theme-picker.mjs.map +1 -1
  48. package/fesm2022/shirkasoft-ui-components-theme.mjs +141 -174
  49. package/fesm2022/shirkasoft-ui-components-theme.mjs.map +1 -1
  50. package/fesm2022/shirkasoft-ui-components-timeline.mjs +791 -203
  51. package/fesm2022/shirkasoft-ui-components-timeline.mjs.map +1 -1
  52. package/fesm2022/shirkasoft-ui-components-toggle.mjs +179 -109
  53. package/fesm2022/shirkasoft-ui-components-toggle.mjs.map +1 -1
  54. package/fesm2022/shirkasoft-ui-components-tooltip.mjs +244 -180
  55. package/fesm2022/shirkasoft-ui-components-tooltip.mjs.map +1 -1
  56. package/fesm2022/shirkasoft-ui-components-utils.mjs +95 -134
  57. package/fesm2022/shirkasoft-ui-components-utils.mjs.map +1 -1
  58. package/fesm2022/shirkasoft-ui-components-wizard.mjs +673 -165
  59. package/fesm2022/shirkasoft-ui-components-wizard.mjs.map +1 -1
  60. package/fesm2022/shirkasoft-ui-components.mjs +0 -9
  61. package/package.json +5 -5
  62. package/types/shirkasoft-ui-components-breadcrumb.d.ts +59 -44
  63. package/types/shirkasoft-ui-components-button.d.ts +142 -49
  64. package/types/shirkasoft-ui-components-chart.d.ts +59 -44
  65. package/types/shirkasoft-ui-components-config.d.ts +193 -204
  66. package/types/shirkasoft-ui-components-confirm-dialog.d.ts +107 -66
  67. package/types/shirkasoft-ui-components-date-picker.d.ts +527 -398
  68. package/types/shirkasoft-ui-components-fieldset.d.ts +135 -60
  69. package/types/shirkasoft-ui-components-file-upload.d.ts +176 -112
  70. package/types/shirkasoft-ui-components-icons.d.ts +1302 -1294
  71. package/types/shirkasoft-ui-components-knob.d.ts +144 -78
  72. package/types/shirkasoft-ui-components-loading.d.ts +155 -64
  73. package/types/shirkasoft-ui-components-modal.d.ts +134 -136
  74. package/types/shirkasoft-ui-components-notification.d.ts +63 -59
  75. package/types/shirkasoft-ui-components-price-input.d.ts +198 -113
  76. package/types/shirkasoft-ui-components-rail-sidebar.d.ts +262 -142
  77. package/types/shirkasoft-ui-components-select.d.ts +301 -196
  78. package/types/shirkasoft-ui-components-sidebar.d.ts +198 -93
  79. package/types/shirkasoft-ui-components-skeleton.d.ts +68 -27
  80. package/types/shirkasoft-ui-components-table.d.ts +849 -660
  81. package/types/shirkasoft-ui-components-tabs.d.ts +102 -61
  82. package/types/shirkasoft-ui-components-tag.d.ts +54 -23
  83. package/types/shirkasoft-ui-components-text-field.d.ts +231 -127
  84. package/types/shirkasoft-ui-components-theme-picker.d.ts +92 -58
  85. package/types/shirkasoft-ui-components-theme.d.ts +56 -64
  86. package/types/shirkasoft-ui-components-timeline.d.ts +325 -150
  87. package/types/shirkasoft-ui-components-toggle.d.ts +73 -49
  88. package/types/shirkasoft-ui-components-tooltip.d.ts +64 -43
  89. package/types/shirkasoft-ui-components-utils.d.ts +15 -16
  90. package/types/shirkasoft-ui-components-wizard.d.ts +236 -87
  91. package/types/shirkasoft-ui-components.d.ts +1 -2
  92. package/fesm2022/shirkasoft-ui-components.mjs.map +0 -1
@@ -1,403 +1,688 @@
1
- import * as i1 from '@angular/common';
2
- import { CommonModule } from '@angular/common';
3
- import * as i0 from '@angular/core';
4
- import { inject, ChangeDetectorRef, input, output, viewChild, model, signal, computed, DestroyRef, effect, untracked, forwardRef, ChangeDetectionStrategy, Component } from '@angular/core';
5
- import * as i2 from '@angular/forms';
6
- import { FormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
7
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
8
- import { merge } from 'rxjs';
9
- import { TranslocoService } from '@jsverse/transloco';
10
- import { LucideEye, ShkIconDirective } from 'shirkasoft-ui-components/icons';
11
- import { getIcon } from 'shirkasoft-ui-components/utils';
12
-
13
- /**
14
- * Shirkasoft UI Components.
15
- * Authors: Roberto Valladares Martin (Ansem13), Julio César García García (Sanjuli14).
16
- * Belongs to Shirkasoft.
17
- */
18
- /**
19
- * Text input (or textarea) that implements ControlValueAccessor with built-in
20
- * validation messages, card/number formatting, password reveal and search mode.
21
- */
22
- class TextFieldComponent {
23
- /** Internal alias kept for the existing implementation. */
24
- get _value() {
25
- return this.value;
26
- }
27
- constructor() {
28
- this.cdr = inject(ChangeDetectorRef);
29
- /** id attribute applied to the native input. */
30
- this.id = input('', ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
31
- /** Formats the value as a credit card number (XXXX-XXXX-XXXX-XXXX). */
32
- this.formatCard = input(false, ...(ngDevMode ? [{ debugName: "formatCard" }] : /* istanbul ignore next */ []));
33
- /** Blocks the minus sign from being typed. */
34
- this.preventNegative = input(false, ...(ngDevMode ? [{ debugName: "preventNegative" }] : /* istanbul ignore next */ []));
35
- /** Label rendered above the field. */
36
- this.label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
37
- /** Native input type ('text', 'password', 'number', etc.). */
38
- this.type = input('text', ...(ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []));
39
- /** Allows digits only, stripping any other character. */
40
- this.numbersOnly = input(false, ...(ngDevMode ? [{ debugName: "numbersOnly" }] : /* istanbul ignore next */ []));
41
- /** When true, allows decimals and normalizes ',' to '.'. */
42
- this.allowDecimals = input(false, ...(ngDevMode ? [{ debugName: "allowDecimals" }] : /* istanbul ignore next */ []));
43
- /** Maximum number of characters the user can type. */
44
- this.maxLength = input(undefined, ...(ngDevMode ? [{ debugName: "maxLength" }] : /* istanbul ignore next */ []));
45
- /** Placeholder text of the native input. */
46
- this.placeholder = input('', ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
47
- /** Custom messages keyed by validation error name. */
48
- this.errorMessages = input({}, ...(ngDevMode ? [{ debugName: "errorMessages" }] : /* istanbul ignore next */ []));
49
- /** Parent reactive form used to resolve the control by label. */
50
- this.formGroup = input(undefined, ...(ngDevMode ? [{ debugName: "formGroup" }] : /* istanbul ignore next */ []));
51
- /** Reactive control bound directly to this field. */
52
- this.control = input(undefined, ...(ngDevMode ? [{ debugName: "control" }] : /* istanbul ignore next */ []));
53
- /** Disables the field. */
54
- this.disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
55
- /** Custom error message shown regardless of validation errors. */
56
- this.errorMessage = input('', ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
57
- /** Renders a textarea instead of an input. */
58
- this.isTextArea = input(false, ...(ngDevMode ? [{ debugName: "isTextArea" }] : /* istanbul ignore next */ []));
59
- /** Height classes applied when `isTextArea` is true. */
60
- this.textAreaHeight = input('h-28', ...(ngDevMode ? [{ debugName: "textAreaHeight" }] : /* istanbul ignore next */ []));
61
- /** Renders the field as a read-only search trigger. */
62
- this.searchMode = input(false, ...(ngDevMode ? [{ debugName: "searchMode" }] : /* istanbul ignore next */ []));
63
- /** Value shown when `searchMode` is enabled. */
64
- this.displayValue = input('', ...(ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []));
65
- /** Native autocomplete attribute. */
66
- this.autocomplete = input('', ...(ngDevMode ? [{ debugName: "autocomplete" }] : /* istanbul ignore next */ []));
67
- /** Emitted when the search button is clicked (search mode). */
68
- this.searchButtonClick = output();
69
- /** Emitted on blur so Signal Forms can mark the field as touched. */
70
- this.touch = output();
71
- this.getIcon = (name) => getIcon(name, LucideEye);
72
- /** Reference to the native input element. */
73
- this.inputElement = viewChild('input', ...(ngDevMode ? [{ debugName: "inputElement" }] : /* istanbul ignore next */ []));
74
- /** Reference to the native textarea element. */
75
- this.textareaElement = viewChild('textarea', ...(ngDevMode ? [{ debugName: "textareaElement" }] : /* istanbul ignore next */ []));
76
- /** Field value. Two-way bindable and used by Signal Forms `[formField]`. */
77
- this.value = model('', ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
78
- /** Reactive disabled state from the form control. */
79
- this._disabledState = signal(false, ...(ngDevMode ? [{ debugName: "_disabledState" }] : /* istanbul ignore next */ []));
80
- /** Whether the password is currently revealed. */
81
- this.showPassword = signal(false, ...(ngDevMode ? [{ debugName: "showPassword" }] : /* istanbul ignore next */ []));
82
- /** Tracks whether the control was in error at some point (for "was fixed" UX). */
83
- this.hadError = signal(false, ...(ngDevMode ? [{ debugName: "hadError" }] : /* istanbul ignore next */ []));
84
- /** Counter bumped to trigger recomputation of derived error signals. */
85
- this.errorTracker = signal(0, ...(ngDevMode ? [{ debugName: "errorTracker" }] : /* istanbul ignore next */ []));
86
- /** Text displayed in search mode when `displayValue` is set. */
87
- this.displayLabel = computed(() => {
88
- if (this.searchMode() && this.displayValue()) {
89
- return this.displayValue();
90
- }
91
- return '';
92
- }, ...(ngDevMode ? [{ debugName: "displayLabel" }] : /* istanbul ignore next */ []));
93
- /** Control whose status/value changes are currently observed. */
94
- this.observedControl = null;
95
- /** Effective disabled state combining the input and the form binding. */
96
- this.isDisabled = computed(() => this.disabled() || this._disabledState(), ...(ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []));
97
- /**
98
- * Internal control used when no reactive control is supplied (`[formField]`,
99
- * `formControlName`/`ngModel` on the host, or plain `[(value)]`). The native
100
- * input always needs a control for its `[formControl]` binding.
101
- */
102
- this.innerControl = new FormControl('');
103
- /** Explicit `control`, or `formGroup.get(label)`, or `undefined` if none. */
104
- this.externalControl = computed(() => {
105
- const ctrl = this.control();
106
- if (ctrl)
107
- return ctrl;
108
- const fg = this.formGroup();
109
- const lbl = this.label();
110
- if (fg && lbl) {
111
- return fg.get(lbl) ?? undefined;
112
- }
113
- return undefined;
114
- }, ...(ngDevMode ? [{ debugName: "externalControl" }] : /* istanbul ignore next */ []));
115
- /** True when the field is driven by its internal control (no reactive control given). */
116
- this.usesInnerControl = computed(() => !this.externalControl(), ...(ngDevMode ? [{ debugName: "usesInnerControl" }] : /* istanbul ignore next */ []));
117
- /** Resolves the reactive control: external one if any, otherwise the internal one. */
118
- this.actualControl = computed(() => this.externalControl() ?? this.innerControl, ...(ngDevMode ? [{ debugName: "actualControl" }] : /* istanbul ignore next */ []));
119
- /** True when the resolved control is invalid and dirty or touched. */
120
- this.shouldShowError = computed(() => {
121
- this.errorTracker();
122
- const ctrl = this.actualControl();
123
- return ctrl?.invalid && (ctrl?.dirty || ctrl?.touched);
124
- }, ...(ngDevMode ? [{ debugName: "shouldShowError" }] : /* istanbul ignore next */ []));
125
- /** True when the control had an error before and is now valid (success state). */
126
- this.wasFixedError = computed(() => {
127
- this.errorTracker();
128
- const ctrl = this.actualControl();
129
- return this.hadError() && ctrl?.valid && ctrl?.touched;
130
- }, ...(ngDevMode ? [{ debugName: "wasFixedError" }] : /* istanbul ignore next */ []));
131
- /** Resolved list of error messages for the current control state. */
132
- this.getErrorMessages = computed(() => {
133
- this.errorTracker();
134
- const customError = this.errorMessage();
135
- if (customError) {
136
- return [customError];
137
- }
138
- const ctrl = this.actualControl();
139
- if (!ctrl?.errors)
140
- return [];
141
- const customErrors = this.errorMessages();
142
- const t = this.transloco;
143
- return Object.keys(ctrl.errors).map((errorKey) => {
144
- if (customErrors[errorKey])
145
- return customErrors[errorKey];
146
- switch (errorKey) {
147
- case 'required':
148
- return t.translate('validation.required');
149
- case 'email':
150
- return t.translate('validation.email');
151
- case 'minlength':
152
- return t.translate('validation.minlength', {
153
- min: ctrl.errors['minlength'].requiredLength,
154
- });
155
- case 'maxlength':
156
- return t.translate('validation.maxlength', {
157
- max: ctrl.errors['maxlength'].requiredLength,
158
- });
159
- case 'pattern':
160
- return t.translate('validation.pattern');
161
- default:
162
- return t.translate('validation.invalid');
163
- }
164
- });
165
- }, ...(ngDevMode ? [{ debugName: "getErrorMessages" }] : /* istanbul ignore next */ []));
166
- /** Effective input type (handles textarea and password reveal). */
167
- this.effectiveType = computed(() => {
168
- if (this.isTextArea())
169
- return 'text';
170
- if (this.type() === 'password' && this.showPassword())
171
- return 'text';
172
- return this.type();
173
- }, ...(ngDevMode ? [{ debugName: "effectiveType" }] : /* istanbul ignore next */ []));
174
- this.transloco = inject(TranslocoService);
175
- /** Callback notified with the new value (ControlValueAccessor). */
176
- this.onChange = () => { };
177
- /** Callback notified when the field is touched (ControlValueAccessor). */
178
- this.onTouched = () => { };
179
- this.destroyRef = inject(DestroyRef);
180
- // Internal-control mode: mirror the value model and disabled state into it
181
- // so the native input shows what the form (CVA / Signal Forms) writes.
182
- effect(() => {
183
- if (!this.usesInnerControl())
184
- return;
185
- const value = this.value() ?? '';
186
- const disabled = this.isDisabled();
187
- untracked(() => {
188
- if (this.innerControl.value !== value) {
189
- this.innerControl.setValue(value, { emitEvent: false });
190
- }
191
- if (disabled && this.innerControl.enabled)
192
- this.innerControl.disable({ emitEvent: false });
193
- if (!disabled && this.innerControl.disabled)
194
- this.innerControl.enable({ emitEvent: false });
195
- });
196
- });
197
- effect(() => {
198
- const ctrl = this.actualControl();
199
- const shouldDisable = this.isDisabled();
200
- if (ctrl && shouldDisable) {
201
- Promise.resolve().then(() => {
202
- ctrl.disable();
203
- });
204
- }
205
- });
206
- // Observe the current control's status/value changes. Re-subscribes when
207
- // the control changes (e.g. `[control]` arrives after init, or the field
208
- // switches from its internal control to an external one).
209
- effect(() => {
210
- const ctrl = this.actualControl();
211
- if (ctrl === this.observedControl)
212
- return;
213
- this.controlSubscription?.unsubscribe();
214
- this.observedControl = ctrl;
215
- if (ctrl.invalid && ctrl.touched) {
216
- this.hadError.set(true);
217
- }
218
- this.controlSubscription = merge(ctrl.statusChanges, ctrl.valueChanges).subscribe(() => {
219
- this.errorTracker.update((v) => v + 1);
220
- if (ctrl.invalid && ctrl.touched) {
221
- this.hadError.set(true);
222
- }
223
- });
224
- });
225
- this.destroyRef.onDestroy(() => this.controlSubscription?.unsubscribe());
226
- this.transloco.langChanges$
227
- .pipe(takeUntilDestroyed(this.destroyRef))
228
- .subscribe(() => {
229
- this.errorTracker.update((v) => v + 1);
230
- });
231
- }
232
- /** Prevents disallowed characters based on the `numbersOnly`/`allowDecimals` config. */
233
- numberValidation(event) {
234
- const allowedKeys = [
235
- 'Backspace',
236
- 'Tab',
237
- 'End',
238
- 'Home',
239
- 'ArrowLeft',
240
- 'ArrowRight',
241
- 'Delete',
242
- ];
243
- if (this.numbersOnly()) {
244
- const isNumber = /^\d$/.test(event.key);
245
- if (!isNumber && !allowedKeys.includes(event.key)) {
246
- event.preventDefault();
247
- }
248
- return;
249
- }
250
- if (this.allowDecimals() || this.type() === 'number') {
251
- allowedKeys.push('.');
252
- }
253
- const isDecimal = event.key === '.' || event.key === ',';
254
- const isNumber = !isNaN(Number(event.key));
255
- if (allowedKeys.includes(event.key)) {
256
- if (isDecimal) {
257
- const input = event.target;
258
- const currentValue = input.value;
259
- const hasDecimalSeparator = currentValue.includes('.') || currentValue.includes(',');
260
- if (hasDecimalSeparator) {
261
- event.preventDefault();
262
- }
263
- }
264
- return;
265
- }
266
- if (isNumber) {
267
- return;
268
- }
269
- event.preventDefault();
270
- }
271
- /** Marks the field as touched and refreshes the error state. */
272
- onBlur() {
273
- this.onTouched();
274
- this.touch.emit();
275
- this.errorTracker.update((v) => v + 1);
276
- const ctrl = this.actualControl();
277
- if (ctrl?.invalid && ctrl?.touched) {
278
- this.hadError.set(true);
279
- }
280
- }
281
- /** Formats the raw input as a credit card number and notifies the control. */
282
- onCardInput(event) {
283
- const input = event.target;
284
- let value = input.value.replace(/[^0-9]/g, '');
285
- if (value.length > 16) {
286
- value = value.substring(0, 16);
287
- }
288
- let formatted = '';
289
- for (let i = 0; i < value.length; i++) {
290
- if (i > 0 && i % 4 === 0) {
291
- formatted += '-';
292
- }
293
- formatted += value[i];
294
- }
295
- input.value = formatted;
296
- this._value.set(formatted);
297
- this.onChange(formatted);
298
- }
299
- /** Handles raw input: applies number/card/max-length formatting and notifies the control. */
300
- onInput(event) {
301
- const input = event.target;
302
- let newValue = input.value;
303
- if (this.allowDecimals()) {
304
- newValue = newValue.replace(/,/g, '.');
305
- const parts = newValue.split('.');
306
- if (parts.length > 2) {
307
- newValue = parts[0] + '.' + parts.slice(1).join('');
308
- }
309
- if (parts.length > 1 && parts[1].length > 2) {
310
- newValue = parts[0] + '.' + parts[1].substring(0, 2);
311
- }
312
- }
313
- if (this.numbersOnly()) {
314
- newValue = newValue.replace(/[^0-9]/g, '');
315
- }
316
- const maxLen = this.maxLength();
317
- if (maxLen && newValue.length > maxLen) {
318
- newValue = newValue.substring(0, maxLen);
319
- input.value = newValue;
320
- const ctrl = this.actualControl();
321
- setTimeout(() => {
322
- ctrl?.updateValueAndValidity();
323
- this.errorTracker.update((v) => v + 1);
324
- });
325
- }
326
- if (this.formatCard()) {
327
- this.onCardInput(event);
328
- }
329
- else {
330
- this._value.set(newValue);
331
- this.onChange(newValue);
332
- }
333
- }
334
- /** Toggles the visibility of a password field. */
335
- togglePasswordVisibility() {
336
- this.showPassword.update((v) => !v);
337
- }
338
- /** Sets the value from the form control applying the same formatting rules. */
339
- writeValue(value) {
340
- let processedValue = value;
341
- if (this.allowDecimals() && value) {
342
- processedValue = String(value).replace(/,/g, '.');
343
- }
344
- if (this.numbersOnly() && value) {
345
- processedValue = value.toString().replace(/[^0-9]/g, '');
346
- }
347
- const maxLen = this.maxLength();
348
- if (maxLen && processedValue?.length > maxLen) {
349
- processedValue = processedValue.substring(0, maxLen);
350
- }
351
- if (this.formatCard() && processedValue) {
352
- const cleaned = processedValue.replace(/[^0-9]/g, '');
353
- let formatted = '';
354
- for (let i = 0; i < cleaned.length; i++) {
355
- if (i > 0 && i % 4 === 0)
356
- formatted += '-';
357
- formatted += cleaned[i];
358
- }
359
- this._value.set(formatted);
360
- }
361
- else {
362
- this._value.set(processedValue);
363
- }
364
- }
365
- /** Registers the callback invoked on value changes (ControlValueAccessor). */
366
- registerOnChange(fn) {
367
- this.onChange = fn;
368
- }
369
- /** Registers the callback invoked when the field is touched. */
370
- registerOnTouched(fn) {
371
- this.onTouched = fn;
372
- }
373
- /** Reflects the disabled state of the form control. */
374
- setDisabledState(isDisabled) {
375
- this._disabledState.set(isDisabled);
376
- this.cdr.markForCheck();
377
- }
378
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: TextFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
379
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.27", type: TextFieldComponent, isStandalone: true, selector: "shk-text-field", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, formatCard: { classPropertyName: "formatCard", publicName: "formatCard", isSignal: true, isRequired: false, transformFunction: null }, preventNegative: { classPropertyName: "preventNegative", publicName: "preventNegative", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, numbersOnly: { classPropertyName: "numbersOnly", publicName: "numbersOnly", isSignal: true, isRequired: false, transformFunction: null }, allowDecimals: { classPropertyName: "allowDecimals", publicName: "allowDecimals", isSignal: true, isRequired: false, transformFunction: null }, maxLength: { classPropertyName: "maxLength", publicName: "maxLength", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, errorMessages: { classPropertyName: "errorMessages", publicName: "errorMessages", isSignal: true, isRequired: false, transformFunction: null }, formGroup: { classPropertyName: "formGroup", publicName: "formGroup", isSignal: true, isRequired: false, transformFunction: null }, control: { classPropertyName: "control", publicName: "control", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, errorMessage: { classPropertyName: "errorMessage", publicName: "errorMessage", isSignal: true, isRequired: false, transformFunction: null }, isTextArea: { classPropertyName: "isTextArea", publicName: "isTextArea", isSignal: true, isRequired: false, transformFunction: null }, textAreaHeight: { classPropertyName: "textAreaHeight", publicName: "textAreaHeight", isSignal: true, isRequired: false, transformFunction: null }, searchMode: { classPropertyName: "searchMode", publicName: "searchMode", isSignal: true, isRequired: false, transformFunction: null }, displayValue: { classPropertyName: "displayValue", publicName: "displayValue", isSignal: true, isRequired: false, transformFunction: null }, autocomplete: { classPropertyName: "autocomplete", publicName: "autocomplete", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { searchButtonClick: "searchButtonClick", touch: "touch", value: "valueChange" }, providers: [
380
- {
381
- provide: NG_VALUE_ACCESSOR,
382
- useExisting: forwardRef(() => TextFieldComponent),
383
- multi: true,
384
- },
385
- ], viewQueries: [{ propertyName: "inputElement", first: true, predicate: ["input"], descendants: true, isSignal: true }, { propertyName: "textareaElement", first: true, predicate: ["textarea"], descendants: true, isSignal: true }], ngImport: i0, template: "<div class=\"relative mb-4\">\n @if (label()) {\n <div class=\"text-sm font-medium _shk-text-surface-700 mb-1\">\n {{ label() }}\n </div>\n }\n\n <div class=\"relative\">\n @if (!isTextArea()) {\n <div class=\"flex\">\n @if (searchMode()) {\n @let isDisabledSearch = actualControl()?.disabled || isDisabled();\n <input\n #input\n [id]=\"id()\"\n type=\"text\"\n [value]=\"displayValue() || ''\"\n [placeholder]=\"placeholder() || label()\"\n [readOnly]=\"true\"\n [disabled]=\"isDisabledSearch\"\n (click)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (keydown.enter)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (blur)=\"onBlur()\"\n autocomplete=\"off\"\n [attr.aria-invalid]=\"(shouldShowError() && !isDisabledSearch) || null\"\n [class.cursor-pointer]=\"!isDisabledSearch\"\n [class.cursor-not-allowed]=\"isDisabledSearch\"\n [class._shk-bg-surface-50]=\"isDisabledSearch\"\n [class._shk-text-surface-400]=\"isDisabledSearch\"\n class=\"shk-control shk-control-addon block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-l-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500': shouldShowError() && !isDisabledSearch,\n '_shk-border': !shouldShowError() || isDisabledSearch,\n 'cursor-pointer': !isDisabledSearch,\n 'cursor-not-allowed _shk-text-surface-400 dark:[color:var(--shk-surface-400)]': isDisabledSearch\n }\"\n />\n <button\n type=\"button\"\n (click)=\"searchButtonClick.emit()\"\n tabindex=\"-1\"\n [disabled]=\"isDisabledSearch\"\n class=\"px-3 flex items-center justify-center shrink-0 _shk-bg-primary hover:[background-color:var(--shk-primary-700)] text-white border _shk-border-primary rounded-r-lg transition-colors duration-200 disabled:[background-color:var(--shk-surface-300)] dark:disabled:[background-color:var(--shk-surface-200)] disabled:[border-color:var(--shk-surface-300)] dark:disabled:[border-color:var(--shk-surface-200)] disabled:cursor-not-allowed\"\n >\n <svg [shkIcon]=\"getIcon('search')\" class=\"w-4 h-4\"></svg>\n </button>\n }\n\n @if (!searchMode()) {\n <input\n #input\n [id]=\"id()\"\n [maxlength]=\"maxLength() || (formatCard() ? 19 : null)\"\n [min]=\"type() === 'number' && preventNegative() ? '0' : null\"\n (keypress)=\"type() === 'number' || numbersOnly() ? numberValidation($event) : null\"\n [type]=\"effectiveType()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n [autocomplete]=\"autocomplete()\"\n (blur)=\"onBlur()\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n [class.pr-8]=\"type() === 'password' && actualControl()?.value?.length > 0\"\n [class.pr-3]=\"type() !== 'password' || !actualControl()?.value?.length\"\n />\n\n @if (type() === 'password' && actualControl()?.value?.length > 0) {\n <button\n type=\"button\"\n (click)=\"togglePasswordVisibility()\"\n [disabled]=\"actualControl()?.disabled\"\n class=\"absolute right-3 top-1/2 -translate-y-1/2 _shk-text-surface-400 hover:[color:var(--shk-surface-600)] dark:hover:[color:var(--shk-surface-600)] focus:outline-none\"\n >\n @if (showPassword()) {\n <svg [shkIcon]=\"getIcon('eye-off')\" class=\"w-4 h-4\"></svg>\n } @else {\n <svg [shkIcon]=\"getIcon('eye')\" class=\"w-4 h-4\"></svg>\n }\n </button>\n }\n }\n </div>\n }\n\n @if (isTextArea()) {\n <textarea\n #textarea\n [id]=\"id()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n (blur)=\"onBlur()\"\n [class]=\"isTextArea() ? textAreaHeight() : 'h-28'\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 resize-none disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed disabled:[color:var(--shk-surface-400)] dark:disabled:[color:var(--shk-surface-400)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n ></textarea>\n }\n </div>\n\n @if (shouldShowError()) {\n <div class=\"mt-1 text-xs text-red-500 max-h-20 overflow-y-auto _shk-scrollbar\" tabindex=\"-1\">\n <ul class=\"list-disc pl-4 space-y-1\">\n @for (error of getErrorMessages(); track error) {\n <li>{{ error }}</li>\n }\n </ul>\n </div>\n }\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i2.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: ShkIconDirective, selector: "svg[shkIcon]", inputs: ["shkIcon", "size", "strokeWidth", "color"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
386
- }
387
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.27", ngImport: i0, type: TextFieldComponent, decorators: [{
388
- type: Component,
389
- args: [{ selector: 'shk-text-field', imports: [CommonModule, ReactiveFormsModule, ShkIconDirective], changeDetection: ChangeDetectionStrategy.OnPush, providers: [
390
- {
391
- provide: NG_VALUE_ACCESSOR,
392
- useExisting: forwardRef(() => TextFieldComponent),
393
- multi: true,
394
- },
395
- ], template: "<div class=\"relative mb-4\">\n @if (label()) {\n <div class=\"text-sm font-medium _shk-text-surface-700 mb-1\">\n {{ label() }}\n </div>\n }\n\n <div class=\"relative\">\n @if (!isTextArea()) {\n <div class=\"flex\">\n @if (searchMode()) {\n @let isDisabledSearch = actualControl()?.disabled || isDisabled();\n <input\n #input\n [id]=\"id()\"\n type=\"text\"\n [value]=\"displayValue() || ''\"\n [placeholder]=\"placeholder() || label()\"\n [readOnly]=\"true\"\n [disabled]=\"isDisabledSearch\"\n (click)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (keydown.enter)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (blur)=\"onBlur()\"\n autocomplete=\"off\"\n [attr.aria-invalid]=\"(shouldShowError() && !isDisabledSearch) || null\"\n [class.cursor-pointer]=\"!isDisabledSearch\"\n [class.cursor-not-allowed]=\"isDisabledSearch\"\n [class._shk-bg-surface-50]=\"isDisabledSearch\"\n [class._shk-text-surface-400]=\"isDisabledSearch\"\n class=\"shk-control shk-control-addon block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-l-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500': shouldShowError() && !isDisabledSearch,\n '_shk-border': !shouldShowError() || isDisabledSearch,\n 'cursor-pointer': !isDisabledSearch,\n 'cursor-not-allowed _shk-text-surface-400 dark:[color:var(--shk-surface-400)]': isDisabledSearch\n }\"\n />\n <button\n type=\"button\"\n (click)=\"searchButtonClick.emit()\"\n tabindex=\"-1\"\n [disabled]=\"isDisabledSearch\"\n class=\"px-3 flex items-center justify-center shrink-0 _shk-bg-primary hover:[background-color:var(--shk-primary-700)] text-white border _shk-border-primary rounded-r-lg transition-colors duration-200 disabled:[background-color:var(--shk-surface-300)] dark:disabled:[background-color:var(--shk-surface-200)] disabled:[border-color:var(--shk-surface-300)] dark:disabled:[border-color:var(--shk-surface-200)] disabled:cursor-not-allowed\"\n >\n <svg [shkIcon]=\"getIcon('search')\" class=\"w-4 h-4\"></svg>\n </button>\n }\n\n @if (!searchMode()) {\n <input\n #input\n [id]=\"id()\"\n [maxlength]=\"maxLength() || (formatCard() ? 19 : null)\"\n [min]=\"type() === 'number' && preventNegative() ? '0' : null\"\n (keypress)=\"type() === 'number' || numbersOnly() ? numberValidation($event) : null\"\n [type]=\"effectiveType()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n [autocomplete]=\"autocomplete()\"\n (blur)=\"onBlur()\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n [class.pr-8]=\"type() === 'password' && actualControl()?.value?.length > 0\"\n [class.pr-3]=\"type() !== 'password' || !actualControl()?.value?.length\"\n />\n\n @if (type() === 'password' && actualControl()?.value?.length > 0) {\n <button\n type=\"button\"\n (click)=\"togglePasswordVisibility()\"\n [disabled]=\"actualControl()?.disabled\"\n class=\"absolute right-3 top-1/2 -translate-y-1/2 _shk-text-surface-400 hover:[color:var(--shk-surface-600)] dark:hover:[color:var(--shk-surface-600)] focus:outline-none\"\n >\n @if (showPassword()) {\n <svg [shkIcon]=\"getIcon('eye-off')\" class=\"w-4 h-4\"></svg>\n } @else {\n <svg [shkIcon]=\"getIcon('eye')\" class=\"w-4 h-4\"></svg>\n }\n </button>\n }\n }\n </div>\n }\n\n @if (isTextArea()) {\n <textarea\n #textarea\n [id]=\"id()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n (blur)=\"onBlur()\"\n [class]=\"isTextArea() ? textAreaHeight() : 'h-28'\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 resize-none disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed disabled:[color:var(--shk-surface-400)] dark:disabled:[color:var(--shk-surface-400)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n ></textarea>\n }\n </div>\n\n @if (shouldShowError()) {\n <div class=\"mt-1 text-xs text-red-500 max-h-20 overflow-y-auto _shk-scrollbar\" tabindex=\"-1\">\n <ul class=\"list-disc pl-4 space-y-1\">\n @for (error of getErrorMessages(); track error) {\n <li>{{ error }}</li>\n }\n </ul>\n </div>\n }\n</div>\n" }]
396
- }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], formatCard: [{ type: i0.Input, args: [{ isSignal: true, alias: "formatCard", required: false }] }], preventNegative: [{ type: i0.Input, args: [{ isSignal: true, alias: "preventNegative", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], type: [{ type: i0.Input, args: [{ isSignal: true, alias: "type", required: false }] }], numbersOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "numbersOnly", required: false }] }], allowDecimals: [{ type: i0.Input, args: [{ isSignal: true, alias: "allowDecimals", required: false }] }], maxLength: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxLength", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], errorMessages: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessages", required: false }] }], formGroup: [{ type: i0.Input, args: [{ isSignal: true, alias: "formGroup", required: false }] }], control: [{ type: i0.Input, args: [{ isSignal: true, alias: "control", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], errorMessage: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessage", required: false }] }], isTextArea: [{ type: i0.Input, args: [{ isSignal: true, alias: "isTextArea", required: false }] }], textAreaHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "textAreaHeight", required: false }] }], searchMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "searchMode", required: false }] }], displayValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "displayValue", required: false }] }], autocomplete: [{ type: i0.Input, args: [{ isSignal: true, alias: "autocomplete", required: false }] }], searchButtonClick: [{ type: i0.Output, args: ["searchButtonClick"] }], touch: [{ type: i0.Output, args: ["touch"] }], inputElement: [{ type: i0.ViewChild, args: ['input', { isSignal: true }] }], textareaElement: [{ type: i0.ViewChild, args: ['textarea', { isSignal: true }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }, { type: i0.Output, args: ["valueChange"] }] } });
397
-
398
- /**
399
- * Generated bundle index. Do not edit.
400
- */
401
-
1
+ import * as i1 from "@angular/common";
2
+ import { CommonModule } from "@angular/common";
3
+ import * as i0 from "@angular/core";
4
+ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, computed, effect, forwardRef, inject, input, model, output, signal, untracked, viewChild } from "@angular/core";
5
+ import * as i2 from "@angular/forms";
6
+ import { FormControl, NG_VALUE_ACCESSOR, ReactiveFormsModule } from "@angular/forms";
7
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
8
+ import { merge } from "rxjs";
9
+ import { TranslocoService } from "@jsverse/transloco";
10
+ import { LucideEye, ShkIconDirective } from "shirkasoft-ui-components/icons";
11
+ import { getIcon } from "shirkasoft-ui-components/utils";
12
+ var TextFieldComponent = class TextFieldComponent {
13
+ get _value() {
14
+ return this.value;
15
+ }
16
+ constructor() {
17
+ this.cdr = inject(ChangeDetectorRef);
18
+ this.id = input("", ...ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []);
19
+ this.formatCard = input(false, ...ngDevMode ? [{ debugName: "formatCard" }] : /* istanbul ignore next */ []);
20
+ this.preventNegative = input(false, ...ngDevMode ? [{ debugName: "preventNegative" }] : /* istanbul ignore next */ []);
21
+ this.label = input("", ...ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []);
22
+ this.type = input("text", ...ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []);
23
+ this.numbersOnly = input(false, ...ngDevMode ? [{ debugName: "numbersOnly" }] : /* istanbul ignore next */ []);
24
+ this.allowDecimals = input(false, ...ngDevMode ? [{ debugName: "allowDecimals" }] : /* istanbul ignore next */ []);
25
+ this.maxLength = input(void 0, ...ngDevMode ? [{ debugName: "maxLength" }] : /* istanbul ignore next */ []);
26
+ this.placeholder = input("", ...ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []);
27
+ this.errorMessages = input({}, ...ngDevMode ? [{ debugName: "errorMessages" }] : /* istanbul ignore next */ []);
28
+ this.formGroup = input(void 0, ...ngDevMode ? [{ debugName: "formGroup" }] : /* istanbul ignore next */ []);
29
+ this.control = input(void 0, ...ngDevMode ? [{ debugName: "control" }] : /* istanbul ignore next */ []);
30
+ this.disabled = input(false, ...ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []);
31
+ this.errorMessage = input("", ...ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []);
32
+ this.isTextArea = input(false, ...ngDevMode ? [{ debugName: "isTextArea" }] : /* istanbul ignore next */ []);
33
+ this.textAreaHeight = input("h-28", ...ngDevMode ? [{ debugName: "textAreaHeight" }] : /* istanbul ignore next */ []);
34
+ this.searchMode = input(false, ...ngDevMode ? [{ debugName: "searchMode" }] : /* istanbul ignore next */ []);
35
+ this.displayValue = input("", ...ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []);
36
+ this.autocomplete = input("", ...ngDevMode ? [{ debugName: "autocomplete" }] : /* istanbul ignore next */ []);
37
+ this.searchButtonClick = output();
38
+ this.touch = output();
39
+ this.getIcon = (name) => getIcon(name, LucideEye);
40
+ this.inputElement = viewChild("input", ...ngDevMode ? [{ debugName: "inputElement" }] : /* istanbul ignore next */ []);
41
+ this.textareaElement = viewChild("textarea", ...ngDevMode ? [{ debugName: "textareaElement" }] : /* istanbul ignore next */ []);
42
+ this.value = model("", ...ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []);
43
+ this._disabledState = signal(false, ...ngDevMode ? [{ debugName: "_disabledState" }] : /* istanbul ignore next */ []);
44
+ this.showPassword = signal(false, ...ngDevMode ? [{ debugName: "showPassword" }] : /* istanbul ignore next */ []);
45
+ this.hadError = signal(false, ...ngDevMode ? [{ debugName: "hadError" }] : /* istanbul ignore next */ []);
46
+ this.errorTracker = signal(0, ...ngDevMode ? [{ debugName: "errorTracker" }] : /* istanbul ignore next */ []);
47
+ this.displayLabel = computed(() => {
48
+ if (this.searchMode() && this.displayValue()) return this.displayValue();
49
+ return "";
50
+ }, ...ngDevMode ? [{ debugName: "displayLabel" }] : /* istanbul ignore next */ []);
51
+ this.observedControl = null;
52
+ this.isDisabled = computed(() => this.disabled() || this._disabledState(), ...ngDevMode ? [{ debugName: "isDisabled" }] : /* istanbul ignore next */ []);
53
+ this.innerControl = new FormControl("");
54
+ this.externalControl = computed(() => {
55
+ const ctrl = this.control();
56
+ if (ctrl) return ctrl;
57
+ const fg = this.formGroup();
58
+ const lbl = this.label();
59
+ if (fg && lbl) return fg.get(lbl) ?? void 0;
60
+ }, ...ngDevMode ? [{ debugName: "externalControl" }] : /* istanbul ignore next */ []);
61
+ this.usesInnerControl = computed(() => !this.externalControl(), ...ngDevMode ? [{ debugName: "usesInnerControl" }] : /* istanbul ignore next */ []);
62
+ this.actualControl = computed(() => this.externalControl() ?? this.innerControl, ...ngDevMode ? [{ debugName: "actualControl" }] : /* istanbul ignore next */ []);
63
+ this.shouldShowError = computed(() => {
64
+ this.errorTracker();
65
+ const ctrl = this.actualControl();
66
+ return ctrl?.invalid && (ctrl?.dirty || ctrl?.touched);
67
+ }, ...ngDevMode ? [{ debugName: "shouldShowError" }] : /* istanbul ignore next */ []);
68
+ this.wasFixedError = computed(() => {
69
+ this.errorTracker();
70
+ const ctrl = this.actualControl();
71
+ return this.hadError() && ctrl?.valid && ctrl?.touched;
72
+ }, ...ngDevMode ? [{ debugName: "wasFixedError" }] : /* istanbul ignore next */ []);
73
+ this.getErrorMessages = computed(() => {
74
+ this.errorTracker();
75
+ const customError = this.errorMessage();
76
+ if (customError) return [customError];
77
+ const ctrl = this.actualControl();
78
+ if (!ctrl?.errors) return [];
79
+ const customErrors = this.errorMessages();
80
+ const t = this.transloco;
81
+ return Object.keys(ctrl.errors).map((errorKey) => {
82
+ if (customErrors[errorKey]) return customErrors[errorKey];
83
+ switch (errorKey) {
84
+ case "required": return t.translate("validation.required");
85
+ case "email": return t.translate("validation.email");
86
+ case "minlength": return t.translate("validation.minlength", { min: ctrl.errors["minlength"].requiredLength });
87
+ case "maxlength": return t.translate("validation.maxlength", { max: ctrl.errors["maxlength"].requiredLength });
88
+ case "pattern": return t.translate("validation.pattern");
89
+ default: return t.translate("validation.invalid");
90
+ }
91
+ });
92
+ }, ...ngDevMode ? [{ debugName: "getErrorMessages" }] : /* istanbul ignore next */ []);
93
+ this.effectiveType = computed(() => {
94
+ if (this.isTextArea()) return "text";
95
+ if (this.type() === "password" && this.showPassword()) return "text";
96
+ return this.type();
97
+ }, ...ngDevMode ? [{ debugName: "effectiveType" }] : /* istanbul ignore next */ []);
98
+ this.transloco = inject(TranslocoService);
99
+ this.onChange = () => {};
100
+ this.onTouched = () => {};
101
+ this.destroyRef = inject(DestroyRef);
102
+ effect(() => {
103
+ if (!this.usesInnerControl()) return;
104
+ const value = this.value() ?? "";
105
+ const disabled = this.isDisabled();
106
+ untracked(() => {
107
+ if (this.innerControl.value !== value) this.innerControl.setValue(value, { emitEvent: false });
108
+ if (disabled && this.innerControl.enabled) this.innerControl.disable({ emitEvent: false });
109
+ if (!disabled && this.innerControl.disabled) this.innerControl.enable({ emitEvent: false });
110
+ });
111
+ });
112
+ effect(() => {
113
+ const ctrl = this.actualControl();
114
+ const shouldDisable = this.isDisabled();
115
+ if (ctrl && shouldDisable) Promise.resolve().then(() => {
116
+ ctrl.disable();
117
+ });
118
+ });
119
+ effect(() => {
120
+ const ctrl = this.actualControl();
121
+ if (ctrl === this.observedControl) return;
122
+ this.controlSubscription?.unsubscribe();
123
+ this.observedControl = ctrl;
124
+ if (ctrl.invalid && ctrl.touched) this.hadError.set(true);
125
+ this.controlSubscription = merge(ctrl.statusChanges, ctrl.valueChanges).subscribe(() => {
126
+ this.errorTracker.update((v) => v + 1);
127
+ if (ctrl.invalid && ctrl.touched) this.hadError.set(true);
128
+ });
129
+ });
130
+ this.destroyRef.onDestroy(() => this.controlSubscription?.unsubscribe());
131
+ this.transloco.langChanges$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
132
+ this.errorTracker.update((v) => v + 1);
133
+ });
134
+ }
135
+ numberValidation(event) {
136
+ const allowedKeys = [
137
+ "Backspace",
138
+ "Tab",
139
+ "End",
140
+ "Home",
141
+ "ArrowLeft",
142
+ "ArrowRight",
143
+ "Delete"
144
+ ];
145
+ if (this.numbersOnly()) {
146
+ if (!/^\d$/.test(event.key) && !allowedKeys.includes(event.key)) event.preventDefault();
147
+ return;
148
+ }
149
+ if (this.allowDecimals() || this.type() === "number") allowedKeys.push(".");
150
+ const isDecimal = event.key === "." || event.key === ",";
151
+ const isNumber = !isNaN(Number(event.key));
152
+ if (allowedKeys.includes(event.key)) {
153
+ if (isDecimal) {
154
+ const currentValue = event.target.value;
155
+ if (currentValue.includes(".") || currentValue.includes(",")) event.preventDefault();
156
+ }
157
+ return;
158
+ }
159
+ if (isNumber) return;
160
+ event.preventDefault();
161
+ }
162
+ onBlur() {
163
+ this.onTouched();
164
+ this.touch.emit();
165
+ this.errorTracker.update((v) => v + 1);
166
+ const ctrl = this.actualControl();
167
+ if (ctrl?.invalid && ctrl?.touched) this.hadError.set(true);
168
+ }
169
+ onCardInput(event) {
170
+ const input = event.target;
171
+ let value = input.value.replace(/[^0-9]/g, "");
172
+ if (value.length > 16) value = value.substring(0, 16);
173
+ let formatted = "";
174
+ for (let i = 0; i < value.length; i++) {
175
+ if (i > 0 && i % 4 === 0) formatted += "-";
176
+ formatted += value[i];
177
+ }
178
+ input.value = formatted;
179
+ this._value.set(formatted);
180
+ this.onChange(formatted);
181
+ }
182
+ onInput(event) {
183
+ const input = event.target;
184
+ let newValue = input.value;
185
+ if (this.allowDecimals()) {
186
+ newValue = newValue.replace(/,/g, ".");
187
+ const parts = newValue.split(".");
188
+ if (parts.length > 2) newValue = parts[0] + "." + parts.slice(1).join("");
189
+ if (parts.length > 1 && parts[1].length > 2) newValue = parts[0] + "." + parts[1].substring(0, 2);
190
+ }
191
+ if (this.numbersOnly()) newValue = newValue.replace(/[^0-9]/g, "");
192
+ const maxLen = this.maxLength();
193
+ if (maxLen && newValue.length > maxLen) {
194
+ newValue = newValue.substring(0, maxLen);
195
+ input.value = newValue;
196
+ const ctrl = this.actualControl();
197
+ setTimeout(() => {
198
+ ctrl?.updateValueAndValidity();
199
+ this.errorTracker.update((v) => v + 1);
200
+ });
201
+ }
202
+ if (this.formatCard()) this.onCardInput(event);
203
+ else {
204
+ this._value.set(newValue);
205
+ this.onChange(newValue);
206
+ }
207
+ }
208
+ togglePasswordVisibility() {
209
+ this.showPassword.update((v) => !v);
210
+ }
211
+ writeValue(value) {
212
+ let processedValue = value;
213
+ if (this.allowDecimals() && value) processedValue = String(value).replace(/,/g, ".");
214
+ if (this.numbersOnly() && value) processedValue = value.toString().replace(/[^0-9]/g, "");
215
+ const maxLen = this.maxLength();
216
+ if (maxLen && processedValue?.length > maxLen) processedValue = processedValue.substring(0, maxLen);
217
+ if (this.formatCard() && processedValue) {
218
+ const cleaned = processedValue.replace(/[^0-9]/g, "");
219
+ let formatted = "";
220
+ for (let i = 0; i < cleaned.length; i++) {
221
+ if (i > 0 && i % 4 === 0) formatted += "-";
222
+ formatted += cleaned[i];
223
+ }
224
+ this._value.set(formatted);
225
+ } else this._value.set(processedValue);
226
+ }
227
+ registerOnChange(fn) {
228
+ this.onChange = fn;
229
+ }
230
+ registerOnTouched(fn) {
231
+ this.onTouched = fn;
232
+ }
233
+ setDisabledState(isDisabled) {
234
+ this._disabledState.set(isDisabled);
235
+ this.cdr.markForCheck();
236
+ }
237
+ static {
238
+ this.ɵfac = i0.ɵɵngDeclareFactory({
239
+ minVersion: "12.0.0",
240
+ version: "22.3.2",
241
+ ngImport: i0,
242
+ type: TextFieldComponent,
243
+ deps: [],
244
+ target: i0.ɵɵFactoryTarget.Component
245
+ });
246
+ }
247
+ static {
248
+ this.ɵcmp = i0.ɵɵngDeclareComponent({
249
+ minVersion: "17.0.0",
250
+ version: "22.3.2",
251
+ type: TextFieldComponent,
252
+ isStandalone: true,
253
+ selector: "shk-text-field",
254
+ inputs: {
255
+ id: {
256
+ classPropertyName: "id",
257
+ publicName: "id",
258
+ isSignal: true,
259
+ isRequired: false,
260
+ transformFunction: null
261
+ },
262
+ formatCard: {
263
+ classPropertyName: "formatCard",
264
+ publicName: "formatCard",
265
+ isSignal: true,
266
+ isRequired: false,
267
+ transformFunction: null
268
+ },
269
+ preventNegative: {
270
+ classPropertyName: "preventNegative",
271
+ publicName: "preventNegative",
272
+ isSignal: true,
273
+ isRequired: false,
274
+ transformFunction: null
275
+ },
276
+ label: {
277
+ classPropertyName: "label",
278
+ publicName: "label",
279
+ isSignal: true,
280
+ isRequired: false,
281
+ transformFunction: null
282
+ },
283
+ type: {
284
+ classPropertyName: "type",
285
+ publicName: "type",
286
+ isSignal: true,
287
+ isRequired: false,
288
+ transformFunction: null
289
+ },
290
+ numbersOnly: {
291
+ classPropertyName: "numbersOnly",
292
+ publicName: "numbersOnly",
293
+ isSignal: true,
294
+ isRequired: false,
295
+ transformFunction: null
296
+ },
297
+ allowDecimals: {
298
+ classPropertyName: "allowDecimals",
299
+ publicName: "allowDecimals",
300
+ isSignal: true,
301
+ isRequired: false,
302
+ transformFunction: null
303
+ },
304
+ maxLength: {
305
+ classPropertyName: "maxLength",
306
+ publicName: "maxLength",
307
+ isSignal: true,
308
+ isRequired: false,
309
+ transformFunction: null
310
+ },
311
+ placeholder: {
312
+ classPropertyName: "placeholder",
313
+ publicName: "placeholder",
314
+ isSignal: true,
315
+ isRequired: false,
316
+ transformFunction: null
317
+ },
318
+ errorMessages: {
319
+ classPropertyName: "errorMessages",
320
+ publicName: "errorMessages",
321
+ isSignal: true,
322
+ isRequired: false,
323
+ transformFunction: null
324
+ },
325
+ formGroup: {
326
+ classPropertyName: "formGroup",
327
+ publicName: "formGroup",
328
+ isSignal: true,
329
+ isRequired: false,
330
+ transformFunction: null
331
+ },
332
+ control: {
333
+ classPropertyName: "control",
334
+ publicName: "control",
335
+ isSignal: true,
336
+ isRequired: false,
337
+ transformFunction: null
338
+ },
339
+ disabled: {
340
+ classPropertyName: "disabled",
341
+ publicName: "disabled",
342
+ isSignal: true,
343
+ isRequired: false,
344
+ transformFunction: null
345
+ },
346
+ errorMessage: {
347
+ classPropertyName: "errorMessage",
348
+ publicName: "errorMessage",
349
+ isSignal: true,
350
+ isRequired: false,
351
+ transformFunction: null
352
+ },
353
+ isTextArea: {
354
+ classPropertyName: "isTextArea",
355
+ publicName: "isTextArea",
356
+ isSignal: true,
357
+ isRequired: false,
358
+ transformFunction: null
359
+ },
360
+ textAreaHeight: {
361
+ classPropertyName: "textAreaHeight",
362
+ publicName: "textAreaHeight",
363
+ isSignal: true,
364
+ isRequired: false,
365
+ transformFunction: null
366
+ },
367
+ searchMode: {
368
+ classPropertyName: "searchMode",
369
+ publicName: "searchMode",
370
+ isSignal: true,
371
+ isRequired: false,
372
+ transformFunction: null
373
+ },
374
+ displayValue: {
375
+ classPropertyName: "displayValue",
376
+ publicName: "displayValue",
377
+ isSignal: true,
378
+ isRequired: false,
379
+ transformFunction: null
380
+ },
381
+ autocomplete: {
382
+ classPropertyName: "autocomplete",
383
+ publicName: "autocomplete",
384
+ isSignal: true,
385
+ isRequired: false,
386
+ transformFunction: null
387
+ },
388
+ value: {
389
+ classPropertyName: "value",
390
+ publicName: "value",
391
+ isSignal: true,
392
+ isRequired: false,
393
+ transformFunction: null
394
+ }
395
+ },
396
+ outputs: {
397
+ searchButtonClick: "searchButtonClick",
398
+ touch: "touch",
399
+ value: "valueChange"
400
+ },
401
+ providers: [{
402
+ provide: NG_VALUE_ACCESSOR,
403
+ useExisting: forwardRef(() => TextFieldComponent),
404
+ multi: true
405
+ }],
406
+ viewQueries: [{
407
+ propertyName: "inputElement",
408
+ first: true,
409
+ predicate: ["input"],
410
+ descendants: true,
411
+ isSignal: true
412
+ }, {
413
+ propertyName: "textareaElement",
414
+ first: true,
415
+ predicate: ["textarea"],
416
+ descendants: true,
417
+ isSignal: true
418
+ }],
419
+ ngImport: i0,
420
+ template: "<div class=\"relative mb-4\">\n @if (label()) {\n <div class=\"text-sm font-medium _shk-text-surface-700 mb-1\">\n {{ label() }}\n </div>\n }\n\n <div class=\"relative\">\n @if (!isTextArea()) {\n <div class=\"flex\">\n @if (searchMode()) {\n @let isDisabledSearch = actualControl()?.disabled || isDisabled();\n <input\n #input\n [id]=\"id()\"\n type=\"text\"\n [value]=\"displayValue() || ''\"\n [placeholder]=\"placeholder() || label()\"\n [readOnly]=\"true\"\n [disabled]=\"isDisabledSearch\"\n (click)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (keydown.enter)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (blur)=\"onBlur()\"\n autocomplete=\"off\"\n [attr.aria-invalid]=\"(shouldShowError() && !isDisabledSearch) || null\"\n [class.cursor-pointer]=\"!isDisabledSearch\"\n [class.cursor-not-allowed]=\"isDisabledSearch\"\n [class._shk-bg-surface-50]=\"isDisabledSearch\"\n [class._shk-text-surface-400]=\"isDisabledSearch\"\n class=\"shk-control shk-control-addon block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-l-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500': shouldShowError() && !isDisabledSearch,\n '_shk-border': !shouldShowError() || isDisabledSearch,\n 'cursor-pointer': !isDisabledSearch,\n 'cursor-not-allowed _shk-text-surface-400 dark:[color:var(--shk-surface-400)]': isDisabledSearch\n }\"\n />\n <button\n type=\"button\"\n (click)=\"searchButtonClick.emit()\"\n tabindex=\"-1\"\n [disabled]=\"isDisabledSearch\"\n class=\"px-3 flex items-center justify-center shrink-0 _shk-bg-primary hover:[background-color:var(--shk-primary-700)] text-white border _shk-border-primary rounded-r-lg transition-colors duration-200 disabled:[background-color:var(--shk-surface-300)] dark:disabled:[background-color:var(--shk-surface-200)] disabled:[border-color:var(--shk-surface-300)] dark:disabled:[border-color:var(--shk-surface-200)] disabled:cursor-not-allowed\"\n >\n <svg [shkIcon]=\"getIcon('search')\" class=\"w-4 h-4\"></svg>\n </button>\n }\n\n @if (!searchMode()) {\n <input\n #input\n [id]=\"id()\"\n [maxlength]=\"maxLength() || (formatCard() ? 19 : null)\"\n [min]=\"type() === 'number' && preventNegative() ? '0' : null\"\n (keypress)=\"type() === 'number' || numbersOnly() ? numberValidation($event) : null\"\n [type]=\"effectiveType()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n [autocomplete]=\"autocomplete()\"\n (blur)=\"onBlur()\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n [class.pr-8]=\"type() === 'password' && actualControl()?.value?.length > 0\"\n [class.pr-3]=\"type() !== 'password' || !actualControl()?.value?.length\"\n />\n\n @if (type() === 'password' && actualControl()?.value?.length > 0) {\n <button\n type=\"button\"\n (click)=\"togglePasswordVisibility()\"\n [disabled]=\"actualControl()?.disabled\"\n class=\"absolute right-3 top-1/2 -translate-y-1/2 _shk-text-surface-400 hover:[color:var(--shk-surface-600)] dark:hover:[color:var(--shk-surface-600)] focus:outline-none\"\n >\n @if (showPassword()) {\n <svg [shkIcon]=\"getIcon('eye-off')\" class=\"w-4 h-4\"></svg>\n } @else {\n <svg [shkIcon]=\"getIcon('eye')\" class=\"w-4 h-4\"></svg>\n }\n </button>\n }\n }\n </div>\n }\n\n @if (isTextArea()) {\n <textarea\n #textarea\n [id]=\"id()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n (blur)=\"onBlur()\"\n [class]=\"isTextArea() ? textAreaHeight() : 'h-28'\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 resize-none disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed disabled:[color:var(--shk-surface-400)] dark:disabled:[color:var(--shk-surface-400)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n ></textarea>\n }\n </div>\n\n @if (shouldShowError()) {\n <div class=\"mt-1 text-xs text-red-500 max-h-20 overflow-y-auto _shk-scrollbar\" tabindex=\"-1\">\n <ul class=\"list-disc pl-4 space-y-1\">\n @for (error of getErrorMessages(); track error) {\n <li>{{ error }}</li>\n }\n </ul>\n </div>\n }\n</div>\n",
421
+ dependencies: [
422
+ {
423
+ kind: "ngmodule",
424
+ type: CommonModule
425
+ },
426
+ {
427
+ kind: "directive",
428
+ type: i1.NgClass,
429
+ selector: "[ngClass]",
430
+ inputs: ["class", "ngClass"]
431
+ },
432
+ {
433
+ kind: "ngmodule",
434
+ type: ReactiveFormsModule
435
+ },
436
+ {
437
+ kind: "directive",
438
+ type: i2.DefaultValueAccessor,
439
+ selector: "input:not([type=checkbox]):not([ngNoCva])[formControlName],textarea:not([ngNoCva])[formControlName],input:not([type=checkbox]):not([ngNoCva])[formControl],textarea:not([ngNoCva])[formControl],input:not([type=checkbox]):not([ngNoCva])[ngModel],textarea:not([ngNoCva])[ngModel],[ngDefaultControl]"
440
+ },
441
+ {
442
+ kind: "directive",
443
+ type: i2.NgControlStatus,
444
+ selector: "[formControlName],[ngModel],[formControl]"
445
+ },
446
+ {
447
+ kind: "directive",
448
+ type: i2.MaxLengthValidator,
449
+ selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]",
450
+ inputs: ["maxlength"]
451
+ },
452
+ {
453
+ kind: "directive",
454
+ type: i2.FormControlDirective,
455
+ selector: "[formControl]",
456
+ inputs: [
457
+ "formControl",
458
+ "disabled",
459
+ "ngModel"
460
+ ],
461
+ outputs: ["ngModelChange"],
462
+ exportAs: ["ngForm"]
463
+ },
464
+ {
465
+ kind: "directive",
466
+ type: ShkIconDirective,
467
+ selector: "svg[shkIcon]",
468
+ inputs: [
469
+ "shkIcon",
470
+ "size",
471
+ "strokeWidth",
472
+ "color"
473
+ ]
474
+ }
475
+ ],
476
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
477
+ });
478
+ }
479
+ };
480
+ i0.ɵɵngDeclareClassMetadata({
481
+ minVersion: "12.0.0",
482
+ version: "22.3.2",
483
+ ngImport: i0,
484
+ type: TextFieldComponent,
485
+ decorators: [{
486
+ type: Component,
487
+ args: [{
488
+ selector: "shk-text-field",
489
+ imports: [
490
+ CommonModule,
491
+ ReactiveFormsModule,
492
+ ShkIconDirective
493
+ ],
494
+ changeDetection: ChangeDetectionStrategy.OnPush,
495
+ providers: [{
496
+ provide: NG_VALUE_ACCESSOR,
497
+ useExisting: forwardRef(() => TextFieldComponent),
498
+ multi: true
499
+ }],
500
+ template: "<div class=\"relative mb-4\">\n @if (label()) {\n <div class=\"text-sm font-medium _shk-text-surface-700 mb-1\">\n {{ label() }}\n </div>\n }\n\n <div class=\"relative\">\n @if (!isTextArea()) {\n <div class=\"flex\">\n @if (searchMode()) {\n @let isDisabledSearch = actualControl()?.disabled || isDisabled();\n <input\n #input\n [id]=\"id()\"\n type=\"text\"\n [value]=\"displayValue() || ''\"\n [placeholder]=\"placeholder() || label()\"\n [readOnly]=\"true\"\n [disabled]=\"isDisabledSearch\"\n (click)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (keydown.enter)=\"!isDisabledSearch && searchButtonClick.emit()\"\n (blur)=\"onBlur()\"\n autocomplete=\"off\"\n [attr.aria-invalid]=\"(shouldShowError() && !isDisabledSearch) || null\"\n [class.cursor-pointer]=\"!isDisabledSearch\"\n [class.cursor-not-allowed]=\"isDisabledSearch\"\n [class._shk-bg-surface-50]=\"isDisabledSearch\"\n [class._shk-text-surface-400]=\"isDisabledSearch\"\n class=\"shk-control shk-control-addon block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-l-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500': shouldShowError() && !isDisabledSearch,\n '_shk-border': !shouldShowError() || isDisabledSearch,\n 'cursor-pointer': !isDisabledSearch,\n 'cursor-not-allowed _shk-text-surface-400 dark:[color:var(--shk-surface-400)]': isDisabledSearch\n }\"\n />\n <button\n type=\"button\"\n (click)=\"searchButtonClick.emit()\"\n tabindex=\"-1\"\n [disabled]=\"isDisabledSearch\"\n class=\"px-3 flex items-center justify-center shrink-0 _shk-bg-primary hover:[background-color:var(--shk-primary-700)] text-white border _shk-border-primary rounded-r-lg transition-colors duration-200 disabled:[background-color:var(--shk-surface-300)] dark:disabled:[background-color:var(--shk-surface-200)] disabled:[border-color:var(--shk-surface-300)] dark:disabled:[border-color:var(--shk-surface-200)] disabled:cursor-not-allowed\"\n >\n <svg [shkIcon]=\"getIcon('search')\" class=\"w-4 h-4\"></svg>\n </button>\n }\n\n @if (!searchMode()) {\n <input\n #input\n [id]=\"id()\"\n [maxlength]=\"maxLength() || (formatCard() ? 19 : null)\"\n [min]=\"type() === 'number' && preventNegative() ? '0' : null\"\n (keypress)=\"type() === 'number' || numbersOnly() ? numberValidation($event) : null\"\n [type]=\"effectiveType()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n [autocomplete]=\"autocomplete()\"\n (blur)=\"onBlur()\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n [class.pr-8]=\"type() === 'password' && actualControl()?.value?.length > 0\"\n [class.pr-3]=\"type() !== 'password' || !actualControl()?.value?.length\"\n />\n\n @if (type() === 'password' && actualControl()?.value?.length > 0) {\n <button\n type=\"button\"\n (click)=\"togglePasswordVisibility()\"\n [disabled]=\"actualControl()?.disabled\"\n class=\"absolute right-3 top-1/2 -translate-y-1/2 _shk-text-surface-400 hover:[color:var(--shk-surface-600)] dark:hover:[color:var(--shk-surface-600)] focus:outline-none\"\n >\n @if (showPassword()) {\n <svg [shkIcon]=\"getIcon('eye-off')\" class=\"w-4 h-4\"></svg>\n } @else {\n <svg [shkIcon]=\"getIcon('eye')\" class=\"w-4 h-4\"></svg>\n }\n </button>\n }\n }\n </div>\n }\n\n @if (isTextArea()) {\n <textarea\n #textarea\n [id]=\"id()\"\n [formControl]=\"$any(actualControl())\"\n [placeholder]=\"placeholder() || label()\"\n (input)=\"onInput($event)\"\n (blur)=\"onBlur()\"\n [class]=\"isTextArea() ? textAreaHeight() : 'h-28'\"\n [attr.aria-invalid]=\"shouldShowError() || null\"\n [class.shk-control-valid]=\"wasFixedError()\"\n class=\"shk-control block w-full px-3 py-2 _shk-text-surface-700 _shk-bg-surface-50 border rounded-lg transition-colors placeholder:[color:var(--shk-surface-400)] dark:placeholder:[color:var(--shk-surface-400)] focus:outline-none focus:[background-color:var(--shk-surface-50)] dark:focus:[background-color:var(--shk-surface-100)] focus:ring-1 resize-none disabled:[background-color:var(--shk-surface-50)] dark:disabled:[background-color:var(--shk-surface-100)] disabled:cursor-not-allowed disabled:[color:var(--shk-surface-400)] dark:disabled:[color:var(--shk-surface-400)] sm:text-sm\"\n [ngClass]=\"{\n 'border-red-500 focus:border-red-500 focus:ring-red-500': shouldShowError(),\n 'border-green-500 focus:border-green-500 focus:ring-green-500': wasFixedError(),\n '_shk-border focus:[border-color:var(--shk-primary-500)] focus:[--tw-ring-color:var(--shk-primary-500)]': !shouldShowError() && !wasFixedError()\n }\"\n ></textarea>\n }\n </div>\n\n @if (shouldShowError()) {\n <div class=\"mt-1 text-xs text-red-500 max-h-20 overflow-y-auto _shk-scrollbar\" tabindex=\"-1\">\n <ul class=\"list-disc pl-4 space-y-1\">\n @for (error of getErrorMessages(); track error) {\n <li>{{ error }}</li>\n }\n </ul>\n </div>\n }\n</div>\n"
501
+ }]
502
+ }],
503
+ ctorParameters: () => [],
504
+ propDecorators: {
505
+ id: [{
506
+ type: i0.Input,
507
+ args: [{
508
+ isSignal: true,
509
+ alias: "id",
510
+ required: false
511
+ }]
512
+ }],
513
+ formatCard: [{
514
+ type: i0.Input,
515
+ args: [{
516
+ isSignal: true,
517
+ alias: "formatCard",
518
+ required: false
519
+ }]
520
+ }],
521
+ preventNegative: [{
522
+ type: i0.Input,
523
+ args: [{
524
+ isSignal: true,
525
+ alias: "preventNegative",
526
+ required: false
527
+ }]
528
+ }],
529
+ label: [{
530
+ type: i0.Input,
531
+ args: [{
532
+ isSignal: true,
533
+ alias: "label",
534
+ required: false
535
+ }]
536
+ }],
537
+ type: [{
538
+ type: i0.Input,
539
+ args: [{
540
+ isSignal: true,
541
+ alias: "type",
542
+ required: false
543
+ }]
544
+ }],
545
+ numbersOnly: [{
546
+ type: i0.Input,
547
+ args: [{
548
+ isSignal: true,
549
+ alias: "numbersOnly",
550
+ required: false
551
+ }]
552
+ }],
553
+ allowDecimals: [{
554
+ type: i0.Input,
555
+ args: [{
556
+ isSignal: true,
557
+ alias: "allowDecimals",
558
+ required: false
559
+ }]
560
+ }],
561
+ maxLength: [{
562
+ type: i0.Input,
563
+ args: [{
564
+ isSignal: true,
565
+ alias: "maxLength",
566
+ required: false
567
+ }]
568
+ }],
569
+ placeholder: [{
570
+ type: i0.Input,
571
+ args: [{
572
+ isSignal: true,
573
+ alias: "placeholder",
574
+ required: false
575
+ }]
576
+ }],
577
+ errorMessages: [{
578
+ type: i0.Input,
579
+ args: [{
580
+ isSignal: true,
581
+ alias: "errorMessages",
582
+ required: false
583
+ }]
584
+ }],
585
+ formGroup: [{
586
+ type: i0.Input,
587
+ args: [{
588
+ isSignal: true,
589
+ alias: "formGroup",
590
+ required: false
591
+ }]
592
+ }],
593
+ control: [{
594
+ type: i0.Input,
595
+ args: [{
596
+ isSignal: true,
597
+ alias: "control",
598
+ required: false
599
+ }]
600
+ }],
601
+ disabled: [{
602
+ type: i0.Input,
603
+ args: [{
604
+ isSignal: true,
605
+ alias: "disabled",
606
+ required: false
607
+ }]
608
+ }],
609
+ errorMessage: [{
610
+ type: i0.Input,
611
+ args: [{
612
+ isSignal: true,
613
+ alias: "errorMessage",
614
+ required: false
615
+ }]
616
+ }],
617
+ isTextArea: [{
618
+ type: i0.Input,
619
+ args: [{
620
+ isSignal: true,
621
+ alias: "isTextArea",
622
+ required: false
623
+ }]
624
+ }],
625
+ textAreaHeight: [{
626
+ type: i0.Input,
627
+ args: [{
628
+ isSignal: true,
629
+ alias: "textAreaHeight",
630
+ required: false
631
+ }]
632
+ }],
633
+ searchMode: [{
634
+ type: i0.Input,
635
+ args: [{
636
+ isSignal: true,
637
+ alias: "searchMode",
638
+ required: false
639
+ }]
640
+ }],
641
+ displayValue: [{
642
+ type: i0.Input,
643
+ args: [{
644
+ isSignal: true,
645
+ alias: "displayValue",
646
+ required: false
647
+ }]
648
+ }],
649
+ autocomplete: [{
650
+ type: i0.Input,
651
+ args: [{
652
+ isSignal: true,
653
+ alias: "autocomplete",
654
+ required: false
655
+ }]
656
+ }],
657
+ searchButtonClick: [{
658
+ type: i0.Output,
659
+ args: ["searchButtonClick"]
660
+ }],
661
+ touch: [{
662
+ type: i0.Output,
663
+ args: ["touch"]
664
+ }],
665
+ inputElement: [{
666
+ type: i0.ViewChild,
667
+ args: ["input", { isSignal: true }]
668
+ }],
669
+ textareaElement: [{
670
+ type: i0.ViewChild,
671
+ args: ["textarea", { isSignal: true }]
672
+ }],
673
+ value: [{
674
+ type: i0.Input,
675
+ args: [{
676
+ isSignal: true,
677
+ alias: "value",
678
+ required: false
679
+ }]
680
+ }, {
681
+ type: i0.Output,
682
+ args: ["valueChange"]
683
+ }]
684
+ }
685
+ });
402
686
  export { TextFieldComponent };
403
- //# sourceMappingURL=shirkasoft-ui-components-text-field.mjs.map
687
+
688
+ //# sourceMappingURL=shirkasoft-ui-components-text-field.mjs.map