Skip to content

Commit

Permalink
feat: added selected row and with checkbox table example
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro authored and Álvaro committed Jun 7, 2024
1 parent 7d06e74 commit 6d636ad
Showing 1 changed file with 109 additions and 3 deletions.
112 changes: 109 additions & 3 deletions packages/react-ui/storybook/stories/molecules/Table.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
IconButton,
MenuItem,
TableFooter,
TablePagination
TablePagination,
Checkbox
} from '@mui/material';
import SelectField from '../../../src/components/atoms/SelectField';
import { MoreVertOutlined } from '@mui/icons-material';
Expand Down Expand Up @@ -47,7 +48,8 @@ const rows = [
name: 'Test Data 5',
type: 'string',
mode: '',
description: 'Test Data 5'
description: 'Test Data 5 - Selected row',
selected: true
}
];

Expand Down Expand Up @@ -92,7 +94,7 @@ const PlaygroundTemplate = (args) => {
</TableHead>
<TableBody>
{rows.map((row, index) => (
<TableRow hover key={index}>
<TableRow hover key={index} selected={row.selected}>
<TableCell component='th' scope='row'>
{index + 1}
</TableCell>
Expand Down Expand Up @@ -327,6 +329,107 @@ const PaginationTemplate = (args) => {
);
};

const CheckboxTemplate = (args) => {
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);

const handleChangePage = (event, newPage) => {
setPage(newPage);
};

const handleChangeRowsPerPage = (event) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
};

return (
<TableContainer>
<Table {...args} aria-label='simple table'>
<TableHead>
<TableRow>
<TableCell>
<Checkbox indeterminate />
</TableCell>
<TableCell>Name</TableCell>
<TableCell>Type</TableCell>
<TableCell>Mode</TableCell>
<TableCell>Description</TableCell>
<TableCell>Actions</TableCell>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, index) => (
<TableRow hover key={index} selected={row.selected}>
<TableCell component='th' scope='row'>
<Checkbox checked={row.selected} />
</TableCell>
<TableCell sx={{ maxWidth: 160 }}>
{index === 1 ? (
<Tooltip title={row.name}>
<Typography variant='inherit' noWrap>
{row.name}
</Typography>
</Tooltip>
) : (
row.name
)}
</TableCell>
<TableCell>
<Chip size='small' color='default' label={row.type} />
</TableCell>
<TableCell>
<SelectField
size='small'
placeholder='Placeholder'
onChange={() => void 0}
value={[]}
>
{[...Array(3)].map((item, index) => {
const itemText = `${index + 1}`;

return (
<MenuItem key={index} value={itemText}>
{itemText}
</MenuItem>
);
})}
</SelectField>
</TableCell>
<TableCell sx={{ maxWidth: 160 }}>
{index === 3 ? (
<Tooltip title={row.description}>
<Typography variant='inherit' noWrap>
{row.description}
</Typography>
</Tooltip>
) : (
row.description
)}
</TableCell>
<TableCell padding='checkbox'>
<IconButton size='small'>
<MoreVertOutlined />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
count={100}
page={page}
onPageChange={handleChangePage}
rowsPerPage={rowsPerPage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
);
};

export const Playground = PlaygroundTemplate.bind({});
Playground.args = {};

Expand All @@ -335,3 +438,6 @@ ScrollTemplate.args = {};

export const WithPagination = PaginationTemplate.bind({});
PaginationTemplate.args = {};

export const WithCheckbox = CheckboxTemplate.bind({});
CheckboxTemplate.args = {};

0 comments on commit 6d636ad

Please sign in to comment.