@easyvision/easyvision-ui 1.7.6 → 1.9.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/README.md +175 -0
- package/dist/EasyVisionTable.css +7 -0
- package/dist/easyvision.css +51 -0
- package/dist/index.cjs +614 -192
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +193 -1
- package/dist/index.d.ts +193 -1
- package/dist/index.js +505 -94
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
- [`clearWhen`](#clearwhen)
|
|
22
22
|
- [Labels (i18n)](#labels-i18n)
|
|
23
23
|
- [`EasyVisionCard`](#easyvisioncard)
|
|
24
|
+
- [`EasyVisionAccordion`](#easyvisionaccordion)
|
|
24
25
|
- [`EasyVisionInput`](#easyvisioninput)
|
|
25
26
|
- [`EasyVisionSelector`](#easyvisionselector)
|
|
26
27
|
- [`EasyVisionMultifilter`](#easyvisionmultifilter)
|
|
@@ -42,6 +43,9 @@ import {
|
|
|
42
43
|
- [Binding a multifilter](#binding-a-multifilter)
|
|
43
44
|
- [External filter and manual refetch](#external-filter-and-manual-refetch)
|
|
44
45
|
- [Toolbar slots](#toolbar-slots)
|
|
46
|
+
- [`EasyVisionExportButton`](#easyvisionexportbutton)
|
|
47
|
+
- [What gets exported](#what-gets-exported)
|
|
48
|
+
- [Resolving table ids](#resolving-table-ids)
|
|
45
49
|
- [Migration cookbook](#migration-cookbook)
|
|
46
50
|
- [Integration recipes](#integration-recipes)
|
|
47
51
|
- [API adapters: LoopBack](#api-adapters-loopback)
|
|
@@ -190,6 +194,91 @@ import {
|
|
|
190
194
|
|
|
191
195
|
---
|
|
192
196
|
|
|
197
|
+
## `EasyVisionAccordion`
|
|
198
|
+
|
|
199
|
+
A list of **unfoldable questions** (FAQ-style). Holds an indefinite number of
|
|
200
|
+
items and accepts **free-format content** — both the `question` header and the
|
|
201
|
+
body are `ReactNode`, so an answer can be plain text or arbitrary JSX (tables,
|
|
202
|
+
tabs, lists, charts…).
|
|
203
|
+
|
|
204
|
+
Like `EasyVisionCard`, it's self-contained and **does not** use the `id`/slice
|
|
205
|
+
machinery — open/closed is ephemeral UI state held locally (optionally
|
|
206
|
+
controlled). Visuals rely only on the standard Tailwind theme tokens
|
|
207
|
+
(`muted`, `card`, `border`, `foreground`) via `.ev-accordion*` classes.
|
|
208
|
+
|
|
209
|
+
### Minimal usage (data-driven)
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
import { EasyVisionAccordion } from '@easyvision/easyvision-ui';
|
|
213
|
+
|
|
214
|
+
<EasyVisionAccordion
|
|
215
|
+
items={[
|
|
216
|
+
{ id: 'what', question: '¿Qué es NML Vision?', content: <p>…</p> },
|
|
217
|
+
{ id: 'scoring', question: '¿Cómo funciona el scoring?', content: <ScoringTable /> },
|
|
218
|
+
]}
|
|
219
|
+
/>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The `items` array can be any length and built dynamically (filter/spread for
|
|
223
|
+
conditional questions) — the FAQ list is not fixed at compile time.
|
|
224
|
+
|
|
225
|
+
### Compound usage
|
|
226
|
+
|
|
227
|
+
Equivalent, when you'd rather write the bodies inline as children:
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
import { EasyVisionAccordion, EasyVisionAccordionItem } from '@easyvision/easyvision-ui';
|
|
231
|
+
|
|
232
|
+
<EasyVisionAccordion mode="multiple">
|
|
233
|
+
<EasyVisionAccordionItem id="what" question="¿Qué es NML Vision?">
|
|
234
|
+
<p>…</p>
|
|
235
|
+
</EasyVisionAccordionItem>
|
|
236
|
+
<EasyVisionAccordionItem id="scoring" question="¿Cómo funciona el scoring?">
|
|
237
|
+
<ScoringTable />
|
|
238
|
+
</EasyVisionAccordionItem>
|
|
239
|
+
</EasyVisionAccordion>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
> Mix-and-match is not supported in a single instance: pass **either** `items`
|
|
243
|
+
> **or** `EasyVisionAccordionItem` children. If `items` is provided, children
|
|
244
|
+
> are ignored.
|
|
245
|
+
|
|
246
|
+
### Open behaviour
|
|
247
|
+
|
|
248
|
+
- `mode="single"` (default) — one item open at a time, like the NML Vision Help
|
|
249
|
+
page. `mode="multiple"` — items open independently.
|
|
250
|
+
- Uncontrolled: set `defaultOpenIds={['scoring']}` or per-item `defaultOpen`.
|
|
251
|
+
- Controlled: pass `openIds` + `onOpenChange` to own the state. Use
|
|
252
|
+
`onOpenChange` to lazily fetch a question's data the first time it opens (the
|
|
253
|
+
callback receives the next list of open ids).
|
|
254
|
+
|
|
255
|
+
### Props
|
|
256
|
+
|
|
257
|
+
#### `EasyVisionAccordion`
|
|
258
|
+
|
|
259
|
+
| prop | type | default | notes |
|
|
260
|
+
|---|---|---|---|
|
|
261
|
+
| `items` | `AccordionItem[]` | — | Data-driven items. Omit when using children. |
|
|
262
|
+
| `children` | `ReactNode` | — | `EasyVisionAccordionItem` elements (alternative to `items`). |
|
|
263
|
+
| `mode` | `'single' \| 'multiple'` | `'single'` | Open behaviour. |
|
|
264
|
+
| `openIds` | `string[]` | — | Controlled set of open ids. |
|
|
265
|
+
| `defaultOpenIds` | `string[]` | — | Uncontrolled initial open ids. |
|
|
266
|
+
| `onOpenChange` | `(openIds: string[]) => void` | — | Fired on every open/close. |
|
|
267
|
+
| `className` | `string` | — | Merged with `ev-accordion`. |
|
|
268
|
+
|
|
269
|
+
`AccordionItem` / `EasyVisionAccordionItem` fields: `id` (required, stable key),
|
|
270
|
+
`question` (`ReactNode`), `content` / children (`ReactNode` body), optional
|
|
271
|
+
`defaultOpen` and `disabled`.
|
|
272
|
+
|
|
273
|
+
### Notes
|
|
274
|
+
|
|
275
|
+
- Each item renders an accessible trigger (`<button>` with `aria-expanded` /
|
|
276
|
+
`aria-controls`) and a `role="region"` panel.
|
|
277
|
+
- The chevron rotates on open; collapsed panels are unmounted (not hidden), so
|
|
278
|
+
heavy bodies don't render until first opened.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
193
282
|
## `EasyVisionInput`
|
|
194
283
|
|
|
195
284
|
A debounced text input that persists its value by `id`.
|
|
@@ -710,6 +799,14 @@ type DataColumn<T> = {
|
|
|
710
799
|
truncate?: boolean;
|
|
711
800
|
/** Allow the user to drag the right edge of the header to resize this column. */
|
|
712
801
|
resizable?: boolean;
|
|
802
|
+
/** Header text in an exported sheet. Defaults to `header` when it's a plain string, else `field`. */
|
|
803
|
+
exportHeader?: string;
|
|
804
|
+
/** Cell value in an exported sheet. Defaults to the value at `field` (arrays joined by ", "). */
|
|
805
|
+
exportValue?: (item: T) => ExportCellValue;
|
|
806
|
+
/** Per-cell styling in an exported sheet. Return `undefined` to leave a cell unstyled. */
|
|
807
|
+
exportStyle?: (value: ExportCellValue, item: T) => ExportCellStyle | undefined;
|
|
808
|
+
/** Include this column in exports. Default: `true` for `data` columns, `false` for `ui` columns. */
|
|
809
|
+
exportable?: boolean;
|
|
713
810
|
};
|
|
714
811
|
|
|
715
812
|
// UI column — no underlying value, never sortable.
|
|
@@ -723,11 +820,34 @@ type UiColumn<T> = {
|
|
|
723
820
|
width?: number | string;
|
|
724
821
|
truncate?: boolean;
|
|
725
822
|
resizable?: boolean;
|
|
823
|
+
/** See data-column docs. */
|
|
824
|
+
exportHeader?: string;
|
|
825
|
+
/** See data-column docs. A `ui` column has no underlying value, so this is the only way to give it one. */
|
|
826
|
+
exportValue?: (item: T) => ExportCellValue;
|
|
827
|
+
/** See data-column docs. */
|
|
828
|
+
exportStyle?: (value: ExportCellValue, item: T) => ExportCellStyle | undefined;
|
|
829
|
+
/** `ui` columns default to `false` here — opt in alongside `exportValue` to export a computed column. */
|
|
830
|
+
exportable?: boolean;
|
|
726
831
|
};
|
|
727
832
|
|
|
728
833
|
export type EasyVisionColumn<T> = DataColumn<T> | UiColumn<T>;
|
|
729
834
|
```
|
|
730
835
|
|
|
836
|
+
`exportHeader` / `exportValue` / `exportStyle` / `exportable` only affect [`EasyVisionExportButton`](#easyvisionexportbutton) — they have no effect on what's rendered on screen. A worked `exportStyle` example, colouring a score cell by band:
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
{
|
|
840
|
+
field: 'score',
|
|
841
|
+
header: 'Score',
|
|
842
|
+
exportStyle: (value) =>
|
|
843
|
+
typeof value === 'number' && value >= 3.5
|
|
844
|
+
? { fill: 'FF991B1B', fontColor: 'FFFFFFFF', bold: true } // dark red, white bold text
|
|
845
|
+
: typeof value === 'number' && value >= 2
|
|
846
|
+
? { fill: 'FFF59E0B', fontColor: 'FF1F2937' } // amber
|
|
847
|
+
: undefined, // leave low scores unstyled
|
|
848
|
+
}
|
|
849
|
+
```
|
|
850
|
+
|
|
731
851
|
**`field` does double duty on data columns:** it's both the column ID and the dot-path used to resolve the value. Internally the library generates an `accessorFn` that reads `row.client?.name` for `field: 'client.name'`. UI columns don't get an accessor — `field` there is just an ID.
|
|
732
852
|
|
|
733
853
|
**`cell` receives the row item directly** (no `{ row, getValue }` wrappers). For columns where you only want the resolved value with default styling, omit `cell` and the library renders it in a standard span. To get the same span styling around custom content, wrap with `defaultCell(content)`. `defaultCell` accepts an optional second argument that becomes the cell's native `title` tooltip — useful when `truncate: true` is set and you want the full text to appear on hover:
|
|
@@ -1130,6 +1250,61 @@ interface TableLabels {
|
|
|
1130
1250
|
|
|
1131
1251
|
---
|
|
1132
1252
|
|
|
1253
|
+
## `EasyVisionExportButton`
|
|
1254
|
+
|
|
1255
|
+
Writes one or more registered tables into a single `.xlsx` file, one worksheet per table. It doesn't hold any data itself — every mounted `EasyVisionTable` registers an **export source** (a pair of resolvers: columns and rows) keyed by its `fullId`, and the button just looks those up by the ids you pass in `tables`.
|
|
1256
|
+
|
|
1257
|
+
### Minimal usage
|
|
1258
|
+
|
|
1259
|
+
```tsx
|
|
1260
|
+
<EasyVisionExportButton
|
|
1261
|
+
tables={['localTable', 'apiTable']}
|
|
1262
|
+
sheetNames={{ localTable: 'Local', apiTable: 'API' }}
|
|
1263
|
+
filename="risk-evaluations"
|
|
1264
|
+
/>
|
|
1265
|
+
```
|
|
1266
|
+
|
|
1267
|
+
Clicking it resolves `localTable` and `apiTable` against the tables mounted nearby, pulls each one's current rows and visible columns, and downloads `risk-evaluations_<ISO timestamp>.xlsx` with two sheets named `Local` and `API`. A table id with no `sheetNames` override falls back to the table's own `id` as the sheet name.
|
|
1268
|
+
|
|
1269
|
+
### Props
|
|
1270
|
+
|
|
1271
|
+
| prop | type | default | notes |
|
|
1272
|
+
|---|---|---|---|
|
|
1273
|
+
| `tables` | `string[]` | — required | Table ids, in sheet order. See [Resolving table ids](#resolving-table-ids) below. |
|
|
1274
|
+
| `filename` | `string` | — required | Base name. An ISO timestamp and `.xlsx` are appended. |
|
|
1275
|
+
| `sheetNames` | `Record<string, string>` | — | Per-table sheet-name override, keyed by the same id passed in `tables`. Sheet names are sanitized (invalid Excel characters replaced with `-`, truncated to 31 chars) and de-duplicated automatically. |
|
|
1276
|
+
| `labels` | `Partial<ExportLabels>` | Spanish defaults | `{ export, exporting }` — button text for idle and in-flight states. |
|
|
1277
|
+
| `onError` | `(error: unknown) => void` | — | A fetch or workbook-building failure aborts the whole export — no partial file is written. Also fires when *some but not all* ids in `tables` fail to resolve, with an `Error` naming the unresolved ids — this catches a typo'd or unmounted table id before it can silently drop a sheet from an otherwise-successful export. |
|
|
1278
|
+
| `onEmpty` | `() => void` | — | Fires when nothing was written: **no** id in `tables` resolved to a mounted table (every id failed together, e.g. the button rendered before any table mounted), or every sheet that did resolve had zero visible columns or zero matching rows. A *partial* resolution failure — some ids resolved, some didn't — is reported via `onError` instead, not `onEmpty`, so it isn't mistaken for "nothing to export". The button does **not** disable itself when a table id fails to resolve or a table has nothing to export — it always attempts the export and reports the outcome via `onEmpty` / `onError`, since a source can legitimately empty out between renders (a hidden column, a narrowed multifilter, an unmounted table). |
|
|
1279
|
+
| `disabled` | `boolean` | `false` | External disable, e.g. while a parent form is invalid. |
|
|
1280
|
+
| `className` | `string` | — | |
|
|
1281
|
+
| `icon` | `ReactNode` | a download icon | Replaces the default idle-state icon. The spinner shown while exporting is not overridable. |
|
|
1282
|
+
|
|
1283
|
+
### What gets exported
|
|
1284
|
+
|
|
1285
|
+
**Rows** are the ticked selection when there is one — page-scope ids, or an all-scope selection minus any `exceptIds` — and otherwise every row matching the table's current multifilter plus `externalFilter`. To assemble "every row" in API mode, the export first pages through `fetchData` under the hood to collect the complete matching set (the same helper `selectAllResolution="eager"` uses internally), then applies the selection filter to it — so an export is never limited to whatever page happens to be on screen, and behaves the same regardless of the table's `selectAllResolution` setting. Local mode already holds the filtered set in memory, so no extra fetching happens there.
|
|
1286
|
+
|
|
1287
|
+
**Columns** are the table's currently visible, exportable columns, in declared order. Concretely:
|
|
1288
|
+
- A column must pass `isVisible` — the same visibility state `ColumnVisibilityMenu` (the **Columnas** button in the table toolbar) toggles. Hide a column there and it's gone from the sheet; show it and it reappears. This makes `ColumnVisibilityMenu` double as export column customization — there is no separate export-column picker.
|
|
1289
|
+
- A column must be exportable: `data` columns are exportable by default, `ui` columns are not (a `ui` column has no underlying value — opt it in with `exportable: true` plus an `exportValue` to export something computed).
|
|
1290
|
+
- **`largeScreensOnly` columns always export**, even when the viewport is too narrow to render them. `largeScreensOnly` is a CSS-only responsive hint — it never enters the visibility state — so if it affected the export, the same click would produce a different file on a phone than on a wide monitor. Hide a column from exports on purpose with `exportable: false` instead.
|
|
1291
|
+
|
|
1292
|
+
Both resolvers run at export-click time, not at table-mount time, so a column toggle, a fresh multifilter query, or a changed selection made a second before clicking is always reflected — nothing needs to be re-registered.
|
|
1293
|
+
|
|
1294
|
+
### Resolving table ids
|
|
1295
|
+
|
|
1296
|
+
The button must render **inside the same namespace as the tables it names**. An id in `tables` is qualified through the surrounding namespace first, the same way a nested multifilter field is (see [The `id` rule](#the-id-rule)): `'localTable'` becomes `localTable-table` when the button sits at the top level (no enclosing namespace), or `parentId.localTable-table` when it's nested under something with `id="parentId"`.
|
|
1297
|
+
|
|
1298
|
+
Rendering the button as a plain sibling of the tables — as in the demo — is the simple case: both the tables and the button see the same (usually empty) surrounding namespace, so local ids just work.
|
|
1299
|
+
|
|
1300
|
+
Rendering it **inside a table's own `toolbarLeft` / `toolbarRight`** (a natural spot per [Toolbar slots](#toolbar-slots)) is different: that slot renders inside *that table's* namespace, so a local id would be qualified as `<hostTableId>-table.<name>-table` — which never matches, even for the table hosting the button itself. In that placement, pass the target table's **fully-qualified id** instead (its own `id` with `-table` appended, e.g. `'orders-table'`).
|
|
1301
|
+
|
|
1302
|
+
Resolution is always **namespace-first**: the id is qualified through the surrounding namespace and looked up under that name first; only if that lookup misses is the raw id tried verbatim as a fallback. A fully-qualified id (one already ending in `-table`) doesn't *bypass* namespace resolution — the namespaced probe still runs first and would win if it happened to match — it just normally misses (a genuine local id doesn't already carry a `-table` suffix), so the fallback is what actually resolves it. This fallback is the escape hatch for exporting a table the button can't reach by local-id lookup, including the table it's nested inside.
|
|
1303
|
+
|
|
1304
|
+
If the target table is itself nested under another namespaced component, its fully-qualified id is the **full chain**, not just its own `id` with `-table` appended: a table declared with `id="orders"` inside something with `id="page"` registers as `page-table.orders-table`, so that's the string to pass — `'orders-table'` alone won't match it.
|
|
1305
|
+
|
|
1306
|
+
---
|
|
1307
|
+
|
|
1133
1308
|
## Migration cookbook
|
|
1134
1309
|
|
|
1135
1310
|
Use this when replacing an existing filter panel or table with EasyVision components. The mappings below cover the most common shapes — TanStack-based and prop-driven implementations — but the pattern generalizes.
|
package/dist/EasyVisionTable.css
CHANGED
package/dist/easyvision.css
CHANGED
|
@@ -838,6 +838,57 @@
|
|
|
838
838
|
padding-top: 0;
|
|
839
839
|
}
|
|
840
840
|
|
|
841
|
+
/* ---------- Accordion (unfoldable questions / FAQ) ---------- */
|
|
842
|
+
.ev-accordion {
|
|
843
|
+
display: flex;
|
|
844
|
+
flex-direction: column;
|
|
845
|
+
gap: 1rem;
|
|
846
|
+
}
|
|
847
|
+
.ev-accordion-item {
|
|
848
|
+
border: 1px solid hsl(var(--border, 220 13% 91%));
|
|
849
|
+
border-radius: 0.375rem;
|
|
850
|
+
overflow: hidden;
|
|
851
|
+
}
|
|
852
|
+
.ev-accordion-trigger {
|
|
853
|
+
width: 100%;
|
|
854
|
+
display: flex;
|
|
855
|
+
align-items: center;
|
|
856
|
+
justify-content: space-between;
|
|
857
|
+
gap: 0.75rem;
|
|
858
|
+
padding: 0.75rem 1rem;
|
|
859
|
+
text-align: left;
|
|
860
|
+
background: hsl(var(--muted, 220 13% 91%));
|
|
861
|
+
color: hsl(var(--foreground, 222 47% 11%));
|
|
862
|
+
border: none;
|
|
863
|
+
cursor: pointer;
|
|
864
|
+
transition: background-color 0.2s ease, opacity 0.2s ease;
|
|
865
|
+
}
|
|
866
|
+
.ev-accordion-trigger:hover {
|
|
867
|
+
background: hsl(var(--muted, 220 13% 91%) / 0.8);
|
|
868
|
+
}
|
|
869
|
+
.ev-accordion-trigger:disabled {
|
|
870
|
+
cursor: not-allowed;
|
|
871
|
+
opacity: 0.6;
|
|
872
|
+
}
|
|
873
|
+
.ev-accordion-question {
|
|
874
|
+
font-weight: 500;
|
|
875
|
+
}
|
|
876
|
+
.ev-accordion-icon {
|
|
877
|
+
height: 1.25rem;
|
|
878
|
+
width: 1.25rem;
|
|
879
|
+
flex-shrink: 0;
|
|
880
|
+
color: hsl(var(--muted-foreground, 215 16% 47%));
|
|
881
|
+
transition: transform 0.2s ease;
|
|
882
|
+
}
|
|
883
|
+
.ev-accordion-trigger-open .ev-accordion-icon {
|
|
884
|
+
transform: rotate(180deg);
|
|
885
|
+
}
|
|
886
|
+
.ev-accordion-panel {
|
|
887
|
+
padding: 0.75rem 1rem;
|
|
888
|
+
background: hsl(var(--card, 0 0% 100%));
|
|
889
|
+
color: hsl(var(--foreground, 222 47% 11%));
|
|
890
|
+
}
|
|
891
|
+
|
|
841
892
|
/* ---------- EasyVisionInput (text + optional search icon + clear) ---------- */
|
|
842
893
|
.ev-input-comp {
|
|
843
894
|
display: flex;
|