-
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.
Created ItemTableCell and LastUpdated cell components for refactoring…
… ItemTable
- Loading branch information
Showing
7 changed files
with
103 additions
and
40 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
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,22 @@ | ||
import { makeStyles, TableCell, useTheme } from '@material-ui/core' | ||
import React from 'react' | ||
|
||
export default function ItemTableCell({ reactTableCellProps, children, style }) { | ||
|
||
const theme = useTheme(); | ||
|
||
const useStyles = makeStyles({ | ||
columnBorders: { | ||
borderLeftWidth: "1px", | ||
borderLeftStyle: "solid", | ||
borderColor: theme.palette.type === "light" ? theme.palette.grey[300] : theme.palette.grey[500] | ||
}, | ||
}) | ||
|
||
const classes = useStyles(); | ||
return ( | ||
<TableCell {...reactTableCellProps} classes={{ root: classes.columnBorders }}> | ||
{children} | ||
</TableCell> | ||
); | ||
} |
Empty file.
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,3 @@ | ||
import ItemTableCell from "./ItemTableCell"; | ||
|
||
export default ItemTableCell; |
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,36 @@ | ||
import React from 'react' | ||
import { red } from '@material-ui/core/colors'; | ||
import RelativeTime from 'react-relative-time'; | ||
import ItemTableCell from '../ItemTableCell'; | ||
|
||
export default function LastUpdatedCell ({ time, reactTableCellProps, classes }){ | ||
const lastUpdated = new Date(time).getTime(); | ||
const now = new Date().getTime(); | ||
const timeDelta = now - lastUpdated; | ||
const day = 24 * 60 * 60 * 1000; | ||
const week = day * 7; | ||
const month = week * 4; | ||
|
||
let backgroundColor = "white"; | ||
if (timeDelta > day && timeDelta <= week) { | ||
backgroundColor = red[100] | ||
} | ||
else if (timeDelta > week && timeDelta <= month) { | ||
backgroundColor = red[300] | ||
} | ||
else if (timeDelta > month) { | ||
backgroundColor = red[500] | ||
} | ||
|
||
return ( | ||
<ItemTableCell | ||
classes={classes} | ||
// Expands table cell props to allow access to style props. | ||
{...reactTableCellProps} | ||
// Expands style prop of table cell to allow addtion of custom styling without losing default styling. | ||
style={{...reactTableCellProps.style, backgroundColor: backgroundColor }} | ||
> | ||
<RelativeTime value={time} /> | ||
</ItemTableCell> | ||
); | ||
} |
Empty file.
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,3 @@ | ||
import LastUpdatedCell from "./ItemTableCell"; | ||
|
||
export default LastUpdatedCell; |