Skip to content

Commit 6b6ec8c

Browse files
authored
fix(ColorPicker): update color conversion logic (#4550)
1 parent e2695ee commit 6b6ec8c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

playground/app/pages/components/color-picker.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<script setup lang="ts">
22
const colorHex = ref('#9C27B0')
3+
4+
function handleColorChange(event: Event) {
5+
colorHex.value = (event.target as HTMLInputElement).value
6+
}
37
</script>
48

59
<template>
610
<div class="flex flex-col gap-5">
711
<div class="flex items-center gap-2">
812
<span :style="{ backgroundColor: colorHex }" class="inline-flex w-5 h-5 rounded" />
9-
<code class="font-mono">{{ colorHex }}</code>
13+
<UInput :model-value="colorHex" @change="handleColorChange" />
1014
</div>
1115
<USeparator />
1216
<div class="flex justify-between gap-2">
@@ -21,6 +25,6 @@ const colorHex = ref('#9C27B0')
2125
</UButton>
2226
</div>
2327
<USeparator />
24-
<UColorPicker v-model="colorHex" @update:model-value="() => console.log('model update')" />
28+
<UColorPicker v-model="colorHex" />
2529
</div>
2630
</template>

src/runtime/components/ColorPicker.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function HSVtoHSL(hsv: HSVColor): HSLObject {
3131
return {
3232
H: hsv.h,
3333
S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)),
34-
L: Math.round(x / 2)
34+
L: x / 2
3535
}
3636
}
3737
@@ -102,7 +102,6 @@ const pickedColor = computed<HSVColor>({
102102
},
103103
set(value) {
104104
const color = new ColorTranslator(HSVtoHSL(value), {
105-
decimals: 2,
106105
labUnit: 'percent',
107106
cmykUnit: 'percent',
108107
cmykFunction: 'cmyk'

0 commit comments

Comments
 (0)