드로어
드로어 (Drawer)
스와이프로 닫는 제스처를 지원하는 고품질의 비스타일 React 드로어 컴포넌트예요.
출처: Base UI Drawer
본문
스와이프로 닫는 제스처가 있는 고품질의 비스타일 React 드로어 컴포넌트예요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawer() {
return (
<Drawer.Root swipeDirection="right">
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open drawer
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] fixed inset-0 flex items-stretch justify-end p-(--viewport-padding)">
<Drawer.Popup className="[--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] h-full w-[calc(20rem+3rem)] max-w-[calc(100vw-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-ending-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-starting-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<Drawer.Content className="mx-auto w-full max-w-[32rem]">
<Drawer.Title className="mb-1 text-base font-bold">Drawer</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 dark:text-neutral-400">
This is a drawer that slides in from the side. You can swipe to dismiss it.
</Drawer.Description>
<div className="flex justify-end gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: fixed;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: calc(20rem + var(--bleed));
max-width: calc(100vw - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}
/* index.tsx */
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawer() {
return (
<Drawer.Root swipeDirection="right">
<Drawer.Trigger className={styles.Button}>Open drawer</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Drawer</Drawer.Title>
<Drawer.Description className={styles.Description}>
This is a drawer that slides in from the side. You can swipe to dismiss it.
</Drawer.Description>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
사용 가이드라인 (Usage guidelines)
- Drawer는 Dialog를 확장해요: 제스처 지원, 스냅 포인트, 인덴트 효과를 추가해요. 이 기능들이 필요 없다면 Dialog를 사용하세요. 화면 가장자리에서 슬라이드되어 들어오고 제스처 지원이 필요 없는 패널은 위치 지정된 Dialog예요.
구조 (Anatomy)
컴포넌트를 임포트하고 파트들을 조립하세요.
import { Drawer } from '@base-ui/react/drawer';
<Drawer.Provider>
<Drawer.IndentBackground />
<Drawer.Indent>
<Drawer.Root>
<Drawer.Trigger />
<Drawer.SwipeArea />
<Drawer.Portal>
<Drawer.Backdrop />
<Drawer.Viewport>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title />
<Drawer.Description />
<Drawer.Close />
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</Drawer.Indent>
</Drawer.Provider>;
Drawer는 닫기에 스와이프 제스처를 지원해요. swipeDirection을 설정해 어느 방향으로 스와이프하면 닫히는지 제어할 수 있어요. <Drawer.Content>는 마우스 포인터 사용 시 스와이프 간섭 없이 자식의 텍스트 선택을 허용해요. 모든 입력 유형에서 스와이프 닫기에서 제외하고 싶은 하위 요소에 data-base-ui-swipe-ignore를 추가하세요.
바텀 시트에 폼 필드가 있고 Base UI가 소프트웨어 키보드에 대한 키보드 인식 포커스·스크롤 처리를 관리하게 하려면 <Drawer.VirtualKeyboardProvider>를 사용하세요. 이 프로바이더가 없는 드로어는 영향을 받지 않아요.
예시 (Examples)
상태 (State)
기본적으로 Drawer는 자체 상태를 관리하는 비제어 컴포넌트예요.
<Drawer.Root>
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title>Example drawer</Drawer.Title>
<Drawer.Close>Close</Drawer.Close>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
드로어의 상태에 접근하거나 제어해야 한다면 open과 onOpenChange prop을 사용하세요.
const [open, setOpen] = React.useState(false);
return (
<Drawer.Root open={open} onOpenChange={setOpen}>
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title>Example drawer</Drawer.Title>
<Drawer.Close>Close</Drawer.Close>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
위치 (Position)
포지셔닝은 여러분의 스타일이 담당해요. swipeDirection은 바텀 시트에서 기본적으로 "down"이에요. 다른 드로어 위치에는 "up", "left", "right"를 사용하세요.
<Drawer.Root swipeDirection="right">
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawer() {
return (
<Drawer.Root>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open bottom drawer
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center">
<Drawer.Popup className="-mb-[3rem] w-full max-h-[calc(80vh+3rem)] border-t border-neutral-950 bg-white px-6 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+3rem)] pt-4 text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateY(var(--drawer-swipe-movement-y))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-ending-style:[transform:translateY(calc(100%-3rem+2px))] data-starting-style:[transform:translateY(calc(100%-3rem+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<div className="mx-auto mb-4 h-1 w-12 bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Content className="mx-auto w-full max-w-[32rem]">
<Drawer.Title className="mb-1 text-base font-bold text-center">
Notifications
</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400">
You are all caught up. Good job!
</Drawer.Description>
<div className="flex justify-center gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: 100%;
max-height: calc(80vh + var(--bleed));
margin-bottom: calc(-1 * var(--bleed));
padding: 1rem 1.5rem 1.5rem;
padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateY(var(--drawer-swipe-movement-y));
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateY(calc(100% - var(--bleed) + 2px));
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 1rem;
background-color: oklch(87% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: center;
gap: 0.75rem;
}
/* index.tsx */
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawer() {
return (
<Drawer.Root>
<Drawer.Trigger className={styles.Button}>Open bottom drawer</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<div className={styles.Handle} />
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Notifications</Drawer.Title>
<Drawer.Description className={styles.Description}>
You are all caught up. Good job!
</Drawer.Description>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
중첩 드로어 (Nested drawers)
중첩 드로어가 열려 있을 때 드로어를 스타일링하려면 [data-nested-drawer-open] 선택자와 --nested-drawers CSS 변수를 사용하세요.
이 데모는 일정한 peek을 사용해 중첩 드로어를 쌓아서, 가장 앞쪽 드로어가 바닥에 고정되고 그 뒤의 드로어는 축소되어 떠오르게 해요. 또 --drawer-height와 --drawer-frontmost-height CSS 변수로 드로어 높이 차이를 처리해요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawerNested() {
return (
<Drawer.Root>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open drawer stack
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center">
<Drawer.Popup className={popupClassName}>
<div className={handleClassName} />
<Drawer.Content className={contentClassName}>
<Drawer.Title className="mb-1 text-base font-bold text-center">Account</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400">
Nested drawers can be styled to stack, while each drawer remains independently focus
managed.
</Drawer.Description>
<div className="flex items-center justify-end gap-4">
<div className="mr-auto">
<Drawer.Root>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Security settings
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center">
<Drawer.Popup className={popupClassName}>
<div className={handleClassName} />
<Drawer.Content className={contentClassName}>
<Drawer.Title className="mb-1 text-base font-bold text-center">
Security
</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400">
Review sign-in activity and update your security preferences.
</Drawer.Description>
<ul className="mb-6 list-disc pl-5 text-neutral-700 dark:text-neutral-300">
<li>Passkeys enabled</li>
<li>2FA via authenticator app</li>
<li>3 signed-in devices</li>
</ul>
<div className="flex items-center justify-end gap-4">
<div className="mr-auto">
<Drawer.Root>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Advanced options
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center">
<Drawer.Popup className={popupClassName}>
<div className={handleClassName} />
<Drawer.Content className={contentClassName}>
<Drawer.Title className="mb-1 text-base font-bold text-center">
Advanced
</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400">
This drawer is taller to demonstrate variable-height
stacking.
</Drawer.Description>
<div className="grid gap-2 mb-4">
<label
className="text-sm font-bold text-neutral-700 dark:text-neutral-300"
htmlFor="device-name-tw"
>
Device name
</label>
<input
id="device-name-tw"
className="h-8 w-full border border-neutral-950 bg-white px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
defaultValue="Personal laptop"
/>
</div>
<div className="grid gap-2 mb-4">
<label
className="text-sm font-bold text-neutral-700 dark:text-neutral-300"
htmlFor="notes-tw"
>
Notes
</label>
<textarea
id="notes-tw"
className="min-h-32 w-full resize-y border border-neutral-950 bg-white p-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
defaultValue="Rotate recovery codes and revoke older sessions."
rows={3}
/>
</div>
<div className="flex justify-end">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Done
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
const popupClassName =
"[--bleed:3rem] [--peek:1rem] [--stack-progress:clamp(0,var(--drawer-swipe-progress),1)] [--stack-step:0.05] [--stack-peek-offset:max(0px,calc((var(--nested-drawers)-var(--stack-progress))*var(--peek)))] [--scale-base:calc(max(0,1-(var(--nested-drawers)*var(--stack-step))))] [--scale:clamp(0,calc(var(--scale-base)+(var(--stack-step)*var(--stack-progress))),1)] [--shrink:calc(1-var(--scale))] [--height:max(0px,calc(var(--drawer-frontmost-height,var(--drawer-height))-var(--bleed)))] group/popup relative -mx-px -mb-[3rem] w-[calc(100%+2px)] max-h-[calc(80vh+3rem)] [height:var(--drawer-height,auto)] border border-neutral-950 border-b-0 bg-white px-6 pt-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform-origin:50%_calc(100%-var(--bleed))] [transform:translateY(calc(var(--drawer-swipe-movement-y)-var(--stack-peek-offset)-(var(--shrink)*var(--height))))_scale(var(--scale))] after:pointer-events-none after:absolute after:inset-0 after:bg-transparent after:content-[''] after:transition-[background-color] after:duration-[450ms] after:ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-swiping:duration-0 data-nested-drawer-swiping:duration-0 data-starting-style:[transform:translateY(calc(100%-var(--bleed)+2px))] data-ending-style:[transform:translateY(calc(100%-var(--bleed)+2px))] data-ending-style:opacity-[0.9999] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-ending-style:data-swiping:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-ending-style:data-nested-drawer-swiping:duration-[calc(var(--drawer-swipe-strength)*400ms)] data-nested-drawer-open:h-[calc(var(--height)+var(--bleed))] data-nested-drawer-open:overflow-hidden data-nested-drawer-open:after:bg-black/5 dark:border-white dark:border-b-0 dark:bg-neutral-950 dark:text-white dark:shadow-none [transition:transform_450ms_cubic-bezier(0.32,0.72,0,1),height_450ms_cubic-bezier(0.32,0.72,0,1),opacity_450ms_cubic-bezier(0.32,0.72,0,1)]";
const contentClassName =
'mx-auto w-full max-w-[32rem] transition-opacity duration-[300ms] ease-[cubic-bezier(0.45,1.005,0,1.005)] group-data-nested-drawer-open/popup:opacity-0 group-data-nested-drawer-swiping/popup:opacity-100';
const handleClassName =
'mx-auto mb-4 h-1 w-12 bg-neutral-300 transition-opacity duration-[200ms] group-data-nested-drawer-open/popup:opacity-0 group-data-nested-drawer-swiping/popup:opacity-100 dark:bg-neutral-700';
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
pointer-events: none;
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
--bleed: 3rem;
--peek: 1rem;
--stack-progress: clamp(0, var(--drawer-swipe-progress), 1);
--stack-step: 0.05;
--stack-peek-offset: max(
0px,
calc((var(--nested-drawers) - var(--stack-progress)) * var(--peek))
);
--stack-scale-base: max(0, calc(1 - (var(--nested-drawers) * var(--stack-step))));
--stack-scale: calc(var(--stack-scale-base) + (var(--stack-step) * var(--stack-progress)));
--stack-shrink: calc(1 - var(--stack-scale));
--stack-height: max(
0px,
calc(var(--drawer-frontmost-height, var(--drawer-height)) - var(--bleed))
);
--translate-y: calc(
var(--drawer-swipe-movement-y) - var(--stack-peek-offset) -
(var(--stack-shrink) * var(--stack-height))
);
box-sizing: border-box;
position: relative;
width: calc(100% + 2px);
margin-left: -1px;
margin-right: -1px;
max-height: calc(80vh + var(--bleed));
height: var(--drawer-height, auto);
margin-bottom: calc(-1 * var(--bleed));
padding: 1rem 1.5rem 1.5rem;
padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
border-width: 1px 1px 0;
border-style: solid;
border-color: oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
transform-origin: 50% calc(100% - var(--bleed));
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
height 450ms cubic-bezier(0.32, 0.72, 0, 1),
opacity 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateY(var(--translate-y)) scale(var(--stack-scale));
@media (prefers-color-scheme: dark) {
border-color: white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-swiping],
&[data-nested-drawer-swiping] {
transition-duration: 0ms;
}
&::after {
content: '';
inset: 0;
position: absolute;
background-color: transparent;
pointer-events: none;
transition: background-color 450ms cubic-bezier(0.32, 0.72, 0, 1);
}
&[data-nested-drawer-open] {
height: calc(var(--stack-height) + var(--bleed));
overflow: hidden;
&::after {
background-color: rgb(0 0 0 / 0.05);
}
}
&[data-starting-style],
&[data-ending-style] {
transform: translateY(calc(100% - var(--bleed) + 2px));
}
&[data-ending-style] {
opacity: 0.9999;
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
transition: opacity 300ms cubic-bezier(0.45, 1.005, 0, 1.005);
[data-nested-drawer-open] & {
opacity: 0;
}
[data-nested-drawer-open][data-nested-drawer-swiping] & {
opacity: 1;
}
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 1rem;
background-color: oklch(87% 0 0deg);
transition: opacity 0.2s;
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
[data-nested-drawer-open] & {
opacity: 0;
}
[data-nested-drawer-open][data-nested-drawer-swiping] & {
opacity: 1;
}
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
align-items: center;
justify-content: end;
gap: 1rem;
}
.ActionsLeft {
margin-right: auto;
}
.List {
margin: 0 0 1.5rem;
padding-left: 1.25rem;
color: oklch(37.1% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(87% 0 0deg);
}
}
.Field {
display: grid;
gap: 0.5rem;
margin-bottom: 1rem;
}
.Label {
font-size: 0.925rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(37.1% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(87% 0 0deg);
}
}
.Input {
box-sizing: border-box;
width: 100%;
height: 2rem;
padding: 0 0.5rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Textarea {
box-sizing: border-box;
width: 100%;
min-height: 8rem;
padding: 0.5rem 0.625rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
background-color: white;
color: oklch(14.5% 0 0deg);
resize: vertical;
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Input:focus-visible,
.Textarea:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
/* index.tsx */
'use client';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawerNested() {
return (
<Drawer.Root>
<Drawer.Trigger className={styles.Button}>Open drawer stack</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<div className={styles.Handle} />
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Account</Drawer.Title>
<Drawer.Description className={styles.Description}>
Nested drawers can be styled to stack, while each drawer remains independently focus
managed.
</Drawer.Description>
<div className={styles.Actions}>
<div className={styles.ActionsLeft}>
<Drawer.Root>
<Drawer.Trigger className={styles.Button}>Security settings</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<div className={styles.Handle} />
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Security</Drawer.Title>
<Drawer.Description className={styles.Description}>
Review sign-in activity and update your security preferences.
</Drawer.Description>
<ul className={styles.List}>
<li>Passkeys enabled</li>
<li>2FA via authenticator app</li>
<li>3 signed-in devices</li>
</ul>
<div className={styles.Actions}>
<div className={styles.ActionsLeft}>
<Drawer.Root>
<Drawer.Trigger className={styles.Button}>
Advanced options
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<div className={styles.Handle} />
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>
Advanced
</Drawer.Title>
<Drawer.Description className={styles.Description}>
This drawer is taller to demonstrate variable-height
stacking.
</Drawer.Description>
<div className={styles.Field}>
<label className={styles.Label} htmlFor="device-name">
Device name
</label>
<input
id="device-name"
className={styles.Input}
defaultValue="Personal laptop"
/>
</div>
<div className={styles.Field}>
<label className={styles.Label} htmlFor="notes">
Notes
</label>
<textarea
id="notes"
className={styles.Textarea}
defaultValue="Rotate recovery codes and revoke older sessions."
rows={3}
/>
</div>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>
Done
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
스냅 포인트 (Snap points)
snapPoints를 사용해 바텀 시트 드로어를 미리 설정된 높이에 스냅할 수 있어요. 0과 1 사이의 숫자는 viewport 높이의 비율을 나타내고, 1보다 큰 숫자는 픽셀 값으로 처리돼요. 문자열 값은 px와 rem 단위를 지원해요(예: '148px' 또는 '30rem').
const snapPoints = ['148px', 1];
const [snapPoint, setSnapPoint] = React.useState<Drawer.Root.SnapPoint | null>(snapPoints[0]);
<Drawer.Root snapPoints={snapPoints} snapPoint={snapPoint} onSnapPointChange={setSnapPoint}>
{/* ... */}
</Drawer.Root>;
세로 드로어를 사용할 때는 스타일에서 스냅 포인트 오프셋을 적용하세요.
.DrawerPopup {
transform: translateY(calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
}
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
const TOP_MARGIN_REM = 1;
const VISIBLE_SNAP_POINTS_REM = [30];
function toViewportSnapPoint(heightRem: number) {
return `${heightRem + TOP_MARGIN_REM}rem`;
}
const snapPoints = [...VISIBLE_SNAP_POINTS_REM.map(toViewportSnapPoint), 1];
export default function ExampleDrawerSnapPoints() {
return (
<Drawer.Root snapPoints={snapPoints}>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open snap drawer
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center touch-none [--bleed:3rem] after:pointer-events-none after:fixed after:inset-x-0 after:bottom-0 after:h-[var(--bleed)] after:bg-white after:content-[''] data-closed:after:opacity-0 dark:after:bg-neutral-950">
<Drawer.Popup
className="relative z-1 flex w-full max-h-[calc(100dvh-var(--top-margin))] min-h-0 flex-col overflow-visible border-t border-neutral-950 bg-white text-neutral-950 outline-none touch-none shadow-[0.25rem_0.25rem_0] shadow-black/12 [padding-bottom:max(0px,calc(var(--drawer-snap-point-offset)+var(--drawer-swipe-movement-y)))] [transform:translateY(calc(var(--drawer-snap-point-offset)+var(--drawer-swipe-movement-y)))] transition-[transform,box-shadow] duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-[var(--bleed)] after:bg-[inherit] after:content-[''] data-ending-style:[transform:translateY(calc(100%+2px))] data-starting-style:[transform:translateY(calc(100%+2px))] data-starting-style:[padding-bottom:0] data-ending-style:[padding-bottom:0] data-starting-style:shadow-[0.25rem_0.25rem_0] data-starting-style:shadow-black/0 data-ending-style:shadow-[0.25rem_0.25rem_0] data-ending-style:shadow-black/0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
style={{ '--top-margin': `${TOP_MARGIN_REM}rem` } as React.CSSProperties}
>
<div className="shrink-0 border-b border-neutral-300 px-6 pt-3.5 pb-4 touch-none select-none dark:border-neutral-700">
<div className="mx-auto mb-2.5 h-1 w-12 shrink-0 bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Title className="cursor-default text-center text-base font-bold">
Snap points
</Drawer.Title>
</div>
<Drawer.Content className="min-h-0 flex-1 overflow-y-auto overscroll-contain touch-auto px-6 pt-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px))]">
<div className="mx-auto w-full max-w-90">
<Drawer.Description className="mb-4 text-sm text-neutral-600 text-center dark:text-neutral-400">
Drag the sheet to snap between a compact peek and a near full-height view.
</Drawer.Description>
<div className="grid gap-3 mb-6" aria-hidden>
{Array.from({ length: 20 }, (_, index) => (
<div key={index} className="h-12 bg-neutral-200 dark:bg-neutral-700" />
))}
</div>
<div className="flex items-center justify-end gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--bleed: 3rem;
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
touch-action: none;
&::after {
content: '';
position: fixed;
inset-inline: 0;
bottom: 0;
height: var(--bleed);
background-color: white;
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: oklch(14.5% 0 0deg);
}
}
&[data-closed]::after {
opacity: 0;
}
}
.Content {
width: 100%;
max-width: 22.5rem;
margin: 0 auto;
}
.Popup {
box-sizing: border-box;
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
width: 100%;
max-height: calc(100dvh - var(--top-margin));
padding-bottom: max(0px, calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
overflow: visible;
touch-action: none;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
box-shadow 450ms cubic-bezier(0.32, 0.72, 0, 1);
transform: translateY(calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
will-change: transform;
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&::after {
content: '';
position: absolute;
inset-inline: 0;
top: 100%;
height: var(--bleed);
background-color: inherit;
pointer-events: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateY(calc(100% + 2px));
padding-bottom: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.DragArea {
flex-shrink: 0;
padding: 0.875rem 1.5rem 1rem;
border-bottom: 1px solid oklch(87% 0 0deg);
touch-action: none;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border-bottom: 1px solid oklch(37.1% 0 0deg);
}
}
.Scroll {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
padding: 1rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 0.625rem;
flex-shrink: 0;
background-color: oklch(87% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
cursor: default;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Cards {
display: grid;
gap: 0.75rem;
margin: 0 0 1.5rem;
}
.Card {
height: 3rem;
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Actions {
display: flex;
align-items: center;
justify-content: end;
gap: 1rem;
}
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
const TOP_MARGIN_REM = 1;
const VISIBLE_SNAP_POINTS_REM = [30];
function toViewportSnapPoint(heightRem: number) {
return `${heightRem + TOP_MARGIN_REM}rem`;
}
const snapPoints = [...VISIBLE_SNAP_POINTS_REM.map(toViewportSnapPoint), 1];
export default function ExampleDrawerSnapPoints() {
return (
<Drawer.Root snapPoints={snapPoints}>
<Drawer.Trigger className={styles.Button}>Open snap drawer</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup
className={styles.Popup}
style={{ '--top-margin': `${TOP_MARGIN_REM}rem` } as React.CSSProperties}
>
<div className={styles.DragArea}>
<div className={styles.Handle} />
<Drawer.Title className={styles.Title}>Snap points</Drawer.Title>
</div>
<Drawer.Content className={styles.Scroll}>
<div className={styles.Content}>
<Drawer.Description className={styles.Description}>
Drag the sheet to snap between a compact peek and a near full-height view.
</Drawer.Description>
<div className={styles.Cards} aria-hidden>
{Array.from({ length: 20 }, (_, index) => (
<div className={styles.Card} key={index} />
))}
</div>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
기본적으로 드로어는 빠르게 스와이프하면 스냅 포인트를 건너뛸 수 있어요. snapToSequentialPoints prop을 지정하면 속도 기반 건너뛰기를 비활성화해서 드래그 거리가 다음 스냅 대상이 되게 해요(여전히 여러 포인트를 지나 드래그할 수 있어요).
가상 키보드 인식
폼 컨트롤이 있는 바텀 시트를 <Drawer.VirtualKeyboardProvider>로 감싸면 소프트웨어 키보드에 반응하게 할 수 있어요. 키보드가 열리면 프로바이더가 포커스된 필드를 보이게 유지하려고 body를 스크롤해요.
- 팝업 프레임을 안정적으로 유지하세요: 일반 스크롤 가능한 body 밖에 헤더와 푸터 콘텐츠를 배치하세요.
- 고정 푸터 input을 들어 올리세요: 푸터에 자체 input이 있으면 스크롤 영역 아래에 푸터 슬롯을 남겨두고
var(--drawer-keyboard-inset, 0px)로 오프셋하세요. 이 데모는 포커스된 푸터를position: fixed로 전환해요 — 팝업의transform이 fixed 하위 요소를 포함하므로 팝업을 기준으로 배치되고, bottom 패딩에 inset을 더해요. - 항상
0px폴백을 포함하세요: 프로바이더는 키보드가 정렬된 동안에만--drawer-keyboard-inset을 설정하므로, 처음 정렬 전과 정리 후에는 맨var(--drawer-keyboard-inset)이 유효하지 않아요.
<Drawer.Root>
<Drawer.VirtualKeyboardProvider>{/* ... */}</Drawer.VirtualKeyboardProvider>
</Drawer.Root>
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import { Drawer } from '@base-ui/react/drawer';
const fields = [
['Name', 'Ada Lovelace'],
['Phone', '+1 (555) 123-4567'],
['Street address', '12 Computing Way'],
['Apartment', 'Unit 4B'],
['City', 'San Francisco'],
['Postal code', '94107'],
['Delivery window', 'After 6 PM'],
['Backup contact', 'Grace Hopper'],
];
export default function ExampleDrawerVirtualKeyboardAware() {
return (
<Drawer.Root>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open keyboard-aware drawer
</Drawer.Trigger>
<Drawer.VirtualKeyboardProvider>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center touch-none [--bleed:3rem] after:pointer-events-none after:fixed after:inset-x-0 after:bottom-0 after:h-[var(--bleed)] after:bg-white after:content-[''] data-closed:after:opacity-0 has-[[data-swiping]]:after:opacity-0 dark:after:bg-neutral-950">
<Drawer.Popup className="relative z-1 -mb-[var(--bleed)] flex h-[calc(100%-1rem+var(--bleed))] max-h-[calc(100%-1rem+var(--bleed))] w-full flex-col overflow-visible border-t border-neutral-950 bg-white text-neutral-950 outline-none touch-none shadow-[0.25rem_0.25rem_0] shadow-black/12 [--bleed:3rem] [--footer-reserved-height:calc(5.25rem+var(--bleed))] [transform:translateY(var(--drawer-swipe-movement-y))] transition-[transform,box-shadow] duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] will-change-transform data-swiping:select-none data-ending-style:[transform:translateY(calc(100%-var(--bleed)+2px))] data-starting-style:[transform:translateY(calc(100%-var(--bleed)+2px))] data-starting-style:shadow-[0.25rem_0.25rem_0] data-starting-style:shadow-black/0 data-ending-style:shadow-[0.25rem_0.25rem_0] data-ending-style:shadow-black/0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<div className="relative shrink-0 border-b border-neutral-300 px-6 py-4 touch-none select-none dark:border-neutral-700">
<div className="absolute top-2 left-1/2 h-1 w-12 shrink-0 -translate-x-1/2 bg-neutral-300 dark:bg-neutral-700" />
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3">
<Drawer.Close className="flex h-8 min-w-0 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none justify-self-start hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Cancel
</Drawer.Close>
<Drawer.Title className="cursor-default text-center text-base font-bold">
Delivery details
</Drawer.Title>
<Drawer.Close className="flex h-8 min-w-0 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none justify-self-end hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Save
</Drawer.Close>
</div>
</div>
<Drawer.Content className="min-h-0 flex-1 overflow-y-auto overscroll-contain touch-auto px-6 pt-4 pb-6">
<div className="mx-auto grid w-full max-w-90 gap-3">
{fields.map(([label, placeholder]) => (
<label className="flex w-full flex-col items-start gap-1" key={label}>
<span className="text-sm font-bold text-neutral-950 dark:text-white">
{label}
</span>
<input
className="h-8 w-full border border-neutral-950 bg-white px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 placeholder:text-neutral-500 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white dark:border-white dark:bg-neutral-950 dark:text-white dark:placeholder:text-neutral-400"
placeholder={placeholder}
type="text"
/>
</label>
))}
<label className="flex w-full flex-col items-start gap-1">
<span className="text-sm font-bold text-neutral-950 dark:text-white">
Instructions
</span>
<textarea
className="min-h-22 w-full resize-y border border-neutral-950 bg-white px-2 py-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 placeholder:text-neutral-500 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white dark:border-white dark:bg-neutral-950 dark:text-white dark:placeholder:text-neutral-400"
placeholder="Gate code, drop-off spot, or anything else the driver should know"
/>
</label>
</div>
</Drawer.Content>
<div className="relative min-h-[var(--footer-reserved-height)] shrink-0 transition-[min-height] duration-[260ms] ease-[cubic-bezier(0.32,0.72,0,1)] focus-within:min-h-[calc(var(--footer-reserved-height)+var(--drawer-keyboard-inset,0px))] motion-reduce:transition-none">
<div className="absolute right-0 bottom-0 left-0 z-1 border-t border-neutral-950 bg-white px-6 pt-2.5 pb-[calc(0.625rem+env(safe-area-inset-bottom,0px)+var(--bleed))] transition-[bottom,padding-bottom] duration-[260ms] ease-[cubic-bezier(0.32,0.72,0,1)] will-change-[bottom,padding-bottom] focus-within:fixed focus-within:z-3 focus-within:bottom-0 focus-within:pb-[calc(0.625rem+env(safe-area-inset-bottom,0px)+var(--bleed)+var(--drawer-keyboard-inset,0px))] focus-within:[transform:translate3d(0,0,0)] motion-reduce:transition-none dark:border-white dark:bg-neutral-950">
<label className="mx-auto flex w-full max-w-90 flex-col gap-1">
<span className="text-sm font-bold text-neutral-950 dark:text-white">
Delivery note
</span>
<input
className="h-10 w-full border border-neutral-950 bg-white px-2.5 text-sm font-normal text-neutral-950 placeholder:text-neutral-500 any-pointer-coarse:text-base focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:placeholder:text-neutral-400 dark:focus:outline-white"
placeholder="Add a note for the driver"
type="text"
/>
</label>
</div>
</div>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.VirtualKeyboardProvider>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--bleed: 3rem;
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
touch-action: none;
&::after {
content: '';
position: fixed;
inset-inline: 0;
bottom: 0;
height: var(--bleed);
background-color: white;
pointer-events: none;
}
@media (prefers-color-scheme: dark) {
&::after {
background-color: oklch(14.5% 0 0deg);
}
}
&[data-closed]::after {
opacity: 0;
}
/* While swiping, the popup's own bleed covers the bottom edge, so hide the
fixed fill — otherwise it paints white over the backdrop once the popup is
dragged far enough down. */
&:has([data-swiping])::after {
opacity: 0;
}
}
.Popup {
--bleed: 3rem;
--footer-reserved-height: calc(5.25rem + var(--bleed));
box-sizing: border-box;
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
width: 100%;
height: calc(100% - 1rem + var(--bleed));
max-height: calc(100% - 1rem + var(--bleed));
margin-bottom: calc(-1 * var(--bleed));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
overflow: visible;
touch-action: none;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
box-shadow 450ms cubic-bezier(0.32, 0.72, 0, 1);
transform: translateY(var(--drawer-swipe-movement-y));
will-change: transform;
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-swiping] {
-webkit-user-select: none;
user-select: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateY(calc(100% - var(--bleed) + 2px));
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Header {
position: relative;
flex-shrink: 0;
padding: 1rem 1.5rem;
border-bottom: 1px solid oklch(87% 0 0deg);
touch-action: none;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border-bottom: 1px solid oklch(37.1% 0 0deg);
}
}
.HeaderActions {
display: grid;
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
align-items: center;
gap: 0.75rem;
}
.HeaderButton {
min-width: 0;
&:first-child {
justify-self: start;
}
&:last-child {
justify-self: end;
}
}
.Handle {
position: absolute;
top: 0.5rem;
left: 50%;
width: 3rem;
height: 0.25rem;
margin: 0;
flex-shrink: 0;
background-color: oklch(87% 0 0deg);
transform: translateX(-50%);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
cursor: default;
}
.Scroll {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
padding: 1rem 1.5rem 1.5rem;
}
.Form {
display: grid;
gap: 0.75rem;
width: 100%;
max-width: 22.5rem;
margin: 0 auto;
}
.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
width: 100%;
}
.FieldLabel {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Input,
.Textarea {
box-sizing: border-box;
width: 100%;
margin: 0;
border-radius: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Input {
height: 2rem;
padding: 0 0.5rem;
}
.Textarea {
min-height: 5.5rem;
padding: 0.5rem;
resize: vertical;
}
.FooterSlot {
position: relative;
flex-shrink: 0;
min-height: var(--footer-reserved-height);
transition-duration: 260ms;
transition-property: min-height;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
&:focus-within {
min-height: calc(var(--footer-reserved-height) + var(--drawer-keyboard-inset, 0px));
}
@media (prefers-reduced-motion: reduce) {
transition-duration: 0ms;
}
}
.StickyFooter {
position: absolute;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
padding: 0.625rem 1.5rem calc(0.625rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
transition-duration: 260ms;
transition-property: bottom, padding-bottom;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
will-change: bottom, padding-bottom;
&:focus-within {
position: fixed;
z-index: 3;
bottom: 0;
padding-bottom: calc(
0.625rem + env(safe-area-inset-bottom, 0px) + var(--bleed) + var(--drawer-keyboard-inset, 0px)
);
transform: translate3d(0, 0, 0);
}
@media (prefers-color-scheme: dark) {
border-top-color: white;
background-color: oklch(14.5% 0 0deg);
}
@media (prefers-reduced-motion: reduce) {
transition-duration: 0ms;
}
}
.Composer {
display: flex;
flex-direction: column;
gap: 0.25rem;
width: 100%;
max-width: 22.5rem;
margin: 0 auto;
}
.ComposerInput {
box-sizing: border-box;
width: 100%;
height: 2.5rem;
margin: 0;
border-radius: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
padding: 0 0.625rem;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
/* index.tsx */
'use client';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
const fields = [
['Name', 'Ada Lovelace'],
['Phone', '+1 (555) 123-4567'],
['Street address', '12 Computing Way'],
['Apartment', 'Unit 4B'],
['City', 'San Francisco'],
['Postal code', '94107'],
['Delivery window', 'After 6 PM'],
['Backup contact', 'Grace Hopper'],
];
export default function ExampleDrawerVirtualKeyboardAware() {
return (
<Drawer.Root>
<Drawer.Trigger className={styles.Button}>Open keyboard-aware drawer</Drawer.Trigger>
<Drawer.VirtualKeyboardProvider>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<div className={styles.Header}>
<div className={styles.Handle} />
<div className={styles.HeaderActions}>
<Drawer.Close className={`${styles.Button} ${styles.HeaderButton}`}>
Cancel
</Drawer.Close>
<Drawer.Title className={styles.Title}>Delivery details</Drawer.Title>
<Drawer.Close className={`${styles.Button} ${styles.HeaderButton}`}>
Save
</Drawer.Close>
</div>
</div>
<Drawer.Content className={styles.Scroll}>
<div className={styles.Form}>
{fields.map(([label, placeholder]) => (
<label className={styles.Field} key={label}>
<span className={styles.FieldLabel}>{label}</span>
<input className={styles.Input} placeholder={placeholder} type="text" />
</label>
))}
<label className={styles.Field}>
<span className={styles.FieldLabel}>Instructions</span>
<textarea
className={styles.Textarea}
placeholder="Gate code, drop-off spot, or anything else the driver should know"
/>
</label>
</div>
</Drawer.Content>
<div className={styles.FooterSlot}>
<div className={styles.StickyFooter}>
<label className={styles.Composer}>
<span className={styles.FieldLabel}>Delivery note</span>
<input
className={styles.ComposerInput}
placeholder="Add a note for the driver"
type="text"
/>
</label>
</div>
</div>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.VirtualKeyboardProvider>
</Drawer.Root>
);
}
인덴트 효과 (Indent effect)
애플리케이션을 <Drawer.Provider>로 감싸고 트리 상단에 <Drawer.IndentBackground> + <Drawer.Indent>를 배치하면, 드로어가 열릴 때 배경을 축소할 수 있어요. 프로바이더 안의 어떤 <Drawer.Root>도 마운트될 때 이를 알리므로 인덴트 파트가 활성화돼요([data-active] 상태 속성을 받아요).
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawer() {
const [portalContainer, setPortalContainer] = React.useState<HTMLDivElement | null>(null);
return (
<Drawer.Provider>
<div ref={setPortalContainer} className="[--bleed:3rem] relative w-full overflow-hidden">
<Drawer.IndentBackground className="absolute inset-0 bg-black dark:bg-neutral-300" />
<Drawer.Indent className="[--indent-radius:calc(1rem*(1-var(--drawer-swipe-progress)))] [--indent-transition:calc(1-clamp(0,calc(var(--drawer-swipe-progress)*100000),1))] relative min-h-80 border border-neutral-950 bg-white p-4 text-neutral-950 [transition:transform_0.4s_cubic-bezier(0.32,0.72,0,1),border-radius_0.25s_cubic-bezier(0.32,0.72,0,1)] origin-[center_top] will-change-transform [transform:scale(1)_translateY(0)] [transition-duration:calc(400ms*var(--indent-transition)),calc(250ms*var(--indent-transition))] data-active:transform-[scale(calc(0.98+(0.02*var(--drawer-swipe-progress))))_translateY(calc(0.5rem*(1-var(--drawer-swipe-progress))))] data-active:rounded-tl-(--indent-radius) data-active:rounded-tr-(--indent-radius) dark:border-white dark:bg-neutral-950 dark:text-white">
<div className="flex min-h-80 items-center justify-center">
<Drawer.Root modal={false}>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open drawer
</Drawer.Trigger>
<Drawer.Portal container={portalContainer}>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] absolute inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="absolute inset-0 flex items-end justify-center">
<Drawer.Popup className="w-full max-h-[calc(80vh+var(--bleed))] -mb-[var(--bleed)] border-t border-neutral-950 bg-white px-6 py-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+var(--bleed))] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] [transform:translateY(var(--drawer-swipe-movement-y))] data-swiping:select-none data-ending-style:[transform:translateY(calc(100%-var(--bleed)+2px))] data-starting-style:[transform:translateY(calc(100%-var(--bleed)+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<div className="mx-auto mb-4 h-1 w-12 bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Content className="mx-auto w-full max-w-[32rem]">
<Drawer.Title className="mt-0 mb-1 text-base font-bold text-center">
Notifications
</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400">
You are all caught up. Good job!
</Drawer.Description>
<div className="flex justify-center gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
</Drawer.Indent>
</div>
</Drawer.Provider>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Root {
--bleed: 3rem;
position: relative;
width: 100%;
overflow: hidden;
}
.Indent {
--indent-radius: calc(1rem * (1 - var(--drawer-swipe-progress)));
--indent-transition: calc(1 - clamp(0, calc(var(--drawer-swipe-progress) * 100000), 1));
position: relative;
min-height: 20rem;
transition:
transform 0.4s cubic-bezier(0.32, 0.72, 0, 1),
border-radius 0.25s cubic-bezier(0.32, 0.72, 0, 1);
transform-origin: center top;
will-change: transform;
border: 1px solid oklch(14.5% 0 0deg);
contain: layout;
padding: 1rem;
color: oklch(14.5% 0 0deg);
background-color: white;
transition-duration:
calc(400ms * var(--indent-transition)), calc(250ms * var(--indent-transition));
@media (prefers-color-scheme: dark) {
border: 1px solid white;
color: white;
background-color: oklch(14.5% 0 0deg);
}
&[data-active] {
transform: scale(calc(0.98 + (0.02 * var(--drawer-swipe-progress))))
translateY(calc(0.5rem * (1 - var(--drawer-swipe-progress))));
border-top-left-radius: var(--indent-radius);
border-top-right-radius: var(--indent-radius);
}
}
.Center {
min-height: 20rem;
display: flex;
align-items: center;
justify-content: center;
}
.IndentBackground {
position: absolute;
inset: 0;
background-color: black;
@media (prefers-color-scheme: dark) {
background-color: oklch(87% 0 0deg);
}
}
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: absolute;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: absolute;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
box-sizing: border-box;
width: 100%;
max-height: calc(80vh + var(--bleed));
margin-bottom: calc(-1 * var(--bleed));
padding: 1rem 1.5rem 1.5rem;
padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateY(var(--drawer-swipe-movement-y));
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateY(calc(100% - var(--bleed) + 2px));
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 1rem;
background-color: oklch(87% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: center;
gap: 0.75rem;
}
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawer() {
const [portalContainer, setPortalContainer] = React.useState<HTMLDivElement | null>(null);
return (
<Drawer.Provider>
<div className={styles.Root} ref={setPortalContainer}>
<Drawer.IndentBackground className={styles.IndentBackground} />
<Drawer.Indent className={styles.Indent}>
<div className={styles.Center}>
<Drawer.Root modal={false}>
<Drawer.Trigger className={styles.Button}>Open drawer</Drawer.Trigger>
<Drawer.Portal container={portalContainer}>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<div className={styles.Handle} />
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Notifications</Drawer.Title>
<Drawer.Description className={styles.Description}>
You are all caught up. Good job!
</Drawer.Description>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
</Drawer.Indent>
</div>
</Drawer.Provider>
);
}
비모달 (Non-modal)
modal={false}를 설정해 포커스 트래핑을 해제하고, disablePointerDismissal로 바깥 클릭에도 드로어가 닫히지 않게 할 수 있어요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawer() {
return (
<Drawer.Root swipeDirection="right" modal={false} disablePointerDismissal>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open non-modal drawer
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport className="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] fixed inset-0 flex items-stretch justify-end p-(--viewport-padding) pointer-events-none">
<Drawer.Popup className="[--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] pointer-events-auto h-full w-[calc(20rem+3rem)] max-w-[calc(100vw-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-[transform,box-shadow] duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-ending-style:shadow-[0.25rem_0.25rem_0] data-ending-style:shadow-black/0 data-ending-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-starting-style:shadow-[0.25rem_0.25rem_0] data-starting-style:shadow-black/0 data-starting-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<Drawer.Content className="mx-auto w-full max-w-[32rem]">
<Drawer.Title className="mb-1 text-base font-bold">Non-modal drawer</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 dark:text-neutral-400">
This drawer does not trap focus and ignores outside clicks. Use the close button or
swipe to dismiss it.
</Drawer.Description>
<div className="flex justify-end gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: fixed;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
pointer-events: none;
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: calc(20rem + var(--bleed));
max-width: calc(100vw - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
pointer-events: auto;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
box-shadow 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}
/* index.tsx */
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawer() {
return (
<Drawer.Root swipeDirection="right" modal={false} disablePointerDismissal>
<Drawer.Trigger className={styles.Button}>Open non-modal drawer</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Non-modal drawer</Drawer.Title>
<Drawer.Description className={styles.Description}>
This drawer does not trap focus and ignores outside clicks. Use the close button or
swipe to dismiss it.
</Drawer.Description>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
모바일 내비게이션 (Mobile navigation)
Drawer 파트를 사용해 전체 화면 모바일 내비게이션 시트를 만들 수 있어요. 위에서 아래로 튕겨서 닫는 제스처도 포함돼요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
import { ScrollArea } from '@base-ui/react/scroll-area';
const ITEMS = [
{ href: '/react/overview', label: 'Overview' },
{ href: '/react/components', label: 'Components' },
{ href: '/react/utils', label: 'Utilities' },
{ href: '/react/overview/releases', label: 'Releases' },
] as const;
const LONG_LIST = [
{ href: '/react/components/accordion', label: 'Accordion' },
{ href: '/react/components/alert-dialog', label: 'Alert Dialog' },
{ href: '/react/components/autocomplete', label: 'Autocomplete' },
{ href: '/react/components/avatar', label: 'Avatar' },
{ href: '/react/components/button', label: 'Button' },
{ href: '/react/components/checkbox', label: 'Checkbox' },
{ href: '/react/components/checkbox-group', label: 'Checkbox Group' },
{ href: '/react/components/collapsible', label: 'Collapsible' },
{ href: '/react/components/combobox', label: 'Combobox' },
{ href: '/react/components/context-menu', label: 'Context Menu' },
{ href: '/react/components/dialog', label: 'Dialog' },
{ href: '/react/components/drawer', label: 'Drawer' },
{ href: '/react/components/field', label: 'Field' },
{ href: '/react/components/fieldset', label: 'Fieldset' },
{ href: '/react/components/form', label: 'Form' },
{ href: '/react/components/input', label: 'Input' },
{ href: '/react/components/menu', label: 'Menu' },
{ href: '/react/components/menubar', label: 'Menubar' },
{ href: '/react/components/meter', label: 'Meter' },
{ href: '/react/components/navigation-menu', label: 'Navigation Menu' },
{ href: '/react/components/number-field', label: 'Number Field' },
{ href: '/react/components/otp-field', label: 'OTP Field' },
{ href: '/react/components/popover', label: 'Popover' },
{ href: '/react/components/preview-card', label: 'Preview Card' },
{ href: '/react/components/progress', label: 'Progress' },
{ href: '/react/components/radio-group', label: 'Radio Group' },
{ href: '/react/components/scroll-area', label: 'Scroll Area' },
{ href: '/react/components/select', label: 'Select' },
{ href: '/react/components/separator', label: 'Separator' },
{ href: '/react/components/slider', label: 'Slider' },
{ href: '/react/components/switch', label: 'Switch' },
{ href: '/react/components/tabs', label: 'Tabs' },
{ href: '/react/components/toast', label: 'Toast' },
{ href: '/react/components/toggle', label: 'Toggle' },
{ href: '/react/components/toggle-group', label: 'Toggle Group' },
{ href: '/react/components/toolbar', label: 'Toolbar' },
{ href: '/react/components/tooltip', label: 'Tooltip' },
] as const;
export default function ExampleDrawerMobileNav() {
return (
<Drawer.Root>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open mobile menu
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:1] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-[linear-gradient(to_bottom,rgb(0_0_0/5%)_0,rgb(0_0_0/10%)_50%)] opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-600 ease-[var(--ease-out-fast)] supports-[-webkit-touch-callout:none]:absolute data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-350 data-ending-style:ease-[cubic-bezier(0.375,0.015,0.545,0.455)]" />
<Drawer.Viewport className="group fixed inset-0">
<ScrollArea.Root
style={{ position: undefined }}
className="h-full overscroll-contain transition-transform duration-600 ease-[cubic-bezier(0.45,1.005,0,1.005)] group-data-starting-style:translate-y-[100dvh] group-data-ending-style:pointer-events-none"
>
<ScrollArea.Viewport className="h-full overscroll-contain touch-auto">
<ScrollArea.Content className="flex min-h-full items-end justify-center pt-8 min-[42rem]:px-16 min-[42rem]:py-16">
<Drawer.Popup className="group w-full max-w-[42rem] outline-none transition-transform duration-600 ease-[cubic-bezier(0.45,1.005,0,1.005)] [transform:translateY(var(--drawer-swipe-movement-y))] data-swiping:select-none data-ending-style:[transform:translateY(calc(max(100dvh,100%)+2px))] data-ending-style:duration-350 data-ending-style:ease-[cubic-bezier(0.375,0.015,0.545,0.455)] motion-reduce:transition-none">
<nav
aria-label="Navigation"
className="relative flex flex-col border-t border-neutral-950 bg-white px-6 pt-4 pb-6 text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 transition-shadow duration-350 ease-[cubic-bezier(0.375,0.015,0.545,0.455)] group-data-ending-style:shadow-[0.25rem_0.25rem_0] group-data-ending-style:shadow-black/0 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none min-[42rem]:border"
>
<div className="grid grid-cols-[1fr_auto_1fr] items-start">
<div aria-hidden className="h-9 w-9" />
<div className="h-1 w-12 justify-self-center bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Close
aria-label="Close menu"
className="flex h-8 w-8 items-center justify-center justify-self-end border-0 bg-transparent text-neutral-950 hover:bg-neutral-100 active:bg-neutral-200 dark:text-white dark:hover:bg-neutral-800 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
<XIcon />
</Drawer.Close>
</div>
<Drawer.Content className="w-full">
<Drawer.Title className="m-0 mb-1 text-base font-bold">Menu</Drawer.Title>
<Drawer.Description className="m-0 mb-5 text-sm text-neutral-600 dark:text-neutral-400">
Scroll the long list. Flick down from the top to dismiss.
</Drawer.Description>
<div className="pb-8">
<ul className="grid list-none gap-1 p-0 m-0">
{ITEMS.map((item) => (
<li key={item.label} className="flex">
<a
className="flex h-12 w-full items-center border border-neutral-950 bg-white px-4 text-sm text-neutral-950 no-underline hover:bg-neutral-100 active:bg-neutral-200 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:bg-neutral-800 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
href={item.href}
>
{item.label}
</a>
</li>
))}
</ul>
<ul
aria-label="Component links"
className="mt-6 grid list-none gap-1 p-0 m-0"
>
{LONG_LIST.map((item) => (
<li key={item.label} className="flex">
<a
className="flex h-12 w-full items-center border border-neutral-950 bg-white px-4 text-sm text-neutral-950 no-underline hover:bg-neutral-100 active:bg-neutral-200 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:bg-neutral-800 dark:active:bg-neutral-700 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
href={item.href}
>
{item.label}
</a>
</li>
))}
</ul>
</div>
</Drawer.Content>
</nav>
</Drawer.Popup>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar className="pointer-events-none absolute m-px flex w-4 justify-center bg-black/12 dark:bg-white/12 opacity-0 transition-opacity duration-250 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-75 data-scrolling:delay-[0ms] hover:pointer-events-auto hover:opacity-100 hover:duration-75 hover:delay-[0ms] data-ending-style:opacity-0 data-ending-style:duration-250">
<ScrollArea.Thumb className="w-full bg-neutral-950 dark:bg-white" />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
function XIcon(props: React.ComponentProps<'svg'>) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeLinecap="square"
strokeLinejoin="round"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="m2.5 2.5 11 11m-11 0 11-11" />
</svg>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 1;
position: fixed;
inset: 0;
min-height: 100dvh;
transition-duration: 600ms;
transition-property: opacity;
transition-timing-function: var(--ease-out-fast);
background-image: linear-gradient(to bottom, rgb(0 0 0 / 5%) 0, rgb(0 0 0 / 10%) 50%);
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-ending-style] {
transition-duration: 350ms;
transition-timing-function: cubic-bezier(0.375, 0.015, 0.545, 0.455);
}
}
.Viewport {
position: fixed;
inset: 0;
}
.ScrollAreaRoot {
box-sizing: border-box;
height: 100%;
overscroll-behavior: contain;
transition: transform 600ms cubic-bezier(0.45, 1.005, 0, 1.005);
[data-ending-style] & {
pointer-events: none;
}
[data-starting-style] & {
transform: translateY(100dvh);
}
}
.ScrollAreaViewport {
box-sizing: border-box;
height: 100%;
overscroll-behavior: contain;
touch-action: auto;
}
.ScrollContent {
display: flex;
align-items: flex-end;
justify-content: center;
min-height: 100%;
padding-top: 2rem;
@media (min-width: 42rem) {
padding-top: 4rem;
padding-bottom: 4rem;
padding-inline: 4rem;
}
}
.Content {
width: 100%;
}
.Popup {
box-sizing: border-box;
width: 100%;
max-width: 42rem;
margin: 0 auto;
outline: 0;
transition: transform 600ms cubic-bezier(0.45, 1.005, 0, 1.005);
will-change: transform;
transform: translateY(var(--drawer-swipe-movement-y));
@media (prefers-reduced-motion: reduce) {
transition: none;
}
&[data-ending-style] {
transform: translateY(calc(max(100dvh, 100%) + 2px));
transition-duration: 350ms;
transition-timing-function: cubic-bezier(0.375, 0.015, 0.545, 0.455);
}
}
.Panel {
position: relative;
display: flex;
flex-direction: column;
padding: 1rem 1.5rem 1.5rem;
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
color: oklch(14.5% 0 0deg);
transition: box-shadow 350ms cubic-bezier(0.375, 0.015, 0.545, 0.455);
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
}
@media (prefers-color-scheme: dark) {
.Panel {
box-shadow: none;
}
}
.Popup[data-ending-style] .Panel {
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
.Header {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: start;
}
.HeaderSpacer {
width: 2.25rem;
height: 2.25rem;
}
@media (min-width: 42rem) {
.Panel {
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Handle {
width: 3rem;
height: 0.25rem;
background-color: oklch(87% 0 0deg);
justify-self: center;
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.CloseButton {
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
border: 0;
background-color: transparent;
color: oklch(14.5% 0 0deg);
justify-self: end;
@media (prefers-color-scheme: dark) {
color: white;
}
@media (hover: hover) {
&:hover {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Title {
margin: 0 0 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.25rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.List {
list-style: none;
padding: 0;
margin: 0;
display: grid;
gap: 0.25rem;
}
.LongList {
list-style: none;
padding: 0;
margin: 1.5rem 0 0;
display: grid;
gap: 0.25rem;
}
.Item {
display: flex;
}
.Link {
box-sizing: border-box;
display: flex;
align-items: center;
width: 100%;
height: 3rem;
padding: 0 1rem;
border: 1px solid oklch(14.5% 0 0deg);
font-size: 0.875rem;
line-height: 1.25rem;
color: inherit;
text-decoration: none;
background-color: white;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
}
@media (hover: hover) {
&:hover {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Scrollbar {
position: absolute;
display: flex;
width: 1rem;
margin: 1px;
justify-content: center;
background-color: rgb(0 0 0 / 12%);
opacity: 0;
transition: opacity 250ms;
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: rgb(255 255 255 / 12%);
}
&:hover,
&[data-scrolling] {
opacity: 1;
transition-duration: 75ms;
transition-delay: 0ms;
pointer-events: auto;
}
[data-ending-style] & {
transition-duration: 250ms;
opacity: 0;
}
}
.ScrollbarThumb {
width: 100%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
import { ScrollArea } from '@base-ui/react/scroll-area';
import styles from './index.module.css';
const ITEMS = [
{ href: '/react/overview', label: 'Overview' },
{ href: '/react/components', label: 'Components' },
{ href: '/react/utils', label: 'Utilities' },
{ href: '/react/overview/releases', label: 'Releases' },
] as const;
const LONG_LIST = [
{ href: '/react/components/accordion', label: 'Accordion' },
{ href: '/react/components/alert-dialog', label: 'Alert Dialog' },
{ href: '/react/components/autocomplete', label: 'Autocomplete' },
{ href: '/react/components/avatar', label: 'Avatar' },
{ href: '/react/components/button', label: 'Button' },
{ href: '/react/components/checkbox', label: 'Checkbox' },
{ href: '/react/components/checkbox-group', label: 'Checkbox Group' },
{ href: '/react/components/collapsible', label: 'Collapsible' },
{ href: '/react/components/combobox', label: 'Combobox' },
{ href: '/react/components/context-menu', label: 'Context Menu' },
{ href: '/react/components/dialog', label: 'Dialog' },
{ href: '/react/components/drawer', label: 'Drawer' },
{ href: '/react/components/field', label: 'Field' },
{ href: '/react/components/fieldset', label: 'Fieldset' },
{ href: '/react/components/form', label: 'Form' },
{ href: '/react/components/input', label: 'Input' },
{ href: '/react/components/menu', label: 'Menu' },
{ href: '/react/components/menubar', label: 'Menubar' },
{ href: '/react/components/meter', label: 'Meter' },
{ href: '/react/components/navigation-menu', label: 'Navigation Menu' },
{ href: '/react/components/number-field', label: 'Number Field' },
{ href: '/react/components/otp-field', label: 'OTP Field' },
{ href: '/react/components/popover', label: 'Popover' },
{ href: '/react/components/preview-card', label: 'Preview Card' },
{ href: '/react/components/progress', label: 'Progress' },
{ href: '/react/components/radio-group', label: 'Radio Group' },
{ href: '/react/components/scroll-area', label: 'Scroll Area' },
{ href: '/react/components/select', label: 'Select' },
{ href: '/react/components/separator', label: 'Separator' },
{ href: '/react/components/slider', label: 'Slider' },
{ href: '/react/components/switch', label: 'Switch' },
{ href: '/react/components/tabs', label: 'Tabs' },
{ href: '/react/components/toast', label: 'Toast' },
{ href: '/react/components/toggle', label: 'Toggle' },
{ href: '/react/components/toggle-group', label: 'Toggle Group' },
{ href: '/react/components/toolbar', label: 'Toolbar' },
{ href: '/react/components/tooltip', label: 'Tooltip' },
] as const;
export default function ExampleDrawerMobileNav() {
return (
<Drawer.Root>
<Drawer.Trigger className={styles.Button}>Open mobile menu</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<ScrollArea.Root style={{ position: undefined }} className={styles.ScrollAreaRoot}>
<ScrollArea.Viewport className={styles.ScrollAreaViewport}>
<ScrollArea.Content className={styles.ScrollContent}>
<Drawer.Popup className={styles.Popup}>
<nav aria-label="Navigation" className={styles.Panel}>
<div className={styles.Header}>
<div aria-hidden className={styles.HeaderSpacer} />
<div className={styles.Handle} />
<Drawer.Close aria-label="Close menu" className={styles.CloseButton}>
<XIcon />
</Drawer.Close>
</div>
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Menu</Drawer.Title>
<Drawer.Description className={styles.Description}>
Scroll the long list. Flick down from the top to dismiss.
</Drawer.Description>
<div className={styles.ScrollArea}>
<ul className={styles.List}>
{ITEMS.map((item) => (
<li key={item.label} className={styles.Item}>
<a className={styles.Link} href={item.href}>
{item.label}
</a>
</li>
))}
</ul>
<ul className={styles.LongList} aria-label="Component links">
{LONG_LIST.map((item) => (
<li key={item.label} className={styles.Item}>
<a className={styles.Link} href={item.href}>
{item.label}
</a>
</li>
))}
</ul>
</div>
</Drawer.Content>
</nav>
</Drawer.Popup>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar className={styles.Scrollbar}>
<ScrollArea.Thumb className={styles.ScrollbarThumb} />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
function XIcon(props: React.ComponentProps<'svg'>) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeLinecap="square"
strokeLinejoin="round"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="m2.5 2.5 11 11m-11 0 11-11" />
</svg>
);
}
스와이프로 열기 (Swipe to open)
viewport 가장자리를 따라 <Drawer.SwipeArea>를 배치해 스와이프로 여는 제스처를 활성화할 수 있어요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawerSwipeArea() {
const [portalContainer, setPortalContainer] = React.useState<HTMLDivElement | null>(null);
return (
<div
ref={setPortalContainer}
className="relative min-h-80 w-full overflow-hidden border border-neutral-950 bg-white text-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white"
>
<Drawer.Root swipeDirection="right" modal={false}>
<Drawer.SwipeArea className="absolute inset-y-0 right-0 z-[1] w-10 border-l-2 border-dashed border-blue-800 bg-blue-800/10 dark:border-blue-500 dark:bg-blue-500/10">
<span className="pointer-events-none absolute right-0 top-1/2 z-0 mr-2 -translate-y-1/2 -rotate-90 origin-center whitespace-nowrap text-xs font-bold tracking-[0.12em] text-blue-800 uppercase dark:text-blue-500">
Swipe here
</span>
</Drawer.SwipeArea>
<div className="flex min-h-80 flex-col items-center justify-center gap-3 p-4 text-center">
<p className="text-sm text-neutral-600 text-center dark:text-neutral-400 pr-12">
Swipe from the right edge to open the drawer.
</p>
</div>
<Drawer.Portal container={portalContainer}>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] absolute inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] absolute inset-0 z-20 flex items-stretch justify-end p-(--viewport-padding)">
<Drawer.Popup className="[--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] h-full w-[calc(20rem+3rem)] max-w-[calc(100vw-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-ending-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-starting-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<Drawer.Content className="mx-auto w-full max-w-[32rem]">
<Drawer.Title className="mb-1 text-base font-bold">Library</Drawer.Title>
<Drawer.Description className="mb-6 text-sm text-neutral-600 dark:text-neutral-400">
Swipe from the edge whenever you want to jump back into your playlists.
</Drawer.Description>
<div className="flex justify-end gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Close
</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Root {
box-sizing: border-box;
position: relative;
width: 100%;
min-height: 20rem;
overflow: hidden;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
}
.Center {
box-sizing: border-box;
min-height: 20rem;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
}
.Instructions {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
text-align: center;
}
.Hint {
box-sizing: border-box;
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
padding-right: 3rem;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.SwipeArea {
box-sizing: border-box;
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 2.5rem;
z-index: 1;
border-left: 2px dashed oklch(42.4% 0.199 265.638deg);
background-color: color-mix(in oklch, oklch(42.4% 0.199 265.638deg), transparent 90%);
@media (prefers-color-scheme: dark) {
border-left-color: oklch(62.3% 0.214 259.815deg);
background-color: color-mix(in oklch, oklch(62.3% 0.214 259.815deg), transparent 90%);
}
}
.SwipeLabel {
position: absolute;
right: 0;
top: 50%;
margin-right: 0.5rem;
transform: translateY(-50%) rotate(-90deg);
transform-origin: center;
z-index: 0;
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
color: oklch(42.4% 0.199 265.638deg);
white-space: nowrap;
pointer-events: none;
@media (prefers-color-scheme: dark) {
color: oklch(62.3% 0.214 259.815deg);
}
}
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: absolute;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: absolute;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
z-index: 2;
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: calc(20rem + var(--bleed));
max-width: calc(100vw - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
touch-action: auto;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawerSwipeArea() {
const [portalContainer, setPortalContainer] = React.useState<HTMLDivElement | null>(null);
return (
<div className={styles.Root} ref={setPortalContainer}>
<Drawer.Root swipeDirection="right" modal={false}>
<Drawer.SwipeArea className={styles.SwipeArea}>
<span className={styles.SwipeLabel}>Swipe here</span>
</Drawer.SwipeArea>
<div className={styles.Center}>
<div className={styles.Instructions}>
<p className={styles.Hint}>Swipe from the right edge to open the drawer.</p>
</div>
</div>
<Drawer.Portal container={portalContainer}>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<Drawer.Content className={styles.Content}>
<Drawer.Title className={styles.Title}>Library</Drawer.Title>
<Drawer.Description className={styles.Description}>
Swipe from the edge whenever you want to jump back into your playlists.
</Drawer.Description>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
);
}
닫기 확인 (Close confirmation)
이 예시는 드로어에 입력된 텍스트가 버려질 때 열리는 중첩 확인 다이얼로그를 보여줘요.
이를 구현하려면 드로어와 확인 다이얼로그 모두 제어 상태여야 해요. textarea에 텍스트가 있는 동안 드로어의 onOpenChange 콜백이 닫기 요청을 받으면 확인 다이얼로그를 열면 돼요. 이렇게 하면 사용자가 백드롭을 클릭하거나 Esc 키를 누르거나 닫기 버튼을 클릭하거나 스와이프 제스처로 드로어를 닫을 때 확인이 자동으로 표시돼요.
확인 프롬프트가 표시되는 동안 드로어가 닫히지 않게 하려면 onOpenChange에서 eventDetails.cancel()을 사용하세요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import * as React from 'react';
import { AlertDialog } from '@base-ui/react/alert-dialog';
import { Drawer } from '@base-ui/react/drawer';
export default function ExampleDrawer() {
const [drawerOpen, setDrawerOpen] = React.useState(false);
const [confirmationOpen, setConfirmationOpen] = React.useState(false);
const [textareaValue, setTextareaValue] = React.useState('');
const titleId = React.useId();
return (
<Drawer.Root
swipeDirection="right"
open={drawerOpen}
onOpenChange={(open, eventDetails) => {
// Show the close confirmation if there’s text in the textarea
if (!open && textareaValue) {
eventDetails.cancel();
setConfirmationOpen(true);
return;
}
if (!open) {
// Reset the textarea value
setTextareaValue('');
}
setDrawerOpen(open);
}}
>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Tweet
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.2] dark:[--backdrop-opacity:0.7] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute" />
<Drawer.Viewport className="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] fixed inset-0 flex items-stretch justify-end p-(--viewport-padding)">
<Drawer.Popup
className={`relative [--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] h-full w-[calc(20rem+3rem)] max-w-[calc(100vw-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-ending-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-starting-style:[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none after:absolute after:inset-0 after:bg-black/5 after:opacity-0 after:transition-opacity after:duration-100 after:ease-out after:pointer-events-none ${
confirmationOpen ? 'after:opacity-100' : ''
}`}
>
<Drawer.Content className="mx-auto flex flex-col gap-4 w-full max-w-[32rem]">
<Drawer.Title id={titleId} className="text-base font-bold">
New tweet
</Drawer.Title>
<form
className="flex flex-col gap-4"
onSubmit={(event) => {
event.preventDefault();
// Close the drawer when submitting
setTextareaValue('');
setDrawerOpen(false);
}}
>
<textarea
aria-labelledby={titleId}
required
className="min-h-32 w-full border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 p-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:text-white placeholder:text-neutral-500 dark:placeholder:text-neutral-400 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white"
placeholder="What’s on your mind?"
value={textareaValue}
onChange={(event) => setTextareaValue(event.target.value)}
/>
<div className="flex justify-end gap-3">
<Drawer.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Cancel
</Drawer.Close>
<button
type="submit"
className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
Tweet
</button>
</div>
</form>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
{/* Confirmation dialog */}
<AlertDialog.Root open={confirmationOpen} onOpenChange={setConfirmationOpen}>
<AlertDialog.Portal>
<AlertDialog.Popup className="fixed top-1/2 left-1/2 -mt-8 flex w-96 max-w-[calc(100vw-3rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 bg-white dark:bg-neutral-950 p-4 text-neutral-950 dark:text-white border border-neutral-950 dark:border-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:shadow-none transition-[translate,scale,opacity] duration-100 ease-out data-ending-style:translate-y-[calc(-50%+0.25rem)] data-ending-style:scale-[0.96] data-ending-style:opacity-0 data-starting-style:translate-y-[calc(-50%+0.25rem)] data-starting-style:scale-[0.96] data-starting-style:opacity-0">
<div className="flex flex-col gap-1">
<AlertDialog.Title className="text-base font-bold">Discard tweet?</AlertDialog.Title>
<AlertDialog.Description className="text-sm text-neutral-600 dark:text-neutral-400">
Your tweet will be lost.
</AlertDialog.Description>
</div>
<div className="flex justify-end gap-3">
<AlertDialog.Close className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Go back
</AlertDialog.Close>
<button
type="button"
className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
onClick={() => {
setConfirmationOpen(false);
setTextareaValue('');
setDrawerOpen(false);
}}
>
Discard
</button>
</div>
</AlertDialog.Popup>
</AlertDialog.Portal>
</AlertDialog.Root>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: fixed;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
position: relative;
width: calc(20rem + var(--bleed));
max-width: calc(100vw - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
&::after {
content: '';
position: absolute;
inset: 0;
background-color: rgb(0 0 0 / 0.05);
opacity: 0;
pointer-events: none;
transition: opacity 100ms ease-out;
}
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.PopupDimmed::after {
opacity: 1;
}
.Content {
display: flex;
flex-direction: column;
gap: 1rem;
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Intro {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.TextareaContainer {
display: flex;
flex-direction: column;
gap: 1rem;
}
.Textarea {
box-sizing: border-box;
padding: 0.5rem;
margin: 0;
border-radius: 0;
border: 1px solid oklch(14.5% 0 0deg);
width: 100%;
min-height: 8rem;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Actions {
display: flex;
justify-content: end;
gap: 0.75rem;
}
.AlertPopup {
box-sizing: border-box;
position: fixed;
top: 50%;
left: 50%;
display: flex;
flex-direction: column;
gap: 1rem;
width: 24rem;
max-width: calc(100vw - 3rem);
margin-top: -2rem;
padding: 1rem;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
translate: -50% -50%;
transition:
translate 100ms ease-out,
scale 100ms ease-out,
opacity 100ms ease-out;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
translate: -50% calc(-50% + 0.25rem);
scale: 0.96;
}
}
/* index.tsx */
'use client';
import * as React from 'react';
import { AlertDialog } from '@base-ui/react/alert-dialog';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
export default function ExampleDrawer() {
const [drawerOpen, setDrawerOpen] = React.useState(false);
const [confirmationOpen, setConfirmationOpen] = React.useState(false);
const [textareaValue, setTextareaValue] = React.useState('');
const titleId = React.useId();
return (
<Drawer.Root
swipeDirection="right"
open={drawerOpen}
onOpenChange={(open, eventDetails) => {
// Show the close confirmation if there’s text in the textarea
if (!open && textareaValue) {
eventDetails.cancel();
setConfirmationOpen(true);
return;
}
if (!open) {
// Reset the textarea value
setTextareaValue('');
}
setDrawerOpen(open);
}}
>
<Drawer.Trigger className={styles.Button}>Tweet</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup
className={`${styles.Popup} ${confirmationOpen ? styles.PopupDimmed : ''}`.trim()}
>
<Drawer.Content className={styles.Content}>
<Drawer.Title id={titleId} className={styles.Title}>
New tweet
</Drawer.Title>
<form
className={styles.TextareaContainer}
onSubmit={(event) => {
event.preventDefault();
// Close the drawer when submitting
setTextareaValue('');
setDrawerOpen(false);
}}
>
<textarea
aria-labelledby={titleId}
required
className={styles.Textarea}
placeholder="What’s on your mind?"
value={textareaValue}
onChange={(event) => setTextareaValue(event.target.value)}
/>
<div className={styles.Actions}>
<Drawer.Close className={styles.Button}>Cancel</Drawer.Close>
<button type="submit" className={styles.Button}>
Tweet
</button>
</div>
</form>
</Drawer.Content>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
{/* Confirmation dialog */}
<AlertDialog.Root open={confirmationOpen} onOpenChange={setConfirmationOpen}>
<AlertDialog.Portal>
<AlertDialog.Popup className={styles.AlertPopup}>
<div className={styles.Intro}>
<AlertDialog.Title className={styles.Title}>Discard tweet?</AlertDialog.Title>
<AlertDialog.Description className={styles.Description}>
Your tweet will be lost.
</AlertDialog.Description>
</div>
<div className={styles.Actions}>
<AlertDialog.Close className={styles.Button}>Go back</AlertDialog.Close>
<button
type="button"
className={styles.Button}
onClick={() => {
setConfirmationOpen(false);
setTextareaValue('');
setDrawerOpen(false);
}}
>
Discard
</button>
</div>
</AlertDialog.Popup>
</AlertDialog.Portal>
</AlertDialog.Root>
</Drawer.Root>
);
}
별도 파괴적 액션이 있는 액션 시트
이 데모는 그룹화된 액션 목록과 별도의 파괴적 액션 버튼을 가진 액션 시트를 만든 예시예요.
데모 (Demo)
Tailwind
이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
const ACTIONS = ['Unfollow', 'Mute', 'Add to Favourites', 'Add to Close Friends', 'Restrict'];
export default function ExampleDrawerUncontained() {
const [open, setOpen] = React.useState(false);
return (
<Drawer.Root open={open} onOpenChange={setOpen}>
<Drawer.Trigger className="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-data-disabled:bg-neutral-100 active:not-data-disabled:bg-neutral-200 data-disabled:border-neutral-500 data-disabled:text-neutral-500 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-data-disabled:bg-neutral-800 dark:active:not-data-disabled:bg-neutral-700 dark:data-disabled:border-neutral-400 dark:data-disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white">
Open action sheet
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className="[--backdrop-opacity:0.4] fixed inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)] supports-[-webkit-touch-callout:none]:absolute dark:[--backdrop-opacity:0.7]" />
<Drawer.Viewport className="fixed inset-0 flex items-end justify-center">
<Drawer.Popup className="pointer-events-none flex w-full max-w-[20rem] flex-col gap-3 px-4 pb-[calc(1rem+env(safe-area-inset-bottom,0px))] outline-none focus-visible:outline-none [transform:translateY(var(--drawer-swipe-movement-y))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-starting-style:[transform:translateY(calc(100%+1rem+2px))] data-ending-style:[transform:translateY(calc(100%+1rem+2px))] data-ending-style:duration-[calc(var(--drawer-swipe-strength)*400ms)]">
<Drawer.Content className="pointer-events-auto overflow-hidden border border-neutral-950 bg-white text-neutral-950 shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none">
<Drawer.Title className="sr-only">Profile actions</Drawer.Title>
<Drawer.Description className="sr-only">
Choose an action for this user.
</Drawer.Description>
<ul
className="m-0 list-none divide-y divide-neutral-950 p-0 dark:divide-white"
aria-label="Profile actions"
>
{ACTIONS.map((action, index) => (
<li key={action}>
{index === 0 && (
<Drawer.Close className="sr-only">Close action sheet</Drawer.Close>
)}
<button
type="button"
className="h-10 w-full border-0 bg-transparent px-5 text-center text-sm text-neutral-950 select-none hover:bg-neutral-100 active:bg-neutral-200 focus-visible:bg-neutral-100 focus-visible:outline-none dark:text-white dark:hover:bg-neutral-800 dark:active:bg-neutral-700 dark:focus-visible:bg-neutral-800"
onClick={() => setOpen(false)}
>
{action}
</button>
</li>
))}
</ul>
</Drawer.Content>
<div className="pointer-events-auto overflow-hidden border border-neutral-950 bg-white shadow-[0.25rem_0.25rem_0] shadow-black/12 dark:border-white dark:bg-neutral-950 dark:shadow-none">
<button
type="button"
className="h-10 w-full border-0 bg-transparent px-5 text-center text-sm text-red-700 select-none dark:text-red-400 hover:bg-neutral-100 active:bg-neutral-200 focus-visible:bg-neutral-100 focus-visible:outline-none dark:hover:bg-neutral-800 dark:active:bg-neutral-700 dark:focus-visible:bg-neutral-800"
onClick={() => setOpen(false)}
>
Block User
</button>
</div>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
CSS Modules
이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.
/* index.module.css */
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not([data-disabled]) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not([data-disabled]) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&[data-disabled] {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.4;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&[data-starting-style],
&[data-ending-style] {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
box-sizing: border-box;
width: 100%;
max-width: 20rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
padding: 0 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
outline: 0;
pointer-events: none;
transform: translateY(var(--drawer-swipe-movement-y));
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
&[data-starting-style],
&[data-ending-style] {
transform: translateY(calc(100% + 1rem + 2px));
}
&[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Surface {
pointer-events: auto;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow: hidden;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
}
.Actions {
list-style: none;
margin: 0;
padding: 0;
}
.Action:not(:first-child) {
border-top: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
}
}
.ActionButton {
box-sizing: border-box;
width: 100%;
height: 2.5rem;
margin: 0;
padding: 0 1.25rem;
border: 0;
background-color: transparent;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
text-align: center;
color: inherit;
-webkit-user-select: none;
user-select: none;
@media (hover: hover) {
&:hover {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:focus-visible {
outline: 0;
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
.DangerSurface {
pointer-events: auto;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow: hidden;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
box-shadow: none;
}
}
.DangerButton {
box-sizing: border-box;
width: 100%;
height: 2.5rem;
margin: 0;
padding: 0 1.25rem;
border: 0;
background-color: transparent;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
text-align: center;
color: oklch(50.5% 0.213 27.518deg);
-webkit-user-select: none;
user-select: none;
@media (hover: hover) {
&:hover {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:focus-visible {
outline: 0;
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
.VisuallyHidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
border: 0;
}
/* index.tsx */
'use client';
import * as React from 'react';
import { Drawer } from '@base-ui/react/drawer';
import styles from './index.module.css';
const ACTIONS = ['Unfollow', 'Mute', 'Add to Favourites', 'Add to Close Friends', 'Restrict'];
export default function ExampleDrawerUncontained() {
const [open, setOpen] = React.useState(false);
return (
<Drawer.Root open={open} onOpenChange={setOpen}>
<Drawer.Trigger className={styles.Button}>Open action sheet</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Backdrop className={styles.Backdrop} />
<Drawer.Viewport className={styles.Viewport}>
<Drawer.Popup className={styles.Popup}>
<Drawer.Content className={styles.Surface}>
<Drawer.Title className={styles.VisuallyHidden}>Profile actions</Drawer.Title>
<Drawer.Description className={styles.VisuallyHidden}>
Choose an action for this user.
</Drawer.Description>
<ul className={styles.Actions} aria-label="Profile actions">
{ACTIONS.map((action, index) => (
<li key={action} className={styles.Action}>
{index === 0 && (
<Drawer.Close className={styles.VisuallyHidden}>
Close action sheet
</Drawer.Close>
)}
<button
type="button"
className={styles.ActionButton}
onClick={() => setOpen(false)}
>
{action}
</button>
</li>
))}
</ul>
</Drawer.Content>
<div className={styles.DangerSurface}>
<button type="button" className={styles.DangerButton} onClick={() => setOpen(false)}>
Block User
</button>
</div>
</Drawer.Popup>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
);
}
분리 트리거 (Detached triggers)
드로어는 <Drawer.Root> 컴포넌트의 안이나 밖에 위치한 트리거로 제어할 수 있어요. 간단한 1회성 상호작용의 경우 <Drawer.Trigger>를 <Drawer.Root> 안에 배치하세요.
하지만 드로어의 콘텐츠를 트리거 옆에 정의하는 게 실용적이지 않다면 분리 트리거를 사용할 수 있어요. 이는 <Drawer.Trigger>를 <Drawer.Root> 밖에 배치하고, Drawer.createHandle() 함수가 만든 handle로 연결하는 방식이에요.
핸들의 명령형 메서드(open(), openWithPayload() 등)는 같은 핸들을 사용하는 <Drawer.Root>가 마운트되어 있어야 해요.
핸들에 root가 연결되지 않은 상태(마운트 전 또는 언마운트 후)에서의 호출은 무시돼요. root가 마운트될 때마다 처음 상태로 시작해서, root가 연결되지 않았을 때의 호출은 재생되지 않고 이전 마운트의 열림 상태도 이어지지 않아요.
const demoDrawer = Drawer.createHandle();
// @highlight
// @highlight-text "handle={demoDrawer}"
<Drawer.Trigger handle={demoDrawer}>Open</Drawer.Trigger>
// @highlight
// @highlight-text "handle={demoDrawer}"
<Drawer.Root handle={demoDrawer}>
...
</Drawer.Root>
드로어는 어느 트리거가 열었는지에 따라 다른 콘텐츠를 렌더링할 수 있어요. 이는 <Drawer.Trigger>에 payload를 전달하고 <Drawer.Root>에서 함수-자식 패턴을 사용해 구현해요.
// @highlight
const demoDrawer = Drawer.createHandle<{ title: string }>();
// @highlight
// @highlight-text "payload"
<Drawer.Trigger handle={demoDrawer} payload={{ title: 'Profile' }}>
Profile
</Drawer.Trigger>
// @highlight
// @highlight-text "payload"
<Drawer.Trigger handle={demoDrawer} payload={{ title: 'Settings' }}>
Settings
</Drawer.Trigger>
<Drawer.Root handle={demoDrawer}>
{({ payload }) => ( // @highlight-text "payload"
<Drawer.Portal>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title>{payload?.title}</Drawer.Title> {/* @highlight-text "payload" */}
</Drawer.Content>
</Drawer.Popup>
</Drawer.Portal>
)}
</Drawer.Root>
스태킹과 애니메이션 (Stacking and animations)
CSS 전환 또는 애니메이션을 사용해 드로어의 열림, 닫힘, 스와이프 상호작용, 중첩 스태킹을 애니메이션할 수 있어요. 드로어가 열리기 시작하면 data-starting-style 속성이 적용되고, 닫히기 시작하면 data-ending-style이 적용돼요.
--nested-drawers CSS 변수로 스택 깊이를 결정할 수 있어요. 가장 앞쪽 드로어의 인덱스는 0이에요.
.DrawerPopup {
--stack-step: 0.05;
--stack-scale: calc(1 - (var(--nested-drawers) * var(--stack-step)));
transform: translateY(var(--drawer-swipe-movement-y)) scale(var(--stack-scale));
}
높이가 다른 드로어를 쌓을 때는 --drawer-height와 --drawer-frontmost-height 변수를 사용해 접힌 드로어를 가장 앞쪽 드로어와 정렬시키세요.
.DrawerPopup {
--bleed: 3rem;
--stack-height: max(
0px,
calc(var(--drawer-frontmost-height, var(--drawer-height)) - var(--bleed))
);
height: var(--drawer-height, auto);
}
.DrawerPopup[data-nested-drawer-open] {
height: calc(var(--stack-height) + var(--bleed));
overflow: hidden;
}
data-nested-drawer-open 속성은 가장 앞쪽 드로어 뒤의 드로어를 표시해요. data-nested-drawer-swiping과 함께 사용해, 중첩 스와이프 상호작용 중에는 부모 드로어 콘텐츠를 보이게 유지하면서 흐리게 하거나 숨길 수 있어요.
.DrawerContent {
transition: opacity 300ms;
}
/* @highlight-text "data-nested-drawer-open" */
.DrawerPopup[data-nested-drawer-open] .DrawerContent {
opacity: 0;
}
/* @highlight-text "data-nested-drawer-open" "data-nested-drawer-swiping" */
.DrawerPopup[data-nested-drawer-open][data-nested-drawer-swiping] .DrawerContent {
opacity: 1;
}
--drawer-swipe-movement-x, --drawer-swipe-movement-y, --drawer-snap-point-offset CSS 변수를 사용해 부드러운 드래그·스냅 오프셋을 만들 수 있어요.
.DrawerPopup[data-swipe-direction='right'] {
/* @highlight-text "--drawer-swipe-movement-x" */
transform: translateX(var(--drawer-swipe-movement-x));
}
.DrawerPopup[data-swipe-direction='down'] {
transform: translateY(
/* @highlight-text "--drawer-swipe-movement-y" */
calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y))
);
}
data-swipe-direction 속성을 data-ending-style과 함께 사용해 방향성 닫기 애니메이션을 할 수 있어요.
/* @highlight-text "data-swipe-direction" */
.DrawerPopup[data-ending-style][data-swipe-direction='right'] {
transform: translateX(100%);
}
/* @highlight-text "data-swipe-direction" */
.DrawerPopup[data-ending-style][data-swipe-direction='down'] {
transform: translateY(100%);
}
--drawer-swipe-progress를 사용해 드로어가 스와이프될 때 백드롭을 페이드하고, --drawer-swipe-strength를 사용해 스와이프 속도에 따라 릴리스 전환 시간을 조정할 수 있어요.
.DrawerBackdrop {
--backdrop-opacity: 0.2;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
}
.DrawerPopup[data-ending-style],
.DrawerBackdrop[data-ending-style] {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
.DrawerPopup[data-swiping],
.DrawerBackdrop[data-swiping] {
transition-duration: 0ms;
}
API 레퍼런스 (API reference)
Root
드로어의 모든 파트를 그룹화해요. 자체 HTML 요소를 렌더링하지 않아요.
Root Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultOpen | boolean |
false |
드로어가 처음에 열려 있는지 여부예요. 제어되는 드로어를 렌더링하려면 open prop을 대신 사용하세요. |
| open | boolean |
- | 드로어가 현재 열려 있는지 여부예요. |
| onOpenChange | ((open: boolean, eventDetails: Drawer.Root.ChangeEventDetails) => void) |
- | 드로어가 열리거나 닫힐 때 호출되는 이벤트 핸들러예요. |
| snapPoints | DrawerSnapPoint[] |
- | 드로어를 배치하는 데 사용하는 스냅 포인트예요.
0과 1 사이의 숫자는 viewport 높이의 비율을,
1보다 큰 숫자는 픽셀 값으로, 또는 px/rem 단위의 문자열을 사용하세요
(예: '148px' 또는 '30rem'). |
| defaultSnapPoint | DrawerSnapPoint | null |
- | 비제어일 때의 초기 스냅 포인트 값이에요. |
| snapPoint | DrawerSnapPoint | null |
- | 현재 활성 스냅 포인트예요. 스냅 포인트를 제어하려면 onSnapPointChange와 함께 사용하세요. |
| onSnapPointChange | ((snapPoint: DrawerSnapPoint | null, eventDetails: Drawer.Root.SnapPointChangeEventDetails) => void) |
- | 스냅 포인트가 변경될 때 호출되는 콜백이에요. |
| actionsRef | React.RefObject<Drawer.Root.Actions | null> |
- | 명령형 액션에 대한 ref예요. unmount: 드로어를 수동으로 언마운트해요.
외부에서 제어하는 닫기 애니메이션이 끝난 후 호출하세요.close: 호출 시 드로어를 명령형으로 닫아요. |
| defaultTriggerId | string | null |
- | 드로어와 연결되는 트리거의 ID예요.
이 값은 defaultOpen prop과 함께 사용해 처음부터 열린 드로어를 만들 때 유용해요. |
| disablePointerDismissal | boolean |
false |
외부 클릭으로 드로어가 닫히는 것을 막을지 여부예요. 비모달 드로어에서는 포커스가 드로어 밖으로 이동할 때 닫히는 것도 막아요. |
| handle | Drawer.Handle<Payload> |
- | 드로어를 트리거와 연결하는 핸들이에요. 지정하면 분리 트리거(Detached trigger)가 드로어의 열림 상태를 제어할 수 있게 해줘요. Drawer.createHandle() 메서드로 만들 수 있어요. |
| modal | boolean | 'trap-focus' |
true |
열렸을 때 드로어가 모달 상태로 들어가는지 결정해요. true: 사용자 상호작용이 드로어로 제한돼요 — 포커스가 트랩되고, 문서 페이지 스크롤이 잠기고, 외부 요소에 대한 포인터 상호작용이 비활성화돼요.false: 문서의 나머지 부분과 사용자 상호작용이 허용돼요.'trap-focus': 포커스는 드로어 안에 트랩되지만, 문서 페이지 스크롤은 잠기지 않고 외부 포인터 상호작용은 유지돼요. |
| onOpenChangeComplete | ((open: boolean) => void) |
- | 드로어가 열리거나 닫힐 때 애니메이션이 모두 끝난 후 호출되는 이벤트 핸들러예요. |
| snapToSequentialPoints | boolean |
false |
속도 기반 스냅 건너뛰기를 비활성화해서 드래그 거리가 다음 스냅 포인트를 결정하게 해요. |
| swipeDirection | DrawerSwipeDirection |
'down' |
드로어를 닫는 데 사용되는 스와이프 방향이에요. |
| triggerId | string | null |
- | 드로어와 연결되는 트리거의 ID예요.
이 값은 open prop과 함께 사용해 제어되는 드로어를 만들 때 유용해요.
드로어가 비제어일 때(open prop이 설정되지 않았을 때)는 이 prop을 지정할 필요가 없어요. |
| children | React.ReactNode | PayloadChildRenderFunction<Payload> |
- | 드로어의 콘텐츠예요. |
Root.Props
Root props의 재내보내기(re-export)예요.
Root.State
type DrawerRootState = {};
Root.Actions
type DrawerRootActions = { unmount: () => void; close: () => void };
Root.ChangeEventReason
type DrawerRootChangeEventReason =
| 'trigger-press'
| 'outside-press'
| 'escape-key'
| 'close-watcher'
| 'close-press'
| 'focus-out'
| 'imperative-action'
| 'swipe'
| 'none';
Root.ChangeEventDetails
type DrawerRootChangeEventDetails = (
| { reason: 'trigger-press'; event: KeyboardEvent | MouseEvent | TouchEvent | PointerEvent }
| { reason: 'outside-press'; event: MouseEvent | TouchEvent | PointerEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'close-press'; event: KeyboardEvent | MouseEvent | PointerEvent }
| { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
| { reason: 'close-watcher'; event: Event }
| { reason: 'swipe'; event: TouchEvent | PointerEvent }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
preventUnmountOnClose: preventUnmountOnClose;
};
Root.SnapPoint
type DrawerRootSnapPoint = number | string;
Root.SnapPointChangeEventDetails
type DrawerRootSnapPointChangeEventDetails = (
| { reason: 'trigger-press'; event: KeyboardEvent | MouseEvent | TouchEvent | PointerEvent }
| { reason: 'outside-press'; event: MouseEvent | TouchEvent | PointerEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'close-press'; event: KeyboardEvent | MouseEvent | PointerEvent }
| { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
| { reason: 'close-watcher'; event: Event }
| { reason: 'swipe'; event: TouchEvent | PointerEvent }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
};
Root.SnapPointChangeEventReason
type DrawerRootSnapPointChangeEventReason =
| 'trigger-press'
| 'outside-press'
| 'escape-key'
| 'close-watcher'
| 'close-press'
| 'focus-out'
| 'imperative-action'
| 'swipe'
| 'none';
Provider
어떤 Drawer가 열려 있는지에 따른 인덴트/배경 효과 같은 전역 Drawer UI를 조정하기 위한 공유 컨텍스트를 제공해요. 자체 HTML 요소를 렌더링하지 않아요.
Provider Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode |
- | - |
Provider.Props
Provider props의 재내보내기(re-export)예요.
Provider.State
type DrawerProviderState = {};
Trigger
드로어를 여는 버튼이에요.
<button> 요소를 렌더링해요.
Trigger Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| handle | Drawer.Handle<Payload> |
- | 트리거를 드로어와 연결하는 핸들이에요. Drawer.createHandle() 메서드로 만들 수 있어요. |
| nativeButton | boolean |
true |
render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부예요.
렌더링되는 요소가 버튼이 아닐 때(예: <div>) false로 설정하세요. |
| payload | Payload |
- | 드로어가 열릴 때 전달할 payload예요. |
| id | string |
- | 트리거의 ID예요. 렌더링되는 요소에 전달되는 것 외에도,
제어 모드에서 드로어의 활성 트리거를 지정하는 데(Drawer.Root triggerId prop) 사용돼요. |
| className | string | ((state: Drawer.Trigger.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Trigger.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Trigger.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Trigger.Props
Trigger props의 재내보내기(re-export)예요.
Trigger.State
type DrawerTriggerState = {
/** Whether the trigger is currently disabled. */
disabled: boolean;
/** Whether the drawer is currently open and was opened by this trigger. */
open: boolean;
};
Portal
팝업을 DOM의 다른 부분으로 옮기는 포털 요소예요.
기본적으로 포털 요소는 <body>에 추가돼요.
<div> 요소를 렌더링해요.
Portal Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| container | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null |
- | 포털 요소를 렌더링할 부모 요소예요. |
| className | string | ((state: Drawer.Portal.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Portal.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| keepMounted | boolean |
false |
팝업이 숨겨져 있는 동안 포털을 DOM에 유지할지 여부예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Portal.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Portal.Props
Portal props의 재내보내기(re-export)예요.
Portal.State
type DrawerPortalState = {};
Backdrop
팝업 아래에 표시되는 오버레이예요.
<div> 요소를 렌더링해요.
Backdrop Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| forceRender | boolean |
false |
중첩된 경우에도 백드롭을 강제로 렌더링할지 여부예요. |
| className | string | ((state: Drawer.Backdrop.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Backdrop.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Backdrop.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Backdrop Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | 드로어가 열려 있을 때 존재해요. |
| data-closed | - | 드로어가 닫혀 있을 때 존재해요. |
| data-starting-style | - | 드로어가 들어오는 애니메이션을 시작할 때 존재해요. |
| data-ending-style | - | 드로어가 나가는 애니메이션 중일 때 존재해요. |
Backdrop CSS Variables:
| Variable | Type | Description |
|---|---|---|
--drawer-swipe-progress |
number |
드로어 제스처의 스와이프 진행도예요. |
Backdrop.Props
Backdrop props의 재내보내기(re-export)예요.
Backdrop.State
type DrawerBackdropState = {
/** Whether the drawer is currently open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};
Popup
드로어 콘텐츠를 위한 컨테이너예요.
<div> 요소를 렌더링해요.
Popup Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| initialFocus | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null) |
- | 드로어가 열릴 때 포커스할 요소를 결정해요. false: 포커스를 옮기지 않아요.true: 기본 동작(첫 tabbable 요소 또는 팝업)에 따라 포커스를 옮겨요.RefObject: ref 요소로 포커스를 옮겨요.function: 상호작용 유형(mouse, touch, pen, keyboard)과 함께 호출돼요.
포커스할 요소를 반환하거나, 기본 동작을 사용하려면 true, 아무것도 하지 않으려면 false/undefined를 반환하세요. |
| finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null) |
- | 드로어가 닫힐 때 포커스할 요소를 결정해요. false: 포커스를 옮기지 않아요.true: 기본 동작(트리거 또는 이전에 포커스된 요소)에 따라 포커스를 옮겨요.RefObject: ref 요소로 포커스를 옮겨요.function: 상호작용 유형(mouse, touch, pen, keyboard)과 함께 호출돼요.
포커스할 요소를 반환하거나, 기본 동작을 사용하려면 true, 아무것도 하지 않으려면 false/undefined를 반환하세요. |
| className | string | ((state: Drawer.Popup.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Popup.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Popup.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Popup Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | 드로어가 열려 있을 때 존재해요. |
| data-closed | - | 드로어가 닫혀 있을 때 존재해요. |
| data-expanded | - | 드로어가 펼쳐진(전체 높이) 스냅 포인트에 있을 때 존재해요. |
| data-nested-drawer-open | - | 중첩 드로어가 열려 있을 때 존재해요. |
| data-nested-drawer-swiping | - | 중첩 드로어가 스와이프 중일 때 존재해요. |
| data-swipe-direction | 'up' | 'down' | 'left' | 'right' |
스와이프 방향을 나타내요. |
| data-swipe-dismiss | - | 드로어가 스와이프로 닫혔을 때 존재해요. |
| data-swiping | - | 드로어가 스와이프 중일 때 존재해요. |
| data-starting-style | - | 드로어가 들어오는 애니메이션을 시작할 때 존재해요. |
| data-ending-style | - | 드로어가 나가는 애니메이션 중일 때 존재해요. |
Popup CSS Variables:
| Variable | Type | Description |
|---|---|---|
--drawer-frontmost-height |
CSS |
현재 중첩 드로어 스택에서 가장 앞쪽 열린 드로어의 높이예요. |
--drawer-height |
CSS |
드로어 팝업의 높이예요. |
--drawer-snap-point-offset |
CSS |
드로어를 변환하는 데 사용되는 스냅 포인트 오프셋이에요. |
--drawer-swipe-movement-x |
CSS |
X축의 스와이프 이동량이에요. |
--drawer-swipe-movement-y |
CSS |
Y축의 스와이프 이동량이에요. |
--drawer-swipe-strength |
number |
CSS에서 스와이프 릴리스 전환 시간을 조정하는 데 사용하는 스칼라(0.1-1)예요. |
--nested-drawers |
number |
현재 열려 있는 중첩 드로어의 개수예요. |
Popup.Props
Popup props의 재내보내기(re-export)예요.
Popup.State
type DrawerPopupState = {
/** Whether the drawer is currently open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
/** Whether the active snap point is the full-height expanded state. */
expanded: boolean;
/** Whether the drawer is nested within a parent drawer. */
nested: boolean;
/** Whether the drawer has nested drawers open. */
nestedDrawerOpen: boolean;
/** Whether a nested drawer is currently being swiped. */
nestedDrawerSwiping: boolean;
/** The swipe direction used to dismiss the drawer. */
swipeDirection: DrawerSwipeDirection;
/** Whether the drawer is being swiped. */
swiping: boolean;
};
Content
드로어 콘텐츠를 위한 컨테이너예요.
<div> 요소를 렌더링해요.
Content Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Drawer.Content.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Content.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Content.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Content.Props
Content props의 재내보내기(re-export)예요.
Content.State
type DrawerContentState = {};
Title
드로어에 라벨을 붙이는 제목이에요.
<h2> 요소를 렌더링해요.
Title Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Drawer.Title.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Title.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Title.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Title.Props
Title props의 재내보내기(re-export)예요.
Title.State
type DrawerTitleState = {};
Description
드로어에 대한 추가 정보를 담은 문단이에요.
<p> 요소를 렌더링해요.
Description Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Drawer.Description.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Description.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Description.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Description.Props
Description props의 재내보내기(re-export)예요.
Description.State
type DrawerDescriptionState = {};
Close
드로어를 닫는 버튼이에요.
<button> 요소를 렌더링해요.
Close Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| nativeButton | boolean |
true |
render prop으로 요소를 대체할 때 네이티브 <button> 요소를 렌더링할지 여부예요.
렌더링되는 요소가 버튼이 아닐 때(예: <div>) false로 설정하세요. |
| className | string | ((state: Drawer.Close.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Close.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Close.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Close.Props
Close props의 재내보내기(re-export)예요.
Close.State
type DrawerCloseState = {
/** Whether the button is currently disabled. */
disabled: boolean;
};
Viewport
드로어 팝업을 위한 포지셔닝 컨테이너로, 스크롤 가능하게 만들 수 있어요.
<div> 요소를 렌더링해요.
Viewport Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Drawer.Viewport.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Viewport.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Viewport.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Viewport Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | 드로어가 열려 있을 때 존재해요. |
| data-closed | - | 드로어가 닫혀 있을 때 존재해요. |
| data-nested | - | 드로어가 다른 드로어 안에 중첩되어 있을 때 존재해요. |
| data-starting-style | - | 드로어가 들어오는 애니메이션을 시작할 때 존재해요. |
| data-ending-style | - | 드로어가 나가는 애니메이션 중일 때 존재해요. |
Viewport CSS Variables:
| Variable | Type | Description |
|---|---|---|
--drawer-keyboard-inset |
CSS |
소프트웨어 키보드 inset으로, 레이아웃 viewport의 아래쪽 가장자리에서 측정돼요.
드로어가 Drawer.VirtualKeyboardProvider로 감싸졌을 때만 존재해요. |
Viewport.Props
Viewport props의 재내보내기(re-export)예요.
Viewport.State
type DrawerViewportState = {
/** Whether the drawer is currently open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
/** Whether the drawer is nested within another drawer. */
nested: boolean;
/** Whether the drawer has nested drawers open. */
nestedDialogOpen: boolean;
};
createHandle
Drawer.Root를 분리된 Drawer.Trigger 컴포넌트와 연결하기 위한 새 핸들을 만들어요.
반환 값 (Return Value):
type ReturnValue = Drawer.Handle<Payload>;
Handle
Drawer를 명령형으로 제어하고, 분리된 Drawer.Trigger 컴포넌트를
Drawer.Root와 연결해요. Drawer.createHandle()로 만들고, root의 handle
prop과 root 밖에 렌더링되는 트리거들에 전달하세요.
명령형 메서드는 이 핸들을 사용하는 root가 마운트되어 있을 때만 적용되며, root가 연결되기 전(또는 언마운트 후)에 호출된 호출은 무시돼요.
Properties:
| Property | Type | Modifiers | Description |
|---|---|---|---|
| isOpen | boolean |
readonly | 다이얼로그가 현재 열려 있는지 여부예요. 핸들에 root가 연결되지 않았으면 false를 반환해요. |
Methods:
function open(triggerId: string | null): void;
선택적으로 트리거와 연결하면서 드로어를 열어요.
이 메서드는 이벤트 핸들러나 이펙트 안에서만 호출해야 해요(렌더링 중에는 안 됨).
function openWithPayload(payload: Payload): void;
트리거와 연결하지 않고 주어진 payload로 드로어를 열어요.
이 메서드는 이벤트 핸들러나 이펙트 안에서만 호출해야 해요(렌더링 중에는 안 됨).
function close(): void;
드로어를 닫아요.
이 메서드는 이벤트 핸들러나 이펙트 안에서만 호출해야 해요(렌더링 중에는 안 됨).
Indent
여러분의 앱 메인 UI를 담기 위한 래퍼 요소예요.
가장 가까운 <Drawer.Provider> 안의 어떤 드로어가 열려 있으면 data-active를 적용해요.
<div> 요소를 렌더링해요.
Indent Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Drawer.Indent.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.Indent.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.Indent.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
Indent.Props
Indent props의 재내보내기(re-export)예요.
Indent.State
type DrawerIndentState = {
/** Whether any drawer within the nearest <Drawer.Provider> is open. */
active: boolean;
};
IndentBackground
<Drawer.Indent> 앞에 배치되는 요소로, 어떤 드로어가 열려 있는지에 따라 스타일링할 수 있는 배경 레이어를 렌더링해요.
<div> 요소를 렌더링해요.
IndentBackground Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | ((state: Drawer.IndentBackground.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.IndentBackground.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.IndentBackground.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
IndentBackground.Props
IndentBackground props의 재내보내기(re-export)예요.
IndentBackground.State
type DrawerIndentBackgroundState = {
/** Whether any drawer within the nearest <Drawer.Provider> is open. */
active: boolean;
};
SwipeArea
드로어를 여는 스와이프 제스처를 감지하는 보이지 않는 영역이에요.
<div> 요소를 렌더링해요.
SwipeArea Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| swipeDirection | DrawerSwipeDirection |
- | 드로어를 여는 스와이프 방향이에요.
기본값은 Drawer.Root swipeDirection의 반대예요. |
| disabled | boolean |
false |
스와이프 영역이 비활성화됐는지 여부예요. |
| className | string | ((state: Drawer.SwipeArea.State) => string | undefined) |
- | 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태를 기반으로 클래스를 반환하는 함수예요. |
| style | React.CSSProperties | ((state: Drawer.SwipeArea.State) => React.CSSProperties | undefined) |
- | 요소에 적용되는 스타일, 또는 컴포넌트 상태를 기반으로 스타일 객체를 반환하는 함수예요. |
| render | ReactElement | ((props: HTMLProps, state: Drawer.SwipeArea.State) => ReactElement) |
- | 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요. |
SwipeArea Data Attributes:
| Attribute | Type | Description |
|---|---|---|
| data-open | - | 드로어가 열려 있을 때 존재해요. |
| data-closed | - | 드로어가 닫혀 있을 때 존재해요. |
| data-disabled | - | 스와이프 영역이 비활성화됐을 때 존재해요. |
| data-swipe-direction | 'up' | 'down' | 'left' | 'right' |
스와이프 방향을 나타내요. |
| data-swiping | - | 드로어가 스와이프 중일 때 존재해요. |
SwipeArea.Props
SwipeArea props의 재내보내기(re-export)예요.
SwipeArea.State
type DrawerSwipeAreaState = {
/** Whether the drawer is currently open. */
open: boolean;
/** Whether the swipe area is currently being swiped. */
swiping: boolean;
/** The swipe direction that opens the drawer. */
swipeDirection: SwipeDirection;
/** Whether the swipe area is disabled. */
disabled: boolean;
};
VirtualKeyboardProvider
폼 필드가 있는 바텀 시트 드로어를 위한 키보드 인식 포커스·스크롤 처리를 제공해요.
VirtualKeyboardProvider Props:
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode |
- | - |
VirtualKeyboardProvider.Props
VirtualKeyboardProvider props의 재내보내기(re-export)예요.
VirtualKeyboardProvider.State
type DrawerVirtualKeyboardProviderState = {};
외부 타입 (External Types)
InteractionType
type InteractionType = 'mouse' | 'touch' | 'pen' | 'keyboard' | '';
DrawerSwipeDirection
type DrawerSwipeDirection = 'up' | 'down' | 'left' | 'right';
PayloadChildRenderFunction
type PayloadChildRenderFunction = (arg: { payload: unknown | undefined }) => ReactNode;
DrawerSnapPoint
type DrawerSnapPoint = number | string;
preventUnmountOnClose
type preventUnmountOnClose = () => void;
SwipeDirection
type SwipeDirection = 'up' | 'down' | 'left' | 'right';
Export Groups
Drawer.Backdrop:Drawer.Backdrop,Drawer.Backdrop.Props,Drawer.Backdrop.StateDrawer.Close:Drawer.Close,Drawer.Close.Props,Drawer.Close.StateDrawer.Content:Drawer.Content,Drawer.Content.Props,Drawer.Content.StateDrawer.Description:Drawer.Description,Drawer.Description.Props,Drawer.Description.StateDrawer.Indent:Drawer.Indent,Drawer.Indent.State,Drawer.Indent.PropsDrawer.IndentBackground:Drawer.IndentBackground,Drawer.IndentBackground.State,Drawer.IndentBackground.PropsDrawer.Popup:Drawer.Popup,Drawer.Popup.Props,Drawer.Popup.StateDrawer.Portal:Drawer.Portal,Drawer.Portal.Props,Drawer.Portal.StateDrawer.Provider:Drawer.Provider,Drawer.Provider.State,Drawer.Provider.PropsDrawer.Root:Drawer.Root,Drawer.Root.State,Drawer.Root.Props,Drawer.Root.Actions,Drawer.Root.ChangeEventReason,Drawer.Root.ChangeEventDetails,Drawer.Root.SnapPointChangeEventReason,Drawer.Root.SnapPointChangeEventDetails,Drawer.Root.SnapPointDrawer.SwipeArea:Drawer.SwipeArea,Drawer.SwipeArea.Props,Drawer.SwipeArea.StateDrawer.Title:Drawer.Title,Drawer.Title.Props,Drawer.Title.StateDrawer.Trigger:Drawer.Trigger,Drawer.Trigger.Props,Drawer.Trigger.StateDrawer.Viewport:Drawer.Viewport,Drawer.Viewport.Props,Drawer.Viewport.StateDrawer.VirtualKeyboardProvider:Drawer.VirtualKeyboardProvider,Drawer.VirtualKeyboardProvider.State,Drawer.VirtualKeyboardProvider.PropsDrawer.createHandleDrawer.HandleDefault:DrawerRootState,DrawerRootProps,DrawerRootActions,DrawerRootChangeEventReason,DrawerRootChangeEventDetails,DrawerRootSnapPointChangeEventReason,DrawerRootSnapPointChangeEventDetails,DrawerProviderState,DrawerProviderProps,DrawerIndentState,DrawerIndentProps,DrawerIndentBackgroundState,DrawerIndentBackgroundProps,DrawerTriggerProps,DrawerTriggerState,DrawerPortalState,DrawerPortalProps,DrawerPopupProps,DrawerPopupState,DrawerSwipeAreaProps,DrawerSwipeAreaState,DrawerContentProps,DrawerContentState,DrawerBackdropProps,DrawerBackdropState,DrawerViewportState,DrawerViewportProps,DrawerTitleProps,DrawerTitleState,DrawerDescriptionProps,DrawerDescriptionState,DrawerCloseProps,DrawerCloseState,DrawerVirtualKeyboardProviderState,DrawerVirtualKeyboardProviderProps
Canonical Types
Canonical: Alias 매핑 — Canonical의 네임스페이스가 이미 임포트되어 있으면 Canonical을, 아니면 Alias를 사용하세요.
Drawer.Backdrop.Props:DrawerBackdropPropsDrawer.Backdrop.State:DrawerBackdropStateDrawer.Close.Props:DrawerClosePropsDrawer.Close.State:DrawerCloseStateDrawer.Content.Props:DrawerContentPropsDrawer.Content.State:DrawerContentStateDrawer.Description.Props:DrawerDescriptionPropsDrawer.Description.State:DrawerDescriptionStateDrawer.Indent.State:DrawerIndentStateDrawer.Indent.Props:DrawerIndentPropsDrawer.IndentBackground.State:DrawerIndentBackgroundStateDrawer.IndentBackground.Props:DrawerIndentBackgroundPropsDrawer.Popup.Props:DrawerPopupPropsDrawer.Popup.State:DrawerPopupStateDrawer.Portal.Props:DrawerPortalPropsDrawer.Portal.State:DrawerPortalStateDrawer.Provider.State:DrawerProviderStateDrawer.Provider.Props:DrawerProviderPropsDrawer.Root.State:DrawerRootStateDrawer.Root.Props:DrawerRootPropsDrawer.Root.Actions:DrawerRootActionsDrawer.Root.ChangeEventReason:DrawerRootChangeEventReasonDrawer.Root.ChangeEventDetails:DrawerRootChangeEventDetailsDrawer.Root.SnapPointChangeEventReason:DrawerRootSnapPointChangeEventReasonDrawer.Root.SnapPointChangeEventDetails:DrawerRootSnapPointChangeEventDetailsDrawer.SwipeArea.Props:DrawerSwipeAreaPropsDrawer.SwipeArea.State:DrawerSwipeAreaStateDrawer.Title.Props:DrawerTitlePropsDrawer.Title.State:DrawerTitleStateDrawer.Trigger.Props:DrawerTriggerPropsDrawer.Trigger.State:DrawerTriggerStateDrawer.Viewport.Props:DrawerViewportPropsDrawer.Viewport.State:DrawerViewportStateDrawer.VirtualKeyboardProvider.State:DrawerVirtualKeyboardProviderStateDrawer.VirtualKeyboardProvider.Props:DrawerVirtualKeyboardProviderProps