Skip to content

Commit 4b61a72

Browse files
committed
add: Pagenation コンポーネントを追加
1 parent 841786c commit 4b61a72

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

Diff for: src/components/Pagenation/index.astro

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
import { pipe } from 'remeda';
3+
4+
interface Props {
5+
page: number;
6+
pageNum: number;
7+
getPagePath: (n: number) => string;
8+
}
9+
const { page, pageNum, getPagePath } = Astro.props;
10+
11+
const N = 2;
12+
13+
const visiblePageNums = pipe(null, () => {
14+
const min = page - N < 1 ? 1 : page - N;
15+
const max = page + N > pageNum ? pageNum : page + N;
16+
return Array.from({ length: max - min + 1 }, (_, i) => min + i);
17+
});
18+
---
19+
20+
<div class="pagenation">
21+
{visiblePageNums.at(0)! > 1 && <a href={getPagePath(1)}>1</a>}
22+
{visiblePageNums.at(0)! > 2 && <span class="leader" />}
23+
24+
{
25+
visiblePageNums.map((n) => (
26+
<a href={getPagePath(n)} data-current={n === page}>
27+
{n}
28+
</a>
29+
))
30+
}
31+
32+
{visiblePageNums.at(-1)! < pageNum - 1 && <span class="leader" />}
33+
{visiblePageNums.at(-1)! < pageNum && <a href={getPagePath(pageNum)}>{pageNum}</a>}
34+
</div>
35+
36+
<style lang="scss">
37+
.pagenation {
38+
margin: 40px auto 0 auto;
39+
width: fit-content;
40+
user-select: none;
41+
display: flex;
42+
align-items: center;
43+
gap: 10px;
44+
45+
a {
46+
width: 30px;
47+
height: 30px;
48+
display: inline-block;
49+
border: solid 1px;
50+
color: $primary-100;
51+
border-color: $primary-100;
52+
border-radius: 999px;
53+
text-align: center;
54+
line-height: 28px;
55+
text-decoration: none;
56+
cursor: pointer;
57+
background-color: transparent;
58+
59+
&[data-current='true'] {
60+
background-color: $primary-400;
61+
}
62+
63+
&[data-hide='true'] {
64+
visibility: hidden;
65+
display: contents;
66+
}
67+
}
68+
69+
.leader {
70+
margin-inline: 15px;
71+
width: 4px;
72+
height: 4px;
73+
display: inline-block;
74+
background-color: $primary-100;
75+
position: relative;
76+
77+
&::before,
78+
&::after {
79+
content: '';
80+
display: block;
81+
width: 4px;
82+
height: 4px;
83+
background-color: $primary-100;
84+
position: absolute;
85+
}
86+
87+
&::before {
88+
left: -10px;
89+
}
90+
91+
&::after {
92+
right: -10px;
93+
}
94+
}
95+
}
96+
</style>

0 commit comments

Comments
 (0)