crdx-components 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/.github/workflows/publish.yml +38 -0
- package/bun.lock +491 -0
- package/crdx-components-1.0.0.tgz +0 -0
- package/crdx-components-tokenized-components-1.0.1.tgz +0 -0
- package/ng-package.json +12 -0
- package/npm +0 -0
- package/package.json +33 -0
- package/src/index.ts +45 -0
- package/src/lib/components/breadcrumb/breadcrumb.component.css +206 -0
- package/src/lib/components/breadcrumb/breadcrumb.component.html +15 -0
- package/src/lib/components/breadcrumb/breadcrumb.component.ts +47 -0
- package/src/lib/components/button/button.css +371 -0
- package/src/lib/components/button/button.html +187 -0
- package/src/lib/components/button/button.ts +103 -0
- package/src/lib/components/card/card.css +285 -0
- package/src/lib/components/card/card.html +69 -0
- package/src/lib/components/card/card.ts +93 -0
- package/src/lib/components/checkbox/checkbox-showcase.component.css +42 -0
- package/src/lib/components/checkbox/checkbox-showcase.component.html +36 -0
- package/src/lib/components/checkbox/checkbox-showcase.component.ts +13 -0
- package/src/lib/components/checkbox/checkbox.css +10 -0
- package/src/lib/components/checkbox/checkbox.html +13 -0
- package/src/lib/components/checkbox/checkbox.ts +64 -0
- package/src/lib/components/circular-progress-stepper/circular-progress-stepper.css +89 -0
- package/src/lib/components/circular-progress-stepper/circular-progress-stepper.html +23 -0
- package/src/lib/components/circular-progress-stepper/circular-progress-stepper.ts +40 -0
- package/src/lib/components/dialogs/alert-modal/alert-modal.css +118 -0
- package/src/lib/components/dialogs/alert-modal/alert-modal.html +29 -0
- package/src/lib/components/dialogs/alert-modal/alert-modal.ts +28 -0
- package/src/lib/components/dialogs/confirm-modal/confirm-modal.css +219 -0
- package/src/lib/components/dialogs/confirm-modal/confirm-modal.html +60 -0
- package/src/lib/components/dialogs/confirm-modal/confirm-modal.store.ts +139 -0
- package/src/lib/components/dialogs/confirm-modal/confirm-modal.ts +63 -0
- package/src/lib/components/dialogs/container-custom/container-custom.css +11 -0
- package/src/lib/components/dialogs/container-custom/container-custom.html +3 -0
- package/src/lib/components/dialogs/container-custom/container-custom.ts +37 -0
- package/src/lib/components/dialogs/container-custom/custom-modal.state.ts +57 -0
- package/src/lib/components/dialogs/error-modal/error-modal.css +53 -0
- package/src/lib/components/dialogs/error-modal/error-modal.html +17 -0
- package/src/lib/components/dialogs/error-modal/error-modal.ts +20 -0
- package/src/lib/components/dialogs/side-modal/side-modal.css +80 -0
- package/src/lib/components/dialogs/side-modal/side-modal.html +30 -0
- package/src/lib/components/dialogs/side-modal/side-modal.state.ts +78 -0
- package/src/lib/components/dialogs/side-modal/side-modal.ts +50 -0
- package/src/lib/components/divider/divider.css +24 -0
- package/src/lib/components/divider/divider.html +7 -0
- package/src/lib/components/divider/divider.ts +13 -0
- package/src/lib/components/footer-actions/footer/footer-flow.store.ts +30 -0
- package/src/lib/components/footer-actions/footer/footer.html +14 -0
- package/src/lib/components/footer-actions/footer/footer.ts +50 -0
- package/src/lib/components/footer-actions/modal-footer-actions/modal-footer-actions.css +44 -0
- package/src/lib/components/footer-actions/modal-footer-actions/modal-footer-actions.html +7 -0
- package/src/lib/components/footer-actions/modal-footer-actions/modal-footer-actions.ts +12 -0
- package/src/lib/components/footer-actions/page-footer-actions/page-footer-actions.css +31 -0
- package/src/lib/components/footer-actions/page-footer-actions/page-footer-actions.html +7 -0
- package/src/lib/components/footer-actions/page-footer-actions/page-footer-actions.ts +12 -0
- package/src/lib/components/form-field/select-field.css +178 -0
- package/src/lib/components/form-field/select-field.html +94 -0
- package/src/lib/components/form-field/select-field.ts +324 -0
- package/src/lib/components/form-field/text-field.css +41 -0
- package/src/lib/components/form-field/text-field.html +38 -0
- package/src/lib/components/form-field/text-field.ts +102 -0
- package/src/lib/components/header/header.css +142 -0
- package/src/lib/components/header/header.html +36 -0
- package/src/lib/components/header/header.ts +101 -0
- package/src/lib/components/icon-button/icon-button.css +445 -0
- package/src/lib/components/icon-button/icon-button.html +15 -0
- package/src/lib/components/icon-button/icon-button.ts +49 -0
- package/src/lib/components/list-item/list-item.css +122 -0
- package/src/lib/components/list-item/list-item.html +79 -0
- package/src/lib/components/list-item/list-item.ts +104 -0
- package/src/lib/components/menu/menu.css +39 -0
- package/src/lib/components/menu/menu.html +57 -0
- package/src/lib/components/menu/menu.ts +159 -0
- package/src/lib/components/shared-table/shared-table-cell-template.directive.ts +25 -0
- package/src/lib/components/shared-table/shared-table.component.css +223 -0
- package/src/lib/components/shared-table/shared-table.component.html +96 -0
- package/src/lib/components/shared-table/shared-table.component.ts +172 -0
- package/src/lib/components/sidebar/sidebar.css +234 -0
- package/src/lib/components/sidebar/sidebar.html +67 -0
- package/src/lib/components/sidebar/sidebar.ts +92 -0
- package/src/lib/components/slide-toggle/slide-toggle.css +0 -0
- package/src/lib/components/slide-toggle/slide-toggle.html +3 -0
- package/src/lib/components/slide-toggle/slide-toggle.ts +18 -0
- package/src/lib/components/spinner/spinner.css +9 -0
- package/src/lib/components/spinner/spinner.html +9 -0
- package/src/lib/components/spinner/spinner.ts +17 -0
- package/src/lib/components/tooltip/tooltip.css +32 -0
- package/src/lib/components/tooltip/tooltip.html +3 -0
- package/src/lib/components/tooltip/tooltip.ts +31 -0
- package/src/lib/icons/configuration-countable.svg +8 -0
- package/src/lib/icons/edit-table.svg +3 -0
- package/src/lib/icons/edit.svg +3 -0
- package/src/lib/icons/error-circle.svg +8 -0
- package/src/lib/icons/hub.svg +3 -0
- package/src/lib/icons/icon-menu.svg +8 -0
- package/src/lib/icons/info-error.svg +8 -0
- package/src/lib/icons/keyboard_arrow_down.svg +1 -0
- package/src/lib/icons/logo.svg +0 -0
- package/src/lib/icons/logout.svg +0 -0
- package/src/lib/icons/notifications.svg +0 -0
- package/src/lib/icons/profile-user-menu.svg +0 -0
- package/src/lib/icons/profile.svg +0 -0
- package/src/lib/icons/register-icons.ts +101 -0
- package/src/lib/icons/visibility.svg +0 -0
- package/src/lib/lib-ui/lib-ui.html +1 -0
- package/src/lib/lib-ui/lib-ui.scss +0 -0
- package/src/lib/lib-ui/lib-ui.ts +9 -0
- package/src/lib/styles/generated/_app-tokens.scss +2757 -0
- package/src/lib/styles/generated/_md3-tokens.scss +179 -0
- package/src/lib/styles/generated/_tokens-avatars.scss +4 -0
- package/src/lib/styles/global-material-theme.scss +69 -0
- package/src/lib/styles/index.scss +16 -0
- package/src/lib/styles/layout.scss +29 -0
- package/src/lib/styles/overrides/_index.scss +11 -0
- package/src/lib/styles/overrides/_mat-button-overrides.scss +105 -0
- package/src/lib/styles/overrides/_mat-checkbox-overrides.scss +49 -0
- package/src/lib/styles/overrides/_mat-form-field-overrides.scss +148 -0
- package/src/lib/styles/overrides/_mat-icon-button-overrides.scss +20 -0
- package/src/lib/styles/overrides/_mat-list-overrides.scss +59 -0
- package/src/lib/styles/overrides/_mat-slide-toggle-overrides.scss +33 -0
- package/src/lib/styles/overrides/_mat-table-overrides.scss +259 -0
- package/src/lib/styles/overrides/_mat-tabs-overrides.scss +116 -0
- package/src/lib/styles/scrollbar.scss +40 -0
- package/src/lib/styles/text-classes.scss +116 -0
- package/src/lib/styles/typography.scss +14 -0
- package/tsconfig.json +30 -0
- package/tsconfig.lib.json +20 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
flex: 1 1 0;
|
|
5
|
+
min-height: 0;
|
|
6
|
+
width: 100%;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.shared-table {
|
|
10
|
+
width: 100%;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
margin: 0;
|
|
14
|
+
flex: 1 1 0;
|
|
15
|
+
min-height: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Paginador en el flujo (como en el ejemplo de Material): el scroll termina justo donde empieza el paginador */
|
|
19
|
+
.shared-table .mat-mdc-paginator {
|
|
20
|
+
flex-shrink: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* Selector de número de páginas: contenedor al tamaño del contenido para que el gap sea 2.12rem */
|
|
24
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select {
|
|
25
|
+
width: fit-content !important;
|
|
26
|
+
min-width: 0;
|
|
27
|
+
max-width: fit-content !important;
|
|
28
|
+
/* No crecer en el flex del paginador */
|
|
29
|
+
flex: 0 0 auto !important;
|
|
30
|
+
--mat-paginator-page-size-select-width: 100%;
|
|
31
|
+
--mat-paginator-page-size-select-touch-target-height: 100%;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field {
|
|
35
|
+
position: relative;
|
|
36
|
+
width: fit-content !important;
|
|
37
|
+
min-width: 0;
|
|
38
|
+
max-width: fit-content !important;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field,
|
|
42
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field-flex,
|
|
43
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field-subscript-wrapper,
|
|
44
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field-infix,
|
|
45
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-select-trigger,
|
|
46
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-select-value {
|
|
47
|
+
border: none !important;
|
|
48
|
+
border-bottom: none !important;
|
|
49
|
+
box-shadow: none !important;
|
|
50
|
+
padding-left: 0 !important;
|
|
51
|
+
padding-right: 0 !important;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Solo selector de número de páginas: padding 0 en wrappers del text-field (Material) */
|
|
55
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-text-field-wrapper,
|
|
56
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-text-field,
|
|
57
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-text-field--outlined {
|
|
58
|
+
padding: 0 !important;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Contenedor del trigger como contexto de posicionamiento para que el touch target = mismo tamaño */
|
|
62
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field-flex {
|
|
63
|
+
position: relative;
|
|
64
|
+
width: fit-content !important;
|
|
65
|
+
min-width: 0;
|
|
66
|
+
max-width: fit-content !important;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Evitar ancho fijo 180px del infix (Material) */
|
|
70
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-form-field-infix {
|
|
71
|
+
width: auto !important;
|
|
72
|
+
min-width: 0 !important;
|
|
73
|
+
flex: 0 0 auto !important;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Touch target solo del tamaño del selector (evitar 180px): topes máximos */
|
|
77
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-paginator-touch-target {
|
|
78
|
+
position: absolute !important;
|
|
79
|
+
inset: 0 !important;
|
|
80
|
+
width: 100% !important;
|
|
81
|
+
height: 100% !important;
|
|
82
|
+
max-width: 5rem !important;
|
|
83
|
+
max-height: 1.625rem !important;
|
|
84
|
+
box-sizing: border-box !important;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-select-value {
|
|
88
|
+
margin-right: 0 !important;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Trigger: min 2.0625rem x 1.625rem, se ensancha si el número es más largo */
|
|
92
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-select-trigger {
|
|
93
|
+
display: flex !important;
|
|
94
|
+
min-width: 2.0625rem !important;
|
|
95
|
+
width: max-content !important;
|
|
96
|
+
height: 1.625rem !important;
|
|
97
|
+
flex-direction: row !important;
|
|
98
|
+
align-items: center !important;
|
|
99
|
+
flex-shrink: 0;
|
|
100
|
+
gap: 0 !important;
|
|
101
|
+
border: none !important;
|
|
102
|
+
border-bottom: 0.0625rem solid var(--pallete-scheme-surface-outline-variant, #C3C7C9) !important;
|
|
103
|
+
box-shadow: none !important;
|
|
104
|
+
align-self: stretch;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mat-mdc-select-arrow-wrapper {
|
|
108
|
+
margin-left: 0 !important;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-notched-outline,
|
|
112
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-notched-outline__leading,
|
|
113
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-notched-outline__notch,
|
|
114
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-notched-outline__trailing,
|
|
115
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-notched-outline .mat-mdc-notch-piece {
|
|
116
|
+
border: none !important;
|
|
117
|
+
border-width: 0 !important;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
:host ::ng-deep .shared-table__paginator .mat-mdc-paginator-page-size-select .mdc-line-ripple {
|
|
121
|
+
display: none !important;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Tabla: ancho por contenido para que aparezca scroll horizontal con muchas columnas o pantalla estrecha */
|
|
125
|
+
.shared-table__mat-table {
|
|
126
|
+
width: max-content;
|
|
127
|
+
min-width: 100%;
|
|
128
|
+
table-layout: auto;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.shared-table__caption {
|
|
132
|
+
margin-bottom: 16px;
|
|
133
|
+
font-weight: 600;
|
|
134
|
+
font-size: 1.125rem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.shared-table__empty {
|
|
138
|
+
text-align: center;
|
|
139
|
+
padding: 24px 16px;
|
|
140
|
+
color: #6b7280;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* Contenedor: solo esquinas superiores redondeadas, sin borde inferior */
|
|
144
|
+
.shared-table__container {
|
|
145
|
+
--border-color: #E9E9E9;
|
|
146
|
+
--table-radius: 0.25rem;
|
|
147
|
+
flex: 1 1 0;
|
|
148
|
+
flex-grow: 1;
|
|
149
|
+
width: 100%;
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
min-height: 0;
|
|
153
|
+
overflow: hidden;
|
|
154
|
+
border-radius: var(--table-radius) var(--table-radius) 0 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* Sin paginador: cerrar "card" de tabla con borde y radio inferior */
|
|
158
|
+
.shared-table__container.shared-table__container--no-paginator {
|
|
159
|
+
border-radius: var(--table-radius) !important;
|
|
160
|
+
border-bottom: 1px solid var(--pallete-scheme-surface-outline-variant, #C3C7C9) !important;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.shared-table__container.shared-table__container--no-paginator .shared-table__body-wrap {
|
|
164
|
+
border-radius: 0 0 var(--table-radius) var(--table-radius);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* Header: esquinas superiores redondeadas */
|
|
168
|
+
.shared-table__header-wrap {
|
|
169
|
+
flex-shrink: 0;
|
|
170
|
+
overflow-x: auto;
|
|
171
|
+
overflow-y: hidden;
|
|
172
|
+
scrollbar-width: none;
|
|
173
|
+
border-radius: var(--table-radius) var(--table-radius) 0 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.shared-table__header-wrap::-webkit-scrollbar {
|
|
177
|
+
display: none;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* Cuerpo: sin radio en esquinas inferiores */
|
|
181
|
+
.shared-table__body-wrap {
|
|
182
|
+
flex: 1 1 0;
|
|
183
|
+
min-height: 0;
|
|
184
|
+
overflow: auto;
|
|
185
|
+
position: relative;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.shared-table__loading-overlay {
|
|
189
|
+
position: absolute;
|
|
190
|
+
top: 0;
|
|
191
|
+
left: 0;
|
|
192
|
+
right: 0;
|
|
193
|
+
bottom: 0;
|
|
194
|
+
background: rgba(255, 255, 255, 0.92);
|
|
195
|
+
display: flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
justify-content: center;
|
|
198
|
+
z-index: 9999;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
::ng-deep .shared-table__loading-spinner,
|
|
202
|
+
::ng-deep .shared-table__loading-spinner .mat-mdc-circular-progress,
|
|
203
|
+
::ng-deep .shared-table__loading-spinner .mdc-circular-progress,
|
|
204
|
+
::ng-deep .shared-table__loading-spinner circle {
|
|
205
|
+
position: relative;
|
|
206
|
+
z-index: 10000;
|
|
207
|
+
color: #d32f2f !important;
|
|
208
|
+
stroke: #d32f2f !important;
|
|
209
|
+
stroke-opacity: 1 !important;
|
|
210
|
+
opacity: 1 !important;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
::ng-deep .shared-table__loading-spinner .mdc-circular-progress__indicator,
|
|
214
|
+
::ng-deep .shared-table__loading-spinner .mdc-circular-progress__indeterminate-outer-circle,
|
|
215
|
+
::ng-deep .shared-table__loading-spinner .mdc-circular-progress__indeterminate-inner-circle {
|
|
216
|
+
stroke: #d32f2f !important;
|
|
217
|
+
stroke-width: 6 !important;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
::ng-deep .shared-table__loading-spinner {
|
|
221
|
+
--mdc-circular-progress-active-indicator-color: #d32f2f !important;
|
|
222
|
+
--mdc-circular-progress-track-color: rgba(0, 0, 0, 0.1) !important;
|
|
223
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<figure class="shared-table">
|
|
2
|
+
<div
|
|
3
|
+
class="shared-table__container mdc-data-table"
|
|
4
|
+
[class.shared-table__container--no-paginator]="!shouldRenderPaginator()"
|
|
5
|
+
>
|
|
6
|
+
<!-- Header: scroll sincronizado con el cuerpo, sin barra visible -->
|
|
7
|
+
<div class="shared-table__header-wrap" #headerWrap>
|
|
8
|
+
<table
|
|
9
|
+
mat-table
|
|
10
|
+
[dataSource]="dataSource"
|
|
11
|
+
class="shared-table__mat-table shared-table__mat-table--header"
|
|
12
|
+
>
|
|
13
|
+
@for (column of columns(); track columnTrackBy($index, column)) {
|
|
14
|
+
<ng-container [matColumnDef]="columnId(column)">
|
|
15
|
+
<th
|
|
16
|
+
mat-header-cell
|
|
17
|
+
*matHeaderCellDef
|
|
18
|
+
[style.text-align]="resolveTextAlign(column)"
|
|
19
|
+
[style.width]="resolveWidth(column)"
|
|
20
|
+
>
|
|
21
|
+
{{ column.header }}
|
|
22
|
+
</th>
|
|
23
|
+
</ng-container>
|
|
24
|
+
}
|
|
25
|
+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
|
26
|
+
</table>
|
|
27
|
+
</div>
|
|
28
|
+
<!-- Cuerpo: scroll horizontal aquí (barra debajo del header) -->
|
|
29
|
+
<div
|
|
30
|
+
class="shared-table__body-wrap"
|
|
31
|
+
[class.shared-table__body-wrap--loading]="loading()"
|
|
32
|
+
#bodyWrap
|
|
33
|
+
>
|
|
34
|
+
<table
|
|
35
|
+
mat-table
|
|
36
|
+
[dataSource]="dataSource"
|
|
37
|
+
class="shared-table__mat-table shared-table__mat-table--body"
|
|
38
|
+
>
|
|
39
|
+
@for (column of columns(); track columnTrackBy($index, column)) {
|
|
40
|
+
<ng-container [matColumnDef]="columnId(column)">
|
|
41
|
+
<td
|
|
42
|
+
mat-cell
|
|
43
|
+
*matCellDef="let row; let i = index"
|
|
44
|
+
[style.text-align]="resolveTextAlign(column)"
|
|
45
|
+
[style.width]="resolveWidth(column)"
|
|
46
|
+
>
|
|
47
|
+
@if (cellTemplates[column.key]) {
|
|
48
|
+
<ng-container
|
|
49
|
+
[ngTemplateOutlet]="cellTemplates[column.key]"
|
|
50
|
+
[ngTemplateOutletContext]="{
|
|
51
|
+
$implicit: row,
|
|
52
|
+
index: i,
|
|
53
|
+
column: column,
|
|
54
|
+
}"
|
|
55
|
+
></ng-container>
|
|
56
|
+
} @else {
|
|
57
|
+
{{ getCellValue(column, row, i) }}
|
|
58
|
+
}
|
|
59
|
+
</td>
|
|
60
|
+
</ng-container>
|
|
61
|
+
}
|
|
62
|
+
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
|
63
|
+
<tr mat-no-data-row>
|
|
64
|
+
<td
|
|
65
|
+
class="shared-table__empty"
|
|
66
|
+
[attr.colspan]="displayedColumns.length || 1"
|
|
67
|
+
>
|
|
68
|
+
|
|
69
|
+
<span>loading: {{ loading() }}</span>
|
|
70
|
+
@if (!loading()) {
|
|
71
|
+
{{ emptyState() }}
|
|
72
|
+
}
|
|
73
|
+
</td>
|
|
74
|
+
</tr>
|
|
75
|
+
</table>
|
|
76
|
+
@if (loading()) {
|
|
77
|
+
<div class="shared-table__loading-overlay">
|
|
78
|
+
<mat-spinner
|
|
79
|
+
class="shared-table__loading-spinner"
|
|
80
|
+
[diameter]="48"
|
|
81
|
+
[strokeWidth]="4"
|
|
82
|
+
></mat-spinner>
|
|
83
|
+
</div>
|
|
84
|
+
}
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
@if (shouldRenderPaginator()) {
|
|
89
|
+
<mat-paginator
|
|
90
|
+
class="shared-table__paginator"
|
|
91
|
+
[length]="totalElements() ?? data().length"
|
|
92
|
+
[pageSize]="pageSize()"
|
|
93
|
+
[pageSizeOptions]="pageSizeOptions()"
|
|
94
|
+
></mat-paginator>
|
|
95
|
+
}
|
|
96
|
+
</figure>
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { CommonModule } from '@angular/common';
|
|
2
|
+
import {
|
|
3
|
+
AfterContentInit,
|
|
4
|
+
AfterViewInit,
|
|
5
|
+
Component,
|
|
6
|
+
ContentChildren,
|
|
7
|
+
DestroyRef,
|
|
8
|
+
ElementRef,
|
|
9
|
+
EventEmitter,
|
|
10
|
+
effect,
|
|
11
|
+
input,
|
|
12
|
+
OnDestroy,
|
|
13
|
+
Output,
|
|
14
|
+
QueryList,
|
|
15
|
+
ViewChild,
|
|
16
|
+
inject,
|
|
17
|
+
} from '@angular/core';
|
|
18
|
+
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
|
|
19
|
+
import { MatPaginator, MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
|
20
|
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
21
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
22
|
+
import { SharedTableCellTemplateDirective } from './shared-table-cell-template.directive';
|
|
23
|
+
|
|
24
|
+
export interface TablePageEvent {
|
|
25
|
+
pageIndex: number;
|
|
26
|
+
pageSize: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface SharedTableColumn<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
30
|
+
key: string;
|
|
31
|
+
header: string;
|
|
32
|
+
align?: 'start' | 'center' | 'end';
|
|
33
|
+
width?: string;
|
|
34
|
+
cell?: (row: T, index: number) => unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Component({
|
|
38
|
+
selector: 'lib-shared-table, shared-table',
|
|
39
|
+
standalone: true,
|
|
40
|
+
imports: [CommonModule, MatTableModule, MatPaginatorModule, MatProgressSpinnerModule],
|
|
41
|
+
templateUrl: './shared-table.component.html',
|
|
42
|
+
styleUrl: './shared-table.component.css'
|
|
43
|
+
})
|
|
44
|
+
export class SharedTableComponent<T extends Record<string, unknown> = Record<string, unknown>>
|
|
45
|
+
implements AfterContentInit, AfterViewInit, OnDestroy {
|
|
46
|
+
readonly columns = input.required<ReadonlyArray<SharedTableColumn<T>>>();
|
|
47
|
+
readonly data = input.required<ReadonlyArray<T>>();
|
|
48
|
+
readonly caption = input<string | undefined>();
|
|
49
|
+
readonly emptyState = input('Sin registros disponibles');
|
|
50
|
+
readonly loading = input(false);
|
|
51
|
+
readonly showPaginator = input(true);
|
|
52
|
+
readonly pageSize = input(10);
|
|
53
|
+
readonly pageSizeOptions = input<ReadonlyArray<number>>([5, 10, 20]);
|
|
54
|
+
readonly enableRowClick = input(false);
|
|
55
|
+
readonly totalElements = input<number | undefined>();
|
|
56
|
+
@Output() rowClick = new EventEmitter<T>();
|
|
57
|
+
@Output() pageChange = new EventEmitter<TablePageEvent>();
|
|
58
|
+
@ContentChildren(SharedTableCellTemplateDirective, { descendants: true })
|
|
59
|
+
cellTemplatesQuery!: QueryList<SharedTableCellTemplateDirective>;
|
|
60
|
+
cellTemplates: Record<string, SharedTableCellTemplateDirective['template']> = {};
|
|
61
|
+
private removeScrollSync: (() => void) | null = null;
|
|
62
|
+
private _paginator?: MatPaginator;
|
|
63
|
+
private readonly destroyRef = inject(DestroyRef);
|
|
64
|
+
|
|
65
|
+
readonly dataSource = new MatTableDataSource<T>();
|
|
66
|
+
displayedColumns: string[] = [];
|
|
67
|
+
|
|
68
|
+
constructor() {
|
|
69
|
+
effect(() => {
|
|
70
|
+
const columns = this.columns();
|
|
71
|
+
this.displayedColumns = columns.map((column) => String(column.key));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
effect(() => {
|
|
75
|
+
const rows = this.data();
|
|
76
|
+
this.dataSource.data = rows.slice();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@ViewChild(MatPaginator) set paginator(paginator: MatPaginator | undefined) {
|
|
81
|
+
this._paginator = paginator;
|
|
82
|
+
// En modo server-side (totalElements definido) NO conectamos al dataSource
|
|
83
|
+
// para que Material no intente paginar los datos localmente
|
|
84
|
+
if (this.totalElements() === undefined) {
|
|
85
|
+
this.dataSource.paginator = paginator ?? null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ViewChild('headerWrap') headerWrapRef?: ElementRef<HTMLDivElement>;
|
|
90
|
+
@ViewChild('bodyWrap') bodyWrapRef?: ElementRef<HTMLDivElement>;
|
|
91
|
+
|
|
92
|
+
ngAfterViewInit(): void {
|
|
93
|
+
const header = this.headerWrapRef?.nativeElement;
|
|
94
|
+
const body = this.bodyWrapRef?.nativeElement;
|
|
95
|
+
if (header && body) {
|
|
96
|
+
const onScroll = () => { header.scrollLeft = body.scrollLeft; };
|
|
97
|
+
body.addEventListener('scroll', onScroll);
|
|
98
|
+
this.removeScrollSync = () => body.removeEventListener('scroll', onScroll);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Modo server-side: escuchar eventos del paginator y emitirlos hacia arriba
|
|
102
|
+
if (this._paginator && this.totalElements() !== undefined) {
|
|
103
|
+
this._paginator.page.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((event: PageEvent) => {
|
|
104
|
+
this.pageChange.emit({ pageIndex: event.pageIndex, pageSize: event.pageSize });
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
ngAfterContentInit(): void {
|
|
110
|
+
const rebuildTemplateMap = () => {
|
|
111
|
+
const map: Record<string, SharedTableCellTemplateDirective['template']> = {};
|
|
112
|
+
this.cellTemplatesQuery.forEach((entry) => {
|
|
113
|
+
if (entry.key) {
|
|
114
|
+
map[entry.key] = entry.template;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
this.cellTemplates = map;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
rebuildTemplateMap();
|
|
121
|
+
this.cellTemplatesQuery.changes
|
|
122
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
123
|
+
.subscribe(() => rebuildTemplateMap());
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
ngOnDestroy(): void {
|
|
127
|
+
this.removeScrollSync?.();
|
|
128
|
+
this.removeScrollSync = null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getCellValue(column: SharedTableColumn<T>, row: T, index: number): unknown {
|
|
132
|
+
if (column.cell) {
|
|
133
|
+
return column.cell(row, index);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const key = column.key as keyof T;
|
|
137
|
+
const fallbackKey = column.key as keyof typeof row;
|
|
138
|
+
return (row?.[key] ?? row?.[fallbackKey]) ?? '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
columnId(column: SharedTableColumn<T>): string {
|
|
142
|
+
return String(column.key);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
columnTrackBy = (_: number, column: SharedTableColumn<T>) => column.key;
|
|
146
|
+
|
|
147
|
+
resolveTextAlign(column: SharedTableColumn<T>): 'start' | 'center' | 'end' {
|
|
148
|
+
return column.align ?? 'start';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
resolveWidth(column: SharedTableColumn<T>): string | null {
|
|
152
|
+
return column.width ?? null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
shouldRenderPaginator(): boolean {
|
|
156
|
+
return this.showPaginator();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
onRowClick(event: MouseEvent, row: T): void {
|
|
160
|
+
if (!this.enableRowClick()) return;
|
|
161
|
+
|
|
162
|
+
const el = event.target as HTMLElement | null;
|
|
163
|
+
// Evita abrir el side modal si el click fue sobre un elemento interactivo (acciones dentro de la fila)
|
|
164
|
+
if (el?.closest('button, a, input, textarea, select, [role="button"], mat-icon, mat-slide-toggle, mat-checkbox')) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.rowClick.emit(row);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { SharedTableCellTemplateDirective } from './shared-table-cell-template.directive';
|