-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
578392d
commit db1e580
Showing
4 changed files
with
153 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react' | ||
|
||
import { Header } from '@tanstack/react-table' | ||
|
||
import { AutoAwesomeMosaic } from '@mui/icons-material' | ||
import { Badge, IconButton } from '@mui/material' | ||
|
||
export type Props<T extends Record<string, any>> = { | ||
header: Header<T, unknown> | ||
showGroupingIndex?: boolean | ||
} | ||
|
||
const TableGroupToggle = <T extends Record<string, any>>({ | ||
header, | ||
showGroupingIndex = false | ||
}: Props<T>): React.ReactElement => { | ||
return ( | ||
<React.Fragment> | ||
{/* If the header can be grouped, let's add a toggle */} | ||
<IconButton | ||
onClick={header.column.getToggleGroupingHandler()} | ||
sx={{ mr: 1 }} | ||
> | ||
<Badge | ||
color='success' | ||
badgeContent={ | ||
showGroupingIndex ? header.column.getGroupedIndex() + 1 : 0 | ||
} | ||
> | ||
<AutoAwesomeMosaic | ||
sx={{ | ||
color: header.column.getIsGrouped() ? 'primary.main' : 'inherit' | ||
}} | ||
/> | ||
</Badge> | ||
</IconButton>{' '} | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
export default TableGroupToggle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react' | ||
|
||
import { Cell, ExpandedState, Row, flexRender } from '@tanstack/react-table' | ||
|
||
import { ExpandLess, ExpandMore } from '@mui/icons-material' | ||
import { IconButton, TableCell } from '@mui/material' | ||
|
||
export type Props<T extends Record<string, any>> = { | ||
cell: Cell<T, unknown> | ||
row: Row<T> | ||
groupingExpand: ExpandedState | undefined | ||
} | ||
|
||
const YuTableCell = <T extends Record<string, any>>({ | ||
cell, | ||
row, | ||
groupingExpand | ||
}: Props<T>): React.ReactElement => { | ||
return ( | ||
<TableCell> | ||
{cell.getIsGrouped() ? ( | ||
// If it's a grouped cell, add an expander and row count | ||
<React.Fragment> | ||
{/* If a manual grouping expand state was passed, don't allow manually changing it */} | ||
{groupingExpand === undefined ? ( | ||
<React.Fragment> | ||
<IconButton | ||
size='small' | ||
sx={{ | ||
mr: 1 | ||
}} | ||
onClick={row.getToggleExpandedHandler()} | ||
disabled={!row.getCanExpand()} | ||
> | ||
{row.getIsExpanded() ? <ExpandLess /> : <ExpandMore />}{' '} | ||
</IconButton> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} ( | ||
{row.subRows.length}) | ||
</React.Fragment> | ||
) : ( | ||
<React.Fragment> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</React.Fragment> | ||
)} | ||
</React.Fragment> | ||
) : cell.getIsAggregated() ? ( | ||
// If the cell is aggregated, use the Aggregated | ||
// renderer for cell | ||
flexRender( | ||
cell.column.columnDef.aggregatedCell ?? cell.column.columnDef.cell, | ||
cell.getContext() | ||
) | ||
) : cell.getIsPlaceholder() ? null : ( // For cells with repeated values, render null | ||
// Otherwise, just render the regular cell | ||
flexRender(cell.column.columnDef.cell, cell.getContext()) | ||
)} | ||
</TableCell> | ||
) | ||
} | ||
|
||
export default YuTableCell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters