Skip to content

Commit 56e2b3a

Browse files
authored
Merge pull request #31 from UIverse-Team/feature/pagination
feature: feature/pagination
2 parents 8c6128c + 6ad834e commit 56e2b3a

13 files changed

Lines changed: 501 additions & 25 deletions

File tree

next.config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import type { NextConfig } from "next";
1+
import type { NextConfig } from 'next'
22

33
const nextConfig: NextConfig = {
44
/* config options here */
5-
};
5+
webpack: (config) => {
6+
config.module.rules.push({
7+
test: /\.svg$/,
8+
use: ['@svgr/webpack'],
9+
})
610

7-
export default nextConfig;
11+
return config
12+
},
13+
}
14+
15+
export default nextConfig

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"dotenv": "^16.4.5",
3333
"msw": "^2.7.1",
3434
"next": "15.1.7",
35+
"next-plugin-svgr": "^1.1.12",
3536
"next-themes": "^0.4.4",
3637
"pretendard": "^1.3.9",
3738
"react": "^18.3.1",
@@ -58,6 +59,7 @@
5859
"@storybook/nextjs": "8.5.8",
5960
"@storybook/react": "^8.5.8",
6061
"@storybook/test": "8.5.8",
62+
"@svgr/webpack": "^8.1.0",
6163
"@types/node": "^20",
6264
"@types/react": "^18.3.3",
6365
"@types/react-dom": "^18.3.0",

public/leftarrow.svg

Lines changed: 3 additions & 0 deletions
Loading

public/rightarrow.svg

Lines changed: 3 additions & 0 deletions
Loading

src/app/page.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
'use client'
2+
import Pagination from '@/components/common/pagination/Pagination'
13
import BreakpointTest from '@/components/design-system/BreakpointTest'
24
import ColorPalette from '@/components/design-system/ColorPalette'
35
import TypoSystem from '@/components/design-system/TypoSystem'
6+
import { useState } from 'react'
47

58
export default function Home() {
9+
//현재 페이지
10+
const [currentPage, setCurrentPage] = useState(1)
11+
//보여줄 데이터의 갯수
12+
const limit = 5
13+
const totlepages = 30
14+
const offset = (currentPage - 1) * limit
15+
console.log(offset)
616
return (
717
// 임시 메인 페이지
818
// 추후 메인페이지 작업 시 수정해도 됨
@@ -14,6 +24,12 @@ export default function Home() {
1424
<ColorPalette />
1525

1626
<TypoSystem />
27+
<Pagination
28+
currentPage={currentPage}
29+
totalPages={totlepages}
30+
onPageChange={setCurrentPage}
31+
limit={limit}
32+
/>
1733
</div>
1834
)
1935
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {
2+
PaginationContainer,
3+
PaginationContent,
4+
// PaginationEllipsis,
5+
PaginationItem,
6+
PaginationLink,
7+
PaginationNext,
8+
PaginationPrevious,
9+
} from '@/components/ui/pagination-container'
10+
11+
//totalpage 전체rottn
12+
//currentPage 현재 페이지
13+
//Page 다음 혹은 이전으로 옮길 때 사용하는 이벤트 함수.
14+
//onPageChange: 변경 될 Page를 만드는 useState함수
15+
//limit 보여줄 데이터 갯수
16+
interface PaginationProps {
17+
totalPages: number
18+
currentPage: number
19+
onPageChange: (page: number) => void
20+
limit: number
21+
}
22+
23+
const Pagination = ({ totalPages, currentPage, onPageChange, limit }: PaginationProps) => {
24+
const numPages = Math.ceil(totalPages / limit)
25+
const handlePrev = () => {
26+
if (currentPage > 1) onPageChange(currentPage - 1)
27+
}
28+
29+
const handleNext = () => {
30+
if (currentPage < totalPages) onPageChange(currentPage + 1)
31+
}
32+
// item 하나당 하나의 숫자가 들어 가야한다.
33+
// Link는 페이지션을 직접적으로 클릭했을 때 이동하는 숫자
34+
// Previous는 이전 값
35+
// nextvious는 다음 값
36+
37+
// 페이지네이션이 1개만 존재한다면 페이지네이션을 보여주지 않음.
38+
if (totalPages <= 1) {
39+
return
40+
}
41+
return (
42+
<PaginationContainer>
43+
<PaginationContent>
44+
<PaginationItem>
45+
<PaginationPrevious href="#" onClick={() => handlePrev()} />
46+
</PaginationItem>
47+
{Array(numPages)
48+
.fill(0)
49+
.map((_, i) => (
50+
<PaginationLink
51+
key={i + 1}
52+
onClick={() => onPageChange(i + 1)}
53+
aria-current={currentPage === i + 1 ? 'page' : undefined}
54+
href="#"
55+
className={`border-none rounded-lg p-2 m-0 bg-black text-secondary text-base hover:bg-red-500 hover:cursor-pointer hover:-translate-y-0.5 ${
56+
currentPage === i + 1
57+
? 'bg-primary font-bold cursor-not-allowed transform-none w-[38px] h-[38px] rounded-4xl text-white'
58+
: ''
59+
}`}
60+
>
61+
{i + 1}
62+
</PaginationLink>
63+
))}
64+
<PaginationItem>
65+
<PaginationNext href="#" onClick={() => handleNext()} />
66+
</PaginationItem>
67+
</PaginationContent>
68+
</PaginationContainer>
69+
)
70+
}
71+
72+
export default Pagination
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Meta, StoryObj } from '@storybook/react'
2+
3+
import { Breadcrumb } from './breadcrumb'
4+
5+
const meta = {
6+
component: Breadcrumb,
7+
} satisfies Meta<typeof Breadcrumb>
8+
9+
export default meta
10+
11+
type Story = StoryObj<typeof meta>
12+
13+
export const Default: Story = {}

src/components/ui/breadcrumb.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react'
22
import { Slot } from '@radix-ui/react-slot'
3-
import { ChevronRight, MoreHorizontal } from 'lucide-react'
43

54
import { cn } from '@/lib/utils'
65

@@ -62,17 +61,15 @@ function BreadcrumbPage({ className, ...props }: React.ComponentProps<'span'>) {
6261
)
6362
}
6463

