|
|
@ -3,10 +3,11 @@ import { Chrome } from '@ckpack/vue-color' |
|
|
|
import { enumColor } from '@/utils' |
|
|
|
import { enumColor } from '@/utils' |
|
|
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
interface Props { |
|
|
|
modelValue: String |
|
|
|
modelValue: string | any |
|
|
|
colors?: String[] |
|
|
|
colors?: string[] |
|
|
|
rowSize?: number |
|
|
|
rowSize?: number |
|
|
|
advanced?: Boolean |
|
|
|
advanced?: Boolean |
|
|
|
|
|
|
|
pickButton?: Boolean |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), { |
|
|
|
const props = withDefaults(defineProps<Props>(), { |
|
|
@ -14,14 +15,21 @@ const props = withDefaults(defineProps<Props>(), { |
|
|
|
colors: () => enumColor.light.concat(enumColor.dark), |
|
|
|
colors: () => enumColor.light.concat(enumColor.dark), |
|
|
|
rowSize: () => 10, |
|
|
|
rowSize: () => 10, |
|
|
|
advanced: () => true, |
|
|
|
advanced: () => true, |
|
|
|
|
|
|
|
pickButton: () => false, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue']) |
|
|
|
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 picked = ref(props.modelValue || enumColor.light[0]) |
|
|
|
|
|
|
|
|
|
|
|
const select = (color: any) => { |
|
|
|
const selectColor = (color: any) => { |
|
|
|
picked.value = color.hex ? color.hex : color |
|
|
|
picked.value = color.hex ? color.hex : color |
|
|
|
vModel.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 |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch(picked, (n, _o) => { |
|
|
|
|
|
|
|
if (!props.pickButton) { |
|
|
|
|
|
|
|
vModel.value = n.hex ? n.hex : n |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
<template> |
|
|
@ -43,17 +57,19 @@ const compare = (colorA: String, colorB: String) => { |
|
|
|
class="color-selector" |
|
|
|
class="color-selector" |
|
|
|
:class="compare(picked, color) ? 'selected' : ''" |
|
|
|
:class="compare(picked, color) ? 'selected' : ''" |
|
|
|
:style="{ 'background-color': `${color}` }" |
|
|
|
:style="{ 'background-color': `${color}` }" |
|
|
|
@click="select(color)" |
|
|
|
@click="selectColor(color)" |
|
|
|
> |
|
|
|
> |
|
|
|
{{ compare(picked, color) ? '✓' : '' }} |
|
|
|
{{ compare(picked, color) ? '✓' : '' }} |
|
|
|
</button> |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<a-card v-if="props.advanced" class="w-full shadow-lg mt-2" :body-style="{ padding: '0px' }"> |
|
|
|
<a-card v-if="props.advanced" class="w-full mt-2" :body-style="{ padding: '0px' }" :bordered="false"> |
|
|
|
<a-collapse accordion ghost expand-icon-position="right"> |
|
|
|
<a-collapse accordion ghost expand-icon-position="right"> |
|
|
|
<a-collapse-panel key="1" header="Advanced" class=""> |
|
|
|
<a-collapse-panel key="1" header="Advanced" class=""> |
|
|
|
<a-button class="!bg-primary text-white w-full" @click="select(picked)"> Pick Color </a-button> |
|
|
|
<a-button v-if="props.pickButton" class="!bg-primary text-white w-full" @click="selectColor(picked)"> |
|
|
|
|
|
|
|
Pick Color |
|
|
|
|
|
|
|
</a-button> |
|
|
|
<div class="flex justify-center py-4"> |
|
|
|
<div class="flex justify-center py-4"> |
|
|
|
<Chrome v-model="picked" /> |
|
|
|
<Chrome v-model="picked" class="!w-full !shadow-none" /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</a-collapse-panel> |
|
|
|
</a-collapse-panel> |
|
|
|
</a-collapse> |
|
|
|
</a-collapse> |
|
|
|