mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-02-02 13:17:57 +01:00
fix(ColorPicker): update color conversion logic (#4550)
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const colorHex = ref('#9C27B0')
|
const colorHex = ref('#9C27B0')
|
||||||
|
|
||||||
|
function handleColorChange(event: Event) {
|
||||||
|
colorHex.value = (event.target as HTMLInputElement).value
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-5">
|
<div class="flex flex-col gap-5">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span :style="{ backgroundColor: colorHex }" class="inline-flex w-5 h-5 rounded" />
|
<span :style="{ backgroundColor: colorHex }" class="inline-flex w-5 h-5 rounded" />
|
||||||
<code class="font-mono">{{ colorHex }}</code>
|
<UInput :model-value="colorHex" @change="handleColorChange" />
|
||||||
</div>
|
</div>
|
||||||
<USeparator />
|
<USeparator />
|
||||||
<div class="flex justify-between gap-2">
|
<div class="flex justify-between gap-2">
|
||||||
@@ -21,6 +25,6 @@ const colorHex = ref('#9C27B0')
|
|||||||
</UButton>
|
</UButton>
|
||||||
</div>
|
</div>
|
||||||
<USeparator />
|
<USeparator />
|
||||||
<UColorPicker v-model="colorHex" @update:model-value="() => console.log('model update')" />
|
<UColorPicker v-model="colorHex" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ function HSVtoHSL(hsv: HSVColor): HSLObject {
|
|||||||
return {
|
return {
|
||||||
H: hsv.h,
|
H: hsv.h,
|
||||||
S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)),
|
S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)),
|
||||||
L: Math.round(x / 2)
|
L: x / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,6 @@ const pickedColor = computed<HSVColor>({
|
|||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
const color = new ColorTranslator(HSVtoHSL(value), {
|
const color = new ColorTranslator(HSVtoHSL(value), {
|
||||||
decimals: 2,
|
|
||||||
labUnit: 'percent',
|
labUnit: 'percent',
|
||||||
cmykUnit: 'percent',
|
cmykUnit: 'percent',
|
||||||
cmykFunction: 'cmyk'
|
cmykFunction: 'cmyk'
|
||||||
|
|||||||
Reference in New Issue
Block a user