add Button component; pager updated
This commit is contained in:
1 parent
843ade58ad
commit
41467aa447
6 files changed
+73
-39
No files matched your search
@@ -18,10 +18,6 @@ export const ArticleCardList:React.FC<IArticleCardListProps> = ({ articles, next
|
|||||||
}
|
}
|
||||||
`}</style>
|
`}</style>
|
||||||
|
|
||||||
{!prevPage ? null : (
|
|
||||||
<Pager url={`/articles/${prevPage}`} position={'top'} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className={'body'}>
|
<div className={'body'}>
|
||||||
{articles.map((article, i) => {
|
{articles.map((article, i) => {
|
||||||
const preview = {
|
const preview = {
|
||||||
@@ -40,8 +36,9 @@ export const ArticleCardList:React.FC<IArticleCardListProps> = ({ articles, next
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!nextPage ? null : (
|
<Pager
|
||||||
<Pager url={`/articles/${nextPage}`} position={'bottom'} />
|
nextHref={nextPage ? `/articles/${nextPage}` : null}
|
||||||
)}
|
prevHref={prevPage ? `/articles/${prevPage}` : null}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import './styles.css'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
|
export type ButtonProps = {
|
||||||
|
style?: React.CSSProperties
|
||||||
|
href?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Button: React.FC<ButtonProps> = props => {
|
||||||
|
if (props.href) {
|
||||||
|
return (
|
||||||
|
<Link href={props.href}>
|
||||||
|
<a className={'button invisible'} style={props.style}>
|
||||||
|
{props.children}
|
||||||
|
</a>
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button className={'button'} style={props.style}>
|
||||||
|
{props.children}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
.button {
|
||||||
|
border: none;
|
||||||
|
font-size: var(--font-size-default);
|
||||||
|
|
||||||
|
text-align: center;
|
||||||
|
margin-top: var(--size-m);
|
||||||
|
margin-bottom: var(--size-m);
|
||||||
|
margin-left: 1px;
|
||||||
|
margin-right: 1px;
|
||||||
|
|
||||||
|
padding: var(--size-s) var(--size-m);
|
||||||
|
border-radius: 100px;
|
||||||
|
|
||||||
|
background-color: var(--color-back);
|
||||||
|
box-shadow: 0 0 0 1px rgba(27, 51, 88, 0.15);
|
||||||
|
|
||||||
|
transition: box-shadow 150ms;
|
||||||
|
|
||||||
|
outline: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
box-shadow: 0 4px 20px rgba(27, 51, 88, 0.15)
|
||||||
|
}
|
||||||
@@ -1,28 +1,20 @@
|
|||||||
import './styles.css'
|
import { Block } from '../Block'
|
||||||
|
import { Button } from '../Button'
|
||||||
import Link from 'next/link'
|
import { Spacer } from '../Spacer'
|
||||||
|
|
||||||
const text = ['↑', '↓']
|
|
||||||
const linkText = ['Предыдущая страница', 'Следующая страница']
|
|
||||||
|
|
||||||
type Position = 'top' | 'bottom'
|
|
||||||
const i = (type: Position) => type === 'top'
|
|
||||||
? 0
|
|
||||||
: 1
|
|
||||||
|
|
||||||
export type PagerProps = {
|
export type PagerProps = {
|
||||||
url: string
|
nextHref: string | null
|
||||||
position: Position
|
prevHref: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Pager: React.FC<PagerProps> = ({ url, position }) => (
|
export const Pager: React.FC<PagerProps> = props => (
|
||||||
<div className={'pager'}>
|
<Block direction={'horizontal'}>
|
||||||
<span className={'pager icon'}>
|
{!props.prevHref ? null : (
|
||||||
{text[i(position)]}
|
<Button href={props.prevHref}>Предыдущая страница</Button>
|
||||||
</span>
|
)}
|
||||||
|
<Spacer />
|
||||||
<Link href={url}>
|
{!props.nextHref ? null : (
|
||||||
<a>{linkText[i(position)]}</a>
|
<Button href={props.nextHref}>Следущая страница</Button>
|
||||||
</Link>
|
)}
|
||||||
</div>
|
</Block>
|
||||||
)
|
)
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
.pager {
|
|
||||||
text-align: center;
|
|
||||||
margin-top: var(--size-m);
|
|
||||||
margin-bottom: var(--size-m);
|
|
||||||
}
|
|
||||||
|
|
||||||
.pager .icon {
|
|
||||||
margin: 0 var(--size-s);
|
|
||||||
}
|
|
||||||
@@ -73,6 +73,10 @@
|
|||||||
--size-l: 2em;
|
--size-l: 2em;
|
||||||
--size-xl: 5em;
|
--size-xl: 5em;
|
||||||
|
|
||||||
|
/* EFFECTS */
|
||||||
|
--radius: 10px;
|
||||||
|
--shadow: 0 0 0 1px rgba(27, 51, 88, 0.15);
|
||||||
|
|
||||||
/* MARGINS */
|
/* MARGINS */
|
||||||
--small-margin: 0.2em;
|
--small-margin: 0.2em;
|
||||||
--half-margin: 0.5em;
|
--half-margin: 0.5em;
|
||||||
|
|||||||
Reference in new issue
Block a user