InputColor는 compound composition 방식으로 만들어진, styled가 없는 접근성 높은 컬러 피커 컴포넌트예요. 영역(area), 슬라이더, 스와치, 입력 등을 완전히 커스텀하게 렌더링할 수 있어요.
출처: 문서
본문
기능 (Features)
- 12개의 하위 컴포넌트(
Root, Area, AreaBackground, AreaHandle, Slider, SliderTrack, SliderHandle, Swatch, SwatchBackground, EyeDropper, Input, TransparencyGrid)로 구성된 compound 컴포넌트 API
- 부드러운 선택을 위한 포인터 캡처가 있는 2D 컬러 그라데이션 영역
- 색조(hue), 알파(alpha) 등 컬러 채널을 위한 채널 기반 슬라이더
- 여러 컬러 포맷: HSBA, HSLA, RGBA, OKLCHA
- 네이티브 EyeDropper API 통합
사용법 (Usage)
import { InputColor } from 'primereact/inputcolor';
<InputColor.Root>
<InputColor.Area>
<InputColor.AreaBackground />
<InputColor.AreaHandle />
</InputColor.Area>
<InputColor.Slider>
<InputColor.TransparencyGrid />
<InputColor.SliderTrack />
<InputColor.SliderHandle />
</InputColor.Slider>
<InputColor.Swatch>
<InputColor.TransparencyGrid />
<InputColor.SwatchBackground />
</InputColor.Swatch>
<InputColor.EyeDropper></InputColor.EyeDropper>
<InputColor.Input />
</InputColor.Root>
동작 (Behavior)
다형적 렌더링 (Polymorphic Rendering)
아무 하위 컴포넌트에 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.
<InputColor.Root as="section">
<InputColor.Area as="div">
<InputColor.AreaBackground as="div" />
<InputColor.AreaHandle as="div" />
</InputColor.Area>
<InputColor.EyeDropper as="a" />
</InputColor.Root>
기본 요소: Root=div, Area=div, AreaBackground=div, AreaHandle=div, Slider=SliderRoot, SliderTrack=SliderTrack, SliderHandle=SliderHandle, Swatch=div, SwatchBackground=div, EyeDropper=button, Input=InputText, TransparencyGrid=div.
렌더 함수 자식 (Render Function Children)
하위 컴포넌트는 렌더 함수를 자식으로 받아 컴포넌트 인스턴스에 접근할 수 있게 해 줘요. 인스턴스는 inputColor(루트 인스턴스이며 state.value와 state.isAreaDragging을 가짐)를 노출해요.
<InputColor.Swatch>{(instance) => <span>{instance.inputColor?.state.value.toString('hex')}</span>}</InputColor.Swatch>
패스 스루 (Pass Through)
<DocPTViewer name="inputcolor-pt" components={['InputColorRoot']} />
API
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"root" |
data-disabled |
Present when disabled |
data-dragging |
Present when area is dragged |
| Label |
Type |
Description |
| root |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| area |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the area's DOM element. |
| areaBackground |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the area background's DOM element. |
| areaHandle |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the area handle's DOM element. |
| input |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the input's DOM element. |
| slider |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the slider's DOM element. |
| sliderTrack |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the slider track's DOM element. |
| sliderHandle |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the slider handle's DOM element. |
| swatch |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the swatch's DOM element. |
| swatchBackground |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the swatch background's DOM element. |
| eyeDropper |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the eye dropper's DOM element. |
| transparencyGrid |
InputColorRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the transparency grid's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"area" |
CSS 커스텀 속성 (CSS Custom Properties)
Area 요소는 그라데이션 렌더링과 핸들 위치 지정을 위해 style에 CSS 커스텀 속성을 설정해요.
| CSS Variable |
Description |
--area-background |
Solid hue background of the area |
--area-gradient |
Combined saturation/brightness gradient overlay |
--handle-background |
Current color for the area handle |
--handle-position-top |
Vertical position of the area handle |
--handle-position-left |
Horizontal position of the area handle |
| Label |
Type |
Description |
| root |
InputColorAreaPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
InputColorAreaBackgroundPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"area-handle" |
| Label |
Type |
Description |
| root |
InputColorAreaHandlePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"slider" |
data-orientation |
"horizontal" or "vertical" |
data-channel |
The slider channel name |
CSS 커스텀 속성 (CSS Custom Properties)
Slider 요소는 트랙과 핸들 렌더링을 위해 style에 CSS 커스텀 속성을 설정해요.
| CSS Variable |
Description |
--slider-background |
Channel gradient for the slider track |
--slider-handle-background |
Current channel color for the handle |
| Label |
Type |
Description |
| root |
InputColorSliderPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
InputColorSliderTrackPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"slider-handle" |
| Label |
Type |
Description |
| root |
InputColorSliderHandlePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"swatch" |
CSS 커스텀 속성 (CSS Custom Properties)
Swatch 요소는 컬러 렌더링을 위해 style에 CSS 커스텀 속성을 설정해요.
| CSS Variable |
Description |
--swatch-background |
Current color for the swatch |
| Label |
Type |
Description |
| root |
InputColorSwatchPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
InputColorSwatchBackgroundPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"eye-dropper" |
| Label |
Type |
Description |
| root |
InputColorEyeDropperPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"inputcolor" |
data-part |
"input" |
data-channel |
The input channel name |
| Label |
Type |
Description |
| root |
InputColorInputPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
InputColorTransparencyGridPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
접근성 (Accessibility)
스크린 리더 (Screen Reader)
area handle은 ara-roledescription="2d slider"를 가진 role="slider"예요. 두 축을 설명하는 aria-label(예: "saturation and brightness"), 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 up. |
down arrow |
Moves the area handle down. |
스크린 리더 (Screen Reader)
slider handle은 현재 채널 값을 설명하는 aria-label, aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext를 가진 role="slider"예요.
키보드 지원 (Keyboard Support)
| Key |
Function |
tab |
Moves focus to the slider handle. |
up arrow || left arrow |
Decrements the slider value. |
down arrow || right arrow |
Increments the slider value. |
더 알아보기 (Learn more)