Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1d8848

Browse files
committed
feat(site): add TimeCell component
Summary: This is direct follow-up to #484, #500, and #501. It is a part of many steps in porting/refactoring the AuditLog from v1. Details: - Port over TimeCell from v1, with refactorings - A jest test was not added because we use locale dates and times, which can be tricky to test. This can be addressed in the future. Impact: This change does not have any user-facing impact yet because AuditLog is not yet available in the product. This is part of an incremental approach; the FE is still waiting on the BE port. Relations: - This commit relates to #472, but does not finish it - This commit should not be merged until after #484, #500 and #501, because it builds off of them
1 parent 0fe6f52 commit d1d8848

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ComponentMeta, Story } from "@storybook/react"
2+
import React from "react"
3+
import { TimeCell, TimeCellProps } from "./TimeCell"
4+
5+
export default {
6+
title: "AuditLog/Cells/TimeCell",
7+
component: TimeCell,
8+
} as ComponentMeta<typeof TimeCell>
9+
10+
const Template: Story<TimeCellProps> = (args) => <TimeCell {...args} />
11+
12+
export const Example = Template.bind({})
13+
Example.args = {
14+
date: new Date(),
15+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Box from "@material-ui/core/Box"
2+
import Typography from "@material-ui/core/Typography"
3+
import React from "react"
4+
5+
export interface TimeCellProps {
6+
date: Date
7+
}
8+
export namespace TimeCellProps {
9+
export const displayTime = (props: TimeCellProps): string => {
10+
return props.date.toLocaleTimeString()
11+
}
12+
13+
export const displayDate = (props: TimeCellProps): string => {
14+
return props.date.toLocaleDateString().replace(/\//g, ".")
15+
}
16+
}
17+
18+
export const TimeCell: React.FC<TimeCellProps> = (props) => {
19+
return (
20+
<Box display="flex" flexDirection="column">
21+
<Typography>{TimeCellProps.displayTime(props)}</Typography>
22+
<Typography variant="caption">{TimeCellProps.displayDate(props)}</Typography>
23+
</Box>
24+
)
25+
}

0 commit comments

Comments
 (0)