ng-comps 0.2.0 → 1.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.
- package/.editorconfig +17 -0
- package/.github/copilot-instructions.md +55 -0
- package/.github/workflows/ci.yml +29 -0
- package/.prettierrc +12 -0
- package/.storybook/main.ts +21 -0
- package/.storybook/preview.ts +27 -0
- package/.storybook/tsconfig.doc.json +10 -0
- package/.storybook/tsconfig.json +15 -0
- package/.storybook/typings.d.ts +4 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +20 -0
- package/.vscode/mcp.json +9 -0
- package/.vscode/tasks.json +42 -0
- package/ACCESSIBILITY.md +127 -0
- package/README.md +79 -62
- package/angular.json +105 -0
- package/documentation.json +13394 -0
- package/ng-package.json +27 -0
- package/package.json +58 -45
- package/public/favicon.ico +0 -0
- package/scripts/prepare-package.mjs +61 -0
- package/src/app/a11y/accessibility.utils.ts +35 -0
- package/src/app/a11y/index.ts +6 -0
- package/src/app/accessibility/ng-comps.a11y.spec.ts +108 -0
- package/src/app/app.config.ts +11 -0
- package/src/app/app.css +107 -0
- package/src/app/app.html +48 -0
- package/src/app/app.routes.ts +3 -0
- package/src/app/app.spec.ts +23 -0
- package/src/app/app.ts +10 -0
- package/src/app/components/accordion/index.ts +2 -0
- package/src/app/components/accordion/mf-accordion.component.css +38 -0
- package/src/app/components/accordion/mf-accordion.component.spec.ts +48 -0
- package/src/app/components/accordion/mf-accordion.component.ts +53 -0
- package/src/app/components/alert/index.ts +2 -0
- package/src/app/components/alert/mf-alert.component.css +100 -0
- package/src/app/components/alert/mf-alert.component.spec.ts +59 -0
- package/src/app/components/alert/mf-alert.component.ts +68 -0
- package/src/app/components/autocomplete/index.ts +5 -0
- package/src/app/components/autocomplete/mf-autocomplete.component.css +105 -0
- package/src/app/components/autocomplete/mf-autocomplete.component.spec.ts +116 -0
- package/src/app/components/autocomplete/mf-autocomplete.component.ts +307 -0
- package/src/app/components/avatar/index.ts +2 -0
- package/src/app/components/avatar/mf-avatar.component.css +27 -0
- package/src/app/components/avatar/mf-avatar.component.spec.ts +49 -0
- package/src/app/components/avatar/mf-avatar.component.ts +99 -0
- package/src/app/components/badge/index.ts +2 -0
- package/src/app/components/badge/mf-badge.component.css +32 -0
- package/src/app/components/badge/mf-badge.component.spec.ts +40 -0
- package/src/app/components/badge/mf-badge.component.ts +105 -0
- package/src/app/components/breadcrumb/index.ts +2 -0
- package/src/app/components/breadcrumb/mf-breadcrumb.component.css +61 -0
- package/src/app/components/breadcrumb/mf-breadcrumb.component.spec.ts +61 -0
- package/src/app/components/breadcrumb/mf-breadcrumb.component.ts +75 -0
- package/src/app/components/button/index.ts +2 -0
- package/src/app/components/button/mf-button.component.css +136 -0
- package/src/app/components/button/mf-button.component.ts +174 -0
- package/src/app/components/card/index.ts +2 -0
- package/src/app/components/card/mf-card.component.css +82 -0
- package/src/app/components/card/mf-card.component.ts +59 -0
- package/src/app/components/checkbox/index.ts +1 -0
- package/src/app/components/checkbox/mf-checkbox.component.css +75 -0
- package/src/app/components/checkbox/mf-checkbox.component.ts +187 -0
- package/src/app/components/chip/index.ts +2 -0
- package/src/app/components/chip/mf-chip.component.css +69 -0
- package/src/app/components/chip/mf-chip.component.spec.ts +47 -0
- package/src/app/components/chip/mf-chip.component.ts +77 -0
- package/src/app/components/datepicker/index.ts +2 -0
- package/src/app/components/datepicker/mf-datepicker.component.css +102 -0
- package/src/app/components/datepicker/mf-datepicker.component.spec.ts +69 -0
- package/src/app/components/datepicker/mf-datepicker.component.ts +233 -0
- package/src/app/components/dialog/index.ts +3 -0
- package/src/app/components/dialog/mf-dialog.component.css +73 -0
- package/src/app/components/dialog/mf-dialog.component.ts +160 -0
- package/src/app/components/dialog/mf-dialog.service.spec.ts +61 -0
- package/src/app/components/dialog/mf-dialog.service.ts +52 -0
- package/src/app/components/divider/index.ts +2 -0
- package/src/app/components/divider/mf-divider.component.css +38 -0
- package/src/app/components/divider/mf-divider.component.spec.ts +40 -0
- package/src/app/components/divider/mf-divider.component.ts +44 -0
- package/src/app/components/form-field/index.ts +1 -0
- package/src/app/components/form-field/mf-form-field.component.css +51 -0
- package/src/app/components/form-field/mf-form-field.component.ts +74 -0
- package/src/app/components/grid-list/index.ts +2 -0
- package/src/app/components/grid-list/mf-grid-list.component.css +47 -0
- package/src/app/components/grid-list/mf-grid-list.component.spec.ts +57 -0
- package/src/app/components/grid-list/mf-grid-list.component.ts +68 -0
- package/src/app/components/icon/index.ts +2 -0
- package/src/app/components/icon/mf-icon.component.css +56 -0
- package/src/app/components/icon/mf-icon.component.ts +41 -0
- package/src/app/components/input/index.ts +2 -0
- package/src/app/components/input/mf-input.component.css +105 -0
- package/src/app/components/input/mf-input.component.ts +217 -0
- package/src/app/components/menu/index.ts +2 -0
- package/src/app/components/menu/mf-menu.component.css +31 -0
- package/src/app/components/menu/mf-menu.component.spec.ts +49 -0
- package/src/app/components/menu/mf-menu.component.ts +66 -0
- package/src/app/components/paginator/index.ts +1 -0
- package/src/app/components/paginator/mf-paginator.component.css +32 -0
- package/src/app/components/paginator/mf-paginator.component.spec.ts +44 -0
- package/src/app/components/paginator/mf-paginator.component.ts +52 -0
- package/src/app/components/progress-bar/index.ts +2 -0
- package/src/app/components/progress-bar/mf-progress-bar.component.css +53 -0
- package/src/app/components/progress-bar/mf-progress-bar.component.spec.ts +65 -0
- package/src/app/components/progress-bar/mf-progress-bar.component.ts +79 -0
- package/src/app/components/progress-spinner/index.ts +2 -0
- package/src/app/components/progress-spinner/mf-progress-spinner.component.css +38 -0
- package/src/app/components/progress-spinner/mf-progress-spinner.component.spec.ts +59 -0
- package/src/app/components/progress-spinner/mf-progress-spinner.component.ts +81 -0
- package/src/app/components/radio-button/index.ts +2 -0
- package/src/app/components/radio-button/mf-radio-button.component.css +86 -0
- package/src/app/components/radio-button/mf-radio-button.component.spec.ts +55 -0
- package/src/app/components/radio-button/mf-radio-button.component.ts +219 -0
- package/src/app/components/select/index.ts +2 -0
- package/src/app/components/select/mf-select.component.css +121 -0
- package/src/app/components/select/mf-select.component.spec.ts +108 -0
- package/src/app/components/select/mf-select.component.ts +252 -0
- package/src/app/components/sidenav/index.ts +2 -0
- package/src/app/components/sidenav/mf-sidenav.component.css +168 -0
- package/src/app/components/sidenav/mf-sidenav.component.spec.ts +57 -0
- package/src/app/components/sidenav/mf-sidenav.component.ts +126 -0
- package/src/app/components/slide-toggle/index.ts +1 -0
- package/src/app/components/slide-toggle/mf-slide-toggle.component.css +42 -0
- package/src/app/components/slide-toggle/mf-slide-toggle.component.spec.ts +43 -0
- package/src/app/components/slide-toggle/mf-slide-toggle.component.ts +188 -0
- package/src/app/components/snackbar/index.ts +2 -0
- package/src/app/components/snackbar/mf-snackbar.service.css +31 -0
- package/src/app/components/snackbar/mf-snackbar.service.spec.ts +81 -0
- package/src/app/components/snackbar/mf-snackbar.service.ts +77 -0
- package/src/app/components/table/index.ts +2 -0
- package/src/app/components/table/mf-table.component.css +68 -0
- package/src/app/components/table/mf-table.component.spec.ts +76 -0
- package/src/app/components/table/mf-table.component.ts +117 -0
- package/src/app/components/tabs/index.ts +2 -0
- package/src/app/components/tabs/mf-tabs.component.css +31 -0
- package/src/app/components/tabs/mf-tabs.component.spec.ts +50 -0
- package/src/app/components/tabs/mf-tabs.component.ts +62 -0
- package/src/app/components/textarea/index.ts +2 -0
- package/src/app/components/textarea/mf-textarea.component.css +48 -0
- package/src/app/components/textarea/mf-textarea.component.spec.ts +55 -0
- package/src/app/components/textarea/mf-textarea.component.ts +227 -0
- package/src/app/components/toolbar/index.ts +2 -0
- package/src/app/components/toolbar/mf-toolbar.component.css +77 -0
- package/src/app/components/toolbar/mf-toolbar.component.ts +56 -0
- package/src/app/components/tooltip/index.ts +3 -0
- package/src/app/components/tooltip/mf-tooltip.component.css +7 -0
- package/src/app/components/tooltip/mf-tooltip.component.spec.ts +37 -0
- package/src/app/components/tooltip/mf-tooltip.component.ts +47 -0
- package/src/app/components/tooltip/mf-tooltip.directive.ts +22 -0
- package/src/index.html +18 -0
- package/src/main.ts +6 -0
- package/src/public-api.ts +31 -0
- package/src/stories/About.mdx +72 -0
- package/src/stories/Accessibility.mdx +59 -0
- package/src/stories/Welcome.mdx +27 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/stories/mf-a11y-contracts.stories.ts +472 -0
- package/src/stories/mf-autocomplete.stories.ts +188 -0
- package/src/stories/mf-button.stories.ts +156 -0
- package/src/stories/mf-card.stories.ts +148 -0
- package/src/stories/mf-checkbox.stories.ts +88 -0
- package/src/stories/mf-datepicker.stories.ts +118 -0
- package/src/stories/mf-dialog.stories.ts +167 -0
- package/src/stories/mf-form-field.stories.ts +108 -0
- package/src/stories/mf-grid-list.stories.ts +105 -0
- package/src/stories/mf-icon.stories.ts +130 -0
- package/src/stories/mf-input.stories.ts +158 -0
- package/src/stories/mf-menu.stories.ts +71 -0
- package/src/stories/mf-progress-bar.stories.ts +119 -0
- package/src/stories/mf-progress-spinner.stories.ts +124 -0
- package/src/stories/mf-radio-button.stories.ts +111 -0
- package/src/stories/mf-select.stories.ts +178 -0
- package/src/stories/mf-sidenav.stories.ts +334 -0
- package/src/stories/mf-table.stories.ts +80 -0
- package/src/stories/mf-toolbar.stories.ts +112 -0
- package/src/stories/user.ts +3 -0
- package/src/styles.css +58 -21
- package/src/theme/tokens.css +7 -4
- package/tsconfig.app.json +15 -0
- package/tsconfig.json +33 -0
- package/tsconfig.spec.json +15 -0
- package/vercel.json +6 -0
- package/fesm2022/ng-comps.mjs +0 -2479
- package/fesm2022/ng-comps.mjs.map +0 -1
- package/types/ng-comps.d.ts +0 -917
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChangeDetectionStrategy,
|
|
3
|
+
ChangeDetectorRef,
|
|
4
|
+
Component,
|
|
5
|
+
computed,
|
|
6
|
+
effect,
|
|
7
|
+
forwardRef,
|
|
8
|
+
inject,
|
|
9
|
+
input,
|
|
10
|
+
output,
|
|
11
|
+
signal,
|
|
12
|
+
} from '@angular/core';
|
|
13
|
+
import { ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
|
|
14
|
+
import { ErrorStateMatcher } from '@angular/material/core';
|
|
15
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
16
|
+
import { MatInputModule } from '@angular/material/input';
|
|
17
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
18
|
+
import {
|
|
19
|
+
createUniqueId,
|
|
20
|
+
hasAccessibleName,
|
|
21
|
+
mergeAriaIds,
|
|
22
|
+
warnInDev,
|
|
23
|
+
} from '../../a11y';
|
|
24
|
+
|
|
25
|
+
export type MfInputSize = 'sm' | 'md' | 'lg';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Campo de texto de la librería ng-comps.
|
|
29
|
+
* Envuelve Angular Material `mat-form-field` + `matInput`
|
|
30
|
+
* y expone una API uniforme con look and feel de marca.
|
|
31
|
+
*/
|
|
32
|
+
@Component({
|
|
33
|
+
selector: 'mf-input',
|
|
34
|
+
imports: [MatFormFieldModule, MatInputModule, MatIconModule],
|
|
35
|
+
providers: [
|
|
36
|
+
{
|
|
37
|
+
provide: NG_VALUE_ACCESSOR,
|
|
38
|
+
useExisting: forwardRef(() => MfInputComponent),
|
|
39
|
+
multi: true,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
template: `
|
|
43
|
+
<mat-form-field [appearance]="'outline'" [class]="hostClasses()">
|
|
44
|
+
@if (label()) {
|
|
45
|
+
<mat-label>{{ label() }}</mat-label>
|
|
46
|
+
}
|
|
47
|
+
@if (leadingIcon()) {
|
|
48
|
+
<mat-icon matPrefix aria-hidden="true">{{ leadingIcon() }}</mat-icon>
|
|
49
|
+
}
|
|
50
|
+
<input
|
|
51
|
+
matInput
|
|
52
|
+
[id]="controlId()"
|
|
53
|
+
[type]="type()"
|
|
54
|
+
[placeholder]="placeholder()"
|
|
55
|
+
[disabled]="isDisabled()"
|
|
56
|
+
[readonly]="readonly()"
|
|
57
|
+
[required]="required()"
|
|
58
|
+
[value]="internalValue()"
|
|
59
|
+
[errorStateMatcher]="errorStateMatcher"
|
|
60
|
+
[attr.aria-label]="resolvedAriaLabel()"
|
|
61
|
+
[attr.aria-labelledby]="ariaLabelledby() || null"
|
|
62
|
+
[attr.aria-describedby]="describedBy()"
|
|
63
|
+
[attr.aria-invalid]="isInvalid() ? 'true' : null"
|
|
64
|
+
[attr.aria-required]="required() ? 'true' : null"
|
|
65
|
+
(input)="onInput($event)"
|
|
66
|
+
(blur)="onBlur()"
|
|
67
|
+
/>
|
|
68
|
+
@if (trailingIcon()) {
|
|
69
|
+
<mat-icon matSuffix aria-hidden="true">{{ trailingIcon() }}</mat-icon>
|
|
70
|
+
}
|
|
71
|
+
@if (hint()) {
|
|
72
|
+
<mat-hint [attr.id]="hintId()">{{ hint() }}</mat-hint>
|
|
73
|
+
}
|
|
74
|
+
</mat-form-field>
|
|
75
|
+
@if (error()) {
|
|
76
|
+
<p class="mf-input__error" [attr.id]="errorId()" role="alert">{{ error() }}</p>
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
79
|
+
styleUrl: './mf-input.component.css',
|
|
80
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
81
|
+
})
|
|
82
|
+
export class MfInputComponent implements ControlValueAccessor {
|
|
83
|
+
private readonly cdr = inject(ChangeDetectorRef);
|
|
84
|
+
private readonly ngControl = inject(NgControl, { self: true, optional: true });
|
|
85
|
+
private readonly generatedId = createUniqueId('mf-input');
|
|
86
|
+
private readonly disabledFromForm = signal(false);
|
|
87
|
+
protected readonly internalValue = signal('');
|
|
88
|
+
private onControlChange: (value: string) => void = () => undefined;
|
|
89
|
+
private onControlTouched: () => void = () => undefined;
|
|
90
|
+
readonly errorStateMatcher: ErrorStateMatcher = {
|
|
91
|
+
isErrorState: (control) =>
|
|
92
|
+
Boolean(
|
|
93
|
+
this.error() || (control?.invalid && (control.touched || control.dirty)),
|
|
94
|
+
),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** ID del control */
|
|
98
|
+
readonly id = input<string | undefined>(undefined);
|
|
99
|
+
/** Etiqueta flotante del campo */
|
|
100
|
+
readonly label = input<string | undefined>(undefined);
|
|
101
|
+
/** Etiqueta accesible alternativa cuando no existe label visible */
|
|
102
|
+
readonly ariaLabel = input<string | undefined>(undefined);
|
|
103
|
+
/** Referencia externa a elementos que etiquetan el control */
|
|
104
|
+
readonly ariaLabelledby = input<string | undefined>(undefined);
|
|
105
|
+
/** Referencia externa a elementos descriptivos adicionales */
|
|
106
|
+
readonly ariaDescribedby = input<string | undefined>(undefined);
|
|
107
|
+
/** Placeholder del input */
|
|
108
|
+
readonly placeholder = input('');
|
|
109
|
+
/** Tipo de input HTML */
|
|
110
|
+
readonly type = input<
|
|
111
|
+
'text' | 'email' | 'password' | 'number' | 'search' | 'tel' | 'url'
|
|
112
|
+
>('text');
|
|
113
|
+
/** Tamaño del campo */
|
|
114
|
+
readonly size = input<MfInputSize>('md');
|
|
115
|
+
/** Valor actual del campo */
|
|
116
|
+
readonly value = input('');
|
|
117
|
+
/** Deshabilitado */
|
|
118
|
+
readonly disabled = input(false);
|
|
119
|
+
/** Solo lectura */
|
|
120
|
+
readonly readonly = input(false);
|
|
121
|
+
/** Requerido */
|
|
122
|
+
readonly required = input(false);
|
|
123
|
+
/** Texto de ayuda debajo del campo */
|
|
124
|
+
readonly hint = input<string | undefined>(undefined);
|
|
125
|
+
/** Mensaje de error */
|
|
126
|
+
readonly error = input<string | undefined>(undefined);
|
|
127
|
+
/** Icono al inicio */
|
|
128
|
+
readonly leadingIcon = input<string | undefined>(undefined);
|
|
129
|
+
/** Icono al final */
|
|
130
|
+
readonly trailingIcon = input<string | undefined>(undefined);
|
|
131
|
+
/** Ancho completo */
|
|
132
|
+
readonly fullWidth = input(false);
|
|
133
|
+
|
|
134
|
+
readonly mfInput = output<string>();
|
|
135
|
+
readonly mfBlur = output<void>();
|
|
136
|
+
|
|
137
|
+
constructor() {
|
|
138
|
+
effect(() => {
|
|
139
|
+
this.internalValue.set(this.value());
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
effect(() => {
|
|
143
|
+
if (
|
|
144
|
+
!hasAccessibleName(
|
|
145
|
+
this.label(),
|
|
146
|
+
this.ariaLabel(),
|
|
147
|
+
this.ariaLabelledby(),
|
|
148
|
+
)
|
|
149
|
+
) {
|
|
150
|
+
warnInDev(
|
|
151
|
+
'mf-input requiere `label`, `ariaLabel` o `ariaLabelledby` para exponer un nombre accesible.',
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
readonly controlId = computed(() => this.id() ?? this.generatedId);
|
|
158
|
+
readonly hintId = computed(() =>
|
|
159
|
+
this.hint() ? `${this.controlId()}-hint` : null,
|
|
160
|
+
);
|
|
161
|
+
readonly errorId = computed(() =>
|
|
162
|
+
this.error() ? `${this.controlId()}-error` : null,
|
|
163
|
+
);
|
|
164
|
+
readonly describedBy = computed(() =>
|
|
165
|
+
mergeAriaIds(this.ariaDescribedby(), this.hintId(), this.errorId()),
|
|
166
|
+
);
|
|
167
|
+
readonly resolvedAriaLabel = computed(() =>
|
|
168
|
+
this.label() ? null : this.ariaLabel() ?? null,
|
|
169
|
+
);
|
|
170
|
+
readonly isDisabled = computed(
|
|
171
|
+
() => this.disabled() || this.disabledFromForm(),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
readonly hostClasses = computed(() => {
|
|
175
|
+
const classes = ['mf-input', `mf-input--${this.size()}`];
|
|
176
|
+
if (this.fullWidth()) classes.push('mf-input--full');
|
|
177
|
+
if (this.error()) classes.push('mf-input--error');
|
|
178
|
+
return classes.join(' ');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
writeValue(value: string | null): void {
|
|
182
|
+
this.internalValue.set(value ?? '');
|
|
183
|
+
this.cdr.markForCheck();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
registerOnChange(fn: (value: string) => void): void {
|
|
187
|
+
this.onControlChange = fn;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
registerOnTouched(fn: () => void): void {
|
|
191
|
+
this.onControlTouched = fn;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
setDisabledState(isDisabled: boolean): void {
|
|
195
|
+
this.disabledFromForm.set(isDisabled);
|
|
196
|
+
this.cdr.markForCheck();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
isInvalid(): boolean {
|
|
200
|
+
const control = this.ngControl?.control;
|
|
201
|
+
return Boolean(
|
|
202
|
+
this.error() || (control?.invalid && (control.touched || control.dirty)),
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
onInput(event: Event): void {
|
|
207
|
+
const target = event.target as HTMLInputElement;
|
|
208
|
+
this.internalValue.set(target.value);
|
|
209
|
+
this.onControlChange(target.value);
|
|
210
|
+
this.mfInput.emit(target.value);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
onBlur(): void {
|
|
214
|
+
this.onControlTouched();
|
|
215
|
+
this.mfBlur.emit();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.mf-menu__trigger {
|
|
6
|
+
color: var(--mf-color-neutral-600) !important;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.mf-menu__trigger:hover {
|
|
10
|
+
color: var(--mf-color-brand) !important;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.mf-menu .mat-mdc-menu-panel {
|
|
14
|
+
border-radius: var(--mf-radius-md) !important;
|
|
15
|
+
box-shadow: var(--mf-shadow-lg) !important;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.mf-menu .mat-mdc-menu-item {
|
|
19
|
+
font-family: var(--mf-font-base) !important;
|
|
20
|
+
font-size: var(--mf-text-sm) !important;
|
|
21
|
+
color: var(--mf-color-on-surface) !important;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.mf-menu .mat-mdc-menu-item:hover {
|
|
25
|
+
background-color: var(--mf-color-brand-light) !important;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.mf-menu .mat-mdc-menu-item .mat-icon {
|
|
29
|
+
color: var(--mf-color-neutral-400) !important;
|
|
30
|
+
margin-right: var(--mf-space-2) !important;
|
|
31
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { MfMenuComponent } from './mf-menu.component';
|
|
3
|
+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
4
|
+
|
|
5
|
+
describe('MfMenuComponent', () => {
|
|
6
|
+
let fixture: ComponentFixture<MfMenuComponent>;
|
|
7
|
+
let component: MfMenuComponent;
|
|
8
|
+
|
|
9
|
+
const testItems = [
|
|
10
|
+
{ label: 'Edit', icon: 'edit', value: 'edit' },
|
|
11
|
+
{ label: 'Delete', icon: 'delete', value: 'delete' },
|
|
12
|
+
{ label: 'Disabled', value: 'disabled', disabled: true },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
await TestBed.configureTestingModule({
|
|
17
|
+
imports: [MfMenuComponent, NoopAnimationsModule],
|
|
18
|
+
}).compileComponents();
|
|
19
|
+
|
|
20
|
+
fixture = TestBed.createComponent(MfMenuComponent);
|
|
21
|
+
component = fixture.componentInstance;
|
|
22
|
+
fixture.componentRef.setInput('items', testItems);
|
|
23
|
+
fixture.detectChanges();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should create', () => {
|
|
27
|
+
expect(component).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should render trigger button', () => {
|
|
31
|
+
const button = fixture.nativeElement.querySelector('button');
|
|
32
|
+
expect(button).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should use more_vert icon by default', () => {
|
|
36
|
+
expect(component.triggerIcon()).toBe('more_vert');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should have accessible trigger label', () => {
|
|
40
|
+
expect(component.triggerLabel()).toBe('Abrir menú');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should emit item click', () => {
|
|
44
|
+
const spy = vi.fn();
|
|
45
|
+
component.mfItemClick.subscribe(spy);
|
|
46
|
+
component.mfItemClick.emit('edit');
|
|
47
|
+
expect(spy).toHaveBeenCalledWith('edit');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChangeDetectionStrategy,
|
|
3
|
+
Component,
|
|
4
|
+
computed,
|
|
5
|
+
input,
|
|
6
|
+
output,
|
|
7
|
+
} from '@angular/core';
|
|
8
|
+
import { MatMenuModule } from '@angular/material/menu';
|
|
9
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
10
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
11
|
+
|
|
12
|
+
export interface MfMenuItem {
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: string;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Menu de la librería ng-comps.
|
|
21
|
+
* Envuelve Angular Material `mat-menu` y expone una API uniforme
|
|
22
|
+
* con look and feel de marca.
|
|
23
|
+
*/
|
|
24
|
+
@Component({
|
|
25
|
+
selector: 'mf-menu',
|
|
26
|
+
imports: [MatMenuModule, MatButtonModule, MatIconModule],
|
|
27
|
+
template: `
|
|
28
|
+
<button
|
|
29
|
+
mat-icon-button
|
|
30
|
+
[matMenuTriggerFor]="menu"
|
|
31
|
+
[class]="triggerClasses()"
|
|
32
|
+
[attr.aria-label]="triggerLabel()"
|
|
33
|
+
>
|
|
34
|
+
<mat-icon>{{ triggerIcon() }}</mat-icon>
|
|
35
|
+
</button>
|
|
36
|
+
<mat-menu #menu="matMenu" [class]="hostClasses()">
|
|
37
|
+
@for (item of items(); track item.value) {
|
|
38
|
+
<button
|
|
39
|
+
mat-menu-item
|
|
40
|
+
[disabled]="item.disabled ?? false"
|
|
41
|
+
(click)="mfItemClick.emit(item.value)"
|
|
42
|
+
>
|
|
43
|
+
@if (item.icon) {
|
|
44
|
+
<mat-icon aria-hidden="true">{{ item.icon }}</mat-icon>
|
|
45
|
+
}
|
|
46
|
+
<span>{{ item.label }}</span>
|
|
47
|
+
</button>
|
|
48
|
+
}
|
|
49
|
+
</mat-menu>
|
|
50
|
+
`,
|
|
51
|
+
styleUrl: './mf-menu.component.css',
|
|
52
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
53
|
+
})
|
|
54
|
+
export class MfMenuComponent {
|
|
55
|
+
/** Items del menú */
|
|
56
|
+
readonly items = input.required<MfMenuItem[]>();
|
|
57
|
+
/** Icono del trigger */
|
|
58
|
+
readonly triggerIcon = input<string>('more_vert');
|
|
59
|
+
/** Label accesible del trigger */
|
|
60
|
+
readonly triggerLabel = input<string>('Abrir menú');
|
|
61
|
+
|
|
62
|
+
readonly mfItemClick = output<string>();
|
|
63
|
+
|
|
64
|
+
readonly hostClasses = computed(() => 'mf-menu');
|
|
65
|
+
readonly triggerClasses = computed(() => 'mf-menu__trigger');
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MfPaginatorComponent } from './mf-paginator.component';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.mf-paginator.mat-mdc-paginator {
|
|
6
|
+
font-family: var(--mf-font-base) !important;
|
|
7
|
+
font-size: var(--mf-text-sm) !important;
|
|
8
|
+
background-color: transparent !important;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.mf-paginator .mat-mdc-paginator-container {
|
|
12
|
+
padding: var(--mf-space-2) 0 !important;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.mf-paginator .mat-mdc-paginator-range-label {
|
|
16
|
+
color: var(--mf-color-neutral-600) !important;
|
|
17
|
+
font-family: var(--mf-font-base) !important;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.mf-paginator .mat-mdc-paginator-navigation-previous,
|
|
21
|
+
.mf-paginator .mat-mdc-paginator-navigation-next,
|
|
22
|
+
.mf-paginator .mat-mdc-paginator-navigation-first,
|
|
23
|
+
.mf-paginator .mat-mdc-paginator-navigation-last {
|
|
24
|
+
color: var(--mf-color-brand) !important;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.mf-paginator .mat-mdc-paginator-navigation-previous:disabled,
|
|
28
|
+
.mf-paginator .mat-mdc-paginator-navigation-next:disabled,
|
|
29
|
+
.mf-paginator .mat-mdc-paginator-navigation-first:disabled,
|
|
30
|
+
.mf-paginator .mat-mdc-paginator-navigation-last:disabled {
|
|
31
|
+
color: var(--mf-color-neutral-300) !important;
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { MfPaginatorComponent } from './mf-paginator.component';
|
|
3
|
+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
4
|
+
|
|
5
|
+
describe('MfPaginatorComponent', () => {
|
|
6
|
+
let fixture: ComponentFixture<MfPaginatorComponent>;
|
|
7
|
+
let component: MfPaginatorComponent;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
imports: [MfPaginatorComponent, NoopAnimationsModule],
|
|
12
|
+
}).compileComponents();
|
|
13
|
+
|
|
14
|
+
fixture = TestBed.createComponent(MfPaginatorComponent);
|
|
15
|
+
component = fixture.componentInstance;
|
|
16
|
+
fixture.componentRef.setInput('length', 100);
|
|
17
|
+
fixture.detectChanges();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should create', () => {
|
|
21
|
+
expect(component).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should render mat-paginator', () => {
|
|
25
|
+
const paginator = fixture.nativeElement.querySelector('mat-paginator');
|
|
26
|
+
expect(paginator).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have default page size of 10', () => {
|
|
30
|
+
expect(component.pageSize()).toBe(10);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should have default page size options', () => {
|
|
34
|
+
expect(component.pageSizeOptions()).toEqual([5, 10, 25, 50]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should show first/last buttons by default', () => {
|
|
38
|
+
expect(component.showFirstLastButtons()).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should apply host classes', () => {
|
|
42
|
+
expect(component.hostClasses()).toBe('mf-paginator');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChangeDetectionStrategy,
|
|
3
|
+
Component,
|
|
4
|
+
computed,
|
|
5
|
+
input,
|
|
6
|
+
output,
|
|
7
|
+
} from '@angular/core';
|
|
8
|
+
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Paginator de la librería ng-comps.
|
|
12
|
+
* Envuelve Angular Material `mat-paginator` y expone una API uniforme
|
|
13
|
+
* con look and feel de marca.
|
|
14
|
+
*/
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'mf-paginator',
|
|
17
|
+
imports: [MatPaginatorModule],
|
|
18
|
+
template: `
|
|
19
|
+
<mat-paginator
|
|
20
|
+
[length]="length()"
|
|
21
|
+
[pageSize]="pageSize()"
|
|
22
|
+
[pageIndex]="pageIndex()"
|
|
23
|
+
[pageSizeOptions]="pageSizeOptions()"
|
|
24
|
+
[showFirstLastButtons]="showFirstLastButtons()"
|
|
25
|
+
[hidePageSize]="hidePageSize()"
|
|
26
|
+
[class]="hostClasses()"
|
|
27
|
+
(page)="mfPageChange.emit($event)"
|
|
28
|
+
/>
|
|
29
|
+
`,
|
|
30
|
+
styleUrl: './mf-paginator.component.css',
|
|
31
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
32
|
+
})
|
|
33
|
+
export class MfPaginatorComponent {
|
|
34
|
+
/** Total de elementos */
|
|
35
|
+
readonly length = input.required<number>();
|
|
36
|
+
/** Tamaño de página */
|
|
37
|
+
readonly pageSize = input(10);
|
|
38
|
+
/** Índice de página actual */
|
|
39
|
+
readonly pageIndex = input(0);
|
|
40
|
+
/** Opciones de tamaño de página */
|
|
41
|
+
readonly pageSizeOptions = input<number[]>([5, 10, 25, 50]);
|
|
42
|
+
/** Mostrar botones de primera/última página */
|
|
43
|
+
readonly showFirstLastButtons = input(true);
|
|
44
|
+
/** Ocultar selector de tamaño de página */
|
|
45
|
+
readonly hidePageSize = input(false);
|
|
46
|
+
|
|
47
|
+
readonly mfPageChange = output<PageEvent>();
|
|
48
|
+
|
|
49
|
+
readonly hostClasses = computed(() => {
|
|
50
|
+
return 'mf-paginator';
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/* ── Wrapper ───────────────────────────────────────────────────── */
|
|
6
|
+
.mf-progress-bar__wrapper {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: var(--mf-space-2);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.mf-progress-bar__label {
|
|
13
|
+
font-family: var(--mf-font-base);
|
|
14
|
+
font-size: var(--mf-text-sm);
|
|
15
|
+
font-weight: var(--mf-weight-medium);
|
|
16
|
+
color: var(--mf-color-on-surface);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.mf-progress-bar__value {
|
|
20
|
+
font-family: var(--mf-font-base);
|
|
21
|
+
font-size: var(--mf-text-xs);
|
|
22
|
+
font-weight: var(--mf-weight-medium);
|
|
23
|
+
color: var(--mf-color-neutral-600);
|
|
24
|
+
align-self: flex-end;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* ── Base ──────────────────────────────────────────────────────── */
|
|
28
|
+
.mf-progress-bar {
|
|
29
|
+
border-radius: var(--mf-radius-full) !important;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.mf-progress-bar.mat-mdc-progress-bar {
|
|
34
|
+
--mdc-linear-progress-track-shape: 9999px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* ── Color: brand ─────────────────────────────────────────────── */
|
|
38
|
+
.mf-progress-bar--brand.mat-mdc-progress-bar {
|
|
39
|
+
--mdc-linear-progress-active-indicator-color: var(--mf-color-brand) !important;
|
|
40
|
+
--mdc-linear-progress-track-color: var(--mf-color-primary-100) !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* ── Color: accent ────────────────────────────────────────────── */
|
|
44
|
+
.mf-progress-bar--accent.mat-mdc-progress-bar {
|
|
45
|
+
--mdc-linear-progress-active-indicator-color: var(--mf-color-accent-500) !important;
|
|
46
|
+
--mdc-linear-progress-track-color: var(--mf-color-accent-300) !important;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* ── Color: warn ──────────────────────────────────────────────── */
|
|
50
|
+
.mf-progress-bar--warn.mat-mdc-progress-bar {
|
|
51
|
+
--mdc-linear-progress-active-indicator-color: var(--mf-color-error-500) !important;
|
|
52
|
+
--mdc-linear-progress-track-color: #fecaca !important;
|
|
53
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { MfProgressBarComponent } from './mf-progress-bar.component';
|
|
3
|
+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
4
|
+
|
|
5
|
+
describe('MfProgressBarComponent', () => {
|
|
6
|
+
let fixture: ComponentFixture<MfProgressBarComponent>;
|
|
7
|
+
let component: MfProgressBarComponent;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
imports: [MfProgressBarComponent, NoopAnimationsModule],
|
|
12
|
+
}).compileComponents();
|
|
13
|
+
|
|
14
|
+
fixture = TestBed.createComponent(MfProgressBarComponent);
|
|
15
|
+
component = fixture.componentInstance;
|
|
16
|
+
fixture.detectChanges();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should create', () => {
|
|
20
|
+
expect(component).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should render mat-progress-bar', () => {
|
|
24
|
+
const bar = fixture.nativeElement.querySelector('mat-progress-bar');
|
|
25
|
+
expect(bar).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should apply brand class by default', () => {
|
|
29
|
+
expect(component.hostClasses()).toContain('mf-progress-bar--brand');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should apply accent class when color is accent', () => {
|
|
33
|
+
fixture.componentRef.setInput('color', 'accent');
|
|
34
|
+
expect(component.hostClasses()).toContain('mf-progress-bar--accent');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should apply warn class when color is warn', () => {
|
|
38
|
+
fixture.componentRef.setInput('color', 'warn');
|
|
39
|
+
expect(component.hostClasses()).toContain('mf-progress-bar--warn');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should render label when provided', () => {
|
|
43
|
+
fixture.componentRef.setInput('label', 'Cargando...');
|
|
44
|
+
fixture.detectChanges();
|
|
45
|
+
const label = fixture.nativeElement.querySelector('.mf-progress-bar__label');
|
|
46
|
+
expect(label?.textContent).toContain('Cargando...');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should show percentage when showValue is true and mode is determinate', () => {
|
|
50
|
+
fixture.componentRef.setInput('mode', 'determinate');
|
|
51
|
+
fixture.componentRef.setInput('value', 75);
|
|
52
|
+
fixture.componentRef.setInput('showValue', true);
|
|
53
|
+
fixture.detectChanges();
|
|
54
|
+
const valueEl = fixture.nativeElement.querySelector('.mf-progress-bar__value');
|
|
55
|
+
expect(valueEl?.textContent).toContain('75%');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should not show percentage in indeterminate mode', () => {
|
|
59
|
+
fixture.componentRef.setInput('mode', 'indeterminate');
|
|
60
|
+
fixture.componentRef.setInput('showValue', true);
|
|
61
|
+
fixture.detectChanges();
|
|
62
|
+
const valueEl = fixture.nativeElement.querySelector('.mf-progress-bar__value');
|
|
63
|
+
expect(valueEl).toBeFalsy();
|
|
64
|
+
});
|
|
65
|
+
});
|