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

Color Picker

원문 보기 위키 갱신

색을 시각적으로 고르는 컴포넌트예요. rgb, hex, hsl 모드를 전환할 수 있고 알파 채널과 색 견본(swatch)도 지원해요. 실제 세계와 달리 이 색 값들은 이산적(discrete)이에요.

출처: 문서

본문

실제 세계와 달리, 이 색 값들은 이산적이에요.

Demos

basic.vue
alpha.vue
size.vue
disabled.vue
modes.vue
actions.vue
form.vue
swatches.vue
trigger.vue
native.vue

API

ColorPicker Props

이름 타입 기본값 설명 버전
default-show boolean undefined 색상 패널을 기본으로 표시할지 여부.
default-value string 1st mode의 대응 값인 검정 색 값. picker의 기본값.
modes Array<'rgb' | 'hex' | 'hsl' | 'hsv'> ['rgb', 'hex', 'hsl'] picker의 값 형식. picker에서 새 값을 선택하면 값이 해당 모드를 따라간다는 점에 유의하세요.
placement 'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end' 'bottom-start' 색상 패널의 위치. 2.25.0
render-label (color: string | null) => VNodeChild undefined color picker 트리거의 라벨 렌더 함수. 2.24.0
show boolean undefined 색상 패널이 표시 중인지 여부.
show-alpha boolean true 알파 채널을 조절할 수 있는지 여부.
show-preview boolean false 색상 미리보기를 표시할지 여부.
size 'small' | 'medium' | 'large' 'medium' picker의 크기.
disabled boolean false color picker를 비활성화할지 여부. 2.24.5
swatches string[] undefined 견본(swatch)의 값.
to string | HTMLElement | false 'body' 패널을 붙일 곳. false를 지정하면 분리(detach)되지 않아요.
value string | null undefined picker의 값.
on-complete (value: string) => void undefined 값의 변경이 완전히 끝났을 때의 콜백(mousemove 중에는 호출되지 않아요).
on-confirm (value: string) => void undefined 확인 버튼을 클릭했을 때의 콜백. 2.29.0
on-clear () => void undefined 지우기 버튼을 클릭했을 때의 콜백. 2.39.0
on-update:show (value: boolean) => void undefined 패널의 표시 상태가 바뀔 때의 콜백.
on-update:value (value: string) => void undefined 값이 바뀔 때의 콜백.
actions Array<'confirm' | 'clear'> | null null 패널에 표시할 버튼의 종류.

ColorPicker Slots

이름 파라미터 설명 버전
action () 커스텀 동작 영역. 2.24.0
label (color: string | null) color picker 트리거의 라벨. 2.24.0
trigger (props: { value: string | null , onClick: (() => void) | undefined, ref: (ref: Element | ComponentPublicInstance | null }) => void }) 커스텀 트리거 요소. 하나의 요소만 허용되며 순수 텍스트는 안 돼요. 2.44.0

Q & A

색 이름으로 색 값을 얻으려면 어떻게 하나요?

Naive는 내장 기능으로 제공하지 않아요. https://github.com/bgrins/TinyColor/blob/master/tinycolor.js#L803처럼 색 맵(color map)을 만들 수 있어요.

아니면 이런 함수를 만들 수도 있어요.

export function getRgb(colorName) {
  const el = document.createElement('div')
  el.style.color = colorName
  document.body.appendChild(el)
  const rgbColor = getComputedStyle(el).color
  document.body.removeChild(el)
  return rgbColor
}

더 알아보기 (Learn more)

색 견본 활용은 swatches 데모를 참고하세요. 동작 버튼 구성은 actions 속성과 action 슬롯으로 조절해요.