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

ColorSlider

원문 보기 위키 갱신

ColorSlider는 사용자가 색상 값의 개별 채널을 조정할 수 있게 해주는 슬라이더예요. 해요체로 쉽게 설명드릴게요.

출처: HeroUI ColorSlider

본문

사용법 (Usage)

import { ColorSlider, Label } from '@heroui/react';
{"name": "color-slider-basic"}

구조 (Anatomy)

import { ColorSlider, Label } from '@heroui/react';

export default () => (
  <ColorSlider channel="hue" defaultValue="hsl(0, 100%, 50%)">
    <Label>Hue</Label>
    <ColorSlider.Output />
    <ColorSlider.Track>
      <ColorSlider.Thumb />
    </ColorSlider.Track>
  </ColorSlider>
)

예시 (Examples)

비활성화 (Disabled)

{"name": "color-slider-disabled"}

세로 (Vertical)

{"name": "color-slider-vertical"}

제어된 상태 (Controlled)

{"name": "color-slider-controlled"}

HSL 채널 (HSL Channels)

여러 개의 ColorSlider를 사용해 색상 값의 서로 다른 채널을 제어할 수 있어요. 슬라이더가 동일한 색상 값을 공유하면 완전한 색상 선택기(color picker)를 만들 수 있어요.

{"name": "color-slider-channels"}

알파 채널 (Alpha Channel)

알파 채널 슬라이더는 투명도 수준을 시각화할 수 있도록 투명 체커보드 패턴을 보여줘요.

{"name": "color-slider-alpha-channel"}

RGB 채널 (RGB Channels)

빨강, 초록, 파랑 채널을 가진 RGB 색 공간도 사용할 수 있어요.

{"name": "color-slider-rgb-channels"}

렌더 함수 (Render Function)

{"name": "color-slider-render-function"}

커스터마이징 (Customization)

Tailwind CSS

{"name": "color-slider-custom-styles"}

Global CSS

ColorSlider 컴포넌트 클래스를 커스터마이징하려면 @layer components 지시어를 사용할 수 있어요. 더 알아보기.

@layer components {
  .color-slider {
    @apply flex flex-col gap-2;
  }

  .color-slider__output {
    @apply text-muted text-sm;
  }

  .color-slider__track {
    @apply relative h-5 w-full rounded-full;
  }

  .color-slider__thumb {
    @apply size-4 rounded-full border-3 border-white shadow-overlay;
  }
}

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.

CSS 클래스 (CSS Classes)

ColorSlider 컴포넌트는 다음 CSS 클래스를 사용해요 (소스 스타일 보기):

Base 클래스 [!toc]

  • .color-slider - 기본 슬라이더 컨테이너
  • .color-slider__output - 현재 값을 표시하는 출력 요소
  • .color-slider__track - 색상 그라데이션이 있는 트랙 요소
  • .color-slider__thumb - 현재 색상을 보여주는 썸 요소

상태 클래스 [!toc]

  • .color-slider[data-disabled="true"] - 비활성화된 슬라이더 상태
  • .color-slider[data-orientation="vertical"] - 세로 방향
  • .color-slider__thumb[data-dragging="true"] - 드래그 중인 썸
  • .color-slider__thumb[data-focus-visible="true"] - 키보드로 포커스된 썸
  • .color-slider__thumb[data-disabled="true"] - 비활성화된 썸 상태

상호작용 상태 (Interactive States)

컴포넌트는 유연성을 위해 CSS 의사 클래스와 데이터 속성을 모두 지원해요:

  • 호버 (Hover): 썸에서 :hover 또는 [data-hovered="true"]
  • 포커스 (Focus): 썸에서 :focus-visible 또는 [data-focus-visible="true"]
  • 드래그 (Dragging): 썸에서 [data-dragging="true"]
  • 비활성화 (Disabled): 슬라이더 또는 썸에서 :disabled 또는 [data-disabled="true"]

API 참고 (API Reference)

ColorSlider

React Aria ColorSlider에서 상속받아요.

Prop Type Default Description
channel ColorChannel - The color channel that the slider manipulates (hue, saturation, lightness, brightness, alpha, red, green, blue)
colorSpace ColorSpace - The color space (hsl, hsb, rgb). Defaults to the color space of the value
value string | Color - The current color value (controlled)
defaultValue string | Color - The default color value (uncontrolled)
onChange (value: Color) => void - Handler called when the value changes during dragging
onChangeEnd (value: Color) => void - Handler called when dragging ends
orientation "horizontal" | "vertical" "horizontal" The orientation of the slider
isDisabled boolean - Whether the slider is disabled
name string - The name of the input element for form submission
aria-label string - Accessibility label for the slider
className string - Additional CSS classes
children ReactNode | RenderFunction - Slider content or render function
render DOMRenderFunction<keyof React.JSX.IntrinsicElements, ColorSliderRenderProps> - Overrides the default DOM element with a custom render function.

ColorSlider.Output

Prop Type Default Description
className string - Additional CSS classes
children ReactNode | RenderFunction - Output content or render function

ColorSlider.Track

Prop Type Default Description
className string - Additional CSS classes
style CSSProperties | RenderFunction - Inline styles or render function
children ReactNode | RenderFunction - Track content or render function

ColorSlider.Thumb

Prop Type Default Description
className string - Additional CSS classes
style CSSProperties | RenderFunction - Inline styles or render function
children ReactNode | RenderFunction - Thumb content or render function

Render Props

렌더 함수를 사용하면 이 값들이 제공돼요:

Prop Type Description
state ColorSliderState The state of the color slider
color Color The current color value
orientation "horizontal" | "vertical" The orientation of the slider
isDisabled boolean Whether the slider is disabled

접근성 (Accessibility)

ColorSlider 컴포넌트는 ARIA 슬라이더 패턴을 구현하며 다음을 제공해요:

  • 전체 키보드 내비게이션 지원 (화살표 키, Home, End, Page Up/Down)
  • 값 변경에 대한 화면 리더 안내
  • 적절한 포커스 관리
  • 비활성화 상태 지원
  • 숨겨진 입력 요소를 통한 HTML 폼 통합
  • 로케일 인식 값 포맷을 통한 국제화 지원

자세한 내용은 React Aria ColorSlider 문서를 참고해요.

더 알아보기 (Learn more)