@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/README.md +284 -33
- package/dist/index.cjs +638 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +364 -4
- package/dist/index.d.ts +364 -4
- package/dist/index.js +623 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -1
- package/src/components/DataTable.tsx +166 -0
- package/src/components/DataTableFilter.tsx +217 -0
- package/src/components/DataTablePagination.tsx +271 -0
- package/src/components/DataTableSearch.tsx +173 -0
- package/src/components/layouts/DataTableSplitLayout.tsx +153 -0
- package/src/components/ui/button.tsx +49 -0
- package/src/components/ui/input.tsx +20 -0
- package/src/components/ui/select.tsx +27 -0
- package/src/components/ui/table.tsx +120 -0
- package/src/hooks/useDataTable.ts +1 -1
- package/src/index.ts +60 -2
- package/src/lib/cn.ts +10 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
type HTMLAttributes,
|
|
4
|
+
type TdHTMLAttributes,
|
|
5
|
+
type ThHTMLAttributes,
|
|
6
|
+
} from 'react'
|
|
7
|
+
|
|
8
|
+
import { cn } from '../../lib/cn'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Shadcn-style Table primitives. These mirror the components produced by
|
|
12
|
+
* `shadcn add table` so users get identical visual output to a hand-rolled
|
|
13
|
+
* shadcn table in their app.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const Table = forwardRef<
|
|
17
|
+
HTMLTableElement,
|
|
18
|
+
HTMLAttributes<HTMLTableElement>
|
|
19
|
+
>(({ className, ...props }, ref) => (
|
|
20
|
+
<div className="relative w-full overflow-auto">
|
|
21
|
+
<table
|
|
22
|
+
ref={ref}
|
|
23
|
+
className={cn('w-full caption-bottom text-sm', className)}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
</div>
|
|
27
|
+
))
|
|
28
|
+
Table.displayName = 'Table'
|
|
29
|
+
|
|
30
|
+
export const TableHeader = forwardRef<
|
|
31
|
+
HTMLTableSectionElement,
|
|
32
|
+
HTMLAttributes<HTMLTableSectionElement>
|
|
33
|
+
>(({ className, ...props }, ref) => (
|
|
34
|
+
<thead ref={ref} className={cn('[&_tr]:border-b', className)} {...props} />
|
|
35
|
+
))
|
|
36
|
+
TableHeader.displayName = 'TableHeader'
|
|
37
|
+
|
|
38
|
+
export const TableBody = forwardRef<
|
|
39
|
+
HTMLTableSectionElement,
|
|
40
|
+
HTMLAttributes<HTMLTableSectionElement>
|
|
41
|
+
>(({ className, ...props }, ref) => (
|
|
42
|
+
<tbody
|
|
43
|
+
ref={ref}
|
|
44
|
+
className={cn('[&_tr:last-child]:border-0', className)}
|
|
45
|
+
{...props}
|
|
46
|
+
/>
|
|
47
|
+
))
|
|
48
|
+
TableBody.displayName = 'TableBody'
|
|
49
|
+
|
|
50
|
+
export const TableFooter = forwardRef<
|
|
51
|
+
HTMLTableSectionElement,
|
|
52
|
+
HTMLAttributes<HTMLTableSectionElement>
|
|
53
|
+
>(({ className, ...props }, ref) => (
|
|
54
|
+
<tfoot
|
|
55
|
+
ref={ref}
|
|
56
|
+
className={cn(
|
|
57
|
+
'border-t bg-muted/50 font-medium [&>tr]:last:border-b-0',
|
|
58
|
+
className,
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
))
|
|
63
|
+
TableFooter.displayName = 'TableFooter'
|
|
64
|
+
|
|
65
|
+
export const TableRow = forwardRef<
|
|
66
|
+
HTMLTableRowElement,
|
|
67
|
+
HTMLAttributes<HTMLTableRowElement>
|
|
68
|
+
>(({ className, ...props }, ref) => (
|
|
69
|
+
<tr
|
|
70
|
+
ref={ref}
|
|
71
|
+
className={cn(
|
|
72
|
+
'border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted',
|
|
73
|
+
className,
|
|
74
|
+
)}
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
))
|
|
78
|
+
TableRow.displayName = 'TableRow'
|
|
79
|
+
|
|
80
|
+
export const TableHead = forwardRef<
|
|
81
|
+
HTMLTableCellElement,
|
|
82
|
+
ThHTMLAttributes<HTMLTableCellElement>
|
|
83
|
+
>(({ className, ...props }, ref) => (
|
|
84
|
+
<th
|
|
85
|
+
ref={ref}
|
|
86
|
+
className={cn(
|
|
87
|
+
'h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0',
|
|
88
|
+
className,
|
|
89
|
+
)}
|
|
90
|
+
{...props}
|
|
91
|
+
/>
|
|
92
|
+
))
|
|
93
|
+
TableHead.displayName = 'TableHead'
|
|
94
|
+
|
|
95
|
+
export const TableCell = forwardRef<
|
|
96
|
+
HTMLTableCellElement,
|
|
97
|
+
TdHTMLAttributes<HTMLTableCellElement>
|
|
98
|
+
>(({ className, ...props }, ref) => (
|
|
99
|
+
<td
|
|
100
|
+
ref={ref}
|
|
101
|
+
className={cn(
|
|
102
|
+
'p-4 align-middle [&:has([role=checkbox])]:pr-0',
|
|
103
|
+
className,
|
|
104
|
+
)}
|
|
105
|
+
{...props}
|
|
106
|
+
/>
|
|
107
|
+
))
|
|
108
|
+
TableCell.displayName = 'TableCell'
|
|
109
|
+
|
|
110
|
+
export const TableCaption = forwardRef<
|
|
111
|
+
HTMLTableCaptionElement,
|
|
112
|
+
HTMLAttributes<HTMLTableCaptionElement>
|
|
113
|
+
>(({ className, ...props }, ref) => (
|
|
114
|
+
<caption
|
|
115
|
+
ref={ref}
|
|
116
|
+
className={cn('mt-4 text-sm text-muted-foreground', className)}
|
|
117
|
+
{...props}
|
|
118
|
+
/>
|
|
119
|
+
))
|
|
120
|
+
TableCaption.displayName = 'TableCaption'
|
|
@@ -61,7 +61,7 @@ export interface UseDataTableResult<TData> {
|
|
|
61
61
|
* const { table, loading } = useDataTable<User>({
|
|
62
62
|
* endpoint: '/datatable/users',
|
|
63
63
|
* columns: [
|
|
64
|
-
* { accessorKey: 'name', header: '
|
|
64
|
+
* { accessorKey: 'name', header: 'Name' },
|
|
65
65
|
* { accessorKey: 'email', header: 'Email' },
|
|
66
66
|
* ],
|
|
67
67
|
* })
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,65 @@ export type {
|
|
|
5
5
|
UseDataTableResult,
|
|
6
6
|
} from './hooks/useDataTable'
|
|
7
7
|
|
|
8
|
+
// Ready-made, shadcn-styled components — customizable via props
|
|
9
|
+
export { DataTable } from './components/DataTable'
|
|
10
|
+
export type {
|
|
11
|
+
DataTableProps,
|
|
12
|
+
DataTableClassNames,
|
|
13
|
+
} from './components/DataTable'
|
|
14
|
+
|
|
15
|
+
export { DataTableSearch } from './components/DataTableSearch'
|
|
16
|
+
export type {
|
|
17
|
+
DataTableSearchProps,
|
|
18
|
+
DataTableSearchRenderProps,
|
|
19
|
+
DataTableSearchDebounce,
|
|
20
|
+
} from './components/DataTableSearch'
|
|
21
|
+
|
|
22
|
+
export { DataTablePagination } from './components/DataTablePagination'
|
|
23
|
+
export type {
|
|
24
|
+
DataTablePaginationProps,
|
|
25
|
+
DataTablePaginationLabels,
|
|
26
|
+
DataTablePaginationClassNames,
|
|
27
|
+
DataTablePaginationRenderProps,
|
|
28
|
+
} from './components/DataTablePagination'
|
|
29
|
+
|
|
30
|
+
export { DataTableFilter } from './components/DataTableFilter'
|
|
31
|
+
export type {
|
|
32
|
+
DataTableFilterProps,
|
|
33
|
+
DataTableFilterOption,
|
|
34
|
+
DataTableFilterRenderProps,
|
|
35
|
+
DataTableFilterValue,
|
|
36
|
+
} from './components/DataTableFilter'
|
|
37
|
+
|
|
38
|
+
// Predefined layouts that compose the components above
|
|
39
|
+
export { DataTableSplitLayout } from './components/layouts/DataTableSplitLayout'
|
|
40
|
+
export type {
|
|
41
|
+
DataTableSplitLayoutProps,
|
|
42
|
+
DataTableSplitLayoutClassNames,
|
|
43
|
+
} from './components/layouts/DataTableSplitLayout'
|
|
44
|
+
|
|
45
|
+
// Shadcn-style UI primitives — re-exported so consumers can use them
|
|
46
|
+
// directly (or swap them for their own).
|
|
47
|
+
export { Button, buttonVariants } from './components/ui/button'
|
|
48
|
+
export type { ButtonProps } from './components/ui/button'
|
|
49
|
+
export { Input } from './components/ui/input'
|
|
50
|
+
export type { InputProps } from './components/ui/input'
|
|
51
|
+
export { Select } from './components/ui/select'
|
|
52
|
+
export type { SelectProps } from './components/ui/select'
|
|
53
|
+
export {
|
|
54
|
+
Table,
|
|
55
|
+
TableHeader,
|
|
56
|
+
TableBody,
|
|
57
|
+
TableFooter,
|
|
58
|
+
TableRow,
|
|
59
|
+
TableHead,
|
|
60
|
+
TableCell,
|
|
61
|
+
TableCaption,
|
|
62
|
+
} from './components/ui/table'
|
|
63
|
+
|
|
64
|
+
// Utilities
|
|
65
|
+
export { cn } from './lib/cn'
|
|
66
|
+
|
|
8
67
|
// Types
|
|
9
68
|
export {
|
|
10
69
|
DataTableError,
|
|
@@ -16,8 +75,7 @@ export type {
|
|
|
16
75
|
DataTableResponse,
|
|
17
76
|
} from './types'
|
|
18
77
|
|
|
19
|
-
// Lower-level utilities, exported for advanced users
|
|
20
|
-
// their own hooks or use the adapter standalone.
|
|
78
|
+
// Lower-level utilities, exported for advanced users.
|
|
21
79
|
export { buildQueryString } from './adapters/buildQueryString'
|
|
22
80
|
export type { BuildQueryStringInput } from './adapters/buildQueryString'
|
|
23
81
|
export { defaultFetcher } from './utils/defaultFetcher'
|
package/src/lib/cn.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { clsx, type ClassValue } from 'clsx'
|
|
2
|
+
import { twMerge } from 'tailwind-merge'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tailwind-aware className combinator (shadcn convention).
|
|
6
|
+
* Resolves conflicting Tailwind utilities so later inputs win.
|
|
7
|
+
*/
|
|
8
|
+
export function cn(...inputs: ClassValue[]): string {
|
|
9
|
+
return twMerge(clsx(inputs))
|
|
10
|
+
}
|