@aaamb/ngx-design-system 1.3.5 → 1.3.6
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 +69 -0
- package/src/components/datepicker-selector/datepicker-selector.component.ts +287 -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 +1333 -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 +157 -0
- package/src/components/side-nav/side-nav.component.ts +306 -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 +441 -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 +486 -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 -4024
- 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 -1132
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
4
|
+
import { delay, of } from 'rxjs';
|
|
5
|
+
import { MultipleSelectorComponent } from './multiple-selector.component';
|
|
6
|
+
import {
|
|
7
|
+
AdsIconName,
|
|
8
|
+
AdsMultipleSelectorAsyncOptions,
|
|
9
|
+
AdsMultipleSelectorOption,
|
|
10
|
+
AdsMultipleSelectorOptionOrGroup,
|
|
11
|
+
} from '../../../core/types';
|
|
12
|
+
|
|
13
|
+
const defaultOptions: AdsMultipleSelectorOption[] = [
|
|
14
|
+
{ label: 'Mexico', value: 'mx' },
|
|
15
|
+
{ label: 'Colombia', value: 'co' },
|
|
16
|
+
{ label: 'Argentina', value: 'ar' },
|
|
17
|
+
{ label: 'Chile', value: 'cl' },
|
|
18
|
+
{ label: 'Peru', value: 'pe' },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const meta: Meta<MultipleSelectorComponent> = {
|
|
22
|
+
title: 'Components/Selectors/MultipleSelector',
|
|
23
|
+
component: MultipleSelectorComponent,
|
|
24
|
+
args: {
|
|
25
|
+
label: 'Countries',
|
|
26
|
+
placeholder: 'Search and select',
|
|
27
|
+
allowClear: true,
|
|
28
|
+
disabled: false,
|
|
29
|
+
loading: false,
|
|
30
|
+
itemName: 'country',
|
|
31
|
+
pluralItemName: 'countries',
|
|
32
|
+
options: defaultOptions,
|
|
33
|
+
errorMessage: '',
|
|
34
|
+
labelIconName: null,
|
|
35
|
+
},
|
|
36
|
+
argTypes: {
|
|
37
|
+
label: { control: 'text' },
|
|
38
|
+
placeholder: { control: 'text' },
|
|
39
|
+
allowClear: { control: 'boolean' },
|
|
40
|
+
disabled: { control: 'boolean' },
|
|
41
|
+
loading: { control: 'boolean' },
|
|
42
|
+
itemName: { control: 'text' },
|
|
43
|
+
pluralItemName: { control: 'text' },
|
|
44
|
+
options: { control: 'object' },
|
|
45
|
+
errorMessage: { control: 'text' },
|
|
46
|
+
labelIconName: { control: 'boolean' },
|
|
47
|
+
},
|
|
48
|
+
render: (args) => {
|
|
49
|
+
const form = new FormGroup({
|
|
50
|
+
countries: new FormControl<(string | number)[]>([]),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
moduleMetadata: {
|
|
55
|
+
imports: [CommonModule, ReactiveFormsModule],
|
|
56
|
+
},
|
|
57
|
+
props: {
|
|
58
|
+
...args,
|
|
59
|
+
form,
|
|
60
|
+
},
|
|
61
|
+
template: `
|
|
62
|
+
<div class="max-w-md space-y-4">
|
|
63
|
+
<form [formGroup]="form">
|
|
64
|
+
<ads-multiple-selector
|
|
65
|
+
formControlName="countries"
|
|
66
|
+
[label]="label"
|
|
67
|
+
[placeholder]="placeholder"
|
|
68
|
+
[allowClear]="allowClear"
|
|
69
|
+
[disabled]="disabled"
|
|
70
|
+
[loading]="loading"
|
|
71
|
+
[itemName]="itemName"
|
|
72
|
+
[pluralItemName]="pluralItemName"
|
|
73
|
+
[options]="options"
|
|
74
|
+
[errorMessage]="errorMessage"
|
|
75
|
+
[labelIconName]="labelIconName ? 'plus' : null"
|
|
76
|
+
></ads-multiple-selector>
|
|
77
|
+
</form>
|
|
78
|
+
|
|
79
|
+
<p class="m-0 text-sm text-green-base">Value: {{ form.controls.countries.value | json }}</p>
|
|
80
|
+
</div>
|
|
81
|
+
`,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default meta;
|
|
87
|
+
type Story = StoryObj<MultipleSelectorComponent>;
|
|
88
|
+
|
|
89
|
+
export const Playground: Story = {};
|
|
90
|
+
|
|
91
|
+
export const AsyncObservableOptions: Story = {
|
|
92
|
+
render: (args) => {
|
|
93
|
+
const form = new FormGroup({
|
|
94
|
+
countries: new FormControl<(string | number)[]>([]),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const asyncOptions: AdsMultipleSelectorAsyncOptions = of(
|
|
98
|
+
defaultOptions,
|
|
99
|
+
).pipe(delay(1200));
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
moduleMetadata: {
|
|
103
|
+
imports: [CommonModule, ReactiveFormsModule],
|
|
104
|
+
},
|
|
105
|
+
props: {
|
|
106
|
+
...args,
|
|
107
|
+
form,
|
|
108
|
+
asyncOptions,
|
|
109
|
+
},
|
|
110
|
+
template: `
|
|
111
|
+
<div class="max-w-md space-y-4">
|
|
112
|
+
<form [formGroup]="form">
|
|
113
|
+
<ads-multiple-selector
|
|
114
|
+
formControlName="countries"
|
|
115
|
+
[label]="label"
|
|
116
|
+
[placeholder]="placeholder"
|
|
117
|
+
[allowClear]="allowClear"
|
|
118
|
+
[disabled]="disabled"
|
|
119
|
+
[itemName]="itemName"
|
|
120
|
+
[pluralItemName]="pluralItemName"
|
|
121
|
+
[asyncOptions]="asyncOptions"
|
|
122
|
+
[errorMessage]="errorMessage"
|
|
123
|
+
[labelIconName]="labelIconName ? 'plus' : null"
|
|
124
|
+
></ads-multiple-selector>
|
|
125
|
+
</form>
|
|
126
|
+
|
|
127
|
+
<p class="m-0 text-sm text-green-base">Value: {{ form.controls.countries.value | json }}</p>
|
|
128
|
+
</div>
|
|
129
|
+
`,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const AsyncPromiseOptions: Story = {
|
|
135
|
+
render: (args) => {
|
|
136
|
+
const form = new FormGroup({
|
|
137
|
+
countries: new FormControl<(string | number)[]>([]),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const asyncOptions: AdsMultipleSelectorAsyncOptions = new Promise(
|
|
141
|
+
(resolve) => {
|
|
142
|
+
setTimeout(() => resolve(defaultOptions), 1200);
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
moduleMetadata: {
|
|
148
|
+
imports: [CommonModule, ReactiveFormsModule],
|
|
149
|
+
},
|
|
150
|
+
props: {
|
|
151
|
+
...args,
|
|
152
|
+
form,
|
|
153
|
+
asyncOptions,
|
|
154
|
+
},
|
|
155
|
+
template: `
|
|
156
|
+
<div class="max-w-md space-y-4">
|
|
157
|
+
<form [formGroup]="form">
|
|
158
|
+
<ads-multiple-selector
|
|
159
|
+
formControlName="countries"
|
|
160
|
+
[label]="label"
|
|
161
|
+
[placeholder]="placeholder"
|
|
162
|
+
[allowClear]="allowClear"
|
|
163
|
+
[disabled]="disabled"
|
|
164
|
+
[itemName]="itemName"
|
|
165
|
+
[pluralItemName]="pluralItemName"
|
|
166
|
+
[asyncOptions]="asyncOptions"
|
|
167
|
+
[errorMessage]="errorMessage"
|
|
168
|
+
[labelIconName]="labelIconName ? 'plus' : null"
|
|
169
|
+
></ads-multiple-selector>
|
|
170
|
+
</form>
|
|
171
|
+
|
|
172
|
+
<p class="m-0 text-sm text-green-base">Value: {{ form.controls.countries.value | json }}</p>
|
|
173
|
+
</div>
|
|
174
|
+
`,
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const WithGroupedOptions: Story = {
|
|
180
|
+
render: (args) => {
|
|
181
|
+
const form = new FormGroup({
|
|
182
|
+
countries: new FormControl<(string | number)[]>([]),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const groupedOptions: AdsMultipleSelectorOptionOrGroup[] = [
|
|
186
|
+
{
|
|
187
|
+
label: 'North America',
|
|
188
|
+
children: [
|
|
189
|
+
{ label: 'Mexico', value: 'mx' },
|
|
190
|
+
{ label: 'Canada', value: 'ca' },
|
|
191
|
+
{ label: 'United States', value: 'us' },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
label: 'South America',
|
|
196
|
+
children: [
|
|
197
|
+
{ label: 'Colombia', value: 'co' },
|
|
198
|
+
{ label: 'Argentina', value: 'ar' },
|
|
199
|
+
{ label: 'Chile', value: 'cl' },
|
|
200
|
+
{ label: 'Peru', value: 'pe' },
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
label: 'Other',
|
|
205
|
+
children: [
|
|
206
|
+
{ label: 'Spain', value: 'es' },
|
|
207
|
+
{ label: 'Brazil', value: 'br' },
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
moduleMetadata: {
|
|
214
|
+
imports: [CommonModule, ReactiveFormsModule],
|
|
215
|
+
},
|
|
216
|
+
props: {
|
|
217
|
+
...args,
|
|
218
|
+
form,
|
|
219
|
+
options: groupedOptions,
|
|
220
|
+
},
|
|
221
|
+
template: `
|
|
222
|
+
<div class="max-w-md space-y-4">
|
|
223
|
+
<form [formGroup]="form">
|
|
224
|
+
<ads-multiple-selector
|
|
225
|
+
formControlName="countries"
|
|
226
|
+
[label]="label"
|
|
227
|
+
[placeholder]="placeholder"
|
|
228
|
+
[allowClear]="allowClear"
|
|
229
|
+
[disabled]="disabled"
|
|
230
|
+
[itemName]="itemName"
|
|
231
|
+
[pluralItemName]="pluralItemName"
|
|
232
|
+
[options]="groupedOptions"
|
|
233
|
+
[errorMessage]="errorMessage"
|
|
234
|
+
[labelIconName]="labelIconName ? 'plus' : null"
|
|
235
|
+
></ads-multiple-selector>
|
|
236
|
+
</form>
|
|
237
|
+
|
|
238
|
+
<p class="m-0 text-sm text-green-base">Value: {{ form.controls.countries.value | json }}</p>
|
|
239
|
+
</div>
|
|
240
|
+
`,
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
export const WithAsyncGroupedOptions: Story = {
|
|
246
|
+
render: (args) => {
|
|
247
|
+
const form = new FormGroup({
|
|
248
|
+
countries: new FormControl<(string | number)[]>([]),
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
const groupedOptions: AdsMultipleSelectorOptionOrGroup[] = [
|
|
252
|
+
{
|
|
253
|
+
label: 'North America',
|
|
254
|
+
children: [
|
|
255
|
+
{ label: 'Mexico', value: 'mx' },
|
|
256
|
+
{ label: 'Canada', value: 'ca' },
|
|
257
|
+
{ label: 'United States', value: 'us' },
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
label: 'South America',
|
|
262
|
+
children: [
|
|
263
|
+
{ label: 'Colombia', value: 'co' },
|
|
264
|
+
{ label: 'Argentina', value: 'ar' },
|
|
265
|
+
{ label: 'Chile', value: 'cl' },
|
|
266
|
+
{ label: 'Peru', value: 'pe' },
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
];
|
|
270
|
+
|
|
271
|
+
const asyncOptions: AdsMultipleSelectorAsyncOptions = of(groupedOptions).pipe(
|
|
272
|
+
delay(1200),
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
moduleMetadata: {
|
|
277
|
+
imports: [CommonModule, ReactiveFormsModule],
|
|
278
|
+
},
|
|
279
|
+
props: {
|
|
280
|
+
...args,
|
|
281
|
+
form,
|
|
282
|
+
asyncOptions,
|
|
283
|
+
},
|
|
284
|
+
template: `
|
|
285
|
+
<div class="max-w-md space-y-4">
|
|
286
|
+
<form [formGroup]="form">
|
|
287
|
+
<ads-multiple-selector
|
|
288
|
+
formControlName="countries"
|
|
289
|
+
[label]="label"
|
|
290
|
+
[placeholder]="placeholder"
|
|
291
|
+
[allowClear]="allowClear"
|
|
292
|
+
[disabled]="disabled"
|
|
293
|
+
[itemName]="itemName"
|
|
294
|
+
[pluralItemName]="pluralItemName"
|
|
295
|
+
[asyncOptions]="asyncOptions"
|
|
296
|
+
[errorMessage]="errorMessage"
|
|
297
|
+
[labelIconName]="labelIconName ? 'plus' : null"
|
|
298
|
+
></ads-multiple-selector>
|
|
299
|
+
</form>
|
|
300
|
+
|
|
301
|
+
<p class="m-0 text-sm text-green-base">Value: {{ form.controls.countries.value | json }}</p>
|
|
302
|
+
</div>
|
|
303
|
+
`,
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
Component,
|
|
4
|
+
CUSTOM_ELEMENTS_SCHEMA,
|
|
5
|
+
effect,
|
|
6
|
+
forwardRef,
|
|
7
|
+
input,
|
|
8
|
+
OnDestroy,
|
|
9
|
+
output,
|
|
10
|
+
signal,
|
|
11
|
+
} from '@angular/core';
|
|
12
|
+
import {
|
|
13
|
+
ControlValueAccessor,
|
|
14
|
+
FormsModule,
|
|
15
|
+
NG_VALUE_ACCESSOR,
|
|
16
|
+
} from '@angular/forms';
|
|
17
|
+
import { Subscription, Observable } from 'rxjs';
|
|
18
|
+
import { NzFilterOptionType, NzSelectModule } from 'ng-zorro-antd/select';
|
|
19
|
+
import {
|
|
20
|
+
AdsIconName,
|
|
21
|
+
AdsMultipleSelectorAsyncOptions,
|
|
22
|
+
AdsMultipleSelectorOption,
|
|
23
|
+
AdsMultipleSelectorOptionGroup,
|
|
24
|
+
AdsMultipleSelectorOptionOrGroup,
|
|
25
|
+
AdsMultipleSelectorValue,
|
|
26
|
+
} from '../../../core/types';
|
|
27
|
+
import { LabelComponent } from '../../label/label.component';
|
|
28
|
+
import { ErrorMessageComponent } from '../../error-message/error-message.component';
|
|
29
|
+
|
|
30
|
+
@Component({
|
|
31
|
+
selector: 'ads-multiple-selector',
|
|
32
|
+
standalone: true,
|
|
33
|
+
imports: [
|
|
34
|
+
CommonModule,
|
|
35
|
+
FormsModule,
|
|
36
|
+
NzSelectModule,
|
|
37
|
+
LabelComponent,
|
|
38
|
+
ErrorMessageComponent,
|
|
39
|
+
],
|
|
40
|
+
templateUrl: './multiple-selector.component.html',
|
|
41
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
42
|
+
providers: [
|
|
43
|
+
{
|
|
44
|
+
provide: NG_VALUE_ACCESSOR,
|
|
45
|
+
useExisting: forwardRef(() => MultipleSelectorComponent),
|
|
46
|
+
multi: true,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
})
|
|
50
|
+
export class MultipleSelectorComponent
|
|
51
|
+
implements ControlValueAccessor, OnDestroy
|
|
52
|
+
{
|
|
53
|
+
label = input<string>('');
|
|
54
|
+
placeholder = input<string>('Select one or more options');
|
|
55
|
+
disabled = input<boolean>(false);
|
|
56
|
+
allowClear = input<boolean>(true);
|
|
57
|
+
loading = input<boolean>(false);
|
|
58
|
+
options = input<AdsMultipleSelectorOptionOrGroup[]>([]);
|
|
59
|
+
asyncOptions = input<AdsMultipleSelectorAsyncOptions | null>(null);
|
|
60
|
+
value = input<AdsMultipleSelectorValue[]>([]);
|
|
61
|
+
itemName = input<string>('item');
|
|
62
|
+
pluralItemName = input<string>('items');
|
|
63
|
+
errorMessage = input<string>('Please select at least one option.');
|
|
64
|
+
labelIconName = input<AdsIconName | null>(null);
|
|
65
|
+
|
|
66
|
+
onLabelButtonClick = output<void>();
|
|
67
|
+
valueChange = output<AdsMultipleSelectorValue[]>();
|
|
68
|
+
|
|
69
|
+
private cvaMode = false;
|
|
70
|
+
private cvaDisabled = false;
|
|
71
|
+
private asyncLoading = signal<boolean>(false);
|
|
72
|
+
private optionsSubscription: Subscription | null = null;
|
|
73
|
+
private asyncRequestId = 0;
|
|
74
|
+
private baseOptions = signal<AdsMultipleSelectorOptionOrGroup[]>([]);
|
|
75
|
+
|
|
76
|
+
currentValue = signal<AdsMultipleSelectorValue[]>([]);
|
|
77
|
+
resolvedOptions = signal<AdsMultipleSelectorOptionOrGroup[]>([]);
|
|
78
|
+
|
|
79
|
+
private onChange: (value: AdsMultipleSelectorValue[]) => void = () => {};
|
|
80
|
+
private onTouched: () => void = () => {};
|
|
81
|
+
|
|
82
|
+
readonly filterOption: NzFilterOptionType = (input, option) => {
|
|
83
|
+
const label = String(option?.nzLabel ?? '').toLowerCase();
|
|
84
|
+
return label.includes(input.toLowerCase());
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
constructor() {
|
|
88
|
+
effect(() => {
|
|
89
|
+
if (!this.cvaMode) {
|
|
90
|
+
this.currentValue.set(this.normalizeValues(this.value()));
|
|
91
|
+
this.reorderOptions();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
effect(() => {
|
|
96
|
+
const providedAsyncOptions = this.asyncOptions();
|
|
97
|
+
|
|
98
|
+
if (!providedAsyncOptions) {
|
|
99
|
+
this.cancelAsyncOptionsSubscription();
|
|
100
|
+
this.asyncLoading.set(false);
|
|
101
|
+
this.baseOptions.set(this.options());
|
|
102
|
+
this.reorderOptions();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.loadAsyncOptions(providedAsyncOptions);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
ngOnDestroy(): void {
|
|
111
|
+
this.cancelAsyncOptionsSubscription();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
isDisabled(): boolean {
|
|
115
|
+
return this.disabled() || this.cvaDisabled;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
isLoading(): boolean {
|
|
119
|
+
return this.loading() || this.asyncLoading();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
onSelectionChange(values: AdsMultipleSelectorValue[]): void {
|
|
123
|
+
const normalizedValues = this.normalizeValues(values);
|
|
124
|
+
this.currentValue.set(normalizedValues);
|
|
125
|
+
this.reorderOptions();
|
|
126
|
+
this.onChange(normalizedValues);
|
|
127
|
+
this.valueChange.emit(normalizedValues);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
onBlur(): void {
|
|
131
|
+
this.onTouched();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
selectedItemsSummary(selectedCount: number): string {
|
|
135
|
+
const name =
|
|
136
|
+
selectedCount > 1 ? `${this.pluralItemName()}` : this.itemName();
|
|
137
|
+
return `${selectedCount} ${name} selected`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
writeValue(value: unknown): void {
|
|
141
|
+
this.cvaMode = true;
|
|
142
|
+
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
this.currentValue.set(this.normalizeValues(value));
|
|
145
|
+
this.reorderOptions();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.currentValue.set([]);
|
|
150
|
+
this.reorderOptions();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
registerOnChange(fn: (value: AdsMultipleSelectorValue[]) => void): void {
|
|
154
|
+
this.onChange = fn;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
registerOnTouched(fn: () => void): void {
|
|
158
|
+
this.onTouched = fn;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
setDisabledState(isDisabled: boolean): void {
|
|
162
|
+
this.cvaDisabled = isDisabled;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private loadAsyncOptions(source: AdsMultipleSelectorAsyncOptions): void {
|
|
166
|
+
this.cancelAsyncOptionsSubscription();
|
|
167
|
+
|
|
168
|
+
const requestId = ++this.asyncRequestId;
|
|
169
|
+
this.asyncLoading.set(true);
|
|
170
|
+
|
|
171
|
+
if (this.isPromise(source)) {
|
|
172
|
+
source
|
|
173
|
+
.then((items) => {
|
|
174
|
+
this.applyAsyncOptionsResult(requestId, items);
|
|
175
|
+
})
|
|
176
|
+
.catch(() => {
|
|
177
|
+
this.applyAsyncOptionsResult(requestId, []);
|
|
178
|
+
})
|
|
179
|
+
.finally(() => {
|
|
180
|
+
this.finishAsyncOptionsRequest(requestId);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
this.optionsSubscription = (
|
|
187
|
+
source as Observable<AdsMultipleSelectorOptionOrGroup[]>
|
|
188
|
+
).subscribe({
|
|
189
|
+
next: (items: AdsMultipleSelectorOptionOrGroup[]) => {
|
|
190
|
+
this.applyAsyncOptionsResult(requestId, items);
|
|
191
|
+
},
|
|
192
|
+
error: () => {
|
|
193
|
+
this.applyAsyncOptionsResult(requestId, []);
|
|
194
|
+
this.finishAsyncOptionsRequest(requestId);
|
|
195
|
+
},
|
|
196
|
+
complete: () => {
|
|
197
|
+
this.finishAsyncOptionsRequest(requestId);
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private applyAsyncOptionsResult(
|
|
203
|
+
requestId: number,
|
|
204
|
+
options: AdsMultipleSelectorOptionOrGroup[],
|
|
205
|
+
): void {
|
|
206
|
+
if (requestId !== this.asyncRequestId) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
this.baseOptions.set(options);
|
|
211
|
+
this.reorderOptions();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private finishAsyncOptionsRequest(requestId: number): void {
|
|
215
|
+
if (requestId !== this.asyncRequestId) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
this.asyncLoading.set(false);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private reorderOptions(): void {
|
|
223
|
+
const selectedValues = this.currentValue();
|
|
224
|
+
const baseOptions = this.baseOptions();
|
|
225
|
+
|
|
226
|
+
if (!selectedValues.length) {
|
|
227
|
+
this.resolvedOptions.set(baseOptions);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const groups: AdsMultipleSelectorOptionGroup[] = [];
|
|
232
|
+
const flatOptions: AdsMultipleSelectorOption[] = [];
|
|
233
|
+
const selectedSet = new Set(selectedValues);
|
|
234
|
+
|
|
235
|
+
for (const item of baseOptions) {
|
|
236
|
+
if ('children' in item) {
|
|
237
|
+
groups.push(item);
|
|
238
|
+
} else {
|
|
239
|
+
flatOptions.push(item);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const selectedByValue = new Map<
|
|
244
|
+
AdsMultipleSelectorValue,
|
|
245
|
+
AdsMultipleSelectorOption
|
|
246
|
+
>();
|
|
247
|
+
for (const option of flatOptions) {
|
|
248
|
+
selectedByValue.set(option.value, option);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const selectedOptions: AdsMultipleSelectorOption[] = [];
|
|
252
|
+
for (const value of selectedValues) {
|
|
253
|
+
const option = selectedByValue.get(value);
|
|
254
|
+
if (option) {
|
|
255
|
+
selectedOptions.push(option);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const unselectedOptions = flatOptions.filter(
|
|
260
|
+
(option) => !selectedSet.has(option.value),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
this.resolvedOptions.set([
|
|
264
|
+
...groups,
|
|
265
|
+
...selectedOptions,
|
|
266
|
+
...unselectedOptions,
|
|
267
|
+
]);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private normalizeValues(values: unknown[]): AdsMultipleSelectorValue[] {
|
|
271
|
+
const normalizedValues: AdsMultipleSelectorValue[] = [];
|
|
272
|
+
|
|
273
|
+
for (const value of values) {
|
|
274
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
275
|
+
normalizedValues.push(value);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return normalizedValues;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private cancelAsyncOptionsSubscription(): void {
|
|
283
|
+
if (!this.optionsSubscription) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
this.optionsSubscription.unsubscribe();
|
|
288
|
+
this.optionsSubscription = null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private isPromise(
|
|
292
|
+
value: AdsMultipleSelectorAsyncOptions,
|
|
293
|
+
): value is Promise<AdsMultipleSelectorOption[]> {
|
|
294
|
+
return (
|
|
295
|
+
typeof (value as Promise<AdsMultipleSelectorOption[]>).then === 'function'
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
onLabelClicked(): void {
|
|
300
|
+
this.onLabelButtonClick.emit();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
isOptionGroup(
|
|
304
|
+
item: AdsMultipleSelectorOptionOrGroup,
|
|
305
|
+
): item is { label: string; children: AdsMultipleSelectorOption[] } {
|
|
306
|
+
return 'children' in item;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<div class="flex w-full flex-col">
|
|
2
|
+
<ads-label
|
|
3
|
+
[text]="label()"
|
|
4
|
+
[iconName]="labelIconName()"
|
|
5
|
+
(iconClicked)="onLabelClicked()"
|
|
6
|
+
></ads-label>
|
|
7
|
+
|
|
8
|
+
<nz-select
|
|
9
|
+
class="w-full"
|
|
10
|
+
[ngModel]="currentValue()"
|
|
11
|
+
[nzPlaceHolder]="placeholder()"
|
|
12
|
+
[nzShowSearch]="true"
|
|
13
|
+
[nzAllowClear]="allowClear()"
|
|
14
|
+
[nzDisabled]="isDisabled()"
|
|
15
|
+
[nzLoading]="isLoading()"
|
|
16
|
+
[nzFilterOption]="filterOption"
|
|
17
|
+
(ngModelChange)="onSelectionChange($event)"
|
|
18
|
+
(nzBlur)="onBlur()"
|
|
19
|
+
[nzStatus]="errorMessage() ? 'error' : ''"
|
|
20
|
+
>
|
|
21
|
+
@for (option of resolvedOptions(); track $index) {
|
|
22
|
+
@if (isOptionGroup(option)) {
|
|
23
|
+
<nz-option-group [nzLabel]="option.label">
|
|
24
|
+
@for (item of option.children; track item.value) {
|
|
25
|
+
<nz-option
|
|
26
|
+
[nzValue]="item.value"
|
|
27
|
+
[nzLabel]="item.label"
|
|
28
|
+
[nzDisabled]="item.disabled"
|
|
29
|
+
></nz-option>
|
|
30
|
+
}
|
|
31
|
+
</nz-option-group>
|
|
32
|
+
} @else {
|
|
33
|
+
<nz-option
|
|
34
|
+
[nzValue]="option.value"
|
|
35
|
+
[nzLabel]="option.label"
|
|
36
|
+
[nzDisabled]="option.disabled"
|
|
37
|
+
></nz-option>
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
</nz-select>
|
|
41
|
+
|
|
42
|
+
<ads-error-message
|
|
43
|
+
[hasError]="!!errorMessage()"
|
|
44
|
+
[errorMessage]="errorMessage()"
|
|
45
|
+
></ads-error-message>
|
|
46
|
+
</div>
|