Flowbite 컴포넌트 — 페이지네이션(Pagination)
Flowbite의 페이지네이션(Pagination) 컴포넌트는 여러 페이지로 나뉜 콘텐츠를 탐색할 수 있게 도와주는 요소예요. 페이지 번호, 이전/다음 버튼, 아이콘만 있는 형태 등 다양한 스타일을 Tailwind CSS 클래스로 만들 수 있어요.
출처: 문서
본문
기본 페이지네이션은 이전/다음 화살표와 페이지 번호로 구성돼요. 아래는 기본 예시예요.
<nav aria-label="Page navigation example">
<ul class="inline-flex -space-x-px text-sm">
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 ms-0 leading-tight text-gray-500 bg-white border border-e-0 border-gray-300 rounded-s-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
Previous
</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">1</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">2</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-white bg-blue-600 border border-blue-300 hover:bg-blue-700 hover:text-white dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">3</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">4</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 rounded-e-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">Next</a>
</li>
</ul>
</nav>
현재 페이지는 bg-blue-600 text-white 같은 강조 클래스로 구분하고, 나머지는 bg-white text-gray-500을 사용해요. -space-x-px와 border를 조합해 촘촘한 테두리 버튼들을 만들어요.
아이콘만 있는 페이지네이션
화살표 아이콘만 사용하는 형태도 흔해요. 아이콘은 SVG를 aria-hidden으로 감싸고 글자 대신 사용해요.
<nav aria-label="Page navigation example">
<ul class="inline-flex -space-x-px text-sm">
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 ms-0 leading-tight text-gray-500 bg-white border border-e-0 border-gray-300 rounded-s-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
<svg class="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 1 1 5l4 4"/>
</svg>
<span class="sr-only">Previous</span>
</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">1</a>
</li>
<li>
<a href="#" class="flex items-center justify-center px-3 h-8 leading-tight text-gray-500 bg-white border border-gray-300 rounded-e-lg hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white">
<svg class="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 9 4-4-4-4"/>
</svg>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
접근성을 위해 aria-label="Page navigation example"과 스크린 리더용 sr-only 텍스트를 꼭 포함하는 걸 권장해요. 페이지네이션은 게시판, 리스트, 검색 결과 등 많은 콘텐츠를 분할해 보여줄 때 필수적이에요.