@manusiakemos/laravel-tanstack-react 0.1.0 → 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/dist/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { ColumnDef, SortingState, ColumnFiltersState, Table, PaginationState } from '@tanstack/react-table';
1
+ import { ColumnDef, SortingState, ColumnFiltersState, Table as Table$1, Column, PaginationState } from '@tanstack/react-table';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import * as react from 'react';
4
+ import { ReactNode, InputHTMLAttributes, ButtonHTMLAttributes, SelectHTMLAttributes, HTMLAttributes, TdHTMLAttributes, ThHTMLAttributes } from 'react';
5
+ import * as class_variance_authority_types from 'class-variance-authority/types';
6
+ import { VariantProps } from 'class-variance-authority';
7
+ import { ClassValue } from 'clsx';
2
8
 
3
9
  /**
4
10
  * Response shape from a `manusiakemos/laravel-tanstack` backend endpoint.
@@ -69,7 +75,7 @@ interface UseDataTableOptions<TData> {
69
75
  manual?: boolean;
70
76
  }
71
77
  interface UseDataTableResult<TData> {
72
- table: Table<TData>;
78
+ table: Table$1<TData>;
73
79
  data: TData[];
74
80
  meta: DataTableMeta | null;
75
81
  loading: boolean;
@@ -85,13 +91,367 @@ interface UseDataTableResult<TData> {
85
91
  * const { table, loading } = useDataTable<User>({
86
92
  * endpoint: '/datatable/users',
87
93
  * columns: [
88
- * { accessorKey: 'name', header: 'Nama' },
94
+ * { accessorKey: 'name', header: 'Name' },
89
95
  * { accessorKey: 'email', header: 'Email' },
90
96
  * ],
91
97
  * })
92
98
  */
93
99
  declare function useDataTable<TData>(options: UseDataTableOptions<TData>): UseDataTableResult<TData>;
94
100
 
