feat: fix datatable storybook

This commit is contained in:
Hafid Nur
2025-03-27 22:52:35 +07:00
parent 2d9473ea7c
commit a4ca53004f
2 changed files with 87 additions and 27 deletions
@@ -30,34 +30,94 @@ export const Default: Story = {
phone: '987-654-3210', phone: '987-654-3210',
address: '456 Elm St', address: '456 Elm St',
}, },
{
id: 3,
name: 'John Smith',
email: 'johns@example.com',
phone: '456-789-1230',
address: '789 Cedar St',
},
], ],
onEdit: (id: number) => console.log('Edit item with id:', id), headers: [
{ label: 'ID', key: 'id' },
{ label: 'Name', key: 'name' },
{ label: 'Email', key: 'email' },
{ label: 'Phone', key: 'phone' },
{ label: 'Address', key: 'address' },
],
onRowClick: (item) => console.log('Row clicked:', item),
}, },
}; };
Default.args = { export const WithCustomRender: Story = {
data: [ args: {
{ data: [
id: 1, {
name: 'John Doe', id: 1,
email: 'john@example.com', name: 'John Doe',
phone: '123-456-7890', email: 'john@example.com',
address: '123 Main St', phone: '123-456-7890',
}, address: '123 Main St',
{ status: 'active',
id: 2, },
name: 'Jane Smith', {
email: 'jane@example.com', id: 2,
phone: '987-654-3210', name: 'Jane Smith',
address: '456 Elm St', email: 'jane@example.com',
}, phone: '987-654-3210',
{ address: '456 Elm St',
id: 3, status: 'inactive',
name: 'John Smith', },
email: 'johns@example.com', {
phone: '456-789-1230', id: 3,
address: '789 Cedar St', name: 'John Smith',
}, email: 'johns@example.com',
], phone: '456-789-1230',
onEdit: (id: number) => console.log('Edit item with id:', id), address: '789 Cedar St',
status: 'active',
},
],
headers: [
{ label: 'ID', key: 'id' },
{ label: 'Name', key: 'name' },
{ label: 'Email', key: 'email' },
{ label: 'Phone', key: 'phone' },
{
label: 'Status',
render: (item) => (
<span
className={`px-2 py-1 rounded-md text-xs ${
item.status === 'active'
? 'bg-green-100 text-green-800'
: 'bg-red-100 text-red-800'
}`}
>
{item.status}
</span>
),
},
{
label: 'Actions',
render: (item) => (
<button
className="px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600"
onClick={(e) => {
e.stopPropagation();
console.log('Edit item with id:', item.id);
}}
>
Edit
</button>
),
},
],
onRowClick: (item) => console.log('Row clicked:', item),
},
};
export const WithoutCheckbox: Story = {
args: {
...Default.args,
showCheckbox: false,
},
}; };
@@ -1,4 +1,4 @@
import { FC, ReactElement, ReactNode } from 'react'; import { ReactElement, ReactNode } from 'react';
interface DataTableProps<T> { interface DataTableProps<T> {
data: T[]; data: T[];