article tags refactoring
This commit is contained in:
1 parent
e7f3b0d7ce
commit
65507c5d80
7 files changed
+70
-48
No files matched your search
@@ -1,21 +1,21 @@
|
||||
import { dateFormat } from 'src/lib/date'
|
||||
import { Share } from '../Share'
|
||||
import { TagList } from '../TagList'
|
||||
import { ITag } from 'src/types'
|
||||
|
||||
const Tag = ({ children }) => (
|
||||
<li className="ArticleTags-Item">
|
||||
{children}
|
||||
</li>
|
||||
)
|
||||
export type ArticleProps = {
|
||||
date: string
|
||||
title: string
|
||||
tags: ITag[]
|
||||
shareable: boolean
|
||||
}
|
||||
|
||||
const TagList = ({ tags }) => (
|
||||
<ul className="ArticleTags">
|
||||
{tags.map((x, i) => (
|
||||
<Tag key={i}># {x.name}</Tag>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
type HeadProps = {
|
||||
date: string
|
||||
tags: ITag[]
|
||||
}
|
||||
|
||||
const Head = ({ date, tags = [], children }) => (
|
||||
const Head: React.FC<HeadProps> = ({ date, tags = [], children }) => (
|
||||
<header className="Article-Head">
|
||||
<style jsx>{`
|
||||
.date {
|
||||
@@ -29,13 +29,13 @@ const Head = ({ date, tags = [], children }) => (
|
||||
<p className={'date'}>{dateFormat(date)}</p>
|
||||
)}
|
||||
|
||||
{!(tags.length) ? null : (
|
||||
<TagList tags={tags} />
|
||||
{!tags.length ? null : (
|
||||
<TagList items={tags} />
|
||||
)}
|
||||
</header>
|
||||
)
|
||||
|
||||
export const Article = ({ children, date, tags, title, shareable }) => (
|
||||
export const Article: React.FC<ArticleProps> = ({ children, date, tags, title, shareable }) => (
|
||||
<article className="Article">
|
||||
<Head
|
||||
date={date}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import './styles.css'
|
||||
|
||||
import { ITag } from 'src/types'
|
||||
import { Button } from '../Button'
|
||||
|
||||
export const Tag: React.FC<{ href: string }> = props => (
|
||||
<li className={'tagsItem'}>
|
||||
<Button href={props.href}>{props.children}</Button>
|
||||
</li>
|
||||
)
|
||||
|
||||
export type TagListProps = {
|
||||
items: ITag[]
|
||||
}
|
||||
|
||||
export const TagList: React.FC<TagListProps> = props => (
|
||||
<ul className={'tags'}>
|
||||
{props.items.map(x => (
|
||||
<Tag
|
||||
key={x.slug}
|
||||
href={x.href}
|
||||
>
|
||||
# {x.name}
|
||||
</Tag>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
/* ELEMENTS */
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
/* justify-content: center; */
|
||||
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.tagsItem {
|
||||
margin-right: var(--size-s);
|
||||
}
|
||||
|
||||
.tagsItem:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
Reference in new issue
Block a user