Browse Source

feat(gui-v2): use A-Rate & integrate with column?.meta

pull/2907/head
Wing-Kam Wong 2 years ago
parent
commit
4a39ed5247
  1. 31
      packages/nc-gui-v2/components/cell/Rating.vue

31
packages/nc-gui-v2/components/cell/Rating.vue

@ -1,8 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject } from '#imports' import { computed, inject } from '#imports'
import { ColumnInj, IsFormInj } from '~/context' import { ColumnInj } from '~/context'
import MdiStarIcon from '~icons/mdi/star' import MdiStarIcon from '~icons/mdi/star'
import MdiStarOutlineIcon from '~icons/mdi/star-outline' import MdiHeartIcon from '~icons/mdi/heart'
import MdiMoonFullIcon from '~icons/mdi/moon-full'
import MdiThumbUpIcon from '~icons/mdi/thumb-up'
import MdiFlagIcon from '~icons/mdi/flag'
interface Props { interface Props {
modelValue?: string | number modelValue?: string | number
@ -10,9 +13,10 @@ interface Props {
} }
const { modelValue: value, readOnly } = defineProps<Props>() const { modelValue: value, readOnly } = defineProps<Props>()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const column = inject(ColumnInj) const column = inject(ColumnInj)
const isForm = inject(IsFormInj)
const ratingMeta = computed(() => { const ratingMeta = computed(() => {
return { return {
@ -22,25 +26,26 @@ const ratingMeta = computed(() => {
}, },
color: '#fcb401', color: '#fcb401',
max: 5, max: 5,
// ...(column?.meta || {}) ...(column?.meta || {}),
} }
}) })
const localState = computed({ const localState = computed({
get: () => value, get: () => value,
set: (val) => emit('update:modelValue', val), set: (val: any) => emit('update:modelValue', val),
}) })
</script> </script>
<template> <template>
<div class="d-100 h-100" :class="{ 'nc-cell-hover-show': localState === 0 || !localState }"> <div class="text-sm" :class="{ 'nc-cell-hover-show': localState === 0 || !localState }">
<v-rating v-model="localState" :length="ratingMeta.max" dense x-small :readonly="readOnly" clearable> <a-rate v-model:value="localState" :count="ratingMeta.max" :style="`color: ${ratingMeta.color}`">
<!-- todo: use the proper slot --> <template #character>
<template #item="{ isFilled, click }"> <MdiStarIcon v-if="ratingMeta.icon.full === 'mdi-star'" />
<!-- todo : custom icon --> <MdiHeartIcon v-if="ratingMeta.icon.full === 'mdi-heart'" />
<MdiStarIcon v-if="isFilled" :style="`color: ${ratingMeta.color}`" @click="click" /> <MdiMoonFullIcon v-if="ratingMeta.icon.full === 'mdi-moon-full'" />
<MdiStarOutlineIcon v-else :style="`color: ${ratingMeta.color}`" @click="click" /> <MdiThumbUpIcon v-if="ratingMeta.icon.full === 'mdi-thumb-up'" />
<MdiFlagIcon v-if="ratingMeta.icon.full === 'mdi-flag'" />
</template> </template>
</v-rating> </a-rate>
</div> </div>
</template> </template>

Loading…
Cancel
Save