import { Pagination } from 'sud-ui';긴 목록을 페이지네이션 형태로 나누어 보여주고 싶을 때.
페이지를 나누어 데이터를 탐색할 때.
current와 onChange로 현재 페이지를 제어해야 할 때.
import React from 'react';
import { Pagination } from 'sud-ui';
const BasicPagination = () => {
return <Pagination total={50} />;
};
export default BasicPagination;import React, { useState } from 'react';
import { Pagination, Input, Card, List } from 'sud-ui';
const PageSizePagination = () => {
const [pageSize, setPageSize] = useState(10);
const [currentPage, setCurrentPage] = useState(1);
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center">
<Input
value={pageSize}
onChange={(e) => setPageSize(Number(e.target.value))}
type="number"
min={1}
max={100}
placeholder="Number of items per page"
/>
</div>
</Card>
<Card style={{ width: "100%" }} shadow="none">
<List
dataSource={Array.from(
{ length: 1000 },
(_, i) => `Item ${i + 1}`
).slice((currentPage - 1) * pageSize, currentPage * pageSize)}
split={true}
gap={8}
/>
</Card>
<Pagination
total={1000}
pageSize={pageSize}
current={currentPage}
onChange={setCurrentPage}
showPrevNext={true}
showFirstLast={true}
maxVisibleButtons={5}
align="center"
/>
</div>
);
};
export default PageSizePagination;import React, { useState } from 'react';
import { Pagination, Input, Card } from 'sud-ui';
const MaxVisiblePagination = () => {
const [maxVisibleButtons, setMaxVisibleButtons] = useState(5);
return (
<div className="flex flex-col gap-[40px] w-full">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center">
<Input
value={maxVisibleButtons}
onChange={(e) => setMaxVisibleButtons(Number(e.target.value))}
type="number"
min={1}
max={100}
/>
</div>
<Pagination total={100} maxVisibleButtons={maxVisibleButtons} />
</Card>
</div>
);
};
export default MaxVisiblePagination;import React, { useState } from 'react';
import { Pagination, Radio, Card } from 'sud-ui';
const AlignPagination = () => {
const [align, setAlign] = useState('left');
const alignOptions = [
{ label: 'left', value: 'left' },
{ label: 'center', value: 'center' },
{ label: 'right', value: 'right' }
];
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center">
<Radio.Group
direction="horizontal"
options={alignOptions}
value={align}
onChange={setAlign}
/>
</div>
</Card>
<Pagination align={align} total={50} />
</div>
);
};
export default AlignPagination;import React from 'react';
import { Pagination, Typography } from 'sud-ui';
const CustomStylePagination = () => {
return (
<div className="flex flex-col gap-[40px] w-full">
<div className="flex flex-col gap-[20px] w-full">
<Typography pretendard="SB">
Customize Current Page Button
</Typography>
<Pagination
total={50}
activeStyle={{
colorType: "warning",
shadow: "md"
}}
/>
</div>
<div className="flex flex-col gap-[20px] w-full">
<Typography pretendard="SB">Customize All Buttons</Typography>
<Pagination
total={50}
defaultStyle={{
colorType: "text",
shadow: "none"
}}
activeStyle={{
colorType: "default",
borderColor: "blue",
shadow: "none"
}}
/>
</div>
</div>
);
};
export default CustomStylePagination;속성 이름 | 설명 | 타입 | 기본값 |
|---|
| current | 제어형 현재 페이지 번호입니다. total/pageSize 범위를 벗어난 값은 유효 범위로 보정됩니다. | number | - |
| defaultCurrent | 비제어형일 때만 사용하는 초기 페이지 번호입니다. | number | 1 |
| total | 전체 아이템 수입니다. 0 이하일 때도 페이지 1을 유지합니다. | number | 0 |
| align | 페이지네이션 정렬 위치 ("left" | "center" | "right") | left | center | right | left |
| pageSize | 한 페이지에 표시할 아이템 수입니다. 0 이하 값은 기본값 10으로 처리됩니다. | number | 10 |
| onChange | 페이지 변경 시 호출되는 콜백 함수 ((page: number) => void) | (page: number) => void | - |
| showPrevNext | 이전/다음 페이지 버튼 표시 여부 | boolean | true |
| showFirstLast | 첫 페이지/마지막 페이지 버튼 표시 여부 | boolean | true |
| maxVisibleButtons | 한 번에 표시할 최대 페이지 버튼 수 | number | 5 |
| activeStyle | 현재 페이지 버튼의 스타일 (PaginationStyle) | PaginationStyle | { colorType: 'primary', shadow: 'sm' } |
| defaultStyle | 기본 페이지 버튼의 스타일 (PaginationStyle) | PaginationStyle | { colorType: 'default', shadow: 'sm' } |
| style | 컨테이너 스타일 | CSSProperties | {} |