터미널 (Terminal)
레이아웃과 스타일을 완전히 제어할 수 있게 해 주는, 커맨드라인 스타일 인터페이스를 만드는 스타일 없는 터미널 컴포넌트예요.
출처: 문서
본문
Features (기능)
- 하위 컴포넌트(
Root, Welcome, CommandList, Command, CommandValue, CommandPromptLabel, CommandResponse, Prompt, PromptLabel, PromptValue)를 갖춘 컴파운드 API예요.
onCommand을 통한 동기/비동기 커맨드 실행이에요.
- Arrow Up을 이용한 내장 커맨드 히스토리 탐색이에요.
onCommand이 null을 반환하면 터미널을 지워요.
- 기본 콘텐츠 렌더링:
CommandList와 Prompt는 children이 제공되지 않으면 자동으로 자식들을 렌더링해요.
Usage (사용법)
import { Terminal } from 'primereact/terminal';
<Terminal.Root>
<Terminal.Welcome />
<Terminal.CommandList />
<Terminal.Prompt>
<Terminal.PromptLabel />
<Terminal.PromptValue />
</Terminal.Prompt>
</Terminal.Root>
Behavior (동작)
다형성 렌더링 (Polymorphic Rendering)
어떤 하위 컴포넌트든 as를 써서 렌더링되는 HTML 요소를 바꿀 수 있어요.
<Terminal.Root as="section"></Terminal.Root>
<Terminal.CommandList as="ul"></Terminal.CommandList>
기본 요소: Root=div, Welcome=div, CommandList=div, Command=div, CommandValue=span, CommandPromptLabel=span, CommandResponse=div, Prompt=div, PromptLabel=span, PromptValue=input이에요.
렌더 함수 children (Render Function Children)
Root는 children으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요.
<Terminal.Root prompt="$" onCommand={commandHandler}>
{(instance) => <span>{instance.state.commands.length} commands executed</span>}
</Terminal.Root>
API
TerminalRoot
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"root" |
| Label |
Type |
Description |
| root |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| commandList |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the commandList's DOM element. |
| commands |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the commands' DOM element. |
| commandValue |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the command value's DOM element. |
| commandResponse |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the command response's DOM element. |
| prompt |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the prompt's DOM element. |
| promptValue |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the prompt value's DOM element. |
| promptLabel |
TerminalRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the prompt label's DOM element. |
TerminalWelcome
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"welcome" |
| Label |
Type |
Description |
| root |
TerminalWelcomePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalCommandList
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"commandlist" |
| Label |
Type |
Description |
| root |
TerminalCommandListPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalCommand
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"command" |
| Label |
Type |
Description |
| root |
TerminalCommandPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalCommandValue
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"commandvalue" |
| Label |
Type |
Description |
| root |
TerminalCommandValuePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalCommandPromptLabel
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"commandpromptlabel" |
| Label |
Type |
Description |
| root |
TerminalCommandPromptLabelPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalCommandResponse
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"commandresponse" |
| Label |
Type |
Description |
| root |
TerminalCommandResponsePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalPrompt
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"prompt" |
| Label |
Type |
Description |
| root |
TerminalPromptPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalPromptLabel
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"promptlabel" |
| Label |
Type |
Description |
| root |
TerminalPromptLabelPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
TerminalPromptValue
| Attribute |
Value |
data-scope |
"terminal" |
data-part |
"promptvalue" |
| Label |
Type |
Description |
| root |
TerminalPromptValuePassThroughType<InputHTMLAttributes> |
Used to pass attributes to the root's DOM element. |
Accessibility (접근성)
스크린 리더 (Screen Reader)
커맨드 응답 요소는 aria-live="polite"를 가져서 새 응답을 스크린 리더가 알려줘요. 터미널 root의 아무 곳이나 클릭하면 입력 요소에 포커스가 가요.
키보드 지원 (Keyboard Support)
| Key |
Function |
tab |
Moves focus through the input element. |
enter |
Executes the command when focus is on the input element. |
arrow up |
Recalls the previous command from history. |
더 알아보기 (Learn more)