Browse Source

feat(nc-gui): add base icon color support

pull/7807/head
Ramesh Mane 9 months ago
parent
commit
25dfa89734
  1. 28
      packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue
  2. 44
      packages/nc-gui/components/general/BaseColorPicker.vue
  3. 60
      packages/nc-gui/lib/constants.ts

28
packages/nc-gui/components/dashboard/TreeView/ProjectNode.vue

@ -172,16 +172,16 @@ defineExpose({
enableEditMode, enableEditMode,
}) })
const setIcon = async (icon: string, base: BaseType) => { const setColor = async (hue: number, base: BaseType) => {
try { try {
const meta = { const meta = {
...((base.meta as object) || {}), ...parseProp(base.meta),
icon, iconHue: hue,
} }
basesStore.updateProject(base.id!, { meta: JSON.stringify(meta) }) basesStore.updateProject(base.id!, { meta: JSON.stringify(meta) })
$e('a:base:icon:navdraw', { icon }) $e('a:base:icon:color:navdraw', { iconHue: hue })
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
} }
@ -385,6 +385,10 @@ const projectDelete = () => {
isProjectDeleteDialogVisible.value = true isProjectDeleteDialogVisible.value = true
$e('c:project:delete') $e('c:project:delete')
} }
watchEffect(() => {
console.log('base', base.value)
})
</script> </script>
<template> <template>
@ -423,16 +427,18 @@ const projectDelete = () => {
<div v-e="['c:base:emojiSelect']" class="flex items-center select-none w-6 h-full"> <div v-e="['c:base:emojiSelect']" class="flex items-center select-none w-6 h-full">
<a-spin v-if="base.isLoading" class="!ml-1.25 !flex !flex-row !items-center !my-0.5 w-8" :indicator="indicator" /> <a-spin v-if="base.isLoading" class="!ml-1.25 !flex !flex-row !items-center !my-0.5 w-8" :indicator="indicator" />
<LazyGeneralEmojiPicker <LazyGeneralBaseColorPicker
v-else v-else
:key="base.meta?.icon" :key="parseProp(base.meta).iconHue"
:emoji="base.meta?.icon" :hue="parseProp(base.meta).iconHue"
:readonly="true"
size="small" size="small"
@emoji-selected="setIcon($event, base)" :readonly="base.type && base.type !== 'database'"
@color-selected="setColor($event, base)"
> >
<GeneralProjectIcon :type="base.type" /> <template #default>
</LazyGeneralEmojiPicker> <GeneralProjectIcon :type="base.type" />
</template>
</LazyGeneralBaseColorPicker>
</div> </div>
</div> </div>

44
packages/nc-gui/components/general/BaseColorPicker.vue

@ -2,8 +2,10 @@
import { Slider } from '@ckpack/vue-color' import { Slider } from '@ckpack/vue-color'
import tinycolor from 'tinycolor2' import tinycolor from 'tinycolor2'
import { BASE_ICON_COLOR_HUE_DATA as preDefinedHueData } from '#imports'
const props = defineProps<{ const props = defineProps<{
hue?: number | undefined hue?: number | null
size?: 'small' | 'medium' | 'large' | 'xlarge' size?: 'small' | 'medium' | 'large' | 'xlarge'
readonly?: boolean readonly?: boolean
disableClearing?: boolean disableClearing?: boolean
@ -13,8 +15,6 @@ const emit = defineEmits(['colorSelected'])
const { hue, size = 'medium', readonly } = props const { hue, size = 'medium', readonly } = props
const hueData = [199, 24, 41, 141, 224, 3, 317, 271, 332]
const defaultHueValue = { const defaultHueValue = {
h: 0, h: 0,
s: 0, s: 0,
@ -92,7 +92,7 @@ watch(
}" }"
@click="onClick" @click="onClick"
> >
<template v-if="colorRef?.h === undefined"> <template v-if="hue === undefined || hue === null">
<slot name="default" /> <slot name="default" />
</template> </template>
<template v-else> <template v-else>
@ -113,13 +113,29 @@ watch(
fill-rule="evenodd" fill-rule="evenodd"
clip-rule="evenodd" clip-rule="evenodd"
d="M638.951 291.265L936.342 462.949C966.129 480.145 980.256 502.958 978.723 525.482V774.266C980.256 796.789 966.129 819.602 936.342 836.798L638.951 1008.48C582.292 1041.19 490.431 1041.19 433.773 1008.48L136.381 836.798C106.595 819.602 92.4675 796.789 93.9999 774.266L93.9999 525.482C92.4675 502.957 106.595 480.145 136.381 462.949L433.773 291.265C490.431 258.556 582.292 258.556 638.951 291.265Z" d="M638.951 291.265L936.342 462.949C966.129 480.145 980.256 502.958 978.723 525.482V774.266C980.256 796.789 966.129 819.602 936.342 836.798L638.951 1008.48C582.292 1041.19 490.431 1041.19 433.773 1008.48L136.381 836.798C106.595 819.602 92.4675 796.789 93.9999 774.266L93.9999 525.482C92.4675 502.957 106.595 480.145 136.381 462.949L433.773 291.265C490.431 258.556 582.292 258.556 638.951 291.265Z"
:fill="tinycolor(`hsv(${colorRef?.h || 'none'}, 100%, 30%)`).toHexString()" :fill="
tinycolor(
preDefinedHueData[`_${colorRef?.h}`]
? `hsv(${preDefinedHueData[`_${colorRef?.h}`].shade.h},${preDefinedHueData[`_${colorRef?.h}`].shade.s}%, ${
preDefinedHueData[`_${colorRef?.h}`].shade.v
}%)`
: `hsv(${colorRef?.h || 'none'}, 100%, 30%)`,
).toHexString()
"
/> />
<path <path
fill-rule="evenodd" fill-rule="evenodd"
clip-rule="evenodd" clip-rule="evenodd"
d="M638.951 65.0055L936.342 236.69C966.129 253.886 980.256 276.699 978.723 299.222V548.006C980.256 570.529 966.129 593.343 936.342 610.538L638.951 782.223C582.292 814.931 490.431 814.931 433.773 782.223L136.381 610.538C106.595 593.343 92.4675 570.529 93.9999 548.006L93.9999 299.222C92.4675 276.699 106.595 253.886 136.381 236.69L433.773 65.0055C490.431 32.2968 582.292 32.2968 638.951 65.0055Z" d="M638.951 65.0055L936.342 236.69C966.129 253.886 980.256 276.699 978.723 299.222V548.006C980.256 570.529 966.129 593.343 936.342 610.538L638.951 782.223C582.292 814.931 490.431 814.931 433.773 782.223L136.381 610.538C106.595 593.343 92.4675 570.529 93.9999 548.006L93.9999 299.222C92.4675 276.699 106.595 253.886 136.381 236.69L433.773 65.0055C490.431 32.2968 582.292 32.2968 638.951 65.0055Z"
:fill="tinycolor(`hsv(${colorRef?.h || 'none'}, 30%, 100%)`).toHexString()" :fill="
tinycolor(
preDefinedHueData[`_${colorRef?.h}`]
? `hsv(${preDefinedHueData[`_${colorRef?.h}`].tint.h},${preDefinedHueData[`_${colorRef?.h}`].tint.s}%, ${
preDefinedHueData[`_${colorRef?.h}`].tint.v
}%)`
: `hsv(${colorRef?.h || 'none'}, 30%, 100%)`,
).toHexString()
"
/> />
</g> </g>
</svg> </svg>
@ -129,7 +145,7 @@ watch(
<div class="relative bg-white rounded-lg p-3 border-1 border-gray-200 shadow-lg"> <div class="relative bg-white rounded-lg p-3 border-1 border-gray-200 shadow-lg">
<div class="w-[164px] flex flex-wrap"> <div class="w-[164px] flex flex-wrap">
<div <div
v-for="(h, i) of hueData" v-for="(h, i) of Object.keys(preDefinedHueData)"
:key="i" :key="i"
class="nc-pre-defined-hue-item p-1 rounded cursor-pointer hover:bg-gray-200" class="nc-pre-defined-hue-item p-1 rounded cursor-pointer hover:bg-gray-200"
:class="{ :class="{
@ -139,12 +155,12 @@ watch(
<div <div
class="rounded h-6 w-6" class="rounded h-6 w-6"
:class="{ :class="{
selected: h === hue, selected: preDefinedHueData[h].tint.h === hue || (h === '_199' && (hue === undefined || hue === null)),
}" }"
:style="{ :style="{
backgroundColor: tinycolor(`hsv(${h}, 30%, 100%) `).toHexString(), backgroundColor: preDefinedHueData[h].pickerColor,
}" }"
@click="selectColor(h)" @click="selectColor(preDefinedHueData[h].tint.h)"
></div> ></div>
</div> </div>
@ -153,7 +169,7 @@ watch(
:trigger="['click']" :trigger="['click']"
:disabled="readonly" :disabled="readonly"
placement="bottom" placement="bottom"
overlayClassName="!left-9" overlay-class-name="!left-9"
> >
<div <div
class="nc-custom-hue-picker-item p-1 rounded cursor-pointer hover:bg-gray-200 mt-3" class="nc-custom-hue-picker-item p-1 rounded cursor-pointer hover:bg-gray-200 mt-3"
@ -164,7 +180,7 @@ watch(
<div <div
class="rounded overflow-hidden h-6 w-6" class="rounded overflow-hidden h-6 w-6"
:class="{ :class="{
selected: hue !== undefined && hue !== null && !hueData.includes(hue), selected: hue !== undefined && hue !== null && !preDefinedHueData[`_${hue}`],
}" }"
:style="{ :style="{
backgroundColor: tinycolor(`hsv(${hue}, 30%, 100%) `).toHexString(), backgroundColor: tinycolor(`hsv(${hue}, 30%, 100%) `).toHexString(),
@ -204,10 +220,6 @@ watch(
</template> </template>
</a-dropdown> </a-dropdown>
</div> </div>
<div class="mt-3 flex items-center justify-end">
<NcButton type="secondary" size="small" @click.stop="selectColor(null)"> {{ $t('general.remove') }} </NcButton>
</div>
</div> </div>
</template> </template>
</a-dropdown> </a-dropdown>

60
packages/nc-gui/lib/constants.ts

@ -18,3 +18,63 @@ export const GROUP_BY_VARS = {
__nc_false__: 'Unchecked', __nc_false__: 'Unchecked',
} as Record<string, string>, } as Record<string, string>,
} }
export const BASE_ICON_COLOR_HUE_DATA: Record<
string,
{ tint: { h: number; s: number; v: number }; shade: { h: number; s: number; v: number }; pickerColor: string }
> = {
// blue
_199: {
tint: { h: 199, s: 79, v: 100 },
shade: { h: 255, s: 80, v: 40 },
pickerColor: '#36BFFF',
},
// orange
_24: {
tint: { h: 24, s: 64, v: 98 },
shade: { h: 24, s: 81, v: 59 },
pickerColor: '#FA8231',
},
// yellow
_41: {
tint: { h: 41, s: 62, v: 99 },
shade: { h: 41, s: 77, v: 40 },
pickerColor: '#FCBE3A',
},
// green
_141: {
tint: { h: 141, s: 63, v: 87 },
shade: { h: 141, s: 81, v: 34 },
pickerColor: '#27D665',
},
// gray
_217: {
tint: { h: 217, s: 12, v: 69 },
shade: { h: 217, s: 32, v: 32 },
pickerColor: '#6A7184',
},
// red
_4: {
tint: { h: 4, s: 60, v: 100 },
shade: { h: 4, s: 74, v: 49 },
pickerColor: '#FF4A3F',
},
// pink
_317: {
tint: { h: 317, s: 62, v: 99 },
shade: { h: 317, s: 77, v: 40 },
pickerColor: '#FC3AC6',
},
// purple
_271: {
tint: { h: 271, s: 62, v: 84 },
shade: { h: 271, s: 82, v: 32 },
pickerColor: '#7D26CD',
},
// maroon
_332: {
tint: { h: 332, s: 58, v: 83 },
shade: { h: 332, s: 93, v: 41 },
pickerColor: '#B33771',
},
}

Loading…
Cancel
Save