PageMeta and TagList mobile layout fix

This commit is contained in:
tmshv committed 2020-03-03 21:56:56 +03:00
1 parent faf9ee0f7c
commit 1767b65856
4 files changed
+52 -15

No files matched your search

+22 -11
View File
@@ -1,8 +1,10 @@
import './styles.css' import './styles.css'
import cx from 'classnames'
import { dateFormat } from 'src/lib/date' import { dateFormat } from 'src/lib/date'
import { ITag } from 'src/types' import { ITag } from 'src/types'
import { TagList } from '../TagList' import { TagList, Direction } from '../TagList'
import { useMobile } from 'src/hooks/useMobile'
export type PageMetaProps = { export type PageMetaProps = {
style?: React.CSSProperties style?: React.CSSProperties
@@ -10,14 +12,23 @@ export type PageMetaProps = {
tags?: ITag[] tags?: ITag[]
} }
export const PageMeta: React.FC<PageMetaProps> = props => ( export const PageMeta: React.FC<PageMetaProps> = props => {
<header className={'pageMeta'} style={props.style}> const mobile = useMobile()
{!props.date ? null : ( const center = mobile ? null : 'center'
<p className={'date'}>Опубликовано {dateFormat(props.date)}</p> const direction: Direction = mobile ? 'vertical' : 'horizontal'
)}
{!(props.tags?.length) ? null : ( return (
<TagList items={props.tags} /> <div className={cx('pageMeta', center)} style={props.style}>
)} {!props.date ? null : (
</header> <p className={'date'}>Опубликовано {dateFormat(props.date)}</p>
) )}
{!(props.tags?.length) ? null : (
<TagList
direction={direction}
items={props.tags}
/>
)}
</div>
)
}
+4 -1
View File
@@ -1,5 +1,8 @@
.pageMeta { .pageMeta {
display: flex; display: flex;
align-items: center;
justify-content: space-between; justify-content: space-between;
} }
.pageMeta.center {
align-items: center;
}
+13 -3
View File
@@ -1,10 +1,18 @@
import './styles.css' import './styles.css'
import cx from 'classnames'
import { ITag } from 'src/types' import { ITag } from 'src/types'
import { Button } from '../Button' import { Button } from '../Button'
export const Tag: React.FC<{ href: string }> = props => ( export type Direction = 'horizontal' | 'vertical'
<li className={'tagsItem'}>
export type TagProps = {
href: string
direction: Direction
}
export const Tag: React.FC<TagProps> = props => (
<li className={cx('tagsItem', props.direction)}>
<Button <Button
href={props.href} href={props.href}
size={'small'} size={'small'}
@@ -17,14 +25,16 @@ export const Tag: React.FC<{ href: string }> = props => (
export type TagListProps = { export type TagListProps = {
items: ITag[] items: ITag[]
direction: Direction
} }
export const TagList: React.FC<TagListProps> = props => ( export const TagList: React.FC<TagListProps> = props => (
<ul className={'tags'}> <ul className={cx('tags', props.direction)}>
{props.items.map(x => ( {props.items.map(x => (
<Tag <Tag
key={x.slug} key={x.slug}
href={x.href} href={x.href}
direction={props.direction}
> >
{x.name} {x.name}
</Tag> </Tag>
+13
View File
@@ -8,10 +8,23 @@
list-style: none; list-style: none;
} }
.tags.vertical {
flex-direction: column;
}
.tagsItem { .tagsItem {
margin-right: var(--size-s); margin-right: var(--size-s);
margin-bottom: var(--size-s);
} }
.tagsItem:last-child { .tagsItem:last-child {
margin-right: 0; margin-right: 0;
} }
.tagsItem.vertical {
margin-bottom: var(--size-s);
}
.tagsItem.tags.vertical:last-child {
margin-bottom: 0;
}