shirkasoft-ui-components 1.3.14 → 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 -24
- package/fesm2022/shirkasoft-ui-components-table.mjs +111 -96
- 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 -69
- package/types/shirkasoft-ui-components-tooltip.d.ts +6 -0
package/README.md
CHANGED
|
@@ -406,9 +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; // with validateRequired: flags rows where it's empty
|
|
410
|
-
missingMessage?: string; // text in the empty cell (default "Falta <header>")
|
|
411
|
-
isMissing?: (row: any) => boolean; // custom rule (default: null/undefined/blank/[])
|
|
412
409
|
format?: (row: any) => string;
|
|
413
410
|
tagValue?: (row: any) => string;
|
|
414
411
|
tagSeverity?: (row: any) => 'success' | 'danger' | 'warn' | 'info' | undefined;
|
|
@@ -483,9 +480,7 @@ interface FilterChangeEvent {
|
|
|
483
480
|
| `searchPlaceholder` | `string` | `''` |
|
|
484
481
|
| `globalFilterFields` | `string[]` (dot paths) | `[]` (all primitive values) |
|
|
485
482
|
| `showGridlines` | `boolean` | `false` |
|
|
486
|
-
| `
|
|
487
|
-
| `missingAsError` | `boolean` (with `validateRequired`) | `true` |
|
|
488
|
-
| `requiredFields` | `(string \| RequiredField)[]` | `[]` |
|
|
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,28 +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
|
-
|
|
544
|
-
|
|
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
|
+
};
|
|
545
543
|
```
|
|
546
544
|
|
|
547
|
-
Fields that aren't columns can be required too with `requiredFields`: a field name (`'phone'`) or `{ field, label?, isMissing? }`. They flag the row the same way and appear in the tooltip (there's no cell to write "Falta…" in), and `validateRow` checks them as well.
|
|
548
|
-
|
|
549
545
|
```html
|
|
550
|
-
<shk-table [data]="
|
|
551
|
-
[requiredFields]="[{ field: 'phone', label: 'Teléfono' }, 'address.street']" />
|
|
546
|
+
<shk-table [data]="items" [columns]="cols" [rowValidations]="rowValidations" />
|
|
552
547
|
```
|
|
553
548
|
|
|
554
|
-
|
|
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`.
|
|
555
550
|
|
|
556
|
-
**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:
|
|
557
552
|
|
|
558
553
|
```typescript
|
|
559
554
|
table = viewChild.required(TableComponent);
|
|
@@ -562,14 +557,14 @@ this.modalSrv.open({
|
|
|
562
557
|
title: 'Nuevo usuario',
|
|
563
558
|
component: NewUserFormComponent, // submitSuccess.emit(this.form.getRawValue())
|
|
564
559
|
onAccept: (payload) => {
|
|
565
|
-
const
|
|
566
|
-
this.users.update((u) => [...u, payload]);
|
|
567
|
-
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');
|
|
568
563
|
},
|
|
569
564
|
});
|
|
570
565
|
```
|
|
571
566
|
|
|
572
|
-
i18n:
|
|
567
|
+
i18n: none — the messages belong to the app (`message` key of each rule).
|
|
573
568
|
|
|
574
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.
|
|
575
570
|
|