@aaamb/ngx-design-system 1.3.9 → 1.4.1
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/.editorconfig +17 -0
- package/.nvmrc +1 -0
- package/.postcssrc.json +5 -0
- package/.storybook/main.ts +20 -0
- package/.storybook/preview.ts +23 -0
- package/.storybook/storybook.css +1 -0
- package/.storybook/tsconfig.json +19 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +20 -0
- package/.vscode/tasks.json +42 -0
- package/CHANGELOG.md +10 -0
- package/LOCAL_DEVELOPMENT.md +129 -0
- package/angular.json +74 -0
- package/bitbucket-pipelines.yml +41 -0
- package/iac/bin/app.ts +42 -0
- package/iac/cdk.json +82 -0
- package/iac/lib/config/environments.ts +19 -0
- package/iac/lib/config/types.ts +13 -0
- package/iac/lib/stacks/certificate-stack.ts +34 -0
- package/iac/lib/stacks/frontend-stack.ts +120 -0
- package/iac/lib/stacks/index.ts +2 -0
- package/iac/package-lock.json +726 -0
- package/iac/package.json +25 -0
- package/iac/tsconfig.json +24 -0
- package/ng-package.json +8 -0
- package/package.json +58 -14
- package/src/components/button/button-green.stories.ts +101 -0
- package/src/components/button/button-text.stories.ts +105 -0
- package/src/components/button/button-white.stories.ts +105 -0
- package/src/components/button/button.component.stories.ts +91 -0
- package/src/components/button/button.component.ts +93 -0
- package/src/components/checkbox/checkbox.component.html +30 -0
- package/src/components/checkbox/checkbox.component.stories.ts +183 -0
- package/src/components/checkbox/checkbox.component.ts +211 -0
- package/src/components/datepicker-selector/datepicker-selector.component.html +103 -0
- package/src/components/datepicker-selector/datepicker-selector.component.stories.ts +123 -0
- package/src/components/datepicker-selector/datepicker-selector.component.ts +337 -0
- package/src/components/error-message/error-message.component.html +3 -0
- package/src/components/error-message/error-message.component.ts +13 -0
- package/src/components/filter-button/filter-button.component.html +286 -0
- package/src/components/filter-button/filter-button.component.stories.ts +123 -0
- package/src/components/filter-button/filter-button.component.ts +582 -0
- package/src/components/icon/icon.component.ts +20 -0
- package/src/components/icon/icon.html +1424 -0
- package/src/components/icon/icon.stories.ts +49 -0
- package/src/components/icon/icons-list.stories.ts +42 -0
- package/src/components/input/input.component.stories.ts +101 -0
- package/src/components/input/input.component.ts +317 -0
- package/src/components/input/input.html +160 -0
- package/src/components/input-datepicker/input-datepicker.component.ts +356 -0
- package/src/components/input-datepicker/input-datepicker.html +69 -0
- package/src/components/input-datepicker/input-datepicker.stories.ts +99 -0
- package/src/components/input-rangepicker/input-rangepicker.component.ts +365 -0
- package/src/components/input-rangepicker/input-rangepicker.html +54 -0
- package/src/components/input-rangepicker/input-rangepicker.stories.ts +88 -0
- package/src/components/input-weekpicker/input-weekpicker.component.ts +417 -0
- package/src/components/input-weekpicker/input-weekpicker.html +54 -0
- package/src/components/input-weekpicker/input-weekpicker.stories.ts +103 -0
- package/src/components/label/label.component.html +20 -0
- package/src/components/label/label.component.ts +22 -0
- package/src/components/modals/delicate-confirmation-modal/delicate-confirmation-modal.component.html +32 -0
- package/src/components/modals/delicate-confirmation-modal/delicate-confirmation-modal.component.stories.ts +57 -0
- package/src/components/modals/delicate-confirmation-modal/delicate-confirmation-modal.component.ts +48 -0
- package/src/components/modals/feedback-modal/feedback-modal.component.html +118 -0
- package/src/components/modals/feedback-modal/feedback-modal.component.stories.ts +93 -0
- package/src/components/modals/feedback-modal/feedback-modal.component.ts +187 -0
- package/src/components/modals/help-modal/help-modal.component.html +32 -0
- package/src/components/modals/help-modal/help-modal.component.stories.ts +76 -0
- package/src/components/modals/help-modal/help-modal.component.ts +54 -0
- package/src/components/modals/information-modal/information-modal.component.html +24 -0
- package/src/components/modals/information-modal/information-modal.component.stories.ts +62 -0
- package/src/components/modals/information-modal/information-modal.component.ts +35 -0
- package/src/components/modals/main-modal/main-modal.component.html +85 -0
- package/src/components/modals/main-modal/main-modal.component.stories.ts +127 -0
- package/src/components/modals/main-modal/main-modal.component.ts +85 -0
- package/src/components/modals/notification-modal/notification-modal.component.html +22 -0
- package/src/components/modals/notification-modal/notification-modal.component.stories.ts +59 -0
- package/src/components/modals/notification-modal/notification-modal.component.ts +37 -0
- package/src/components/selectors/multiple-selector/multiple-selector.component.html +51 -0
- package/src/components/selectors/multiple-selector/multiple-selector.component.stories.ts +306 -0
- package/src/components/selectors/multiple-selector/multiple-selector.component.ts +308 -0
- package/src/components/selectors/single-selector/single-selector.component.html +46 -0
- package/src/components/selectors/single-selector/single-selector.component.stories.ts +294 -0
- package/src/components/selectors/single-selector/single-selector.component.ts +239 -0
- package/src/components/side-nav/side-nav.component.stories.ts +176 -0
- package/src/components/side-nav/side-nav.component.ts +325 -0
- package/src/components/snackbar/snackbar.component.ts +150 -0
- package/src/components/snackbar/snackbar.html +21 -0
- package/src/components/snackbar/snackbar.stories.ts +51 -0
- package/src/components/state/state.component.ts +30 -0
- package/src/components/state/state.html +13 -0
- package/src/components/state/state.stories.ts +74 -0
- package/src/components/table/table.component.html +466 -0
- package/src/components/table/table.component.scss +28 -0
- package/src/components/table/table.component.stories.ts +655 -0
- package/src/components/table/table.component.ts +475 -0
- package/src/components/tabs/tabs.component.stories.ts +114 -0
- package/src/components/tabs/tabs.component.ts +69 -0
- package/src/core/types.ts +494 -0
- package/src/public-api.ts +23 -0
- package/tsconfig.json +37 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +13 -0
- package/fesm2022/aaamb-ngx-design-system.mjs +0 -4075
- package/fesm2022/aaamb-ngx-design-system.mjs.map +0 -1
- package/styles/compiled.css +0 -2
- package/types/aaamb-ngx-design-system.d.ts +0 -1142
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import { IconComponent } from './icon.component';
|
|
3
|
+
import { ICONS } from '../../public-api';
|
|
4
|
+
|
|
5
|
+
type IconProps = IconComponent;
|
|
6
|
+
|
|
7
|
+
const meta: Meta<IconProps> = {
|
|
8
|
+
title: 'Components/Icon',
|
|
9
|
+
component: IconComponent,
|
|
10
|
+
argTypes: {
|
|
11
|
+
iconName: {
|
|
12
|
+
control: 'select',
|
|
13
|
+
options: Object.keys(ICONS),
|
|
14
|
+
},
|
|
15
|
+
size: {
|
|
16
|
+
control: 'select',
|
|
17
|
+
options: [16, 24],
|
|
18
|
+
},
|
|
19
|
+
color: {
|
|
20
|
+
control: 'select',
|
|
21
|
+
options: ['Default', 'Black', 'Green', 'Red'],
|
|
22
|
+
labels: {
|
|
23
|
+
Default: '',
|
|
24
|
+
Black: '#111827',
|
|
25
|
+
Green: '#16a34a',
|
|
26
|
+
red: '#ef4444',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
title: {
|
|
30
|
+
control: 'text',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
render: (args) => ({
|
|
34
|
+
props: args,
|
|
35
|
+
template: `<ads-icon [iconName]="iconName" [size]="size" [color]="color" [title]="title"></ads-icon>`,
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default meta;
|
|
40
|
+
type Story = StoryObj<IconProps>;
|
|
41
|
+
|
|
42
|
+
export const Playground: Story = {
|
|
43
|
+
args: {
|
|
44
|
+
iconName: 'chart_bars',
|
|
45
|
+
size: 24,
|
|
46
|
+
color: '',
|
|
47
|
+
title: 'Icon',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import { IconComponent } from './icon.component';
|
|
3
|
+
import { ICONS } from '../../core/types';
|
|
4
|
+
|
|
5
|
+
const iconNames = Object.keys(ICONS).sort((a, b) => a.localeCompare(b));
|
|
6
|
+
|
|
7
|
+
const meta: Meta = {
|
|
8
|
+
title: 'Components/Icon/List',
|
|
9
|
+
component: IconComponent,
|
|
10
|
+
parameters: {
|
|
11
|
+
controls: { disable: true },
|
|
12
|
+
},
|
|
13
|
+
render: () => ({
|
|
14
|
+
props: {
|
|
15
|
+
iconNames,
|
|
16
|
+
copyIconName: async (iconName: string) => {
|
|
17
|
+
await navigator.clipboard.writeText(iconName);
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
template: `
|
|
21
|
+
<div class="grid w-full grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-7">
|
|
22
|
+
@for (iconName of iconNames; track iconName) {
|
|
23
|
+
<div class="flex min-h-27.5 flex-col items-center justify-center gap-2 rounded-lg border border-solid border-neutral-disabled-bg p-3">
|
|
24
|
+
<ads-icon [iconName]="iconName" [size]="30" color="#014744"></ads-icon>
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
class="wrap-break-word cursor-pointer text-center text-xs text-black underline"
|
|
28
|
+
(click)="copyIconName(iconName)"
|
|
29
|
+
>
|
|
30
|
+
{{ iconName }}
|
|
31
|
+
</button>
|
|
32
|
+
</div>
|
|
33
|
+
}
|
|
34
|
+
</div>
|
|
35
|
+
`,
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default meta;
|
|
40
|
+
type Story = StoryObj;
|
|
41
|
+
|
|
42
|
+
export const AllIcons: Story = {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
3
|
+
import { InputComponent } from './input.component';
|
|
4
|
+
import { AdsInputType } from '../../core/types';
|
|
5
|
+
|
|
6
|
+
type InputProps = InputComponent & { value: string };
|
|
7
|
+
|
|
8
|
+
const INPUT_TYPES: AdsInputType[] = [
|
|
9
|
+
'text',
|
|
10
|
+
'text_area',
|
|
11
|
+
'number',
|
|
12
|
+
'cellphone',
|
|
13
|
+
'password',
|
|
14
|
+
'rate',
|
|
15
|
+
'search',
|
|
16
|
+
'payment_card',
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const meta: Meta<InputProps> = {
|
|
20
|
+
title: 'Components/Input',
|
|
21
|
+
component: InputComponent,
|
|
22
|
+
argTypes: {
|
|
23
|
+
label: { control: 'text' },
|
|
24
|
+
placeholder: { control: 'text' },
|
|
25
|
+
inputType: { control: 'select', options: INPUT_TYPES },
|
|
26
|
+
value: { control: 'text' },
|
|
27
|
+
hasError: { control: 'boolean' },
|
|
28
|
+
disabled: { control: 'boolean' },
|
|
29
|
+
},
|
|
30
|
+
render: (args) => ({
|
|
31
|
+
props: args,
|
|
32
|
+
template: `
|
|
33
|
+
<div class="w-100">
|
|
34
|
+
<ads-input
|
|
35
|
+
[label]="label"
|
|
36
|
+
[placeholder]="placeholder"
|
|
37
|
+
[inputType]="inputType"
|
|
38
|
+
[value]="value"
|
|
39
|
+
[hasError]="hasError"
|
|
40
|
+
[disabled]="disabled"
|
|
41
|
+
(valueChange)="value = $event"
|
|
42
|
+
></ads-input>
|
|
43
|
+
<span>Value: {{ value }}</span>
|
|
44
|
+
</div>
|
|
45
|
+
`,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default meta;
|
|
50
|
+
type Story = StoryObj<InputProps>;
|
|
51
|
+
|
|
52
|
+
export const Playground: Story = {
|
|
53
|
+
args: {
|
|
54
|
+
label: 'Input label',
|
|
55
|
+
placeholder: 'Escribe aquí',
|
|
56
|
+
inputType: 'text',
|
|
57
|
+
value: '',
|
|
58
|
+
hasError: false,
|
|
59
|
+
disabled: false,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const ReactiveForms: Story = {
|
|
64
|
+
args: {
|
|
65
|
+
label: 'Input label',
|
|
66
|
+
placeholder: 'Escribe aquí',
|
|
67
|
+
inputType: 'text',
|
|
68
|
+
hasError: false,
|
|
69
|
+
disabled: false,
|
|
70
|
+
},
|
|
71
|
+
render: (args) => {
|
|
72
|
+
const form = new FormGroup({
|
|
73
|
+
field: new FormControl(''),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
moduleMetadata: {
|
|
78
|
+
imports: [ReactiveFormsModule],
|
|
79
|
+
},
|
|
80
|
+
props: {
|
|
81
|
+
...args,
|
|
82
|
+
form,
|
|
83
|
+
},
|
|
84
|
+
template: `
|
|
85
|
+
<div class="w-100">
|
|
86
|
+
<form [formGroup]="form">
|
|
87
|
+
<ads-input
|
|
88
|
+
formControlName="field"
|
|
89
|
+
[label]="label"
|
|
90
|
+
[placeholder]="placeholder"
|
|
91
|
+
[inputType]="inputType"
|
|
92
|
+
[hasError]="hasError"
|
|
93
|
+
[disabled]="disabled"
|
|
94
|
+
></ads-input>
|
|
95
|
+
</form>
|
|
96
|
+
<span>Value: {{ form.get('field')?.value }}</span>
|
|
97
|
+
</div>
|
|
98
|
+
`,
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { NgClass } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
Component,
|
|
4
|
+
ElementRef,
|
|
5
|
+
effect,
|
|
6
|
+
forwardRef,
|
|
7
|
+
input,
|
|
8
|
+
output,
|
|
9
|
+
signal,
|
|
10
|
+
ViewChild,
|
|
11
|
+
} from '@angular/core';
|
|
12
|
+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
13
|
+
import { NgxMaskDirective, provideNgxMask } from 'ngx-mask';
|
|
14
|
+
import { AdsIconName, AdsInputType, PaymentCardBrand } from '../../core/types';
|
|
15
|
+
import { IconComponent } from '../icon/icon.component';
|
|
16
|
+
import { LabelComponent } from '../label/label.component';
|
|
17
|
+
import { ErrorMessageComponent } from '../error-message/error-message.component';
|
|
18
|
+
|
|
19
|
+
@Component({
|
|
20
|
+
selector: 'ads-input',
|
|
21
|
+
standalone: true,
|
|
22
|
+
imports: [NgxMaskDirective, IconComponent, NgClass, LabelComponent, ErrorMessageComponent],
|
|
23
|
+
templateUrl: './input.html',
|
|
24
|
+
providers: [
|
|
25
|
+
provideNgxMask(),
|
|
26
|
+
{
|
|
27
|
+
provide: NG_VALUE_ACCESSOR,
|
|
28
|
+
useExisting: forwardRef(() => InputComponent),
|
|
29
|
+
multi: true,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
export class InputComponent implements ControlValueAccessor {
|
|
34
|
+
label = input<string>('');
|
|
35
|
+
placeholder = input<string>('');
|
|
36
|
+
inputType = input<AdsInputType>('text');
|
|
37
|
+
textAreaRows = input<number>(4);
|
|
38
|
+
value = input<string>('');
|
|
39
|
+
hasError = input<boolean>(false);
|
|
40
|
+
disabled = input<boolean>(false);
|
|
41
|
+
errorMessage = input<string>('Error message');
|
|
42
|
+
showPassword = signal<boolean>(false);
|
|
43
|
+
|
|
44
|
+
passwordIconNames: { show: AdsIconName; hide: AdsIconName } = {
|
|
45
|
+
show: 'eye',
|
|
46
|
+
hide: 'hide',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
moneyIconName: AdsIconName = 'dolar_sign';
|
|
50
|
+
|
|
51
|
+
basicClass =
|
|
52
|
+
'w-full rounded-[10px] border border-solid px-3 py-2 text-sm outline-none placeholder:neutral-disabled-text';
|
|
53
|
+
|
|
54
|
+
valueChange = output<string>();
|
|
55
|
+
|
|
56
|
+
private cvaMode = false;
|
|
57
|
+
private cvaDisabled = false;
|
|
58
|
+
currentValue = signal<string>('');
|
|
59
|
+
@ViewChild('textAreaRef') textAreaRef?: ElementRef<HTMLTextAreaElement>;
|
|
60
|
+
|
|
61
|
+
private onChange: (value: string) => void = () => {};
|
|
62
|
+
private onTouched: () => void = () => {};
|
|
63
|
+
|
|
64
|
+
constructor() {
|
|
65
|
+
effect(() => {
|
|
66
|
+
if (!this.cvaMode) {
|
|
67
|
+
this.currentValue.set(this.value());
|
|
68
|
+
this.scheduleTextAreaResize();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
effect(() => {
|
|
73
|
+
if (this.inputType() === 'text_area') {
|
|
74
|
+
this.scheduleTextAreaResize();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isDisabled(): boolean {
|
|
80
|
+
return this.disabled() || this.cvaDisabled;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
activeInputClass(): string {
|
|
84
|
+
return 'hover:border-aqua-2 focus:border-aqua-2';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
errorActiveClass(): string {
|
|
88
|
+
return 'hover:border-red-1 focus:border-red-1';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
inputStateClass(): string {
|
|
92
|
+
if (this.isDisabled()) {
|
|
93
|
+
return `${this.basicClass} border-neutral-disabled-bg bg-neutral-disabled-bg text-neutral-disabled-text placeholder:neutral-disabled-text cursor-default`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (this.hasError()) {
|
|
97
|
+
return `${this.basicClass} ${this.errorActiveClass()} border-red-3 bg-red-6 text-green-base`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return `${this.basicClass} ${this.activeInputClass()} border-aqua-5 bg-aqua-6 focus:border-primary text-green-base`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
rateClass(): string {
|
|
104
|
+
const basicStyles =
|
|
105
|
+
'w-full rounded-[10px] border border-solid pl-8 py-2 text-sm outline-none text-green-base';
|
|
106
|
+
|
|
107
|
+
if (this.isDisabled()) {
|
|
108
|
+
return `${basicStyles} border-neutral-disabled-bg bg-neutral-disabled-bg text-neutral-disabled-text placeholder:neutral-disabled-text cursor-default`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (this.hasError()) {
|
|
112
|
+
return `${basicStyles} ${this.errorActiveClass()} border-red-3 bg-red-6 text-green-base`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return `${basicStyles} ${this.activeInputClass()} border-aqua-5 bg-aqua-6 focus:border-primary text-green-base`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
cardInputClass(): string {
|
|
119
|
+
const basicStyles =
|
|
120
|
+
'w-full rounded-[10px] border border-solid pl-12 py-2 text-sm outline-none text-green-base';
|
|
121
|
+
|
|
122
|
+
if (this.isDisabled()) {
|
|
123
|
+
return `${basicStyles} border-neutral-disabled-bg bg-neutral-disabled-bg text-neutral-disabled-text placeholder:neutral-disabled-text cursor-default`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (this.hasError()) {
|
|
127
|
+
return `${basicStyles} ${this.errorActiveClass()} border-red-3 bg-red-6 text-green-base`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return `${basicStyles} ${this.activeInputClass()} border-aqua-5 bg-aqua-6 focus:border-primary text-green-base`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
resolvedPlaceholder(): string {
|
|
134
|
+
if (this.placeholder()) {
|
|
135
|
+
return this.placeholder();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (this.inputType() === 'number') {
|
|
139
|
+
return '0';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (this.inputType() === 'password') {
|
|
143
|
+
return 'Enter your password';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (this.inputType() === 'text') {
|
|
147
|
+
return 'Text here...';
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (this.inputType() === 'text_area') {
|
|
151
|
+
return 'Write here...';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (this.inputType() === 'rate') {
|
|
155
|
+
return '0.00';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (this.inputType() === 'cellphone') {
|
|
159
|
+
return '(000) 000-0000';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.inputType() === 'search') {
|
|
163
|
+
return 'Search...';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (this.inputType() === 'payment_card') {
|
|
167
|
+
return '1111-2222-3333-4444';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return '';
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
maskPattern(): string | null {
|
|
174
|
+
switch (this.inputType()) {
|
|
175
|
+
case 'number':
|
|
176
|
+
return 'separator.2';
|
|
177
|
+
case 'cellphone':
|
|
178
|
+
return '(000) 000-0000';
|
|
179
|
+
case 'rate':
|
|
180
|
+
return 'separator.4';
|
|
181
|
+
case 'payment_card':
|
|
182
|
+
return '0000-0000-0000-0000';
|
|
183
|
+
default:
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
onInputValue(value: string): void {
|
|
189
|
+
this.currentValue.set(value);
|
|
190
|
+
const emitted = this.sanitizeOutput(value);
|
|
191
|
+
this.onChange(emitted);
|
|
192
|
+
this.valueChange.emit(emitted);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
onInputBlur(): void {
|
|
196
|
+
this.onTouched();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
onTextAreaInput(value: string, textArea: HTMLTextAreaElement): void {
|
|
200
|
+
this.onInputValue(value);
|
|
201
|
+
this.resizeTextArea(textArea);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
writeValue(value: unknown): void {
|
|
205
|
+
this.cvaMode = true;
|
|
206
|
+
this.currentValue.set(value == null ? '' : String(value));
|
|
207
|
+
this.scheduleTextAreaResize();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
registerOnChange(fn: (value: string) => void): void {
|
|
211
|
+
this.onChange = fn;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
registerOnTouched(fn: () => void): void {
|
|
215
|
+
this.onTouched = fn;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
setDisabledState(isDisabled: boolean): void {
|
|
219
|
+
this.cvaDisabled = isDisabled;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
toggleShowPassword(): void {
|
|
223
|
+
this.showPassword.update((current) => !current);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private scheduleTextAreaResize(): void {
|
|
227
|
+
queueMicrotask(() => {
|
|
228
|
+
if (this.inputType() !== 'text_area' || !this.textAreaRef) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
this.resizeTextArea(this.textAreaRef.nativeElement);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private resizeTextArea(textArea: HTMLTextAreaElement): void {
|
|
237
|
+
textArea.style.height = '2rem';
|
|
238
|
+
const nextHeight = Math.max(textArea.scrollHeight, 32);
|
|
239
|
+
textArea.style.height = `${nextHeight}px`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private sanitizeCardNumber(value: string): string {
|
|
243
|
+
return value.replace(/\D/g, '');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private sanitizeNumericPreserveDot(value: string): string {
|
|
247
|
+
const cleaned = String(value).replace(/[^0-9.]/g, '');
|
|
248
|
+
const parts = cleaned.split('.');
|
|
249
|
+
if (parts.length <= 1) return cleaned;
|
|
250
|
+
const first = parts.shift() ?? '';
|
|
251
|
+
return `${first}.${parts.join('')}`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private sanitizeOutput(value: string): string {
|
|
255
|
+
const type = this.inputType();
|
|
256
|
+
|
|
257
|
+
if (type === 'payment_card') {
|
|
258
|
+
return this.sanitizeCardNumber(value);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (type === 'cellphone') {
|
|
262
|
+
return String(value).replace(/\D/g, '');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (type === 'number' || type === 'rate') {
|
|
266
|
+
return this.sanitizeNumericPreserveDot(value);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
detectPaymentCardBrand(
|
|
273
|
+
value: string = this.currentValue(),
|
|
274
|
+
): PaymentCardBrand {
|
|
275
|
+
const digits = this.sanitizeCardNumber(value);
|
|
276
|
+
|
|
277
|
+
if (/^4/.test(digits)) {
|
|
278
|
+
return 'visa';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (/^(5[1-5]|2(2[2-9]|[3-6]\d|7[01]|720))/.test(digits)) {
|
|
282
|
+
return 'mastercard';
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (/^3[47]/.test(digits)) {
|
|
286
|
+
return 'amex';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (/^(6011|65|64[4-9])/.test(digits)) {
|
|
290
|
+
return 'discover';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return 'icon_card';
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
paymentCardIconName(): AdsIconName {
|
|
297
|
+
const brand = this.detectPaymentCardBrand();
|
|
298
|
+
|
|
299
|
+
if (brand === 'visa') {
|
|
300
|
+
return 'visa';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (brand === 'mastercard') {
|
|
304
|
+
return 'mastercard';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (brand === 'amex') {
|
|
308
|
+
return 'amex';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (brand === 'discover') {
|
|
312
|
+
return 'discover';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return 'icon_card';
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<div class="flex w-full flex-col">
|
|
2
|
+
<ads-label [text]="label()"></ads-label>
|
|
3
|
+
|
|
4
|
+
@switch (inputType()) {
|
|
5
|
+
@case ("text") {
|
|
6
|
+
<input
|
|
7
|
+
[class]="inputStateClass()"
|
|
8
|
+
type="text"
|
|
9
|
+
[value]="currentValue()"
|
|
10
|
+
[placeholder]="resolvedPlaceholder()"
|
|
11
|
+
[disabled]="isDisabled()"
|
|
12
|
+
(input)="onInputValue($any($event.target).value)"
|
|
13
|
+
(blur)="onInputBlur()"
|
|
14
|
+
/>
|
|
15
|
+
}
|
|
16
|
+
@case ("text_area") {
|
|
17
|
+
<textarea
|
|
18
|
+
#textAreaRef
|
|
19
|
+
[class]="inputStateClass() + ' resize-none overflow-hidden min-h-8'"
|
|
20
|
+
[rows]="textAreaRows()"
|
|
21
|
+
[value]="currentValue()"
|
|
22
|
+
[placeholder]="resolvedPlaceholder()"
|
|
23
|
+
[disabled]="isDisabled()"
|
|
24
|
+
(input)="
|
|
25
|
+
onTextAreaInput($any($event.target).value, $any($event.target))
|
|
26
|
+
"
|
|
27
|
+
(blur)="onInputBlur()"
|
|
28
|
+
></textarea>
|
|
29
|
+
}
|
|
30
|
+
@case ("password") {
|
|
31
|
+
<div class="relative flex items-center">
|
|
32
|
+
<input
|
|
33
|
+
[class]="inputStateClass()"
|
|
34
|
+
[type]="showPassword() ? 'text' : 'password'"
|
|
35
|
+
[value]="currentValue()"
|
|
36
|
+
[placeholder]="resolvedPlaceholder()"
|
|
37
|
+
[disabled]="isDisabled()"
|
|
38
|
+
(input)="onInputValue($any($event.target).value)"
|
|
39
|
+
(blur)="onInputBlur()"
|
|
40
|
+
/>
|
|
41
|
+
<ads-icon
|
|
42
|
+
[iconName]="
|
|
43
|
+
showPassword() ? passwordIconNames.hide : passwordIconNames.show
|
|
44
|
+
"
|
|
45
|
+
[size]="16"
|
|
46
|
+
class="absolute right-3 cursor-pointer"
|
|
47
|
+
[ngClass]="{
|
|
48
|
+
'text-red-3': hasError(),
|
|
49
|
+
'text-green-1': !hasError(),
|
|
50
|
+
'text-neutral-disabled-text': isDisabled(),
|
|
51
|
+
}"
|
|
52
|
+
(click)="toggleShowPassword()"
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
}
|
|
56
|
+
@case ("number") {
|
|
57
|
+
<input
|
|
58
|
+
[class]="inputStateClass()"
|
|
59
|
+
type="text"
|
|
60
|
+
[value]="currentValue()"
|
|
61
|
+
[mask]="maskPattern()"
|
|
62
|
+
[placeholder]="resolvedPlaceholder()"
|
|
63
|
+
[disabled]="isDisabled()"
|
|
64
|
+
(input)="onInputValue($any($event.target).value)"
|
|
65
|
+
(blur)="onInputBlur()"
|
|
66
|
+
/>
|
|
67
|
+
}
|
|
68
|
+
@case ("cellphone") {
|
|
69
|
+
<input
|
|
70
|
+
[class]="inputStateClass()"
|
|
71
|
+
type="text"
|
|
72
|
+
[value]="currentValue()"
|
|
73
|
+
[mask]="maskPattern()"
|
|
74
|
+
[dropSpecialCharacters]="false"
|
|
75
|
+
[placeholder]="resolvedPlaceholder()"
|
|
76
|
+
[disabled]="isDisabled()"
|
|
77
|
+
(input)="onInputValue($any($event.target).value)"
|
|
78
|
+
(blur)="onInputBlur()"
|
|
79
|
+
/>
|
|
80
|
+
}
|
|
81
|
+
@case ("rate") {
|
|
82
|
+
<div class="relative flex items-center">
|
|
83
|
+
<div
|
|
84
|
+
class="absolute left-2 text-green-1 pointer-events-none border-0 border-r border-solid border-neutral-disabled-bg h-5 pr-1 flex items-center justify-center"
|
|
85
|
+
>
|
|
86
|
+
<ads-icon
|
|
87
|
+
[ngClass]="{
|
|
88
|
+
'text-red-3': hasError(),
|
|
89
|
+
'text-green-1': !hasError(),
|
|
90
|
+
'text-neutral-disabled-text': isDisabled(),
|
|
91
|
+
}"
|
|
92
|
+
[iconName]="moneyIconName"
|
|
93
|
+
[size]="16"
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
<input
|
|
97
|
+
[class]="rateClass()"
|
|
98
|
+
type="text"
|
|
99
|
+
[value]="currentValue()"
|
|
100
|
+
[mask]="maskPattern()"
|
|
101
|
+
[placeholder]="resolvedPlaceholder()"
|
|
102
|
+
[disabled]="isDisabled()"
|
|
103
|
+
(input)="onInputValue($any($event.target).value)"
|
|
104
|
+
(blur)="onInputBlur()"
|
|
105
|
+
[allowNegativeNumbers]="false"
|
|
106
|
+
thousandSeparator=","
|
|
107
|
+
decimalMarker="."
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
}
|
|
111
|
+
@case ("search") {
|
|
112
|
+
<div class="relative flex items-center">
|
|
113
|
+
<ads-icon
|
|
114
|
+
class="absolute left-3 text-green-1 pointer-events-none"
|
|
115
|
+
[ngClass]="{
|
|
116
|
+
'text-red-3': hasError(),
|
|
117
|
+
'text-green-1': !hasError(),
|
|
118
|
+
'text-neutral-disabled-text': isDisabled(),
|
|
119
|
+
}"
|
|
120
|
+
iconName="search"
|
|
121
|
+
[size]="16"
|
|
122
|
+
/>
|
|
123
|
+
<input
|
|
124
|
+
[class]="inputStateClass() + ' pl-9'"
|
|
125
|
+
type="text"
|
|
126
|
+
[value]="currentValue()"
|
|
127
|
+
[placeholder]="resolvedPlaceholder()"
|
|
128
|
+
[disabled]="isDisabled()"
|
|
129
|
+
(input)="onInputValue($any($event.target).value)"
|
|
130
|
+
(blur)="onInputBlur()"
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
}
|
|
134
|
+
@case ("payment_card") {
|
|
135
|
+
<div class="relative flex items-center">
|
|
136
|
+
<ads-icon
|
|
137
|
+
class="absolute left-3 text-green-1 pointer-events-none"
|
|
138
|
+
[iconName]="paymentCardIconName()"
|
|
139
|
+
[size]="30"
|
|
140
|
+
/>
|
|
141
|
+
<input
|
|
142
|
+
[class]="cardInputClass()"
|
|
143
|
+
type="text"
|
|
144
|
+
[value]="currentValue()"
|
|
145
|
+
[mask]="maskPattern()"
|
|
146
|
+
[dropSpecialCharacters]="false"
|
|
147
|
+
[placeholder]="resolvedPlaceholder()"
|
|
148
|
+
[disabled]="isDisabled()"
|
|
149
|
+
(input)="onInputValue($any($event.target).value)"
|
|
150
|
+
(blur)="onInputBlur()"
|
|
151
|
+
/>
|
|
152
|
+
</div>
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<ads-error-message
|
|
158
|
+
[hasError]="hasError()"
|
|
159
|
+
[errorMessage]="errorMessage()"
|
|
160
|
+
></ads-error-message>
|