Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/Table/Table.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ const meta = {
export default meta;
type Story = StoryObj<typeof meta>;

const defaultProps = {
const columns = [
{ key: 'name', label: 'name' },
{ key: 'age', label: 'age' },
{ key: 'address', label: 'address' },
];

const data = [
{ name: 'Anand Medarametla', age: 24, address: '123 Main St' },
{ name: 'John', age: 25, address: '456 Elm St' },
];


const defaultProps = {
columns,
data
};

const disableControls = {
Expand Down
33 changes: 31 additions & 2 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
import { FC, PropsWithChildren } from 'react';
import { StyledTable } from './Table.style';
interface TableColumn {
key: string;
label: string;
render?: (data: any) => React.ReactNode;
}

interface TableProps extends PropsWithChildren {
columns: TableColumn[];
data: any[];
}

export const Table: FC<PropsWithChildren> = ({ children }) => {
export const Table: FC<TableProps> = ({ columns,data,children}) => {
return (
<StyledTable data-testid="Table">
{children}
<thead>
<tr>
{columns.map((col) => (
<th key={col.key}>{col.label}</th>
))}
</tr>
</thead>
<tbody>
{data.map((row, rowIndex) => (
<tr key={rowIndex}>
{columns.map((col) => (
<td key={col.key}>
{col.render ? col.render(row[col.key]) : row[col.key]}
</td>
))}
</tr>
))}
{children}
</tbody>
</StyledTable>
);
};