@eztrak/shared 0.4.5 → 0.4.6

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.
Files changed (2) hide show
  1. package/README.md +134 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -40,6 +40,18 @@ handleApiError(error, { fallbackMessage: "Save failed" });
40
40
  handleApiError(error, { showAlert: true });
41
41
  ```
42
42
 
43
+ Confirmation dialog (SweetAlert2):
44
+
45
+ ```js
46
+ import { confirmationAlert } from "@eztrak/shared/utils";
47
+
48
+ confirmationAlert(() => resetLayout(), {
49
+ title: "Reset column layout to default",
50
+ text: "Reset column order, widths, and visibility to defaults?",
51
+ icon: "warning",
52
+ });
53
+ ```
54
+
43
55
  ### Hooks
44
56
 
45
57
  ```js
@@ -48,6 +60,87 @@ import { usePaginationUrlSync, useGridHeight } from "@eztrak/shared/hooks";
48
60
  const gridHeight = useGridHeight({ offset: 390 });
49
61
  ```
50
62
 
63
+ Pair `usePaginationUrlSync` with `CustomPagination` so URL query params stay in sync with your data fetch:
64
+
65
+ ```tsx
66
+ import { useSearchParams } from "react-router-dom";
67
+ import { usePaginationUrlSync } from "@eztrak/shared/hooks";
68
+
69
+ const [searchParams, setSearchParams] = useSearchParams();
70
+ const [page, setPage] = useState(1);
71
+ const [perPage, setPerPage] = useState(20);
72
+
73
+ usePaginationUrlSync(
74
+ searchParams,
75
+ setSearchParams,
76
+ page,
77
+ setPage,
78
+ perPage,
79
+ setPerPage
80
+ );
81
+ ```
82
+
83
+ ### Components — CustomPagination
84
+
85
+ URL-driven pagination bar with page controls, results summary, items-per-page select, and an optional reset-columns button. Requires a React Router context (`useSearchParams`).
86
+
87
+ ```tsx
88
+ import { CustomPagination } from "@eztrak/shared/components";
89
+
90
+ <CustomPagination
91
+ paginationData={{
92
+ currentPage: 1,
93
+ pageCount: 10,
94
+ perPage: 20,
95
+ totalCount: 193,
96
+ }}
97
+ className="bg-white"
98
+ pageSizeOptions={[10, 20, 30, 50, 100]}
99
+ onResetLayout={handleResetLayout}
100
+ layoutStatus={{
101
+ isLayoutLoading,
102
+ isLayoutSaving,
103
+ isLayoutResetting,
104
+ }}
105
+ />
106
+ ```
107
+
108
+ #### With loading state
109
+
110
+ ```tsx
111
+ <CustomPagination
112
+ paginationData={data ?? null}
113
+ isLoading={isFetching}
114
+ />
115
+ ```
116
+
117
+ #### Custom URL param names
118
+
119
+ ```tsx
120
+ <CustomPagination
121
+ paginationData={paginationData}
122
+ paramNames={{ page: "p", perPage: "size" }}
123
+ />
124
+ ```
125
+
126
+ #### Standalone reset button
127
+
128
+ ```tsx
129
+ import {
130
+ ResetColumnsButton,
131
+ TableLayoutToolbarControls,
132
+ } from "@eztrak/shared/components";
133
+
134
+ <ResetColumnsButton onReset={handleResetLayout} isLoading={isResetting} />
135
+
136
+ <TableLayoutToolbarControls
137
+ onResetLayout={handleResetLayout}
138
+ layoutStatus={{ isLayoutSaving: true }}
139
+ />
140
+ ```
141
+
142
+ `ResetColumnsButton` shows a SweetAlert2 confirmation before calling `onReset`.
143
+
51
144
  ### Components — EztrakTabs
52
145
 
53
146
  Import styles once in your app entry or layout:
@@ -162,17 +255,34 @@ Pass classes per slot — they merge with the default `eztrak-tabs-*` styles via
162
255
  ### Root import
163
256
 
164
257
  ```js
