본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

InputColor

원문 보기 위키 갱신

InputColor는 사용자가 색상을 선택할 수 있게 해주는 컴포넌트예요. 색상 영역, 슬라이더, 채널 입력 등을 조립해 원하는 색상 선택 UI를 만들 수 있죠.

출처: 문서

본문

InputColor는 사용자가 색상을 선택할 수 있게 하는 컴포넌트예요.

설치 (Installation)

Shadcn CLI Manual ```bash npx shadcn@latest add https://primereact.dev/r/inputcolor.json ``` 프로젝트에 다음 코드를 복사해서 붙여넣으세요. 가져오기(import) 경로를 프로젝트 설정에 맞게 업데이트하세요.

사용법 (Usage)

import { InputColor, InputColorArea, InputColorEyeDropper, InputColorInput, InputColorSlider, InputColorSwatch } from '@/components/ui/inputcolor';
<InputColor>
    <InputColorArea />
    <InputColorSlider />
    <InputColorSlider channel="alpha" />
    <InputColorSwatch />
    <InputColorInput channel="hex" />
    <InputColorEyeDropper />
</InputColor>

예시 (Examples)

기본 (Basic)

format prop을 사용해 색상 공간을 변경해요. InputColor.Slider와 InputColor.Input의 channel prop을 사용하면 제어할 채널을 선택할 수 있어요.

세로 슬라이더 (Vertical Slider)

orientation prop을 사용해 슬라이더의 방향을 변경해요.

제어 (Controlled)

value와 onColorChange prop을 사용해 색상을 제어해요.

고급 (Advanced)

colorManager

Color 클래스 (Color class)

Color 클래스는 모든 색상 클래스의 기본 클래스예요. 모든 색상 클래스에 기본 기능을 제공해요.

  • clone(): 색상을 복제해요.
  • toString(format): 색상을 문자열로 변환해요.
  • toFormat(format): 색상을 특정 형식으로 변환해요.
  • toJSON(): 색상을 JSON 객체로 변환해요.
  • getChannelRange(channel): 채널의 범위를 반환해요.
  • getFormat(): 색상의 형식을 반환해요.
  • getChannels(): 색상의 채널을 반환해요.
  • getChannelValue(channel): 채널의 값을 반환해요.
  • getColorAxes(xyChannels): 색상의 축(axes)을 반환해요.
  • incChannelValue(channel, step): 채널의 값을 step만큼 증가시켜요.
  • decChannelValue(channel, step): 채널의 값을 step만큼 감소시켜요.
  • withChannelValue(channel, value): 채널의 값이 변경된 새 색상을 반환해요.

접근성 (Accessibility)

InputColorArea

화면 낭독기 지원 (Screen Reader Support)

aria-label은 컴포넌트를 설명하는 데 사용돼요. aria-roledescription은 컴포넌트의 역할을 설명하는 데 사용돼요. aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext는 컴포넌트의 값을 설명하는 데 사용돼요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the area handle.
right arrow Moves the area handle to the right.
left arrow Moves the area handle to the left.
up arrow Moves the area handle to the up.
down arrow Moves the area handle to the down.

InputColorSlider

화면 낭독기 지원 (Screen Reader Support)

aria-label은 컴포넌트를 설명하는 데 사용돼요. aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext는 컴포넌트의 값을 설명하는 데 사용돼요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the slider handle.
up arrow || left arrow Decrements the slider handle.
down arrow || right arrow Increments the slider handle.

더 알아보기 (Learn more)