From 76abb4afb185905381bfb323dfe852edbfb008ac Mon Sep 17 00:00:00 2001 From: "Samuel M. Bednarz" Date: Sat, 3 Feb 2024 21:44:09 +0100 Subject: [PATCH] scope umbra to the entire color picker not just the pallet --- packages/dye/App.vue | 11 ++ .../dye/components/Canvas/ColorCanvas.vue | 16 ++- packages/dye/components/DyePicker.vue | 57 +++++----- packages/dye/components/Pallet.vue | 17 +-- packages/dye/composables/colorName/index.ts | 17 ++- packages/dye/css/block.scss | 67 ++++++++++++ packages/dye/css/color.scss | 13 +++ packages/dye/css/elements.scss | 61 +++++++++++ packages/dye/css/index.scss | 50 +++++++++ packages/dye/css/spaces.scss | 20 ++++ packages/dye/css/type.scss | 100 ++++++++++++++++++ packages/dye/index.html | 13 +++ packages/dye/main.ts | 4 + 13 files changed, 388 insertions(+), 58 deletions(-) create mode 100644 packages/dye/App.vue create mode 100644 packages/dye/css/block.scss create mode 100644 packages/dye/css/color.scss create mode 100644 packages/dye/css/elements.scss create mode 100644 packages/dye/css/index.scss create mode 100644 packages/dye/css/spaces.scss create mode 100644 packages/dye/css/type.scss create mode 100644 packages/dye/index.html create mode 100644 packages/dye/main.ts diff --git a/packages/dye/App.vue b/packages/dye/App.vue new file mode 100644 index 0000000..af1354d --- /dev/null +++ b/packages/dye/App.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/packages/dye/components/Canvas/ColorCanvas.vue b/packages/dye/components/Canvas/ColorCanvas.vue index d602a08..38ade41 100644 --- a/packages/dye/components/Canvas/ColorCanvas.vue +++ b/packages/dye/components/Canvas/ColorCanvas.vue @@ -57,15 +57,11 @@ function getHue(color: string = props.color.value) { const { width, height } = responsiveCanvas({ canvas: props.getRef(), - updateCanvas: () => - fillColorCanvas( - { - hue: getHue(), - saturation: 100, - lightness: 100 - }, - props.getRef().value - ) + updateCanvas: () => { + const hue = getHue() + const data = { hue, saturation: 100, lightness: 100 } + fillColorCanvas(data, props.getRef().value) + } }) function getPercent(percent: number, height?: number) { @@ -114,6 +110,6 @@ canvas.color-canvas { aspect-ratio: 1/1; width: 100%; height: 100%; - background-color: var(--base-20, rgb(64, 0, 0)); + background-color: var(--base-20, rgb(30, 0, 64)); } diff --git a/packages/dye/components/DyePicker.vue b/packages/dye/components/DyePicker.vue index 028a7de..0d94b7c 100644 --- a/packages/dye/components/DyePicker.vue +++ b/packages/dye/components/DyePicker.vue @@ -3,7 +3,8 @@ import { colord } from 'colord' import type { Colord } from 'colord' import { vOnClickOutside } from '@vueuse/components' -import { ref } from 'vue' +import { umbra } from '@umbrajs/core' +import { ref, watch } from 'vue' import { colorName } from '../composables/colorName' import { hexType } from '../composables/canvas' import Pallet from './Pallet.vue' @@ -22,10 +23,10 @@ const emit = defineEmits<{ }>() interface Props { - default: string - compact: boolean - compactSize: number - hueWidth: number + default?: string + compact?: boolean + compactSize?: number + hueWidth?: number } const props = withDefaults(defineProps(), { @@ -35,9 +36,21 @@ const props = withDefaults(defineProps(), { hueWidth: 25 }) -const pallet = ref(null) +const pickerRef = ref(null) const colorCanvas = ref(null) +const color = ref({ + name: 'red', + value: props.default +}) + +watch(color, (c) => { + if (!pickerRef.value) return + umbra({ + background: c.value + }).apply({ target: pickerRef.value }) +}) + function getRef() { return colorCanvas } @@ -46,11 +59,6 @@ function setRef(el: HTMLCanvasElement) { colorCanvas.value = el } -const color = ref({ - name: 'red', - value: props.default -}) - function handleChange(hex?: hexType, mounted = false) { if (!hex) return const get = colorName(hex.color) @@ -71,18 +79,19 @@ const hueWidth = ref(props.hueWidth)