MenuBar
MenuBar 컴포넌트는 데스크톱 애플리케이션 스타일의 메뉴 인터페이스를 제공합니다. 수평으로 배치된 메뉴 항목과 드롭다운 메뉴, 키보드 단축키 등을 지원합니다.
기본 사용법
기본적인 메뉴바 구현 예시입니다.
import { MenuBar } from 'react-common-components-library';
function BasicExample() {
return (
<MenuBar
items={[
{
id: 'file',
label: '파일',
items: [
{
id: 'new-file',
label: '새 파일',
shortcut: '⌘N',
onClick: () => console.log('새 파일 클릭됨'),
},
{
id: 'open',
label: '열기',
shortcut: '⌘O',
onClick: () => console.log('열기 클릭됨'),
},
{
id: 'separator-1',
isSeparator: true,
},
{
id: 'save',
label: '저장',
shortcut: '⌘S',
onClick: () => console.log('저장 클릭됨'),
},
],
},
{
id: 'edit',
label: '편집',
items: [
{
id: 'undo',
label: '실행 취소',
shortcut: '⌘Z',
onClick: () => console.log('실행 취소 클릭됨'),
},
{
id: 'redo',
label: '다시 실행',
shortcut: '⌘⇧Z',
onClick: () => console.log('다시 실행 클릭됨'),
},
],
},
{
id: 'view',
label: '보기',
items: [
{
id: 'zoom-in',
label: '확대',
shortcut: '⌘+',
onClick: () => console.log('확대 클릭됨'),
},
{
id: 'zoom-out',
label: '축소',
shortcut: '⌘-',
onClick: () => console.log('축소 클릭됨'),
},
],
},
]}
/>
);
}
아이콘 사용
메뉴 항목에 아이콘을 추가하여 시각적으로 구분할 수 있습니다.
import { MenuBar } from 'react-common-components-library';
// 아이콘 컴포넌트
const FileIcon = () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
</svg>
);
const PrintIcon = () => (
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="6 9 6 2 18 2 18 9"></polyline>
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"></path>
<rect x="6" y="14" width="12" height="8"></rect>
</svg>
);
function IconExample() {
return (
<MenuBar
items={[
{
id: 'file',
label: '파일',
items: [
{
id: 'new-file',
label: '새 파일',
icon: <FileIcon />,
onClick: () => console.log('새 파일 클릭됨'),
},
{
id: 'separator-1',
isSeparator: true,
},
{
id: 'print',
label: '인쇄',
icon: <PrintIcon />,
shortcut: '⌘P',
onClick: () => console.log('인쇄 클릭됨'),
},
],
},
]}
/>
);
}
서브메뉴 사용
메뉴 항목에 하위 메뉴를 추가할 수 있습니다.
import { MenuBar } from 'react-common-components-library';
function SubmenuExample() {
return (
<MenuBar
items={[
{
id: 'file',
label: '파일',
items: [
{
id: 'new',
label: '새로 만들기',
items: [
{
id: 'text-file',
label: '텍스트 파일',
onClick: () => console.log('텍스트 파일 클릭됨'),
},
{
id: 'image-file',
label: '이미지 파일',
onClick: () => console.log('이미지 파일 클릭됨'),
},
],
},
{
id: 'open',
label: '열기',
onClick: () => console.log('열기 클릭됨'),
},
],
},
{
id: 'view',
label: '보기',
items: [
{
id: 'tools',
label: '도구',
items: [
{
id: 'inspector',
label: '검사기',
onClick: () => console.log('검사기 클릭됨'),
},
{
id: 'console',
label: '콘솔',
onClick: () => console.log('콘솔 클릭됨'),
},
],
},
],
},
]}
/>
);
}
비활성화된 항목
특정 메뉴 항목이나 전체 메뉴를 비활성화할 수 있습니다.
import { MenuBar } from 'react-common-components-library';
function DisabledItemsExample() {
return (
<MenuBar
items={[
{
id: 'file',
label: '파일',
items: [
{
id: 'new-tab',
label: '새 탭',
onClick: () => console.log('새 탭 클릭됨'),
},
{
id: 'incognito-window',
label: '시크릿 창',
disabled: true, // 개별 항목 비활성화
},
],
},
{
id: 'edit',
label: '편집',
disabled: true, // 전체 메뉴 비활성화
items: [],
},
]}
/>
);
}
API 참조
MenuBar
속성 | 타입 | 기본값 | 설명 |
---|---|---|---|
items | MenuBarItemProps[] | 필수 | 메뉴바 아이템 배열 |
className | string | '' | 메뉴바에 적용할 추가 CSS 클래스 |
style | React.CSSProperties | - | 메뉴바에 적용할 스타일 |
width | string | 'max-content' | 메뉴바의 너비. '100%', '300px' 등 CSS 너비 값 사용 가능 |
MenuBarItemProps
속성 | 타입 | 기본값 | 설명 |
---|---|---|---|
id | string | 필수 | 메뉴 아이템 ID |
label | string | 필수 | 메뉴 아이템 레이블 |
disabled | boolean | false | 메뉴 아이템 비활성화 여부 |
items | MenuItemProps[] | - | 서브메뉴 항목 |
className | string | '' | 메뉴 아이템에 적용할 추가 CSS 클래스 |
MenuItemProps
메뉴 항목은 일반 메뉴 항목과 구분선 두 가지 타입이 있습니다.