Panel
선택적으로 접을 수 있는 콘텐츠를 가진 컨테이너 컴포넌트예요. 헤더 영역과 본문 영역을 나눠 콘텐츠를 정리할 때 써요.
출처: 문서
본문
설치 (Installation)
Shadcn CLI Manual ```bash npx shadcn@latest add https://primereact.dev/r/panel.json ``` 다음 코드를 프로젝트에 복사해서 붙여넣으세요. import 경로를 프로젝트 설정에 맞게 수정하세요.사용법 (Usage)
import { Panel, PanelContent, PanelHeader, PanelIndicator, PanelTitle, PanelTrigger } from '@/components/ui/panel';
<Panel>
<PanelHeader>
<PanelTitle>Header</PanelTitle>
</PanelHeader>
<PanelContent />
</Panel>
예시 (Examples)
기본 (Basic)
접기 가능 (Toggleable)
헤더 안에 Panel.Trigger를 두면 패널을 접을 수 있어요. defaultOpen prop으로 초기 상태를 설정하고, 콘텐츠 가시성은 기본적으로 애니메이션 처리돼요.
제어 (Controlled)
open과 onOpenChange props로 패널 상태를 외부에서 제어해요.
표시기 (Indicator)
Panel.Indicator는 패널 상태에 따라 조건부 렌더링을 지원해요. match prop을 사용해 상태가 일치할 때만 콘텐츠를 렌더링해요.
<Panel.Header>
<Panel.Title>Header</Panel.Title>
<Panel.Trigger>
<Panel.Indicator match="open">
<Minus />
</Panel.Indicator>
<Panel.Indicator match="closed">
<Plus />
</Panel.Indicator>
</Panel.Trigger>
</Panel.Header>
사용 가능한 값은 open, closed예요. match prop이 없으면 표시기는 모든 상태에서 렌더링돼요.
템플릿 (Template)
Panel.Trigger 옆에 아바타, 액션 버튼, 추가 메타데이터 같은 커스텀 레이아웃으로 헤더를 꾸밀 수 있어요.
접근성 (Accessibility)
화면 낭독기 (Screen Reader)
접을 수 있는 패널의 경우 트리거 버튼이 aria-controls로 콘텐츠 영역을 참조하고 aria-expanded로 가시성 상태를 반영해요. 접근 가능한 라벨은 aria-label 또는 aria-labelledby로 커스터마이즈할 수 있어요.
키보드 지원 (Keyboard Support)
| Key | Function |
|---|---|
tab |
Moves focus to the next focusable element in the page tab sequence. |
shift + tab |
Moves focus to the previous focusable element in the page tab sequence. |
enter |
Toggles the visibility of the content. |
space |
Toggles the visibility of the content. |