@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 { NgClass } from '@angular/common';
|
|
2
|
+
import { Component, computed, input, output, signal } from '@angular/core';
|
|
3
|
+
import { NzTooltipModule } from 'ng-zorro-antd/tooltip';
|
|
4
|
+
import {
|
|
5
|
+
AdsSideNavFooterButton,
|
|
6
|
+
AdsSideNavOption,
|
|
7
|
+
AdsSideNavRoute,
|
|
8
|
+
} from '../../core/types';
|
|
9
|
+
import { IconComponent } from '../icon/icon.component';
|
|
10
|
+
|
|
11
|
+
@Component({
|
|
12
|
+
selector: 'ads-side-nav',
|
|
13
|
+
standalone: true,
|
|
14
|
+
imports: [NgClass, IconComponent, NzTooltipModule],
|
|
15
|
+
template: `
|
|
16
|
+
<aside
|
|
17
|
+
class="w-full h-full bg-green-base flex flex-col items-center select-none"
|
|
18
|
+
>
|
|
19
|
+
<div
|
|
20
|
+
class="w-full h-16 flex items-center justify-center bg-white p-2"
|
|
21
|
+
>
|
|
22
|
+
@if (currentLogoSrc()) {
|
|
23
|
+
<img
|
|
24
|
+
[src]="currentLogoSrc()"
|
|
25
|
+
[alt]="logoAlt()"
|
|
26
|
+
class="h-full w-full object-contain"
|
|
27
|
+
/>
|
|
28
|
+
}
|
|
29
|
+
</div>
|
|
30
|
+
<nav
|
|
31
|
+
class="relative w-full flex-1 flex flex-col gap-5 overflow-hidden"
|
|
32
|
+
[ngClass]="isCollapsed() ? 'px-0 py-8' : 'px-5 py-8'"
|
|
33
|
+
>
|
|
34
|
+
@for (option of options(); track option.name; let idx = $index) {
|
|
35
|
+
<div>
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
nz-tooltip
|
|
39
|
+
class="cursor-pointer flex items-center max-h-12 transition-colors duration-300 border-none outline-none"
|
|
40
|
+
[ngClass]="optionButtonClasses(option)"
|
|
41
|
+
[attr.data-testid]="'side-nav-option-' + idx"
|
|
42
|
+
(click)="onOptionClick(option)"
|
|
43
|
+
[nzTooltipTitle]="isCollapsed() ? option.name : null"
|
|
44
|
+
nzTooltipPlacement="right"
|
|
45
|
+
[nzTooltipMouseEnterDelay]="0.3"
|
|
46
|
+
>
|
|
47
|
+
@if (option.icon) {
|
|
48
|
+
<ads-icon
|
|
49
|
+
[iconName]="option.icon"
|
|
50
|
+
[size]="16"
|
|
51
|
+
[color]="isOptionActive(option) ? '#014744' : '#ffffff'"
|
|
52
|
+
[ngClass]="!isCollapsed() ? 'mr-2' : ''"
|
|
53
|
+
></ads-icon>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@if (!isCollapsed()) {
|
|
57
|
+
<span
|
|
58
|
+
class="text-base font-medium whitespace-nowrap flex items-center justify-between w-full"
|
|
59
|
+
animate.enter="fade-in"
|
|
60
|
+
animate.leave="fade-out"
|
|
61
|
+
[ngClass]="
|
|
62
|
+
isOptionActive(option)
|
|
63
|
+
? 'text-green-base'
|
|
64
|
+
: 'text-neutral-light-text'
|
|
65
|
+
"
|
|
66
|
+
>
|
|
67
|
+
{{ option.name }}
|
|
68
|
+
@if (option.children?.length) {
|
|
69
|
+
<ads-icon
|
|
70
|
+
iconName="arrow_right"
|
|
71
|
+
[size]="16"
|
|
72
|
+
[color]="isOptionActive(option) ? '#014744' : '#ffffff'"
|
|
73
|
+
class="ml-2 transition-transform duration-200"
|
|
74
|
+
[ngClass]="
|
|
75
|
+
expandedMenus()[option.name]
|
|
76
|
+
? 'rotate-90'
|
|
77
|
+
: '-rotate-90'
|
|
78
|
+
"
|
|
79
|
+
></ads-icon>
|
|
80
|
+
}
|
|
81
|
+
</span>
|
|
82
|
+
}
|
|
83
|
+
</button>
|
|
84
|
+
|
|
85
|
+
@if (option.children?.length && expandedMenus()[option.name]) {
|
|
86
|
+
<div
|
|
87
|
+
class="flex flex-col w-full mt-2"
|
|
88
|
+
[ngClass]="isCollapsed() ? 'items-center gap-2' : 'pl-8 gap-4'"
|
|
89
|
+
animate.enter="fade-in"
|
|
90
|
+
>
|
|
91
|
+
@for (
|
|
92
|
+
child of option.children;
|
|
93
|
+
track child.name;
|
|
94
|
+
let subIdx = $index
|
|
95
|
+
) {
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
nz-tooltip
|
|
99
|
+
class="cursor-pointer rounded-[44px] h-9 flex items-center transition-colors duration-300 border-none outline-none"
|
|
100
|
+
[ngClass]="childButtonClasses(child.url, isCollapsed())"
|
|
101
|
+
[attr.data-testid]="
|
|
102
|
+
'side-nav-sub-option-' + idx + '-' + subIdx
|
|
103
|
+
"
|
|
104
|
+
(click)="onChildClick(child.url)"
|
|
105
|
+
[nzTooltipTitle]="isCollapsed() ? child.name : null"
|
|
106
|
+
nzTooltipPlacement="right"
|
|
107
|
+
[nzTooltipMouseEnterDelay]="0.3"
|
|
108
|
+
>
|
|
109
|
+
@if (!isCollapsed()) {
|
|
110
|
+
<span animate.enter="fade-in" animate.leave="fade-out">{{
|
|
111
|
+
child.name
|
|
112
|
+
}}</span>
|
|
113
|
+
} @else {
|
|
114
|
+
<span
|
|
115
|
+
class="rounded-full bg-neutral-light-text"
|
|
116
|
+
animate.enter="fade-in"
|
|
117
|
+
animate.leave="fade-out"
|
|
118
|
+
[ngClass]="
|
|
119
|
+
isPathActive(child.url) ? 'w-2 h-2' : 'w-1.25 h-1.25'
|
|
120
|
+
"
|
|
121
|
+
></span>
|
|
122
|
+
}
|
|
123
|
+
</button>
|
|
124
|
+
}
|
|
125
|
+
</div>
|
|
126
|
+
}
|
|
127
|
+
</div>
|
|
128
|
+
}
|
|
129
|
+
</nav>
|
|
130
|
+
@if (footerButton()) {
|
|
131
|
+
<div
|
|
132
|
+
class="w-full h-12 py-0 px-5 overflow-hidden mt-auto"
|
|
133
|
+
animate.enter="fade-in"
|
|
134
|
+
animate.leave="fade-out"
|
|
135
|
+
>
|
|
136
|
+
<button
|
|
137
|
+
type="button"
|
|
138
|
+
nz-tooltip
|
|
139
|
+
class="w-full h-10 flex items-center gap-2 rounded-[3rem] border-none outline-none bg-transparent text-white font-medium transition-colors duration-300 hover:bg-[#005f58] cursor-pointer"
|
|
140
|
+
[ngClass]="
|
|
141
|
+
isCollapsed() ? 'px-2 justify-center' : 'px-5 justify-start'
|
|
142
|
+
"
|
|
143
|
+
[disabled]="footerButton()!.disabled ?? false"
|
|
144
|
+
(click)="footerButton()!.callback()"
|
|
145
|
+
[nzTooltipTitle]="isCollapsed() ? footerButton()!.text : null"
|
|
146
|
+
nzTooltipPlacement="right"
|
|
147
|
+
[nzTooltipMouseEnterDelay]="0.3"
|
|
148
|
+
>
|
|
149
|
+
<ads-icon
|
|
150
|
+
[iconName]="footerButton()!.icon"
|
|
151
|
+
[size]="16"
|
|
152
|
+
[color]="'#ffffff'"
|
|
153
|
+
></ads-icon>
|
|
154
|
+
|
|
155
|
+
@if (!isCollapsed()) {
|
|
156
|
+
<span>{{ footerButton()!.text }}</span>
|
|
157
|
+
}
|
|
158
|
+
</button>
|
|
159
|
+
</div>
|
|
160
|
+
}
|
|
161
|
+
@if (!isCollapsed()) {
|
|
162
|
+
<div
|
|
163
|
+
class="w-full h-fit py-1 px-4 overflow-hidden"
|
|
164
|
+
animate.enter="fade-in"
|
|
165
|
+
>
|
|
166
|
+
<div
|
|
167
|
+
class="w-full h-full flex flex-col items-center justify-center bg-transparent p-2 border-t border-white gap-2"
|
|
168
|
+
>
|
|
169
|
+
@if (currentLogoSrc()) {
|
|
170
|
+
<img
|
|
171
|
+
[src]="footerLogoSrc()"
|
|
172
|
+
[alt]="logoAlt()"
|
|
173
|
+
class="h-12 w-full object-contain"
|
|
174
|
+
/>
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
<span class="text-white text-[0.75rem]">Copyrights by AAAMB</span>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
}
|
|
181
|
+
</aside>
|
|
182
|
+
`,
|
|
183
|
+
})
|
|
184
|
+
export class SideNavComponent {
|
|
185
|
+
isCollapsed = input<boolean>(false);
|
|
186
|
+
options = input<AdsSideNavOption[]>([]);
|
|
187
|
+
activePath = input<string>('');
|
|
188
|
+
logoSrc = input<string>('');
|
|
189
|
+
footerLogoSrc = input<string>('');
|
|
190
|
+
collapsedLogoSrc = input<string>('');
|
|
191
|
+
footerButton = input<AdsSideNavFooterButton | null>(null);
|
|
192
|
+
logoAlt = input<string>('Side navigation logo');
|
|
193
|
+
|
|
194
|
+
optionSelected = output<AdsSideNavRoute>();
|
|
195
|
+
childSelected = output<string>();
|
|
196
|
+
activePathChange = output<string>();
|
|
197
|
+
|
|
198
|
+
expandedMenus = signal<Record<string, boolean>>({});
|
|
199
|
+
private internalActivePath = signal<string>('');
|
|
200
|
+
readonly currentLogoSrc = computed(() =>
|
|
201
|
+
this.isCollapsed()
|
|
202
|
+
? this.collapsedLogoSrc() || this.logoSrc()
|
|
203
|
+
: this.logoSrc(),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
onOptionClick(option: AdsSideNavOption): void {
|
|
207
|
+
if (option.children?.length) {
|
|
208
|
+
this.toggleMenu(option.name);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!option.url) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const normalized = this.normalizeRoute(option.url);
|
|
217
|
+
this.internalActivePath.set(normalized);
|
|
218
|
+
this.optionSelected.emit(option.url);
|
|
219
|
+
this.activePathChange.emit(normalized);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
onChildClick(childUrl: string): void {
|
|
223
|
+
this.internalActivePath.set(childUrl);
|
|
224
|
+
this.childSelected.emit(childUrl);
|
|
225
|
+
this.activePathChange.emit(childUrl);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
toggleMenu(menuName: string): void {
|
|
229
|
+
this.expandedMenus.update((current) => ({
|
|
230
|
+
...current,
|
|
231
|
+
[menuName]: !current[menuName],
|
|
232
|
+
}));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
isOptionActive(option: AdsSideNavOption): boolean {
|
|
236
|
+
const isCurrentUrlActive = option.url
|
|
237
|
+
? this.isRouteActive(option.url)
|
|
238
|
+
: false;
|
|
239
|
+
|
|
240
|
+
const isChildActive =
|
|
241
|
+
option.children?.some((child) => this.isRouteActive(child.url)) ?? false;
|
|
242
|
+
|
|
243
|
+
return isCurrentUrlActive || isChildActive;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
isPathActive(path: string): boolean {
|
|
247
|
+
return this.isRouteActive(path);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
optionButtonClasses(option: AdsSideNavOption): string {
|
|
251
|
+
const base = this.isCollapsed()
|
|
252
|
+
? 'justify-center w-12 h-12 rounded-full mx-auto px-2 bg-transparent'
|
|
253
|
+
: 'w-full px-5 py-2 rounded-[3rem] bg-transparent';
|
|
254
|
+
|
|
255
|
+
if (this.isOptionActive(option)) {
|
|
256
|
+
return `${base} bg-white text-green-base`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return `${base} hover:bg-[#006761]`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
childButtonClasses(path: string, collapsed: boolean): string {
|
|
263
|
+
const base = collapsed
|
|
264
|
+
? 'justify-center bg-transparent p-0 w-5 h-5'
|
|
265
|
+
: 'text-base font-normal px-4';
|
|
266
|
+
|
|
267
|
+
if (this.isPathActive(path)) {
|
|
268
|
+
return collapsed
|
|
269
|
+
? 'justify-center bg-transparent p-0 w-5 h-5'
|
|
270
|
+
: `${base} bg-white text-green-base`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return collapsed
|
|
274
|
+
? base
|
|
275
|
+
: `${base} bg-transparent text-neutral-light-text hover:bg-[#006761]`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private isRouteActive(route: AdsSideNavRoute): boolean {
|
|
279
|
+
const normalizedRoute = this.normalizeRoute(route);
|
|
280
|
+
const activePath = this.normalizeRoute(this.currentActivePath());
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
activePath === normalizedRoute ||
|
|
284
|
+
activePath.startsWith(`${normalizedRoute}/`)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private normalizeRoute(route: AdsSideNavRoute): string {
|
|
289
|
+
if (Array.isArray(route)) {
|
|
290
|
+
return `/${route
|
|
291
|
+
.map((segment) => String(segment).replace(/^\/+|\/+$/g, ''))
|
|
292
|
+
.filter(Boolean)
|
|
293
|
+
.join('/')}`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (typeof route === 'string') {
|
|
297
|
+
return route.startsWith('/') ? route : `/${route}`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return '/';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private currentActivePath(): string {
|
|
304
|
+
return this.activePath() || this.internalActivePath();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Component, OnDestroy, signal } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
AdsIconName,
|
|
4
|
+
SnackbarAlert,
|
|
5
|
+
SnackbarAlertType,
|
|
6
|
+
} from '../../core/types';
|
|
7
|
+
import { IconComponent } from '../icon/icon.component';
|
|
8
|
+
|
|
9
|
+
@Component({
|
|
10
|
+
selector: 'ads-snackbar',
|
|
11
|
+
standalone: true,
|
|
12
|
+
templateUrl: './snackbar.html',
|
|
13
|
+
imports: [IconComponent],
|
|
14
|
+
})
|
|
15
|
+
export class SnackbarComponent implements OnDestroy {
|
|
16
|
+
private static readonly AUTO_CLOSE_MS = 7000;
|
|
17
|
+
|
|
18
|
+
alerts = signal<SnackbarAlert[]>([]);
|
|
19
|
+
|
|
20
|
+
private nextId = 1;
|
|
21
|
+
private paused = false;
|
|
22
|
+
private tickStartedAt = 0;
|
|
23
|
+
private intervalId: number | null = null;
|
|
24
|
+
|
|
25
|
+
addAlert(
|
|
26
|
+
type: SnackbarAlertType,
|
|
27
|
+
message: string,
|
|
28
|
+
remainingMs: number = SnackbarComponent.AUTO_CLOSE_MS,
|
|
29
|
+
): void {
|
|
30
|
+
const next: SnackbarAlert = {
|
|
31
|
+
id: this.nextId++,
|
|
32
|
+
type,
|
|
33
|
+
message,
|
|
34
|
+
remainingMs: remainingMs,
|
|
35
|
+
icon: this.iconForType(type),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
this.alerts.update((current) => [...current, next]);
|
|
39
|
+
this.ensureTicker();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private iconForType(type: SnackbarAlertType): AdsIconName {
|
|
43
|
+
switch (type) {
|
|
44
|
+
case 'error':
|
|
45
|
+
return 'error';
|
|
46
|
+
case 'warning':
|
|
47
|
+
return 'warning';
|
|
48
|
+
case 'info':
|
|
49
|
+
return 'info';
|
|
50
|
+
case 'success':
|
|
51
|
+
return 'check';
|
|
52
|
+
default:
|
|
53
|
+
return 'check';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
closeAlert(id: number): void {
|
|
58
|
+
this.alerts.update((current) => current.filter((alert) => alert.id !== id));
|
|
59
|
+
this.stopTickerIfEmpty();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
onHoverStart(): void {
|
|
63
|
+
this.paused = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
onHoverEnd(): void {
|
|
67
|
+
this.paused = false;
|
|
68
|
+
this.tickStartedAt = Date.now();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
alertClasses(type: SnackbarAlertType): string {
|
|
72
|
+
const base =
|
|
73
|
+
'w-full h-15 cursor-pointer select-none rounded-md border border-solid px-4 py-3 text-sm shadow-sm flex items-center justify-center gap-2 font-semibold';
|
|
74
|
+
|
|
75
|
+
if (type === 'error') {
|
|
76
|
+
return `${base} border-red-2 bg-red-5 text-red-2`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (type === 'warning') {
|
|
80
|
+
return `${base} border-yellow-1 bg-yellow-2 text-yellow-1`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (type === 'info') {
|
|
84
|
+
return `${base} border-neutral-disabled-text bg-white-secondary-pressed text-aqua-base`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return `${base} border-aqua-1 bg-aqua-5 text-aqua-base`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
visualAlerts(): SnackbarAlert[] {
|
|
91
|
+
return [...this.alerts()].reverse();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ngOnDestroy(): void {
|
|
95
|
+
this.clearTicker();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private ensureTicker(): void {
|
|
99
|
+
if (this.intervalId !== null) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.tickStartedAt = Date.now();
|
|
104
|
+
this.intervalId = window.setInterval(() => this.tick(), 100);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private tick(): void {
|
|
108
|
+
if (this.paused) {
|
|
109
|
+
this.tickStartedAt = Date.now();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const now = Date.now();
|
|
114
|
+
const elapsed = now - this.tickStartedAt;
|
|
115
|
+
this.tickStartedAt = now;
|
|
116
|
+
|
|
117
|
+
this.alerts.update((current) => {
|
|
118
|
+
if (current.length === 0) {
|
|
119
|
+
return current;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const updated = [...current];
|
|
123
|
+
updated[0] = {
|
|
124
|
+
...updated[0],
|
|
125
|
+
remainingMs: updated[0].remainingMs - elapsed,
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
while (updated.length > 0 && updated[0].remainingMs <= 0) {
|
|
129
|
+
updated.shift();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return updated;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
this.stopTickerIfEmpty();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private stopTickerIfEmpty(): void {
|
|
139
|
+
if (this.alerts().length === 0) {
|
|
140
|
+
this.clearTicker();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private clearTicker(): void {
|
|
145
|
+
if (this.intervalId !== null) {
|
|
146
|
+
window.clearInterval(this.intervalId);
|
|
147
|
+
this.intervalId = null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<div
|
|
2
|
+
class="pointer-events-none fixed left-1/2 bottom-4 z-50 flex -translate-x-1/2 flex-col items-center gap-2 w-110"
|
|
3
|
+
>
|
|
4
|
+
@for (alert of visualAlerts(); track alert.id) {
|
|
5
|
+
<div
|
|
6
|
+
animate.enter="fade-up"
|
|
7
|
+
animate.leave="fade-down"
|
|
8
|
+
class="pointer-events-auto w-full"
|
|
9
|
+
(mouseenter)="onHoverStart()"
|
|
10
|
+
(mouseleave)="onHoverEnd()"
|
|
11
|
+
(click)="closeAlert(alert.id)"
|
|
12
|
+
>
|
|
13
|
+
<div [class]="alertClasses(alert.type)">
|
|
14
|
+
@if (alert.icon) {
|
|
15
|
+
<ads-icon [iconName]="alert.icon" [size]="16" />
|
|
16
|
+
}
|
|
17
|
+
{{ alert.message }}
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
}
|
|
21
|
+
</div>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import { SnackbarComponent } from './snackbar.component';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<SnackbarComponent> = {
|
|
5
|
+
title: 'Components/Snackbar',
|
|
6
|
+
component: SnackbarComponent,
|
|
7
|
+
parameters: {
|
|
8
|
+
controls: { disable: true },
|
|
9
|
+
},
|
|
10
|
+
render: () => ({
|
|
11
|
+
template: `
|
|
12
|
+
<div class="flex gap-3 p-6">
|
|
13
|
+
<button
|
|
14
|
+
type="button"
|
|
15
|
+
class="rounded-md border border-solid border-green-5 bg-green-1 px-3 py-2 text-sm text-white"
|
|
16
|
+
(click)="snackbar.addAlert('success', 'Success: operación exitosa')"
|
|
17
|
+
>
|
|
18
|
+
Add Success
|
|
19
|
+
</button>
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
class="rounded-md border border-solid border-red-2 bg-red-1 px-3 py-2 text-sm text-white"
|
|
23
|
+
(click)="snackbar.addAlert('error', 'Error: algo salió mal')"
|
|
24
|
+
>
|
|
25
|
+
Add Error
|
|
26
|
+
</button>
|
|
27
|
+
<button
|
|
28
|
+
type="button"
|
|
29
|
+
class="rounded-md border border-solid border-aqua-2 bg-aqua-1 px-3 py-2 text-sm text-white"
|
|
30
|
+
(click)="snackbar.addAlert('info', 'Info: operación completada')"
|
|
31
|
+
>
|
|
32
|
+
Add Info
|
|
33
|
+
</button>
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
class="rounded-md border border-solid border-yellow-1 bg-yellow-1 px-3 py-2 text-sm text-black"
|
|
37
|
+
(click)="snackbar.addAlert('warning', 'Warning: revisa los datos')"
|
|
38
|
+
>
|
|
39
|
+
Add Warning
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<ads-snackbar #snackbar></ads-snackbar>
|
|
44
|
+
`,
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default meta;
|
|
49
|
+
type Story = StoryObj<SnackbarComponent>;
|
|
50
|
+
|
|
51
|
+
export const Playground: Story = {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Component, input } from '@angular/core';
|
|
2
|
+
import {
|
|
3
|
+
containerShapes,
|
|
4
|
+
stateBackgroundColors,
|
|
5
|
+
stateBorderColors,
|
|
6
|
+
stateTextColors,
|
|
7
|
+
} from '../../public-api';
|
|
8
|
+
import { CommonModule } from '@angular/common';
|
|
9
|
+
|
|
10
|
+
@Component({
|
|
11
|
+
selector: 'ads-state',
|
|
12
|
+
standalone: true,
|
|
13
|
+
templateUrl: './state.html',
|
|
14
|
+
imports: [CommonModule],
|
|
15
|
+
})
|
|
16
|
+
export class StateComponent {
|
|
17
|
+
SHAPES = containerShapes;
|
|
18
|
+
|
|
19
|
+
boldText = input<boolean>(false);
|
|
20
|
+
fullWidth = input<boolean>(false);
|
|
21
|
+
shape = input<containerShapes>(containerShapes.ROUNDED);
|
|
22
|
+
text = input<string>('State');
|
|
23
|
+
borderColor = input<stateBorderColors>(stateBorderColors.BORDER_AQUA1);
|
|
24
|
+
bgColor = input<stateBackgroundColors>(stateBackgroundColors.BG_AQUA1);
|
|
25
|
+
textColor = input<stateTextColors>(stateTextColors.TEXT_AQUA1);
|
|
26
|
+
containerShapes = input<containerShapes>(this.SHAPES.ROUNDED);
|
|
27
|
+
|
|
28
|
+
baseClases =
|
|
29
|
+
'inline-flex items-center justify-center px-5 py-1 text-sm border border-solid select-none';
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div
|
|
2
|
+
[class]="
|
|
3
|
+
borderColor() + ' ' + bgColor() + ' ' + textColor() + ' ' + baseClases
|
|
4
|
+
"
|
|
5
|
+
[ngClass]="{
|
|
6
|
+
'rounded-2xl': containerShapes() === SHAPES.ROUNDED,
|
|
7
|
+
'rounded-[10px]': containerShapes() === SHAPES.SQUARE,
|
|
8
|
+
'w-full': fullWidth(),
|
|
9
|
+
'font-semibold': boldText(),
|
|
10
|
+
}"
|
|
11
|
+
>
|
|
12
|
+
{{ text() }}
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/angular';
|
|
2
|
+
import {
|
|
3
|
+
containerShapes,
|
|
4
|
+
stateBackgroundColors,
|
|
5
|
+
stateBorderColors,
|
|
6
|
+
stateTextColors,
|
|
7
|
+
} from '../../core/types';
|
|
8
|
+
import { StateComponent } from './state.component';
|
|
9
|
+
|
|
10
|
+
type StateProps = StateComponent;
|
|
11
|
+
|
|
12
|
+
const meta: Meta<StateProps> = {
|
|
13
|
+
title: 'Components/State',
|
|
14
|
+
component: StateComponent,
|
|
15
|
+
argTypes: {
|
|
16
|
+
shape: {
|
|
17
|
+
control: 'select',
|
|
18
|
+
options: Object.values(containerShapes),
|
|
19
|
+
},
|
|
20
|
+
borderColor: {
|
|
21
|
+
control: 'select',
|
|
22
|
+
options: Object.values(stateBorderColors),
|
|
23
|
+
},
|
|
24
|
+
bgColor: {
|
|
25
|
+
control: 'select',
|
|
26
|
+
options: Object.values(stateBackgroundColors),
|
|
27
|
+
},
|
|
28
|
+
textColor: {
|
|
29
|
+
control: 'select',
|
|
30
|
+
options: Object.values(stateTextColors),
|
|
31
|
+
},
|
|
32
|
+
text: {
|
|
33
|
+
control: 'text',
|
|
34
|
+
},
|
|
35
|
+
fullWidth: {
|
|
36
|
+
control: 'boolean',
|
|
37
|
+
},
|
|
38
|
+
boldText: {
|
|
39
|
+
control: 'boolean',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
render: (args) => ({
|
|
43
|
+
props: args,
|
|
44
|
+
template: `
|
|
45
|
+
<div class="p-6">
|
|
46
|
+
<ads-state
|
|
47
|
+
[shape]="shape"
|
|
48
|
+
[containerShapes]="shape"
|
|
49
|
+
[borderColor]="borderColor"
|
|
50
|
+
[bgColor]="bgColor"
|
|
51
|
+
[textColor]="textColor"
|
|
52
|
+
[text]="text ?? 'State Text'"
|
|
53
|
+
[fullWidth]="fullWidth"
|
|
54
|
+
[boldText]="boldText"
|
|
55
|
+
>
|
|
56
|
+
</ads-state>
|
|
57
|
+
</div>
|
|
58
|
+
`,
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default meta;
|
|
63
|
+
type Story = StoryObj<StateProps>;
|
|
64
|
+
|
|
65
|
+
export const Playground: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
shape: containerShapes.ROUNDED,
|
|
68
|
+
borderColor: stateBorderColors.BORDER_AQUA1,
|
|
69
|
+
bgColor: stateBackgroundColors.BG_AQUA5,
|
|
70
|
+
textColor: stateTextColors.TEXT_AQUA1,
|
|
71
|
+
fullWidth: false,
|
|
72
|
+
boldText: false,
|
|
73
|
+
},
|
|
74
|
+
};
|