본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Flowbite 컴포넌트 — 드로어(Drawer)

원문 보기 위키 갱신

Flowbite의 드로어(Drawer) 컴포넌트는 화면 가장자리에서 슬라이드되어 나오는 패널로, 사이드바, 쇼핑카트, 알림, 메뉴 등을 담는 데 사용해요. 툴팁이나 모달과 달리 화면의 한쪽 끝에서 콘텐츠가 미끄러져 등장하는 방식이에요.

출처: 문서

본문

드로어를 사용하려면 Flowbite의 자바스크립트 초기화 코드를 함께 로드해야 해요. 아래는 기본 드로어 예시예요.

<!-- Drawer button -->
<button type="button" data-drawer-target="drawer-example" data-drawer-show="drawer-example" aria-controls="drawer-example" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
    Show drawer
</button>

<!-- Drawer component -->
<div id="drawer-example" class="fixed top-0 left-0 z-40 h-screen p-4 overflow-y-auto transition-transform -translate-x-full bg-white w-80 dark:bg-gray-800" tabindex="-1" aria-labelledby="drawer-label">
    <h5 id="drawer-label" class="inline-flex items-center mb-6 text-base font-semibold text-gray-500 uppercase dark:text-gray-400">
        <svg class="w-4 h-4 me-2.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
            <path d="M10 0a10 10 0 1 0 10 10A10.011 10.011 0 0 0 10 0Zm3.982 13.982a1 1 0 0 1-1.414 0l-3.274-3.274A1.012 1.012 0 0 1 9 10V6a1 1 0 0 1 2 0v3.586l2.982 2.982a1 1 0 0 1 0 1.414Z"/>
        </svg>
        Drawer
    </h5>
    <button type="button" data-drawer-hide="drawer-example" aria-controls="drawer-example" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 absolute top-2.5 end-2.5 inline-flex items-center justify-center dark:hover:bg-gray-600 dark:hover:text-white">
        <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
        </svg>
        <span class="sr-only">Close menu</span>
    </button>
    <p class="mb-6 text-sm text-gray-500 dark:text-gray-400">Drawer content goes here.</p>
</div>

핵심 요소를 정리하면 다음과 같아요.

  • 열기 버튼: data-drawer-target과 data-drawer-show 속성으로 대상 드로어의 id를 지정해요.
  • 드로어 본체: fixed + 방향 클래스(-translate-x-full 등)로 초기 숨김 상태를 만들고, 열리면 해당 변환이 해제돼요.
  • 닫기 버튼: data-drawer-hide로 닫을 드로어를 지정해요.

오른쪽 드로어

드로어는 방향 클래스에 따라 화면의 어느 쪽이든 열 수 있어요. 오른쪽에서 열려면 translate-x-full을 초기값으로 잡아요.

<div id="drawer-right" class="fixed top-0 right-0 z-40 h-screen p-4 overflow-y-auto transition-transform translate-x-full bg-white w-80 dark:bg-gray-800" tabindex="-1" aria-labelledby="drawer-right-label">
    <h5 id="drawer-right-label" class="inline-flex items-center mb-6 text-base font-semibold text-gray-500 uppercase dark:text-gray-400">Right drawer</h5>
    <button type="button" data-drawer-hide="drawer-right" aria-controls="drawer-right" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 absolute top-2.5 end-2.5 inline-flex items-center justify-center dark:hover:bg-gray-600 dark:hover:text-white">
        <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
        </svg>
        <span class="sr-only">Close menu</span>
    </button>
    <p class="mb-6 text-sm text-gray-500 dark:text-gray-400">Right drawer content goes here.</p>
</div>

자바스크립트 초기화

드로어의 열기·닫기 동작을 위해 flowbite 스크립트를 로드해야 해요.

<script src="https://cdn.jsdelivr.net/npm/flowbite@latest/dist/flowbite.min.js"></script>

드로어는 사이드 메뉴, 장바구니, 알림 패널, 로그인 폼 등 화면 공간을 절약하면서 풍부한 콘텐츠를 담기에 아주 유용한 컴포넌트예요.

더 알아보기 (Learn more)