Skip to content

feat(table): add Table component variants following Button pattern #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
47 changes: 46 additions & 1 deletion src/base/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
import { Table as MuiTable, type TableProps as MuiTableProps } from '@mui/material';
import { styled } from '@mui/material/styles';

export function Table(props: MuiTableProps): JSX.Element {
export interface TableProps extends MuiTableProps {
children?: React.ReactNode;
}

export function Table(props: TableProps): JSX.Element {
return <MuiTable {...props} />;
}

const BorderedTableStyled = styled(MuiTable)(({ theme }) => ({
borderCollapse: 'separate',
borderSpacing: '0',
border: `1px solid ${theme.palette.divider}`,
'& .MuiTableCell-root': {
borderRight: `1px solid ${theme.palette.divider}`,
'&:last-child': {
borderRight: 'none'
}
}
}));

const StripedTableStyled = styled(MuiTable)(({ theme }) => ({
borderCollapse: 'separate',
borderSpacing: '0',
'& .MuiTableBody-root .MuiTableRow-root:nth-of-type(even)': {
backgroundColor: theme.palette.action.hover
}
}));

const CompactTableStyled = styled(MuiTable)(({ theme }) => ({
borderCollapse: 'separate',
borderSpacing: '0',
'& .MuiTableCell-root': {
padding: theme.spacing(0.5, 1)
}
}));

export const BorderedTable = (props: TableProps): JSX.Element => (
<BorderedTableStyled {...props}>{props.children}</BorderedTableStyled>
);

export const StripedTable = (props: TableProps): JSX.Element => (
<StripedTableStyled {...props}>{props.children}</StripedTableStyled>
);

export const CompactTable = (props: TableProps): JSX.Element => (
<CompactTableStyled {...props}>{props.children}</CompactTableStyled>
);

export default Table;
2 changes: 0 additions & 2 deletions src/base/Table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { TableProps } from '@mui/material';
import Table from './Table';

export { Table };
export type { TableProps };