101
+ interface DataTableClassNames {
102
+ root?: string;
103
+ table?: string;
104
+ header?: string;
105
+ headerRow?: string;
106
+ head?: string;
107
+ body?: string;
108
+ row?: string;
109
+ cell?: string;
110
+ empty?: string;
111
+ loading?: string;
112
+ }
113
+ interface DataTableProps<TData> {
114
+ table: Table$1<TData>;
115
+ /** Loading flag from `useDataTable`. */
116
+ loading?: boolean;
117
+ /** Slot rendered inside the empty <tbody> when there are no rows. */
118
+ emptyMessage?: ReactNode;
119
+ /** Slot rendered inside the loading <tbody>. */
120
+ loadingMessage?: ReactNode;
121
+ /** Class for the outer wrapper. */
122
+ className?: string;
123
+ /** Fine-grained class names for table parts. */
124
+ classNames?: DataTableClassNames;
125
+ /** Called when a row is clicked. */
126
+ onRowClick?: (row: TData) => void;
127
+ }
128
+ /**
129
+ * Shadcn-styled table component wired to a TanStack `Table` instance.
130
+ * Renders header (with sort indicators), body, empty state, and loading state.
131
+ *
132
+ * @example
133
+ * const { table, loading } = useDataTable<User>({ ... })
134
+ * <DataTable table={table} loading={loading} />
135
+ */
136
+ declare function DataTable<TData>(props: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
137
+
138
+ interface DataTableSearchRenderProps {
139
+ /** Current uncommitted input value (pre-debounce / pre-submit). */
140
+ value: string;
141
+ /** Update the input value (debounced commit if `debounce` is on). */
142
+ setValue: (next: string) => void;
143
+ /** Immediately commit the current value to the table's global filter. */
144
+ submit: () => void;
145
+ /** The value currently applied to the table's global filter. */
146
+ appliedValue: string;
147
+ }
148
+ type DataTableSearchDebounce = boolean | number;
149
+ interface DataTableSearchProps<TData> {
150
+ table: Table$1<TData>;
151
+ /**
152
+ * Debounce behavior:
153
+ * - `true` → debounced with default delay (300ms)
154
+ * - number → debounced with the given delay in ms
155
+ * - `false` → no debounce; instead the component renders a Search button
156
+ * and only commits to the table on submit (button click / Enter)
157
+ *
158
+ * Defaults to `true`.
159
+ */
160
+ debounce?: DataTableSearchDebounce;
161
+ /** Placeholder text for the default input. */
162
+ placeholder?: string;
163
+ /** Label for the search submit button (when `debounce` is `false`). */
164
+ submitLabel?: ReactNode;
165
+ /** Class for the root wrapper element (ignored when `render` is provided). */
166
+ className?: string;
167
+ /** Class merged into the underlying shadcn Input. */
168
+ inputClassName?: string;
169
+ /** Class merged into the submit Button (when `debounce` is `false`). */
170
+ buttonClassName?: string;
171
+ /** Extra props spread onto the underlying Input. */
172
+ inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'type' | 'className'>;
173
+ /** Fired whenever the search value is committed to the table. */
174
+ onSearch?: (value: string) => void;
175
+ /**
176
+ * Full render override. Receives the controlled value, setter, and a manual
177
+ * `submit()` so you can drop in any custom UI.
178
+ */
179
+ render?: (props: DataTableSearchRenderProps) => ReactNode;
180
+ }
181
+ /**
182
+ * Debounced (or manual-submit) global search wired to a TanStack `Table`.
183
+ *
184
+ * @example Debounced (default)
185
+ * <DataTableSearch table={table} placeholder="Search users..." />
186
+ *
187
+ * @example Manual submit (search button)
188
+ * <DataTableSearch table={table} debounce={false} placeholder="Search..." />
189
+ *
190
+ * @example Custom UI
191
+ * <DataTableSearch
192
+ * table={table}
193
+ * render={({ value, setValue, submit }) => (
194
+ * <MyCombobox value={value} onChange={setValue} onSubmit={submit} />
195
+ * )}
196
+ * />
197
+ */
198
+ declare function DataTableSearch<TData>(props: DataTableSearchProps<TData>): react_jsx_runtime.JSX.Element;
199
+
200
+ interface DataTablePaginationLabels {
201
+ previous?: ReactNode;
202
+ next?: ReactNode;
203
+ first?: ReactNode;
204
+ last?: ReactNode;
205
+ page?: string;
206
+ of?: string;
207
+ rowsPerPage?: string;
208
+ /** Renderer for the row-count summary. */
209
+ summary?: (info: {
210
+ pageIndex: number;
211
+ pageCount: number;
212
+ pageSize: number;
213
+ filtered: number;
214
+ total: number | null;
215
+ }) => ReactNode;
216
+ }
217
+ interface DataTablePaginationClassNames {
218
+ root?: string;
219
+ info?: string;
220
+ controls?: string;
221
+ button?: string;
222
+ select?: string;
223
+ pageSize?: string;
224
+ }
225
+ interface DataTablePaginationRenderProps<TData> {
226
+ table: Table$1<TData>;
227
+ meta: DataTableMeta | null;
228
+ pageIndex: number;
229
+ pageCount: number;
230
+ pageSize: number;
231
+ canPreviousPage: boolean;
232
+ canNextPage: boolean;
233
+ goToFirst: () => void;
234
+ goToPrevious: () => void;
235
+ goToNext: () => void;
236
+ goToLast: () => void;
237
+ setPageSize: (size: number) => void;
238
+ }
239
+ interface DataTablePaginationProps<TData> {
240
+ table: Table$1<TData>;
241
+ /** Meta from `useDataTable`. Used for the row-count summary. */
242
+ meta?: DataTableMeta | null;
243
+ /** Show the page-size selector. Defaults to false. */
244
+ showPageSize?: boolean;
245
+ /** Available page size options when `showPageSize` is true. */
246
+ pageSizeOptions?: number[];
247
+ /** Show first/last page buttons. Defaults to false. */
248
+ showFirstLast?: boolean;
249
+ /** Hide the "Page X of Y · N rows" summary. */
250
+ hideSummary?: boolean;
251
+ /** Override individual labels / the summary renderer. */
252
+ labels?: DataTablePaginationLabels;
253
+ /** Class for the root container. */
254
+ className?: string;
255
+ /** Fine-grained class names for sub-elements. */
256
+ classNames?: DataTablePaginationClassNames;
257
+ /** Extra props for the prev/next/first/last buttons. */
258
+ buttonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'disabled' | 'className' | 'type'>;
259
+ /** Extra props for the page-size <select>. */
260
+ selectProps?: Omit<SelectHTMLAttributes<HTMLSelectElement>, 'value' | 'onChange' | 'className'>;
261
+ /**
262
+ * Full render override. Receives the pagination API so any custom UI can
263
+ * still drive the table.
264
+ */
265
+ render?: (props: DataTablePaginationRenderProps<TData>) => ReactNode;
266
+ }
267
+ /**
268
+ * Shadcn-styled pagination controls (prev/next, optional first/last, optional
269
+ * page-size selector, row-count summary) wired to a TanStack `Table`.
270
+ */
271
+ declare function DataTablePagination<TData>(props: DataTablePaginationProps<TData>): react_jsx_runtime.JSX.Element;
272
+
273
+ type DataTableFilterValue = string | string[] | undefined;
274
+ interface DataTableFilterOption {
275
+ label: string;
276
+ value: string;
277
+ }
278
+ interface DataTableFilterRenderProps<TData> {
279
+ /** The current filter value for this column. */
280
+ value: DataTableFilterValue;
281
+ /** Commit a new filter value (use `undefined` or `''` to clear). */
282
+ setValue: (next: DataTableFilterValue) => void;
283
+ /** The TanStack column instance. */
284
+ column: Column<TData, unknown>;
285
+ /** The parent table instance. */
286
+ table: Table$1<TData>;
287
+ }
288
+ interface BaseFilterProps<TData> {
289
+ table: Table$1<TData>;
290
+ /** The column id this filter applies to. */
291
+ columnId: string;
292
+ /** Class for the root element (when not using `render`). */
293
+ className?: string;
294
+ /**
295
+ * Full render override. You get the raw column filter value + setter, so
296
+ * any UI (popover, multi-select combobox, date picker, …) can be plugged
297
+ * in while still feeding the same TanStack column filter pipeline.
298
+ */
299
+ render?: (props: DataTableFilterRenderProps<TData>) => ReactNode;
300
+ }
301
+ interface SelectFilterProps<TData> extends BaseFilterProps<TData> {
302
+ type?: 'select';
303
+ options: DataTableFilterOption[];
304
+ /** Placeholder option label (renders an empty value option). */
305
+ placeholder?: string;
306
+ /** Whether to render the empty/placeholder option. Defaults to true. */
307
+ includeEmptyOption?: boolean;
308
+ selectProps?: Omit<SelectHTMLAttributes<HTMLSelectElement>, 'value' | 'onChange' | 'className'>;
309
+ }
310
+ interface MultiSelectFilterProps<TData> extends BaseFilterProps<TData> {
311
+ type: 'multiselect';
312
+ options: DataTableFilterOption[];
313
+ selectProps?: Omit<SelectHTMLAttributes<HTMLSelectElement>, 'value' | 'onChange' | 'multiple' | 'className'>;
314
+ }
315
+ interface InputFilterProps<TData> extends BaseFilterProps<TData> {
316
+ type: 'input';
317
+ placeholder?: string;
318
+ inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'type' | 'className'>;
319
+ }
320
+ interface CustomFilterProps<TData> extends BaseFilterProps<TData> {
321
+ type?: 'custom';
322
+ /** Required when `type` is `"custom"` (or when no `options` given). */
323
+ render: (props: DataTableFilterRenderProps<TData>) => ReactNode;
324
+ }
325
+ type DataTableFilterProps<TData> = SelectFilterProps<TData> | MultiSelectFilterProps<TData> | InputFilterProps<TData> | CustomFilterProps<TData>;
326
+ /**
327
+ * Shadcn-styled per-column filter wired to a TanStack `Table`.
328
+ *
329
+ * Supports four modes:
330
+ * - `type="select"` — single-select (default when `options` given)
331
+ * - `type="multiselect"` — multi-select
332
+ * - `type="input"` — text input
333
+ * - `type="custom"` (or `render`) — fully custom UI
334
+ *
335
+ * @example Select
336
+ * <DataTableFilter
337
+ * table={table}
338
+ * columnId="status"
339
+ * options={[
340
+ * { label: 'Active', value: 'active' },
341
+ * { label: 'Inactive', value: 'inactive' },
342
+ * ]}
343
+ * placeholder="All statuses"
344
+ * />
345
+ *
346
+ * @example Custom render
347
+ * <DataTableFilter
348
+ * table={table}
349
+ * columnId="status"
350
+ * render={({ value, setValue }) => (
351
+ * <MyCustomFilter value={value} onChange={setValue} />
352
+ * )}
353
+ * />
354
+ */
355
+ declare function DataTableFilter<TData>(props: DataTableFilterProps<TData>): react_jsx_runtime.JSX.Element | null;
356
+
357
+ interface DataTableSplitLayoutClassNames {
358
+ root?: string;
359
+ toolbar?: string;
360
+ toolbarLeft?: string;
361
+ toolbarRight?: string;
362
+ body?: string;
363
+ footer?: string;
364
+ }
365
+ interface DataTableSplitLayoutProps<TData> {
366
+ table: Table$1<TData>;
367
+ meta?: DataTableMeta | null;
368
+ loading?: boolean;
369
+ /**
370
+ * Right-side toolbar slot — typically one or more `<DataTableFilter />`s.
371
+ * Rendered to the right of the search input on the same row.
372
+ */
373
+ filters?: ReactNode;
374
+ /**
375
+ * Optional far-right toolbar slot for page-level actions (e.g. an
376
+ * "+ Add" button). Appears after `filters`.
377
+ */
378
+ actions?: ReactNode;
379
+ /**
380
+ * Override the entire search slot. By default, a `<DataTableSearch />`
381
+ * wired to `table` is rendered with sensible defaults.
382
+ */
383
+ search?: ReactNode;
384
+ /** Forwarded to the auto-rendered `<DataTableSearch />`. */
385
+ searchProps?: Omit<DataTableSearchProps<TData>, 'table'>;
386
+ /** Forwarded to the auto-rendered `<DataTable />`. */
387
+ tableProps?: Omit<DataTableProps<TData>, 'table' | 'loading'>;
388
+ /** Forwarded to the auto-rendered `<DataTablePagination />`. */
389
+ paginationProps?: Omit<DataTablePaginationProps<TData>, 'table' | 'meta'>;
390
+ className?: string;
391
+ classNames?: DataTableSplitLayoutClassNames;
392
+ }
393
+ /**
394
+ * Pre-built "split toolbar" layout: search on the left, filters/actions on
395
+ * the right; pagination info on the left, controls on the right.
396
+ *
397
+ * @example
398
+ * <DataTableSplitLayout
399
+ * table={table}
400
+ * meta={meta}
401
+ * loading={loading}
402
+ * searchProps={{ placeholder: 'Search users...' }}
403
+ * filters={
404
+ * <>
405
+ * <DataTableFilter table={table} columnId="status" options={statusOpts} />
406
+ * <DataTableFilter table={table} columnId="role" type="multiselect" options={roleOpts} />
407
+ * </>
408
+ * }
409
+ * actions={<Button>+ Add user</Button>}
410
+ * paginationProps={{ showPageSize: true, showFirstLast: true }}
411
+ * />
412
+ */
413
+ declare function DataTableSplitLayout<TData>(props: DataTableSplitLayoutProps<TData>): react_jsx_runtime.JSX.Element;
414
+
415
+ declare const buttonVariants: (props?: ({
416
+ variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
417
+ size?: "default" | "sm" | "lg" | "icon" | null | undefined;
418
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
419
+ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
420
+ }
421
+ declare const Button: react.ForwardRefExoticComponent<ButtonProps & react.RefAttributes<HTMLButtonElement>>;
422
+
423
+ type InputProps = InputHTMLAttributes<HTMLInputElement>;
424
+ declare const Input: react.ForwardRefExoticComponent<InputProps & react.RefAttributes<HTMLInputElement>>;
425
+
426
+ type SelectProps = SelectHTMLAttributes<HTMLSelectElement>;
427
+ /**
428
+ * Shadcn-styled native <select>. We use the native element (not Radix) to
429
+ * keep the dependency footprint minimal; consumers who want a Radix-based
430
+ * popover select can swap it in via the `render` prop on the parent
431
+ * component.
432
+ */
433
+ declare const Select: react.ForwardRefExoticComponent<SelectProps & react.RefAttributes<HTMLSelectElement>>;
434
+
435
+ /**
436
+ * Shadcn-style Table primitives. These mirror the components produced by
437
+ * `shadcn add table` so users get identical visual output to a hand-rolled
438
+ * shadcn table in their app.
439
+ */
440
+ declare const Table: react.ForwardRefExoticComponent<HTMLAttributes<HTMLTableElement> & react.RefAttributes<HTMLTableElement>>;
441
+ declare const TableHeader: react.ForwardRefExoticComponent<HTMLAttributes<HTMLTableSectionElement> & react.RefAttributes<HTMLTableSectionElement>>;
442
+ declare const TableBody: react.ForwardRefExoticComponent<HTMLAttributes<HTMLTableSectionElement> & react.RefAttributes<HTMLTableSectionElement>>;
443
+ declare const TableFooter: react.ForwardRefExoticComponent<HTMLAttributes<HTMLTableSectionElement> & react.RefAttributes<HTMLTableSectionElement>>;
444
+ declare const TableRow: react.ForwardRefExoticComponent<HTMLAttributes<HTMLTableRowElement> & react.RefAttributes<HTMLTableRowElement>>;
445
+ declare const TableHead: react.ForwardRefExoticComponent<ThHTMLAttributes<HTMLTableCellElement> & react.RefAttributes<HTMLTableCellElement>>;
446
+ declare const TableCell: react.ForwardRefExoticComponent<TdHTMLAttributes<HTMLTableCellElement> & react.RefAttributes<HTMLTableCellElement>>;
447
+ declare const TableCaption: react.ForwardRefExoticComponent<HTMLAttributes<HTMLTableCaptionElement> & react.RefAttributes<HTMLTableCaptionElement>>;
448
+
449
+ /**
450
+ * Tailwind-aware className combinator (shadcn convention).
451
+ * Resolves conflicting Tailwind utilities so later inputs win.
452
+ */
453
+ declare function cn(...inputs: ClassValue[]): string;
454
+
95
455
  /**
96
456
  * Build a query string from TanStack Table state, matching the protocol
97
457
  * expected by `manusiakemos/laravel-tanstack`:
@@ -125,4 +485,4 @@ declare function defaultFetcher<TData>(url: string, init?: RequestInit): Promise
125
485
  */
126
486
  declare function useDebouncedValue<T>(value: T, delay?: number): T;
127
487
 
128
- export { type BuildQueryStringInput, DataTableError, type DataTableFetcher, type DataTableMeta, type DataTableRequestParams, type DataTableResponse, type UseDataTableOptions, type UseDataTableResult, buildQueryString, defaultFetcher, useDataTable, useDebouncedValue };
488
+ export { type BuildQueryStringInput, Button, type ButtonProps, DataTable, type DataTableClassNames, DataTableError, type DataTableFetcher, DataTableFilter, type DataTableFilterOption, type DataTableFilterProps, type DataTableFilterRenderProps, type DataTableFilterValue, type DataTableMeta, DataTablePagination, type DataTablePaginationClassNames, type DataTablePaginationLabels, type DataTablePaginationProps, type DataTablePaginationRenderProps, type DataTableProps, type DataTableRequestParams, type DataTableResponse, DataTableSearch, type DataTableSearchDebounce, type DataTableSearchProps, type DataTableSearchRenderProps, DataTableSplitLayout, type DataTableSplitLayoutClassNames, type DataTableSplitLayoutProps, Input, type InputProps, Select, type SelectProps, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, type UseDataTableOptions, type UseDataTableResult, buildQueryString, buttonVariants, cn, defaultFetcher, useDataTable, useDebouncedValue };