---
title: "ColorPicker"
description: "Компонент выбора цвета."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/color-picker"
---
# ColorPicker

> Компонент выбора цвета.

## Использование

Директива `v-model` управляет значением ColorPicker.

```vue
<script setup lang="ts">
const value = ref('#00C16A')
</script>

<template>
  <B24ColorPicker v-model="value" />
</template>
```

Пропс `default-value` задаёт начальное значение, если состоянием управлять не нужно.

```vue
<template>
  <B24ColorPicker default-value="#00BCD4" />
</template>
```

### Формат RGB

Пропс `format` со значением `rgb` задаёт значение ColorPicker в формате RGB.

```vue
<script setup lang="ts">
const value = ref('rgb(0, 193, 106)')
</script>

<template>
  <B24ColorPicker format="rgb" v-model="value" />
</template>
```

### Формат HSL

Пропс `format` со значением `hsl` задаёт значение ColorPicker в формате HSL.

```vue
<script setup lang="ts">
const value = ref('hsl(153, 100%, 37.8%)')
</script>

<template>
  <B24ColorPicker format="hsl" v-model="value" />
</template>
```

### Формат CMYK

Пропс `format` со значением `cmyk` задаёт значение ColorPicker в формате CMYK.

```vue
<script setup lang="ts">
const value = ref('cmyk(100%, 0%, 45.08%, 24.31%)')
</script>

<template>
  <B24ColorPicker format="cmyk" v-model="value" />
</template>
```

### Формат CIELab

Пропс `format` со значением `lab` задаёт значение ColorPicker в формате CIELab.

```vue
<script setup lang="ts">
const value = ref('lab(68.88% -60.41% 32.55%)')
</script>

<template>
  <B24ColorPicker format="lab" v-model="value" />
</template>
```

### Троттлинг

Пропс `throttle` задаёт частоту обновления значения ColorPicker.

```vue
<script setup lang="ts">
const value = ref('#00C16A')
</script>

<template>
  <B24ColorPicker :throttle="100" v-model="value" />
</template>
```

### Размер

Пропс `size` задаёт размер ColorPicker.

```vue
<template>
  <B24ColorPicker size="lg" />
</template>
```

### Отключение

Пропс `disabled` отключает ColorPicker.

```vue
<template>
  <B24ColorPicker disabled />
</template>
```

## Примеры

### Выбор цвета в выпадающем окне

Чтобы собрать выбор цвета, используйте компоненты [Button](https://b24-ui.bx-shef.by/raw/docs/components/button.md) и [Popover](https://b24-ui.bx-shef.by/raw/docs/components/popover.md).

```vue [ColorPickerChooserExample.vue]
<script setup lang="ts">
const color = ref('#00C16A')

const chip = computed(() => ({ backgroundColor: color.value }))
</script>

<template>
  <B24Popover>
    <B24Button label="Выбрать цвет">
      <template #leading>
        <span :style="chip" class="size-3 rounded-full" />
      </template>
    </B24Button>

    <template #content>
      <B24ColorPicker v-model="color" class="p-2" />
    </template>
  </B24Popover>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the ColorPicker component
 */
interface ColorPickerProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * Throttle time in ms for the color picker
   * @default 50
   */
  throttle?: number | undefined;
  /**
   * Disable the color picker
   */
  disabled?: boolean | undefined;
  /**
   * The default value of the color picker
   * @default '#FFFFFF'
   */
  defaultValue?: string | undefined;
  /**
   * Format of the color
   * @default 'hex'
   */
  format?: "hex" | "rgb" | "hsl" | "cmyk" | "lab" | undefined;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | undefined;
  b24ui?: { root?: SlotClass; picker?: SlotClass; selector?: SlotClass; selectorBackground?: SlotClass; selectorThumb?: SlotClass; track?: SlotClass; trackThumb?: SlotClass; } | undefined;
  modelValue?: string | undefined;
}
```

### События

```ts
/**
 * Emitted events for the ColorPicker component
 */
interface ColorPickerEmits {
  update:modelValue: (payload: [value: string | undefined]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    colorPicker: {
      slots: {
        root: 'data-[disabled]:opacity-30',
        picker: 'flex gap-4',
        selector: 'rounded-(--ui-border-radius-md) touch-none',
        selectorBackground: 'w-full h-full relative rounded-(--ui-border-radius-md)',
        selectorThumb: '-translate-y-1/2 -translate-x-1/2 absolute size-4 ring-2 ring-(--ui-color-base-white-fixed) rounded-full cursor-pointer data-[disabled]:cursor-not-allowed',
        track: 'w-2 relative rounded-(--ui-border-radius-md) touch-none',
        trackThumb: 'absolute transform -translate-y-1/2 -translate-x-[4px] rtl:translate-x-[4px] size-4 rounded-full ring-2 ring-(--ui-color-base-white-fixed) cursor-pointer data-[disabled]:cursor-not-allowed'
      },
      variants: {
        size: {
          xs: {
            selector: 'w-[152px] h-[152px]',
            track: 'h-[152px]'
          },
          sm: {
            selector: 'w-[160px] h-[160px]',
            track: 'h-[160px]'
          },
          md: {
            selector: 'w-[168px] h-[168px]',
            track: 'h-[168px]'
          },
          lg: {
            selector: 'w-[176px] h-[176px]',
            track: 'h-[176px]'
          }
        }
      },
      defaultVariants: {
        size: 'md'
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
