-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtable.tsx
More file actions
81 lines (80 loc) · 2.39 KB
/
table.tsx
File metadata and controls
81 lines (80 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// table.tsx implementation
import { ComponentRegistry } from '../../registry';
import {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption
} from '@object-ui/ui';
// A simple data-driven table
ComponentRegistry.register('table',
({ schema, className, ...props }) => (
<Table className={className} {...props}>
{schema.caption && <TableCaption>{schema.caption}</TableCaption>}
<TableHeader>
<TableRow>
{schema.columns?.map((col: any, index: number) => (
<TableHead key={index} className={col.className} style={{ width: col.width }}>
{col.header}
</TableHead>
))}
</TableRow>
</TableHeader>
<TableBody>
{schema.data?.map((row: any, rowIndex: number) => (
<TableRow key={rowIndex}>
{schema.columns?.map((col: any, colIndex: number) => (
<TableCell key={colIndex} className={col.cellClassName}>
{row[col.accessorKey]}
</TableCell>
))}
</TableRow>
))}
</TableBody>
{schema.footer && (
<TableFooter>
<TableRow>
<TableCell colSpan={schema.columns?.length}>{schema.footer}</TableCell>
</TableRow>
</TableFooter>
)}
</Table>
),
{
label: 'Table',
inputs: [
{ name: 'caption', type: 'string', label: 'Caption' },
{ name: 'footer', type: 'string', label: 'Footer Content' },
{
name: 'columns',
type: 'array',
label: 'Columns',
description: 'Array of { header, accessorKey, className, width }'
},
{
name: 'data',
type: 'array',
label: 'Data',
description: 'Array of objects'
},
{ name: 'className', type: 'string', label: 'CSS Class' }
],
defaultProps: {
caption: 'Table Caption',
columns: [
{ header: 'Column 1', accessorKey: 'col1' },
{ header: 'Column 2', accessorKey: 'col2' },
{ header: 'Column 3', accessorKey: 'col3' }
],
data: [
{ col1: 'Row 1, Col 1', col2: 'Row 1, Col 2', col3: 'Row 1, Col 3' },
{ col1: 'Row 2, Col 1', col2: 'Row 2, Col 2', col3: 'Row 2, Col 3' },
{ col1: 'Row 3, Col 1', col2: 'Row 3, Col 2', col3: 'Row 3, Col 3' }
]
}
}
);