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 @@
export default meta;
type Story = StoryObj<typeof meta>;

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

Check failure on line 16 in src/components/Table/Table.stories.ts

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 0 tabs but found 2 spaces

const data = [

Check failure on line 18 in src/components/Table/Table.stories.ts

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 0 tabs but found 2 spaces
{ name: 'Anand Medarametla', age: 24, address: '123 Main St' },
{ name: 'John', age: 25, address: '456 Elm St' },
];

Check failure on line 21 in src/components/Table/Table.stories.ts

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 0 tabs but found 2 spaces


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;

Check failure on line 6 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Unexpected any. Specify a different type
}

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

Check failure on line 11 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Unexpected any. Specify a different type
}

export const Table: FC<PropsWithChildren> = ({ children }) => {
export const Table: FC<TableProps> = ({ columns,data,children}) => {

Check failure on line 14 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

A space is required before '}'
return (
<StyledTable data-testid="Table">
{children}
<thead>
<tr>

Check failure on line 18 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 4 tabs but found 8 spaces
{columns.map((col) => (

Check failure on line 19 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 5 tabs but found 10 spaces
<th key={col.key}>{col.label}</th>

Check failure on line 20 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 6 tabs but found 12 spaces
))}

Check failure on line 21 in src/components/Table/Table.tsx

View workflow job for this annotation

GitHub Actions / tests-and-file-checks

Expected indentation of 5 tabs but found 10 spaces
</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>
);
};

Loading