165
- import { cn, useGridHeight, EztrakTabs } from "@eztrak/shared";
258
+ import {
259
+ cn,
260
+ useGridHeight,
261
+ EztrakTabs,
262
+ CustomPagination,
263
+ } from "@eztrak/shared";
264
+ ```
265
+
266
+ ## Storybook
267
+
268
+ Run the component playground locally (dev-only, not published to npm):
269
+
270
+ ```bash
271
+ npm run storybook
272
+ # or from the monorepo root:
273
+ npm run storybook -w @eztrak/shared
166
274
  ```
167
275
 
276
+ Opens on [http://localhost:6006](http://localhost:6006) with stories for `EztrakTabs`, `CustomPagination`, and `ResetColumnsButton`.
277
+
168
278
  ## Exports
169
279
 
170
280
  | Subpath | Description |
171
281
  | --- | --- |
172
282
  | `@eztrak/shared` | Main entry — re-exports utils, hooks, and components |
173
- | `@eztrak/shared/utils` | `cn`, `handleApiError`, date/format helpers, API error helpers, form field helpers |
283
+ | `@eztrak/shared/utils` | `cn`, `handleApiError`, `confirmationAlert`, date/format helpers, API error helpers, form field helpers |
174
284
  | `@eztrak/shared/hooks` | `usePaginationUrlSync`, `useGridHeight` |
175
- | `@eztrak/shared/components` | `EztrakTabs` and related types |
285
+ | `@eztrak/shared/components` | `EztrakTabs`, `CustomPagination`, `ResetColumnsButton`, `TableLayoutToolbarControls`, and related types |
176
286
  | `@eztrak/shared/components/tabs.css` | Default tab styles (CSS variables) |
177
287
 
178
288
  ### EztrakTabs props
@@ -190,10 +300,31 @@ import { cn, useGridHeight, EztrakTabs } from "@eztrak/shared";
190
300
 
191
301
  Keyboard: Arrow keys move between tabs; Home/End jump to first/last enabled tab.
192
302
 
303
+ ### CustomPagination props
304
+
305
+ | Prop | Type | Default | Description |
306
+ | --- | --- | --- | --- |
307
+ | `paginationData` | `PaginationData \| null` | required | Server pagination metadata (`currentPage`, `pageCount`, `perPage`, `totalCount`) |
308
+ | `pageSizeOptions` | `number[]` | `[10, 20, 30, 50, 100]` | Options shown in the per-page select |
309
+ | `paginationPageSize` | `number[]` | — | Deprecated alias for `pageSizeOptions` |
310
+ | `isLoading` | `boolean` | `false` | Show loading state when data is not ready |
311
+ | `paramNames` | `{ page?: string; perPage?: string }` | `{ page: "page", perPage: "perPage" }` | URL query param keys |
312
+ | `onPageChange` | `(page: number) => void` | — | Called after page URL param is updated (1-based page) |
313
+ | `onPageSizeChange` | `(perPage: number) => void` | — | Called after per-page URL param is updated |
314
+ | `onResetLayout` | `() => void` | — | When set, shows a reset-columns button |
315
+ | `renderResetControl` | `(onReset: () => void) => ReactNode` | — | Custom reset control instead of the default button |
316
+ | `layoutStatus` | `LayoutStatus` | — | Disables reset button while layout is loading/saving/resetting |
317
+ | `classNames` | `CustomPaginationClassNames` | — | Per-slot class overrides (`root`, `info`, `nav`, `pageButton`, `activePageButton`, `select`) |
318
+ | `className` | `string` | — | Root wrapper class |
319
+
320
+ `CustomPagination` writes `page` and `perPage` to the URL via `react-router-dom`. Your page should read those params, fetch data, and pass the result back as `paginationData`.
321
+
193
322
  ## Requirements
194
323
 
195
324
  - Node.js 18+
196
325
  - React 18+ (for hooks and components)
326
+ - `react-router-dom` (required for `CustomPagination` and `usePaginationUrlSync`)
327
+ - `sweetalert2` (required for `ResetColumnsButton` and `confirmationAlert`)
197
328
  - Works with any bundler that supports the [Node.js `exports` field](https://nodejs.org/api/packages.html#exports)
198
329
 
199
330
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eztrak/shared",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "homepage": "https://github.com/mehrancentangle/eztrak-packages",
5
5
  "description": "Shared hooks, utils, and UI for Eztrak federation apps",
6
6
  "main": "./dist/index.js",