diff --git a/app/frontend/src/components/Pagination/index.css.ts b/app/frontend/src/components/Pagination/index.css.ts new file mode 100644 index 00000000..11ffe80b --- /dev/null +++ b/app/frontend/src/components/Pagination/index.css.ts @@ -0,0 +1,49 @@ +import { globalStyle, style } from '@vanilla-extract/css'; + +import { vars } from '@/styles'; +import { sansRegular16 } from '@/styles/font.css'; + +const { grayscale200, grayscale500, grayscale50 } = vars.color; + +export const container = style({ + display: 'flex', + gap: '1.2rem', + justifyContent: 'center', + width: '100%', +}); + +globalStyle(`${container} button`, { + padding: '0.4rem', + borderRadius: '100%', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', +}); + +globalStyle(`${container} button:hover`, { + backgroundColor: grayscale50, +}); + +export const current = style({}); +export const page = style([ + sansRegular16, + { + color: grayscale200, + + selectors: { + [`${current}&`]: { + color: grayscale500, + }, + }, + + '@media': { + 'screen and (max-width: 768px)': { + fontSize: '1.2rem', + }, + }, + }, +]); + +export const rotateArrow = style({ + transform: 'rotate(180deg)', +}); diff --git a/app/frontend/src/components/Pagination/index.tsx b/app/frontend/src/components/Pagination/index.tsx new file mode 100644 index 00000000..90d61eda --- /dev/null +++ b/app/frontend/src/components/Pagination/index.tsx @@ -0,0 +1,51 @@ +import { ReactComponent as Arrow } from '@/assets/icons/arrow_left.svg'; +import { vars } from '@/styles'; +import { createRangeArray, get10UnitRange } from '@/utils'; + +import * as styles from './index.css'; + +const { grayscale200 } = vars.color; +type PaginationProps = { + currentPage: number; + onClickPrev: () => void; + onClickNext: () => void; + onClickItem: React.MouseEventHandler; +}; + +export function Pagination({ + currentPage, + onClickPrev, + onClickNext, + onClickItem, +}: PaginationProps) { + const [start, end] = get10UnitRange(currentPage); + const array = createRangeArray(start, end); + const arrow = ; + return ( +
+ + {array.map((page) => ( + + ))} + +
+ ); +} diff --git a/app/frontend/src/components/index.ts b/app/frontend/src/components/index.ts index de113c31..8d99d25c 100644 --- a/app/frontend/src/components/index.ts +++ b/app/frontend/src/components/index.ts @@ -15,6 +15,7 @@ export * from './Modal/InputModal'; export * from './Modal/MapModal'; export * from './Modal/ModalContainer'; export * from './MogacoItem'; +export * from './Pagination'; export * from './Popover'; export * from './Sidebar'; export * from './Sidebar/Contents/Chatting'; diff --git a/app/frontend/src/hooks/index.ts b/app/frontend/src/hooks/index.ts index 5297a025..a039905b 100644 --- a/app/frontend/src/hooks/index.ts +++ b/app/frontend/src/hooks/index.ts @@ -1,4 +1,5 @@ export * from './useDebounce'; export * from './useModal'; +export * from './usePagination'; export * from './useRouter'; export * from './useSetUserInfo'; diff --git a/app/frontend/src/hooks/usePagination.ts b/app/frontend/src/hooks/usePagination.ts new file mode 100644 index 00000000..19ce0f64 --- /dev/null +++ b/app/frontend/src/hooks/usePagination.ts @@ -0,0 +1,19 @@ +import { useState } from 'react'; + +export const usePagination = () => { + const [currentPage, setCurrentPage] = useState(1); + + const onClickNext = () => { + setCurrentPage(currentPage + 1); + }; + + const onClickPrev = () => { + setCurrentPage(currentPage - 1); + }; + + const onClickItem = (e: React.MouseEvent) => { + setCurrentPage(Number(e.currentTarget.value)); + }; + + return { currentPage, onClickItem, onClickNext, onClickPrev }; +}; diff --git a/app/frontend/src/utils/createRangeArray.ts b/app/frontend/src/utils/createRangeArray.ts new file mode 100644 index 00000000..85160c05 --- /dev/null +++ b/app/frontend/src/utils/createRangeArray.ts @@ -0,0 +1,2 @@ +export const createRangeArray = (start: number, end: number) => + Array.from({ length: end - start + 1 }, (_, k) => k + start); diff --git a/app/frontend/src/utils/get10UnitRange.ts b/app/frontend/src/utils/get10UnitRange.ts new file mode 100644 index 00000000..d2a36aa6 --- /dev/null +++ b/app/frontend/src/utils/get10UnitRange.ts @@ -0,0 +1,5 @@ +export const get10UnitRange = (current: number) => { + const start = Math.floor((current - 1) / 10) * 10 + 1; + const end = start + 9; + return [start, end]; +}; diff --git a/app/frontend/src/utils/index.ts b/app/frontend/src/utils/index.ts index e867fc6f..aa8c4d05 100644 --- a/app/frontend/src/utils/index.ts +++ b/app/frontend/src/utils/index.ts @@ -1,2 +1,4 @@ export * from './cookies'; +export * from './createRangeArray'; +export * from './get10UnitRange'; export * from './mocking';