@htmlbricks/hb-table 0.66.12 → 0.66.14

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 CHANGED
@@ -5,7 +5,9 @@
5
5
 
6
6
  ### What it does
7
7
 
8
- Bootstrap-striped data table driven by JSON `headers` and `rows` (`_id` required): column sort, header search (text, enum, date range), formatted values (nested keys, datetime via dayjs), copy-to-clipboard, row highlight and `selectrow` clicks. Global `actions` and per-row `_actions` can open confirm or schema dialogs (`hb-dialog` / `hb-dialogform`). Optional multi-select with `selectactions`, `add_item` slot, and `hb-paginate` for page size, sort sync, and server-style `externalfilter` / `total` workflows. i18n via `i18nlang`.
8
+ Bootstrap-striped data table driven by JSON `headers` and `rows` (`_id` required): column sort, header search (text, enum, date range), formatted values (nested keys, datetime via dayjs), copy-to-clipboard, row highlight and `selectrow` clicks. Global `actions` and per-row `_actions` can open confirm or schema dialogs (`hb-dialog` / `hb-dialogform`). Optional multi-select with `selectactions`, `add_item` slot, and `hb-paginate` for page size, sort sync, and server-style `externalfilter` / `total` workflows.
9
+
10
+ While **`is_loading`** is enabled, the tbody shows Bootstrap **placeholder** skeleton rows (count follows **`size`**, capped at 100), and the same flag is passed to **`hb-paginate`** so the pagination bar shows placeholders too. i18n via `i18nlang`.
9
11
 
10
12
  ### Custom element
11
13
 
