shirkasoft-ui-components 1.3.15 → 1.13.16
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/README.md +19 -28
- package/fesm2022/shirkasoft-ui-components-table.mjs +109 -87
- package/fesm2022/shirkasoft-ui-components-table.mjs.map +1 -1
- package/fesm2022/shirkasoft-ui-components-tooltip.mjs +24 -6
- package/fesm2022/shirkasoft-ui-components-tooltip.mjs.map +1 -1
- package/package.json +1 -1
- package/types/shirkasoft-ui-components-table.d.ts +64 -72
- package/types/shirkasoft-ui-components-tooltip.d.ts +6 -0
package/README.md
CHANGED
|
@@ -406,10 +406,6 @@ interface Column {
|
|
|
406
406
|
currency?: string; // template 'currency', default 'USD'
|
|
407
407
|
image?: (row: any) => string | undefined; // avatar/flag before the text
|
|
408
408
|
imageWidth?: number; // default 28
|
|
409
|
-
required?: boolean | ((row: any) => boolean); // with validateRequired: flags rows where it's empty (function = conditional)
|
|
410
|
-
missingMessage?: string; // text in the empty cell (default "Falta <header>")
|
|
411
|
-
missingSeverity?: 'error' | 'warning'; // mandatory (red) or informative (amber); default: table's missingAsError
|
|
412
|
-
isMissing?: (row: any) => boolean; // custom rule (default: null/undefined/blank/[])
|
|
413
409
|
format?: (row: any) => string;
|
|
414
410
|
tagValue?: (row: any) => string;
|
|
415
411
|
tagSeverity?: (row: any) => 'success' | 'danger' | 'warn' | 'info' | undefined;
|
|
@@ -484,8 +480,7 @@ interface FilterChangeEvent {
|
|
|
484
480
|
| `searchPlaceholder` | `string` | `''` |
|
|
485
481
|
| `globalFilterFields` | `string[]` (dot paths) | `[]` (all primitive values) |
|
|
486
482
|
| `showGridlines` | `boolean` | `false` |
|
|
487
|
-
| `
|
|
488
|
-
| `missingAsError` | `boolean` (with `validateRequired`) | `true` |
|
|
483
|
+
| `rowValidations` | `Record<string, RowValidation>` | `{}` |
|
|
489
484
|
| `resizableColumns` | `boolean` (only with `showGridlines`) | `true` |
|
|
490
485
|
| `columnWidths` | `Record<string, number>` (two-way `[(columnWidths)]`) | `{}` |
|
|
491
486
|
| `stateKey` | `string` (persists column widths) | `''` |
|
|
@@ -532,32 +527,28 @@ i18n keys used: `table.selected` (`{{count}}`), `table.selectAll`, `table.select
|
|
|
532
527
|
- `boolean`: tri-state checkbox (any → yes → no), applied immediately.
|
|
533
528
|
- `range`: two-thumb slider between `filterMin` and `filterMax`, applied on release.
|
|
534
529
|
|
|
535
|
-
**
|
|
530
|
+
**Row severity validation.** `[rowValidations]` takes one rule per payload field (the key is the field; dot paths like `'invoice.total'` work). Each rule applies a `condition(value, row)` and, when it returns `true`, paints the **whole row** with a tinted tone: `low` blue (informational), `moderate` amber (needs attention) or `critical` red (blocks). When a row has several issues the worst severity wins (`critical` > `moderate` > `low`). Nothing is written into the cells: they keep showing their real values. The rows that have issues also get a severity icon (info / triangle / octagon in the row color) at the beginning of the **actions column**, before the row actions; its tooltip lists every message, one per line, on hover or keyboard focus.
|
|
536
531
|
|
|
537
532
|
```typescript
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
533
|
+
rowValidations: Record<string, RowValidation> = {
|
|
534
|
+
valor_factura: {
|
|
535
|
+
condition: (value, row) => !row.factura_id || value == null || Number(value) <= 0,
|
|
536
|
+
severity: 'critical',
|
|
537
|
+
message: 'items.validation.valorFactura', // i18n key (Transloco)
|
|
538
|
+
messageParams: (value, row) => ({ invoice: row.factura_id ?? '—' }),
|
|
539
|
+
},
|
|
540
|
+
documentos: { condition: (value) => !value?.trim(), severity: 'moderate', message: 'items.validation.documentos' },
|
|
541
|
+
peso_bruto: { condition: (value, row) => Number(value) > Number(row.peso_neto), severity: 'low' },
|
|
542
|
+
};
|
|
544
543
|
```
|
|
545
544
|
|
|
546
|
-
`required` can be a function evaluated per row (and per payload in `validateRow`): when it returns `false` the field is optional for that row; when `true`, it's checked like a regular required field.
|
|
547
545
|
```html
|
|
548
|
-
<shk-table [data]="
|
|
546
|
+
<shk-table [data]="items" [columns]="cols" [rowValidations]="rowValidations" />
|
|
549
547
|
```
|
|
550
548
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
```typescript
|
|
554
|
-
cols: Column[] = [
|
|
555
|
-
{ field: 'email', header: 'Email', required: true }, // error
|
|
556
|
-
{ field: 'phone', header: 'Teléfono', required: true, missingSeverity: 'warning' }, // informative
|
|
557
|
-
];
|
|
558
|
-
```
|
|
549
|
+
`message` is a translation key resolved with the table's Transloco service (`{{param}}` interpolation included); when the app doesn't register the key, the string is used as literal text. `rowSeverity(row)` returns `'low' | 'moderate' | 'critical' | null`. The actions column is rendered automatically when there are violations, even if the table has no `rowActions`.
|
|
559
550
|
|
|
560
|
-
**Validating a modal payload.** `validateRow(obj)` returns the
|
|
551
|
+
**Validating a modal payload.** `validateRow(obj)` returns the violations of any object (`[{ field, severity, message }]`, empty when clean) with the messages already translated. It doesn't need the row to be displayed, so it can be used before adding it:
|
|
561
552
|
|
|
562
553
|
```typescript
|
|
563
554
|
table = viewChild.required(TableComponent);
|
|
@@ -566,14 +557,14 @@ this.modalSrv.open({
|
|
|
566
557
|
title: 'Nuevo usuario',
|
|
567
558
|
component: NewUserFormComponent, // submitSuccess.emit(this.form.getRawValue())
|
|
568
559
|
onAccept: (payload) => {
|
|
569
|
-
const
|
|
570
|
-
this.users.update((u) => [...u, payload]);
|
|
571
|
-
if (
|
|
560
|
+
const issues = this.table().validateRow(payload); // [{ field, severity, message }]
|
|
561
|
+
this.users.update((u) => [...u, payload]); // the new row is painted by severity
|
|
562
|
+
if (issues.length) this.notify(issues.map((i) => i.message).join(' · '), 'warning');
|
|
572
563
|
},
|
|
573
564
|
});
|
|
574
565
|
```
|
|
575
566
|
|
|
576
|
-
i18n: `
|
|
567
|
+
i18n: none — the messages belong to the app (`message` key of each rule).
|
|
577
568
|
|
|
578
569
|
**Resizable columns.** With `[showGridlines]="true"` each header has a handle on its right border: drag it to widen/narrow the column (minimum 60px; the table scrolls horizontally when it no longer fits), use the arrow keys on it (Shift = 50px steps), or double click it to go back to the automatic width. Disable it with `[resizableColumns]="false"`. Every change emits `columnResize`. The row actions column can be resized too (its width is stored under the `actions` key); its automatic width fits the most actions visible in a row of the current page (honouring each action's `isVisible`), not every action defined.
|
|
579
570
|
|