65-
function BreadcrumbSeparator({ children, className, ...props }: React.ComponentProps<'li'>) {
64+
function BreadcrumbSeparator({ className, ...props }: React.ComponentProps<'li'>) {
6665
return (
6766
<li
6867
data-slot="breadcrumb-separator"
6968
role="presentation"
7069
aria-hidden="true"
7170
className={cn('[&>svg]:size-3.5', className)}
7271
{...props}
73-
>
74-
{children ?? <ChevronRight />}
75-
</li>
72+
></li>
7673
)
7774
}
7875

@@ -85,7 +82,6 @@ function BreadcrumbEllipsis({ className, ...props }: React.ComponentProps<'span'
8582
className={cn('flex size-9 items-center justify-center', className)}
8683
{...props}
8784
>
88-
<MoreHorizontal className="size-4" />
8985
<span className="sr-only">More</span>
9086
</span>
9187
)

src/components/ui/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { cva, type VariantProps } from 'class-variance-authority'
55
import { cn } from '@/lib/utils'
66

77
const buttonVariants = cva(
8-
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[color,box-shadow] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
8+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[color,box-shadow] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
99
{
1010
variants: {
1111
variant: {

src/components/ui/pagination.tsx renamed to src/components/ui/pagination-container.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as React from 'react'
2-
import { ChevronLeftIcon, ChevronRightIcon, MoreHorizontalIcon } from 'lucide-react'
2+
import RightArrowIcon from '../../../public/rightarrow.svg'
3+
import LeftArrowIcon from '../../../public/leftarrow.svg'
34

45
import { cn } from '@/lib/utils'
56
import { Button, buttonVariants } from '@/components/ui/button'
67

7-
function Pagination({ className, ...props }: React.ComponentProps<'nav'>) {
8+
function PaginationContainer({ className, ...props }: React.ComponentProps<'nav'>) {
89
return (
910
<nav
1011
role="navigation"
@@ -61,7 +62,7 @@ function PaginationPrevious({ className, ...props }: React.ComponentProps<typeof
6162
className={cn('gap-1 px-2.5 sm:pl-2.5', className)}
6263
{...props}
6364
>
64-
<ChevronLeftIcon />
65+
<LeftArrowIcon />
6566
<span className="hidden sm:block">Previous</span>
6667
</PaginationLink>
6768
)
@@ -75,8 +76,8 @@ function PaginationNext({ className, ...props }: React.ComponentProps<typeof Pag
7576
className={cn('gap-1 px-2.5 sm:pr-2.5', className)}
7677
{...props}
7778
>
79+
<RightArrowIcon />
7880
<span className="hidden sm:block">Next</span>
79-
<ChevronRightIcon />
8081
</PaginationLink>
8182
)
8283
}
@@ -89,14 +90,13 @@ function PaginationEllipsis({ className, ...props }: React.ComponentProps<'span'
8990
className={cn('flex size-9 items-center justify-center', className)}
9091
{...props}
9192
>
92-
<MoreHorizontalIcon className="size-4" />
9393
<span className="sr-only">More pages</span>
9494
</span>
9595
)
9696
}
9797

9898
export {
99-
Pagination,
99+
PaginationContainer,
100100
PaginationContent,
101101
PaginationLink,
102102
PaginationItem,

0 commit comments

Comments
 (0)