-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-table-stories.components.tsx
More file actions
147 lines (144 loc) · 3.79 KB
/
data-table-stories.components.tsx
File metadata and controls
147 lines (144 loc) · 3.79 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import type { ColumnDef } from '@tanstack/react-table';
import {
assigneeOptions,
CalendarIcon,
CheckCircledIcon,
createColumnConfigHelper,
DataTableColumnHeader,
type MockIssue,
PersonIcon,
priorityOptions,
StarIcon,
statusOptions,
TextIcon,
} from './data-table-stories.helpers';
// --- Column Configuration ---
const dtf = createColumnConfigHelper<MockIssue>();
export const columnConfigs = [
dtf
.text()
.id('title')
.accessor((row) => row.title)
.displayName('Title')
.icon(TextIcon)
.build(),
dtf
.option()
.id('status')
.accessor((row) => row.status)
.displayName('Status')
.icon(CheckCircledIcon)
.options(statusOptions)
.build(),
dtf
.option()
.id('assignee')
.accessor((row) => row.assignee)
.displayName('Assignee')
.icon(PersonIcon)
.options(assigneeOptions)
.build(),
dtf
.option()
.id('priority')
.accessor((row) => row.priority)
.displayName('Priority')
.icon(StarIcon)
.options(priorityOptions)
.build(),
dtf
.date()
.id('createdDate')
.accessor((row) => row.createdDate)
.displayName('Created Date')
.icon(CalendarIcon)
.build(),
dtf
.number()
.id('estimatedHours')
.accessor((row) => row.estimatedHours)
.displayName('Estimated Hours')
.icon(TextIcon)
.build(),
];
// --- Table Columns Definition ---
export const columns: ColumnDef<MockIssue>[] = [
{
accessorKey: 'id',
header: ({ column }) => <DataTableColumnHeader column={column} title="Task" />,
cell: ({ row }) => <div className="w-[80px]">{row.getValue('id')}</div>,
enableSorting: false,
enableHiding: false,
},
{
accessorKey: 'title',
header: ({ column }) => <DataTableColumnHeader column={column} title="Title" />,
cell: ({ row }) => {
return (
<div className="flex space-x-2">
<span className="max-w-[500px] truncate font-medium">{row.getValue('title')}</span>
</div>
);
},
},
{
accessorKey: 'status',
header: ({ column }) => <DataTableColumnHeader column={column} title="Status" />,
cell: ({ row }) => {
const status = row.getValue('status') as string;
return (
<div className="flex w-[100px] items-center">
<span className="capitalize">{status}</span>
</div>
);
},
filterFn: (row, id, value) => {
return value.includes(row.getValue(id));
},
},
{
accessorKey: 'assignee',
header: ({ column }) => <DataTableColumnHeader column={column} title="Assignee" />,
cell: ({ row }) => {
return (
<div className="flex items-center">
<span>{row.getValue('assignee')}</span>
</div>
);
},
filterFn: (row, id, value) => {
return value.includes(row.getValue(id));
},
},
{
accessorKey: 'priority',
header: ({ column }) => <DataTableColumnHeader column={column} title="Priority" />,
cell: ({ row }) => {
const priority = row.getValue('priority') as string;
return (
<div className="flex items-center">
<span className="capitalize">{priority}</span>
</div>
);
},
filterFn: (row, id, value) => {
return value.includes(row.getValue(id));
},
},
{
accessorKey: 'createdDate',
header: ({ column }) => <DataTableColumnHeader column={column} title="Created" />,
cell: ({ row }) => {
const date = row.getValue('createdDate') as Date;
return <div className="w-[100px]">{date.toLocaleDateString()}</div>;
},
},
{
accessorKey: 'estimatedHours',
header: ({ column }) => <DataTableColumnHeader column={column} title="Hours" />,
cell: ({ row }) => {
const hours = row.getValue('estimatedHours') as number;
return <div className="w-[80px]">{hours}h</div>;
},
},
];