@mistersee/global-table 0.1.1

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 ADDED
@@ -0,0 +1,376 @@
1
+ # @mistersee/global-table
2
+
3
+ A lightweight, Tailwind-first React data table for product UIs that need sticky columns, pagination, column visibility, drag-and-drop reordering, and flexible styling — without a heavy grid framework.
4
+
5
+ ![@mistersee/global-table demo](./media/demo-table.png)
6
+
7
+ <p align="center">
8
+ <em>Demo UI: index column, sticky Actions, field colors, column toggle, and pagination.</em>
9
+ </p>
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **Sticky columns** — pin any fields left or right while scrolling horizontally
16
+ - **Hybrid pagination** — controlled or uncontrolled (`limit` / `skip`)
17
+ - **Column visibility** — toggle which fields are shown
18
+ - **Column reorder** — optional drag-and-drop header reordering
19
+ - **Custom actions** — inject any React nodes into the actions column
20
+ - **Row index** — optional leading `#` column (pagination-aware)
21
+ - **Field styling** — map Tailwind classes to fields from outside (e.g. price → green)
22
+ - **Design slots** — style structure via `classNames` without rewriting markup
23
+ - **Sensible defaults** — column min-width `120px`, max-width `310px`
24
+ - **Tailwind CSS only** — no CSS-in-JS runtime for styles
25
+
26
+ ---
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ npm install @mistersee/global-table
32
+ # or
33
+ bun add @mistersee/global-table
34
+ # or
35
+ pnpm add @mistersee/global-table
36
+ ```
37
+
38
+ ### Peer dependencies
39
+
40
+ ```bash
41
+ npm install react react-dom framer-motion tailwindcss
42
+ ```
43
+
44
+ | Package | Version |
45
+ | --- | --- |
46
+ | `react` | `>=18` |
47
+ | `react-dom` | `>=18` |
48
+ | `framer-motion` | `>=11` |
49
+ | `tailwindcss` | `>=4` |
50
+
51
+ ### Tailwind v4 setup
52
+
53
+ `@mistersee/global-table` ships utility class names inside its ESM build. Your app must scan them:
54
+
55
+ ```css
56
+ @import 'tailwindcss';
57
+ @source "../node_modules/@mistersee/global-table/dist";
58
+ ```
59
+
60
+ Adjust the `@source` path to match your project layout.
61
+
62
+ ---
63
+
64
+ ## Quick start
65
+
66
+ ```tsx
67
+ import { SeeTable } from '@mistersee/global-table'
68
+ import type { ColumnDef } from '@mistersee/global-table'
69
+
70
+ type Customer = {
71
+ id: string
72
+ code: string
73
+ firstName: string
74
+ lastName: string
75
+ company: string
76
+ status: 'active' | 'inactive' | 'pending'
77
+ orders: number
78
+ spent: number
79
+ }
80
+
81
+ const columns: ColumnDef<Customer>[] = [
82
+ { key: 'code', header: 'Code' },
83
+ { key: 'firstName', header: 'First name' },
84
+ { key: 'lastName', header: 'Last name' },
85
+ { key: 'company', header: 'Company' },
86
+ { key: 'status', header: 'Status' },
87
+ { key: 'orders', header: 'Orders' },
88
+ {
89
+ key: 'spent',
90
+ header: 'Spent',
91
+ cell: (row) => `$${row.spent.toFixed(2)}`,
92
+ },
93
+ { key: 'actions', header: 'Actions' },
94
+ ]
95
+
96
+ export function CustomersTable({ rows }: { rows: Customer[] }) {
97
+ return (
98
+ <SeeTable
99
+ columns={columns}
100
+ data={rows}
101
+ getRowId={(row) => row.id}
102
+ showIndex
103
+ stickyRight={['actions']}
104
+ fieldClassNames={{
105
+ orders: 'text-blue-500',
106
+ spent: 'text-green-500 font-medium',
107
+ }}
108
+ renderActions={(row) => (
109
+ <button type="button" onClick={() => console.log(row.id)}>
110
+ View
111
+ </button>
112
+ )}
113
+ classNames={{
114
+ root: 'rounded-xl bg-white p-3 shadow-sm',
115
+ th: 'bg-zinc-100 font-medium text-zinc-700',
116
+ }}
117
+ />
118
+ )
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## UI overview
125
+
126
+ The screenshot above shows a typical configuration:
127
+
128
+ | Area | Behavior |
129
+ | --- | --- |
130
+ | Header | Drag handles when reordering is enabled |
131
+ | `#` | Optional index column |
132
+ | `Orders` / `Spent` | Colored via `fieldClassNames` |
133
+ | `Actions` | Sticky right + custom `renderActions` |
134
+ | Footer | Column toggle, page size select, pagination |
135
+
136
+ ---
137
+
138
+ ## Column definition
139
+
140
+ ```ts
141
+ type ColumnDef<T> = {
142
+ key: string
143
+ header: React.ReactNode
144
+ width?: number | 'auto' // omit = default min 120 / max 310
145
+ sticky?: 'left' | 'right' // optional; prefer stickyLeft / stickyRight props
146
+ defaultVisible?: boolean
147
+ cell?: (row: T, rowIndex: number) => React.ReactNode
148
+ className?: string
149
+ }
150
+ ```
151
+
152
+ **Width defaults (when `width` is omitted):**
153
+
154
+ - `min-width: 120px`
155
+ - `max-width: 310px`
156
+
157
+ Use `width: 'auto'` for content-sized columns such as action button groups.
158
+
159
+ ---
160
+
161
+ ## `SeeTable` props
162
+
163
+ ### Data & columns
164
+
165
+ | Prop | Type | Default | Description |
166
+ | --- | --- | --- | --- |
167
+ | `columns` | `ColumnDef<T>[]` | — | Column definitions |
168
+ | `data` | `T[]` | — | Row data for the current view (or full list in uncontrolled pagination) |
169
+ | `getRowId` | `(row, index) => string` | row index | Stable row key |
170
+ | `defaultVisibleColumns` | `string[]` | all visible | Initial visible column keys |
171
+ | `loading` | `boolean` | `false` | Shows skeleton rows |
172
+
173
+ ### Sticky columns
174
+
175
+ | Prop | Type | Default | Description |
176
+ | --- | --- | --- | --- |
177
+ | `stickyLeft` | `string[]` | — | Column keys pinned to the left |
178
+ | `stickyRight` | `string[]` | — | Column keys pinned to the right |
179
+
180
+ ```tsx
181
+ <SeeTable
182
+ stickyLeft={['firstName']}
183
+ stickyRight={['actions']}
184
+ {...props}
185
+ />
186
+ ```
187
+
188
+ When `stickyLeft` / `stickyRight` are provided, they become the source of truth for sticky sides.
189
+
190
+ ### Pagination (hybrid)
191
+
192
+ | Prop | Type | Default | Description |
193
+ | --- | --- | --- | --- |
194
+ | `limit` | `number` | internal `10` | Page size |
195
+ | `skip` | `number` | internal `0` | Offset |
196
+ | `total` | `number` | `data.length` | Total row count (useful for server paging) |
197
+ | `onPaginationChange` | `({ limit, skip }) => void` | — | Enables controlled mode when used with `limit` + `skip` |
198
+ | `limitOptions` | `number[]` | `[10, 20, 50]` | Page-size options |
199
+
200
+ **Uncontrolled (client-side):** pass the full `data` array; the table slices pages internally.
201
+
202
+ **Controlled (API / server):** pass the current page `data`, plus `limit`, `skip`, `total`, and `onPaginationChange`.
203
+
204
+ ### Column visibility toggle
205
+
206
+ | Prop | Type | Default | Description |
207
+ | --- | --- | --- | --- |
208
+ | `showColumnToggle` | `boolean` | `true` | Show/hide the Columns button |
209
+ | `columnsLabel` | `ReactNode` | `"Columns"` | Button label |
210
+
211
+ ```tsx
212
+ <SeeTable showColumnToggle={false} {...props} />
213
+ ```
214
+
215
+ ### Column reorder (drag & drop)
216
+
217
+ | Prop | Type | Default | Description |
218
+ | --- | --- | --- | --- |
219
+ | `columnOrder` | `string[]` | column definition order | Controlled key order |
220
+ | `onColumnOrderChange` | `(next) => void` | — | Called after a successful drop |
221
+ | `enableColumnReorder` | `boolean` | `true` if `onColumnOrderChange` is set | Force enable/disable |
222
+
223
+ ```tsx
224
+ const [columnOrder, setColumnOrder] = useState(columns.map((c) => c.key))
225
+
226
+ <SeeTable
227
+ columnOrder={columnOrder}
228
+ onColumnOrderChange={setColumnOrder}
229
+ enableColumnReorder
230
+ {...props}
231
+ />
232
+ ```
233
+
234
+ To disable reordering entirely:
235
+
236
+ ```tsx
237
+ <SeeTable enableColumnReorder={false} {...props} />
238
+ ```
239
+
240
+ ### Actions column
241
+
242
+ | Prop | Type | Default | Description |
243
+ | --- | --- | --- | --- |
244
+ | `renderActions` | `(row, rowIndex) => ReactNode` | — | Custom action UI per row |
245
+ | `actionsKey` | `string` | `"actions"` | Target column key |
246
+ | `actionsHeader` | `ReactNode` | `"Actions"` | Header if column is auto-created |
247
+
248
+ ```tsx
249
+ <SeeTable
250
+ renderActions={(row) => (
251
+ <div className="flex gap-1.5">
252
+ <button type="button">View</button>
253
+ <button type="button">Edit</button>
254
+ </div>
255
+ )}
256
+ stickyRight={['actions']}
257
+ {...props}
258
+ />
259
+ ```
260
+
261
+ ### Row index
262
+
263
+ | Prop | Type | Default | Description |
264
+ | --- | --- | --- | --- |
265
+ | `showIndex` | `boolean` | `false` | Show leading index column |
266
+ | `indexHeader` | `ReactNode` | `"#"` | Index header label |
267
+ | `indexWidth` | `number` | `56` | Index column width (px) |
268
+ | `renderIndex` | `(row, rowIndex, index) => ReactNode` | `index` | Custom index cell |
269
+
270
+ `index` is pagination-aware: `skip + rowIndex + 1`.
271
+
272
+ ### Field colors / classes
273
+
274
+ | Prop | Type | Description |
275
+ | --- | --- | --- |
276
+ | `fieldClassNames` | `Record<string, string \| ((row, rowIndex) => string \| undefined)>` | Per-field Tailwind classes |
277
+
278
+ ```tsx
279
+ <SeeTable
280
+ fieldClassNames={{
281
+ spent: 'text-green-500 font-medium',
282
+ orders: 'text-blue-500',
283
+ status: (row) =>
284
+ row.status === 'active'
285
+ ? 'text-emerald-600'
286
+ : row.status === 'pending'
287
+ ? 'text-amber-600'
288
+ : 'text-zinc-400',
289
+ }}
290
+ {...props}
291
+ />
292
+ ```
293
+
294
+ ### Design slots (`classNames`)
295
+
296
+ | Slot | Applies to |
297
+ | --- | --- |
298
+ | `root` | Outer wrapper |
299
+ | `tableWrapper` | Scroll container |
300
+ | `table` | `<table>` |
301
+ | `thead` / `th` | Header |
302
+ | `tbody` / `tr` / `td` | Body |
303
+ | `skeleton` | Loading rows |
304
+ | `columnToggle` | Columns button |
305
+ | `pagination` | Footer controls |
306
+
307
+ ```tsx
308
+ <SeeTable
309
+ classNames={{
310
+ root: 'rounded-xl bg-white p-3 shadow-sm',
311
+ th: 'bg-zinc-100 font-medium text-zinc-700',
312
+ td: 'text-zinc-600',
313
+ }}
314
+ {...props}
315
+ />
316
+ ```
317
+
318
+ Sticky headers/cells respect `classNames.th` / `classNames.td` (including custom backgrounds such as `bg-orange-500`).
319
+
320
+ ---
321
+
322
+ ## Loading state
323
+
324
+ ```tsx
325
+ <SeeTable columns={columns} data={rows} loading />
326
+ ```
327
+
328
+ When `loading` is `true`, skeleton rows are rendered to match the current page size and visible column count.
329
+
330
+ ---
331
+
332
+ ## Exports
333
+
334
+ ```ts
335
+ import {
336
+ SeeTable,
337
+ INDEX_COLUMN_KEY,
338
+ DEFAULT_COL_MIN_WIDTH, // 120
339
+ DEFAULT_COL_MAX_WIDTH, // 310
340
+ } from '@mistersee/global-table'
341
+
342
+ import type {
343
+ ColumnDef,
344
+ SeeTableProps,
345
+ SeeTableClassNames,
346
+ StickySide,
347
+ } from '@mistersee/global-table'
348
+ ```
349
+
350
+ ---
351
+
352
+ ## Local development
353
+
354
+ ```bash
355
+ bun install
356
+ bun run dev # demo app
357
+ bun run build # library → dist/
358
+ bun run build:demo # demo production build
359
+ ```
360
+
361
+ ---
362
+
363
+ ## Design principles
364
+
365
+ - **Composable, not opinionated** — bring your own buttons, badges, and Tailwind tokens
366
+ - **Opt-in complexity** — drag-and-drop, index, and column toggle can be turned off
367
+ - **Predictable layout** — default column bounds keep dense tables readable
368
+ - **Peer-first styling** — consumers own Tailwind; the library stays thin
369
+
370
+ ---
371
+
372
+ ## Developed by
373
+
374
+ - **MisterSee VANG**
375
+ - mistersee.dev@gmail.com
376
+ - Senior Software Engineer
@@ -0,0 +1,11 @@
1
+ export interface ColumnToggleItem {
2
+ key: string;
3
+ label: React.ReactNode;
4
+ }
5
+ export declare function ColumnToggle({ columns, visibleKeys, onChange, className, label, }: {
6
+ columns: ColumnToggleItem[];
7
+ visibleKeys: Set<string>;
8
+ onChange: (next: Set<string>) => void;
9
+ className?: string;
10
+ label?: React.ReactNode;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ export declare function LimitSelect({ value, options, onChange, className, }: {
2
+ value: number;
3
+ options: number[];
4
+ onChange: (value: number) => void;
5
+ className?: string;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from 'react';
2
+ export declare function Pagination({ skip, limit, total, limitOptions, onChange, className, startAddon, }: {
3
+ skip: number;
4
+ limit: number;
5
+ total: number;
6
+ limitOptions?: number[];
7
+ onChange: (next: {
8
+ skip: number;
9
+ limit: number;
10
+ }) => void;
11
+ className?: string;
12
+ /** Extra control shown before the limit select (e.g. column toggle) */
13
+ startAddon?: ReactNode;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import type { SeeTableProps } from './types';
2
+ export declare const INDEX_COLUMN_KEY = "__see_table_index__";
3
+ export declare const DEFAULT_COL_MIN_WIDTH = 120;
4
+ export declare const DEFAULT_COL_MAX_WIDTH = 310;
5
+ export declare function SeeTable<T extends Record<string, unknown>>({ columns, data, getRowId, defaultVisibleColumns, limit: limitProp, skip: skipProp, total: totalProp, onPaginationChange, limitOptions, loading, stickyLeft, stickyRight, renderActions, actionsKey, actionsHeader, columnOrder, onColumnOrderChange, enableColumnReorder, showColumnToggle, columnsLabel, showIndex, indexHeader, indexWidth, renderIndex, fieldClassNames, classNames, }: SeeTableProps<T>): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ export declare function SkeletonRows({ rowCount, columnCount, className, }: {
2
+ rowCount: number;
3
+ columnCount: number;
4
+ className?: string;
5
+ }): import("react").JSX.Element;