Colorpimiento

Un componente para seleccionar un color.

xph0000xUso

Utilice la directiva v-model para controlar el valor del ColorPicker.

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

<template>
  <UColorPicker v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('#00C16A')
</script>

<template>
  <UColorPicker v-model="value" />
</template>

Utilice el prop default-value para establecer el valor inicial cuando no necesite controlar su estado.

<template>
  <UColorPicker default-value="#00BCD4" />
</template>

XPH017xRGB en formato

Utilice el prop format para establecer el valor rgb del ColorPicker.

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

<template>
  <UColorPicker format="rgb" v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('rgb(0, 193, 106)')
</script>

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

Formato ### HSL

Utilice el prop format para establecer el valor hsl del ColorPicker.

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

<template>
  <UColorPicker format="hsl" v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('hsl(153, 100%, 37.8%)')
</script>

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

Formato ### CMYK

Utilice el prop format para establecer el valor cmyk del ColorPicker.

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

<template>
  <UColorPicker format="cmyk" v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('cmyk(100%, 0%, 45.08%, 24.31%)')
</script>

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

CIELab en formato

Utilice el prop format para establecer el valor lab del ColorPicker.

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

<template>
  <UColorPicker format="lab" v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('lab(68.88% -60.41% 32.55%)')
</script>

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

Throttle (Edición española)

Utilice el prop throttle para ajustar el valor del acelerador del ColorPicker.

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

<template>
  <UColorPicker :throttle="100" v-model="value" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref('#00C16A')
</script>

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

Tamaño

Utilice el prop size para establecer el tamaño del ColorPicker.

<template>
  <UColorPicker size="xl" />
</template>

Desactivado

Utilice el prop disabled para desactivar el ColorPicker.

<template>
  <UColorPicker disabled />
</template>

Ejemplos

As un selector de color

Utilice un componente Button y un componente Popover para crear un selector de color.

<script setup lang="ts">
const color = ref('#00C16A')

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

<template>
  <UPopover>
    <UButton label="Choose color" color="neutral" variant="outline">
      <template #leading>
        <span :style="chip" class="size-3 rounded-full" />
      </template>
    </UButton>

    <template #content>
      <UColorPicker v-model="color" class="p-2" />
    </template>
  </UPopover>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'

const color = ref('#00C16A')

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

<template>
  <UPopover>
    <UButton label="Choose color" color="neutral" variant="outline">
      <template #leading>
        <span :style="chip" class="size-3 rounded-full" />
      </template>
    </UButton>

    <template #content>
      <UColorPicker v-model="color" class="p-2" />
    </template>
  </UPopover>
</template>

API (Edición española)

Props (Edición española)

Prop Default Type
as
'div'
any

The element or component this component should render as.

throttle
50
number

Throttle time in ms for the color picker

disabled
boolean

Disable the color picker

defaultValue
'#FFFFFF'
string

The default value of the color picker

format
'hex'
"hex" | "rgb" | "hsl" | "cmyk" | "lab"

Format of the color

size
'md'
"xs" | "sm" | "md" | "lg" | "xl"
modelValue
string
ui
{ root?: SlotClass; picker?: SlotClass; selector?: SlotClass; selectorBackground?: SlotClass; selectorThumb?: SlotClass; track?: SlotClass; trackThumb?: SlotClass; }

Emisiones

Event Type
update:modelValue
[value: string | undefined]

Temas

app.config.ts
export default defineAppConfig({
  ui: {
    colorPicker: {
      slots: {
        root: 'data-[disabled]:opacity-75',
        picker: 'flex gap-4',
        selector: 'rounded-md touch-none',
        selectorBackground: 'w-full h-full relative rounded-md',
        selectorThumb: '-translate-y-1/2 -translate-x-1/2 absolute size-4 ring-2 ring-white rounded-full cursor-pointer data-[disabled]:cursor-not-allowed',
        track: 'w-[8px] relative rounded-md touch-none',
        trackThumb: 'absolute transform -translate-y-1/2 -translate-x-[4px] rtl:translate-x-[4px] size-4 rounded-full ring-2 ring-white cursor-pointer data-[disabled]:cursor-not-allowed'
      },
      variants: {
        size: {
          xs: {
            selector: 'w-38 h-38',
            track: 'h-38'
          },
          sm: {
            selector: 'w-40 h-40',
            track: 'h-40'
          },
          md: {
            selector: 'w-42 h-42',
            track: 'h-42'
          },
          lg: {
            selector: 'w-44 h-44',
            track: 'h-44'
          },
          xl: {
            selector: 'w-46 h-46',
            track: 'h-46'
          }
        }
      },
      defaultVariants: {
        size: 'md'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        colorPicker: {
          slots: {
            root: 'data-[disabled]:opacity-75',
            picker: 'flex gap-4',
            selector: 'rounded-md touch-none',
            selectorBackground: 'w-full h-full relative rounded-md',
            selectorThumb: '-translate-y-1/2 -translate-x-1/2 absolute size-4 ring-2 ring-white rounded-full cursor-pointer data-[disabled]:cursor-not-allowed',
            track: 'w-[8px] relative rounded-md touch-none',
            trackThumb: 'absolute transform -translate-y-1/2 -translate-x-[4px] rtl:translate-x-[4px] size-4 rounded-full ring-2 ring-white cursor-pointer data-[disabled]:cursor-not-allowed'
          },
          variants: {
            size: {
              xs: {
                selector: 'w-38 h-38',
                track: 'h-38'
              },
              sm: {
                selector: 'w-40 h-40',
                track: 'h-40'
              },
              md: {
                selector: 'w-42 h-42',
                track: 'h-42'
              },
              lg: {
                selector: 'w-44 h-44',
                track: 'h-44'
              },
              xl: {
                selector: 'w-46 h-46',
                track: 'h-46'
              }
            }
          },
          defaultVariants: {
            size: 'md'
          }
        }
      }
    })
  ]
})

Changelog (Edición española)

No recent changes