Skip to content

Commit

Permalink
EventsDataGrid: color rows for even and odd turns differently
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad Jamrozik committed Jun 12, 2024
1 parent 6e83240 commit d014b4b
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions web/src/components/EventsDataGrid/EventsDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Box } from '@mui/material'
import { DataGrid, type GridColDef } from '@mui/x-data-grid'
import {
DataGrid,
type GridCellParams,
type GridValidRowModel,
type GridColDef,
gridClasses,
} from '@mui/x-data-grid'
import _ from 'lodash'
import type { GameEventWithTurn } from '../../lib/codesync/GameEvent'
import { useGameSessionContext } from '../../lib/gameSession/GameSession'
Expand Down Expand Up @@ -32,14 +38,13 @@ export function EventsDataGrid(): React.JSX.Element {

return (
<Box
sx={[
{
height: defaultComponentHeight,
minWidth: defaultComponentMinWidth,
maxWidth: 960,
width: '100%',
},
]}
sx={{
height: defaultComponentHeight,
minWidth: defaultComponentMinWidth,
maxWidth: 960,
width: '100%',
[`& .${gridClasses.row}.odd`]: { backgroundColor: '#202020' },
}}
>
<DataGrid
rows={rows}
Expand All @@ -55,6 +60,9 @@ export function EventsDataGrid(): React.JSX.Element {
}}
pageSizeOptions={[50]}
sx={(theme) => ({ bgcolor: theme.palette.background.default })}
getRowClassName={(params) =>
params.row.turn % 2 === 0 ? 'even' : 'odd'
}
/>
</Box>
)
Expand All @@ -79,6 +87,12 @@ const columns: GridColDef<GameEventRow>[] = [
headerName: 'Turn',
width: 80,
disableColumnMenu: true,
cellClassName: (
params: GridCellParams<GridValidRowModel, number>,
): string => {
const turnValue: number = params.value!
return turnValue % 2 === 0 ? 'UNUSED-even' : 'UNUSED-odd'
},
},
{
field: 'kind',
Expand Down

0 comments on commit d014b4b

Please sign in to comment.