ArticleCard Date component refactoring + moved to separate file

This commit is contained in:
tmshv committed 2019-10-17 12:33:09 +03:00
1 parent 9fb815081c
commit 0207f85f00
4 files changed
+37 -30

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
import * as React from 'react'
import { dateFormat } from '../../lib/date'
export const Date: React.FC<{ children: string }> = ({ children }) => (
<p>
<style jsx>{`
p {
color: #ccc;
font-size: small;
}
`}</style>
{dateFormat(children)}
</p>
)
+5 -12
View File
@@ -1,10 +1,6 @@
import React from 'react'
import * as React from 'react'
import cx from 'classnames'
import { dateFormat } from '../../lib/date'
const Date = ({ children }) => (
<p className="date">{dateFormat(children)}</p>
)
import { Date } from './Date'
interface IImage {
alt: string
@@ -75,11 +71,6 @@ export const ArticleCard: React.FC<IArticleCardProps> = ({ article, ...props })
padding: .75em 1em;
}
.ArticleCard .date {
color: #ccc;
font-size: small;
}
.ArticleCard:hover img {
width: 105%;
height: 105%;
@@ -128,7 +119,9 @@ export const ArticleCard: React.FC<IArticleCardProps> = ({ article, ...props })
{article.title}
{!article.date ? null : (
<Date>{article.date}</Date>
<Date>
{article.date}
</Date>
)}
</div>
</a>
-18
View File
@@ -1,18 +0,0 @@
const moment = require('moment')
moment.locale('ru')
/**
*
* Date -> DD.MM.YYYY
*
* @param date
*/
exports.dateFormat = date => moment(date).format('L')
/**
*
* Date -> Unix time
*
* @param date
*/
exports.timestamp = date => date.getTime()
+18
View File
@@ -0,0 +1,18 @@
import moment from 'moment'
moment.locale('ru')
/**
*
* Date -> DD.MM.YYYY
*
* @param date
*/
export const dateFormat = (date: string) => moment(date).format('L')
/**
*
* Date -> Unix time
*
* @param date
*/
export const timestamp = (date: Date) => date.getTime()