Drawer
Overlay: dialog, drawer, popover and menu
A centered panel on a dim backdrop with a thin close icon, or a sheet sliding from the edge for row details and a lightbox for media. Blur is allowed here because layers overlap.
실제로 돌아가는 부품입니다. 눌러 보고 입력해 보세요.
내 앱에 넣기
아직 npm 패키지가 없어서 Taster 리포를 받아 그 안의 명령을 씁니다. 내 앱 폴더가 들어 있는 폴더에서 한 번만 받습니다.
git clone https://github.com/makim-414/taster.git && npm ci --prefix taster/packages/engine내 앱 폴더에서 이 부품을 넣습니다. 부품 파일과 토큰 파일이
src/components/taster에 들어갑니다.node ../taster/packages/engine/cli.mjs add blocks/drawer --from https://taster-six.vercel.app --dir src/components/taster부품은 Tailwind 클래스로 그리고, Taster 프리셋이 그 클래스를 토큰에 연결합니다. Tailwind CSS 를 설치하고,
tokens.css를 앱 루트에서 한 번 불러온 뒤, 앱 루트에 이 설정을 둡니다. 프리셋이 없으면 빌드는 되어도 부품이 스타일 없이 나옵니다.// tailwind.config.cjs module.exports = { presets: [require('./src/components/taster/tailwind-preset.cjs')], content: ['./index.html', './src/**/*.{ts,tsx}'], };Tailwind v3 는 이 파일을 그대로 읽습니다. v4 는 Tailwind 를 불러오는
src/의 스타일시트 맨 위에 이 두 줄을 넣습니다.@import "tailwindcss"; @config "../tailwind.config.cjs";tokens.css는:root에--bg,--text,--border,--accent를 정의합니다. 내 앱의 스타일시트가 같은 이름을 뒤에서 다시 정의하면 그쪽 색이 이깁니다. 새 Vite 앱의 스타터 CSS 처럼 그런 변수가 있으면 지우거나 이름을 바꾸세요.
언제 쓰나요
- Dialog and sheetA centered panel on a dim backdrop with a thin close icon, or a sheet sliding from the edge for row details and a lightbox for media. Blur is allowed here because layers overlap.
대신 없애 주는 AI 티
- Same large radius and same soft shadow on everything (CMP-04)
- Glass panels everywhere (CMP-05)
정보
코드 보기
'use client'
import * as React from 'react'
import * as DialogPrimitive from '@radix-ui/react-dialog'
import { cn } from './_cn'
// Drawer and bottom sheet. Built on @radix-ui/react-dialog, so focus is trapped, Escape and the scrim close it,
// and focus returns to the trigger. A side drawer suits a record's details or an edit form next to a list; a
// bottom sheet suits short choices on phones. Header, scrolling body and a fixed footer for the actions.
// It slides in on the drawer easing and --dur-modal; reduced motion turns the slide into an instant change.
export const Drawer = DialogPrimitive.Root
export const DrawerTrigger = DialogPrimitive.Trigger
export const DrawerClose = DialogPrimitive.Close
export interface DrawerContentProps extends React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> {
side?: 'right' | 'left' | 'bottom'
closeLabel?: string
}
const SIDE = {
right: { panel: 'inset-y-0 right-0 h-full w-full max-w-md border-l', hidden: 'translate-x-full' },
left: { panel: 'inset-y-0 left-0 h-full w-full max-w-md border-r', hidden: '-translate-x-full' },
bottom: { panel: 'inset-x-0 bottom-0 max-h-[85vh] w-full rounded-t-xl border-t', hidden: 'translate-y-full' },
}
export const DrawerContent = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Content>, DrawerContentProps>(
({ side = 'right', closeLabel = 'Close', className, children, ...props }, ref) => {
const [entered, setEntered] = React.useState(false)
React.useEffect(() => {
const raf = requestAnimationFrame(() => setEntered(true))
return () => cancelAnimationFrame(raf)
}, [])
return (
<DialogPrimitive.Portal>
<DialogPrimitive.Overlay
className="fixed inset-0 z-50 transition-opacity duration-modal ease-out"
style={{ background: 'var(--scrim)', opacity: entered ? 1 : 0 }}
/>
<DialogPrimitive.Content
ref={ref}
className={cn(
'fixed z-50 flex flex-col border-border bg-bg-popover text-text shadow-pop outline-none',
'transition-transform duration-modal ease-drawer motion-reduce:transition-none',
SIDE[side].panel,
entered ? 'translate-x-0 translate-y-0' : SIDE[side].hidden,
className,
)}
{...props}
>
{side === 'bottom' && <div aria-hidden="true" className="mx-auto mt-2 h-1 w-10 shrink-0 rounded-pill bg-border" />}
{children}
<DialogPrimitive.Close
className={cn(
'absolute right-2 top-2 inline-flex size-11 items-center justify-center rounded-md text-text-subtle outline-none desk:size-9',
'transition-colors duration-press hover:text-text focus-visible:ring-2 focus-visible:ring-ring',
)}
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.75} strokeLinecap="round" aria-hidden="true">
<path d="M6 6l12 12M18 6L6 18" />
</svg>
<span className="sr-only">{closeLabel}</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPrimitive.Portal>
)
},
)
DrawerContent.displayName = 'DrawerContent'
export function DrawerHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return <div className={cn('flex shrink-0 flex-col gap-1 border-b border-border py-4 pl-5 pr-14', className)} {...props} />
}
export function DrawerBody({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return <div className={cn('min-h-0 flex-1 overflow-y-auto p-5', className)} {...props} />
}
export function DrawerFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return <div className={cn('flex shrink-0 flex-wrap justify-end gap-2 border-t border-border px-5 py-3', className)} {...props} />
}
export const DrawerTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title ref={ref} className={cn('text-title font-semibold text-text', className)} {...props} />
))
DrawerTitle.displayName = 'DrawerTitle'
export const DrawerDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description ref={ref} className={cn('text-sm text-text-muted', className)} {...props} />
))
DrawerDescription.displayName = 'DrawerDescription'