From 9453ce13974101b15280df42e6abdbc979d3dc17 Mon Sep 17 00:00:00 2001 From: "Samuel M. Bednarz" Date: Mon, 29 Jan 2024 02:57:33 +0100 Subject: [PATCH] lots of type and props improvements --- .../dye/components/Canvas/ColorCanvas.vue | 5 ++- packages/dye/components/Canvas/HueCanvas.vue | 19 ++++---- packages/dye/components/DyePicker.vue | 43 +++++++++++++++---- packages/dye/package.json | 2 +- packages/playground/src/App.vue | 9 +++- 5 files changed, 59 insertions(+), 19 deletions(-) diff --git a/packages/dye/components/Canvas/ColorCanvas.vue b/packages/dye/components/Canvas/ColorCanvas.vue index 86c3aa3..d602a08 100644 --- a/packages/dye/components/Canvas/ColorCanvas.vue +++ b/packages/dye/components/Canvas/ColorCanvas.vue @@ -13,7 +13,10 @@ import { import { fillColorCanvas } from '../../composables/gradient' import Handle from '../Handle.vue' -const emit = defineEmits(['change']) +const emit = defineEmits<{ + (e: 'change', hex: hexType): void +}>() + const props = defineProps<{ getRef: () => Ref setRef: (el: any) => void diff --git a/packages/dye/components/Canvas/HueCanvas.vue b/packages/dye/components/Canvas/HueCanvas.vue index 130af28..b73a5cb 100644 --- a/packages/dye/components/Canvas/HueCanvas.vue +++ b/packages/dye/components/Canvas/HueCanvas.vue @@ -20,7 +20,10 @@ interface Hsl { l: number } -const emit = defineEmits(['change']) +const emit = defineEmits<{ + (e: 'change', props: { hex: hexType; mounted: boolean }): void +}>() + const props = defineProps<{ width: number colorCanvas: () => Ref @@ -44,7 +47,6 @@ function hueGradient( hsl: Hsl = { h: 0, s: 1, l: 0.5 } ) { const gradient = ctx.createLinearGradient(0, 0, 0, height) - console.log('rex: ', hsl) for (var hue = 0; hue <= 360; hue++) { var hslColor = `hsl(${hue}, ${hsl.s}%, ${hsl.l}%)` gradient.addColorStop(hue / 360, hslColor) @@ -79,9 +81,9 @@ function hueChange(e: MouseEvent, click = false) { mouseOn.value = true } -function updateCanvas(hex: hexType) { +function updateCanvas(hex: hexType, mounted = false) { if (!hex) return - emit('change', hex) + emit('change', { hex, mounted }) fillColorCanvas({ hue: hex.color }, props.colorCanvas().value) position.value = { x: position.value.x, @@ -116,16 +118,17 @@ onMounted(() => { fillHueCanvas() setCenterHandle() - var color = colord(props.color.value) + const color = colord(props.color.value) const hsl = color.toHsl() - - updateCanvas({ + const hex = { color: props.color.value, position: { x: 0, y: huePercent(hsl.h, canvasHeight.value) } - }) + } + + updateCanvas(hex, true) }) diff --git a/packages/dye/components/DyePicker.vue b/packages/dye/components/DyePicker.vue index 4b12f49..028a7de 100644 --- a/packages/dye/components/DyePicker.vue +++ b/packages/dye/components/DyePicker.vue @@ -1,5 +1,6 @@ diff --git a/packages/dye/package.json b/packages/dye/package.json index 525e65d..afa94d3 100644 --- a/packages/dye/package.json +++ b/packages/dye/package.json @@ -1,7 +1,7 @@ { "name": "@umbrajs/dye", "private": false, - "version": "0.0.0", + "version": "0.0.002", "description": "Vue color picker using umbra", "author": "Samuel M. Bednarz", "license": "MIT", diff --git a/packages/playground/src/App.vue b/packages/playground/src/App.vue index 0948edd..28d3cc2 100644 --- a/packages/playground/src/App.vue +++ b/packages/playground/src/App.vue @@ -92,7 +92,14 @@ const height = ref('8rem')