From f0330825190506f101cf85633e754f59e5f1a7a9 Mon Sep 17 00:00:00 2001 From: SatooRu65536 Date: Sun, 2 Feb 2025 15:38:34 +0900 Subject: [PATCH] =?UTF-8?q?add:=20Pagenation=20=E3=82=B3=E3=83=B3=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=8D=E3=83=B3=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Pagenation/index.astro | 96 +++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/components/Pagenation/index.astro diff --git a/src/components/Pagenation/index.astro b/src/components/Pagenation/index.astro new file mode 100644 index 0000000..00cdcd8 --- /dev/null +++ b/src/components/Pagenation/index.astro @@ -0,0 +1,96 @@ +--- +import { pipe } from 'remeda'; + +interface Props { + page: number; + pageNum: number; + getPagePath: (n: number) => string; +} +const { page, pageNum, getPagePath } = Astro.props; + +const N = 2; + +const visiblePageNums = pipe(null, () => { + const min = page - N < 1 ? 1 : page - N; + const max = page + N > pageNum ? pageNum : page + N; + return Array.from({ length: max - min + 1 }, (_, i) => min + i); +}); +--- + +
+ {visiblePageNums.at(0)! > 1 && 1} + {visiblePageNums.at(0)! > 2 && } + + { + visiblePageNums.map((n) => ( + + {n} + + )) + } + + {visiblePageNums.at(-1)! < pageNum - 1 && } + {visiblePageNums.at(-1)! < pageNum && {pageNum}} +
+ +