@@ -16,13 +18,13 @@ Bootstrap-striped data table driven by JSON `headers` and `rows` (`_id` required
16
18
  - `id` (optional), `style` (optional): strings.
17
19
  - `rows` (required): JSON string — row objects with `_id` and column keys; optional `_actions`, `_evidenced`.
18
20
  - `headers` (required): JSON string — `ITableHeader[]` (`label`, `key`, optional `type`, `format`, `search`, `click`, `select`, `nosort`, `sortBy`, `truncateAt`, `copyTxt`, `tooltip`).
19
- - `actions` (optional): JSON string — global `IActionButton[]`.
20
- - `selectactions` (optional): JSON string.
21
+ - `actions` (optional): JSON string — global row `IActionButton[]` (see **Actions** below).
22
+ - `selectactions` (optional): JSON string — toolbar buttons when multi-select is enabled (different shape from `actions`; see **Multi-select**).
21
23
  - `selectrow`, `enableselect`, `selected` (optional): strings (selection mode / ids).
22
24
  - `size`, `page`, `pages`, `total` (optional): numbers as strings for pagination / server totals.
23
25
  - `externalfilter` (optional): boolean string — host-driven filters.
24
26
  - `disablepagination` (optional): boolean string.
25
- - `add_item` (optional): boolean string — show add row UI.
27
+ - `add_item` (optional): boolean string — show the **Add** button (see **Add button** below).
26
28
  - `i18nlang` (optional): string (`it`, `en`, … per registered i18n).
27
29
  - `page_size_type` (optional): `"number"` | `"select"`.
28
30
  - `page_size_options` (optional): comma-separated sizes, e.g. `"10,25,50,100"`.
@@ -31,6 +33,53 @@ Bootstrap-striped data table driven by JSON `headers` and `rows` (`_id` required
31
33
  - `disable_paginate_sort` (optional): boolean string.
32
34
  - `sort_strict_direction` (optional): boolean string.
33
35
  - `sort_direction` (optional): string — current sort direction.
36
+ - **`is_loading` (optional):** boolean string (`"yes"` / `"true"`) or boolean in frameworks — enables loading placeholders in the table body (row count = `size`) and forwards the same state to **`hb-paginate`**.
37
+
38
+ ### Actions (`actions` and `_actions`)
39
+
40
+ Use **`actions`** for a column of buttons that is the same for every row (one set per row, same definitions). Use **`_actions`** on a single row object for buttons only on that row (e.g. variable actions per record). Both use the same **`IActionButton`** shape.
41
+
42
+ | Field | Purpose |
43
+ | --- | --- |
44
+ | `name` | Stable id for the action; emitted in events as `action`. |
45
+ | `type` | `"text"` — show `iconOrText` as label; `"icon"` — show a **Bootstrap Icon** (see below). |
46
+ | `iconOrText` | For `type: "text"`, the visible label. For `type: "icon"`, the **icon name** as on [Bootstrap Icons](https://icons.getbootstrap.com/) **without** the `bi-` prefix (e.g. `pencil`, `trash3`, `github`). The component renders a `<i>` with class `bi-{iconOrText}` (e.g. `bi-pencil`). |
47
+ | `btnClass` | Optional Bootstrap **button colour / style suffix** after `btn-`. Examples: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark`, `link`. If omitted, **text** buttons default to `link`, **icon** buttons default to `light`. The full class is `btn btn-{btnClass}`. |
48
+ | `disabled` | If true, the control is disabled. |
49
+ | `confirm` | If set, clicking opens **`hb-dialog`** confirm; on confirm the table emits `tableaction` / related confirm events. |
50
+ | `edit` | If set (and no `confirm`), clicking opens **`hb-dialogform`** with the given `schema`. |
51
+ | `tooltip` | Optional; passed to **`hb-tooltip`** for icon buttons. |
52
+
53
+ **Behaviour without `confirm` / `edit`:** the table dispatches **`tableaction`** with `{ itemId, action }` where `action` is the button `name`. For **`_actions`** on a row, the same flow applies but the event **`tableCustomActionClick`** is also fired with `{ itemId, action }` so you can distinguish custom per-row actions if needed.
54
+
55
+ **Icons:** load Bootstrap Icons CSS in the host page (the component already injects the icons stylesheet in the light DOM head for tooltips; for consistent icon font inside the shadow tree, ensure Bootstrap Icons are available). Icon names must match the Bootstrap Icons set.
56
+
57
+ ### Multi-select (`enableselect`, `selectactions`)
58
+
59
+ - Set **`enableselect`** to `"yes"` / `"true"` and pass **`selectactions`**: an array of `{ name, type, iconOrText }` used for bulk actions on checked rows. **`actiononselected`** fires with `{ key: name, selectedItems }`.
60
+ - Row checkboxes appear only when **`selectactions`** has entries.
61
+
62
+ ### Add button (`add_item`)
63
+
64
+ Set **`add_item`** to `"yes"` / `"true"` (or boolean `true` in frameworks) to show a primary **Add** control in the toolbar below the table (same **`nav`** as pagination — `part="table-actions"`). It is meant to let the user start creating a **new row**; the table does not insert data by itself.
65
+
66
+ - **Visibility:** the button is rendered only when **`enableselect`** is *not* active (multi-select gear mode hides it).
67
+ - **Click:** dispatches the **`addItem`** custom event with payload **`{ id }`**, where **`id`** is the table’s own **`id`** attribute (empty string if unset). The host should listen for `addItem` and open a form, navigate to a create page, call an API, etc.
68
+ - **Label / icon:** default content is a Bootstrap **plus** icon (`bi-plus`). Override with the **`add-button-content`** slot if you need text or a different icon.
69
+
70
+ ```html
71
+ <hb-table
72
+ id="my-list"
73
+ add_item="yes"
74
+ headers='[{"label":"Title","key":"title"}]'
75
+ rows='[{"_id":"1","title":"A"}]'
76
+ ></hb-table>
77
+ <script>
78
+ document.querySelector("hb-table").addEventListener("addItem", (e) => {
79
+ console.log("Create new item for table:", e.detail.id); // "my-list"
80
+ });
81
+ </script>
82
+ ```
34
83
 
35
84
  ### Events
36
85
 
@@ -46,14 +95,15 @@ Bootstrap-striped data table driven by JSON `headers` and `rows` (`_id` required
46
95
  - `showConfirmModal` / `showConfirmModalForm`: modal visibility payloads with `action` and `detail: { id; show }`.
47
96
  - `confirmActionModal` / `confirmActionModalForm`: `{ action; id; confirm }`.
48
97
  - `clipboardCopyText`: `{ text: string }`.
49
- - `addItem`: `{ id: string }`.
98
+ - **`addItem`:** `{ id: string }` — fired when the **Add** button is clicked; `id` is the table `id` attribute (see **Add button**).
50
99
 
51
100
  ### Usage notes
52
101
 
53
- - **Slots:** `add-button-content`, `buttons-container`.
102
+ - **Slots:** `add-button-content` (Add button body), `buttons-container` (extra toolbar content).
54
103
  - **CSS parts:** `table`, `table-actions`, `selected-row`, `common-row`.
55
- - **i18n:** italian and english in docs metadata; set `i18nlang` accordingly.
56
- - Pair with `hb-paginate` / dialogs as in Storybook examples in `extra/docs.ts`.
104
+ - **i18n:** Italian and English in docs metadata; set `i18nlang` accordingly.
105
+ - **`hb-paginate`:** embedded when pagination is enabled; receives **`is_loading`** automatically when the table is loading.
106
+ - See `extra/docs.ts` for Storybook-style examples.
57
107
 
58
108
  ### Minimal HTML example
59
109
 
@@ -65,3 +115,32 @@ Bootstrap-striped data table driven by JSON `headers` and `rows` (`_id` required
65
115
  pages="1"
66
116
  ></hb-table>
67
117
  ```
118
+
119
+ ### Loading example
120
+
121
+ ```html
122
+ <hb-table
123
+ is_loading="yes"
124
+ size="10"
125
+ headers='[{"label":"Title","key":"title"}]'
126
+ rows='[]'
127
+ total="0"
128
+ page="0"
129
+ pages="0"
130
+ ></hb-table>
131
+ ```
132
+
133
+ ### Actions example (global column + Bootstrap icon)
134
+
135
+ ```html
136
+ <hb-table
137
+ headers='[{"label":"Name","key":"name"},{"label":"Tools","key":"tools","type":"actions","nosort":true}]'
138
+ rows='[{"_id":"1","name":"Alice"}]'
139
+ actions='[
140
+ {"name":"edit","type":"icon","iconOrText":"pencil","btnClass":"primary"},
141
+ {"name":"delete","type":"icon","iconOrText":"trash","btnClass":"danger"}
142
+ ]'
143
+ ></hb-table>
144
+ ```
145
+
146
+ Listen for `tableaction` to handle `edit` / `delete` by `event.detail.itemId` and `event.detail.action`.