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

Skip to content

feat(site): add TimeCell component #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions site/src/components/AuditLog/TimeCell.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ComponentMeta, Story } from "@storybook/react"
import React from "react"
import { TimeCell, TimeCellProps } from "./TimeCell"

export default {
title: "AuditLog/Cells/TimeCell",
component: TimeCell,
} as ComponentMeta<typeof TimeCell>

const Template: Story<TimeCellProps> = (args) => <TimeCell {...args} />

export const Example = Template.bind({})
Example.args = {
date: new Date(),
}
25 changes: 25 additions & 0 deletions site/src/components/AuditLog/TimeCell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Box from "@material-ui/core/Box"
import Typography from "@material-ui/core/Typography"
import React from "react"

export interface TimeCellProps {
date: Date
}
export namespace TimeCellProps {
export const displayTime = (props: TimeCellProps): string => {
return props.date.toLocaleTimeString()
}

export const displayDate = (props: TimeCellProps): string => {
return props.date.toLocaleDateString().replace(/\//g, ".")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never thought about this before, but why do we use periods in dates?

}
}

export const TimeCell: React.FC<TimeCellProps> = (props) => {
return (
<Box display="flex" flexDirection="column">
<Typography>{TimeCellProps.displayTime(props)}</Typography>
<Typography variant="caption">{TimeCellProps.displayDate(props)}</Typography>
</Box>
)
}