Command
빠르고 구성 가능하며 스타일이 지정되지 않은 명령 메뉴입니다.
언제 사용해야 하는가
전역 검색 및 명령 실행 인터페이스를 제공하여 사용자가 키보드 단축키를 통해 기능에 빠르게 접근하고 탐색할 수 있도록 하는 데 사용됩니다.
사용법
CommandBasic.astro
<Command>
<CommandGroup heading="Suggestions">
<CommandItem id="1" label="Calendar" icon="Calendar" shortcut={['Cmd', 'C']} />
<CommandItem id="2" label="Search Emoji" icon="Smile" shortcut={['Cmd', 'E']} />
<CommandItem id="3" label="Calculator" icon="Calculator" />
</CommandGroup>
</Command>
<script>
document.addEventListener('command:select', (e) => {
console.log('Selected command ID:', e.detail.id);
if (e.detail.action) {
// Handle custom action payload if provided
}
});
</script> API 참조
Command
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| placeholder | 검색 입력의 자리표시자 텍스트입니다. | string | "Type a command or search..." |
| shortcut | 트리거 버튼의 시각적 단축키 힌트입니다. | string | "⌘K" |
CommandGroup
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| heading | The heading title for the command group. | string | - |
CommandItem
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| label | The display label for the item. | string | - |
| icon | Optional icon name. | IconName | - |
| shortcut | Optional keyboard shortcut to display. | string[] | - |
| onSelect | The action or URL to execute when selected. | string | - |
| id | The unique identifier for the command item. | string | - |