From 4a163772fb3d122cbe2e66ee34f2bea12fb4f697 Mon Sep 17 00:00:00 2001 From: mertmit Date: Wed, 10 Aug 2022 10:05:17 +0300 Subject: [PATCH] feat(gui-v2): ColorPicker improved Signed-off-by: mertmit --- .../components/general/ColorPicker.vue | 32 ++++++++++++++----- .../smartsheet-column/CheckboxOptions.vue | 2 +- .../smartsheet-column/RatingOptions.vue | 2 +- .../smartsheet-column/SelectOptions.vue | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/nc-gui-v2/components/general/ColorPicker.vue b/packages/nc-gui-v2/components/general/ColorPicker.vue index 44300663d8..c319f83299 100644 --- a/packages/nc-gui-v2/components/general/ColorPicker.vue +++ b/packages/nc-gui-v2/components/general/ColorPicker.vue @@ -3,10 +3,11 @@ import { Chrome } from '@ckpack/vue-color' import { enumColor } from '@/utils' interface Props { - modelValue: String - colors?: String[] + modelValue: string | any + colors?: string[] rowSize?: number advanced?: Boolean + pickButton?: Boolean } const props = withDefaults(defineProps(), { @@ -14,14 +15,21 @@ const props = withDefaults(defineProps(), { colors: () => enumColor.light.concat(enumColor.dark), rowSize: () => 10, advanced: () => true, + pickButton: () => false, }) const emit = defineEmits(['update:modelValue']) -const vModel = useVModel(props, 'modelValue', emit) + +const vModel = computed({ + get: () => props.modelValue, + set: (val) => { + emit('update:modelValue', val.hex ? val.hex : val || null) + }, +}) const picked = ref(props.modelValue || enumColor.light[0]) -const select = (color: any) => { +const selectColor = (color: any) => { picked.value = color.hex ? color.hex : color vModel.value = color.hex ? color.hex : color } @@ -32,6 +40,12 @@ const compare = (colorA: String, colorB: String) => { } return false } + +watch(picked, (n, _o) => { + if (!props.pickButton) { + vModel.value = n.hex ? n.hex : n + } +})