mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.4 KiB
67 lines
1.4 KiB
3 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import { ColumnInj, IsFormInj, ReadonlyInj, getMdiIcon, inject } from '#imports'
|
||
3 years ago
|
|
||
2 years ago
|
interface Props {
|
||
2 years ago
|
modelValue?: boolean | undefined | number
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
interface Emits {
|
||
|
(event: 'update:modelValue', model: boolean | undefined | number): void
|
||
|
}
|
||
|
|
||
|
const props = defineProps<Props>()
|
||
|
|
||
|
const emits = defineEmits<Emits>()
|
||
2 years ago
|
|
||
|
let vModel = $(useVModel(props, 'modelValue', emits))
|
||
2 years ago
|
|
||
2 years ago
|
const column = inject(ColumnInj)
|
||
2 years ago
|
|
||
2 years ago
|
const isForm = inject(IsFormInj)
|
||
3 years ago
|
|
||
2 years ago
|
const readOnly = inject(ReadonlyInj)
|
||
2 years ago
|
|
||
2 years ago
|
const checkboxMeta = $computed(() => {
|
||
3 years ago
|
return {
|
||
|
icon: {
|
||
2 years ago
|
checked: 'mdi-check-circle-outline',
|
||
|
unchecked: 'mdi-checkbox-blank-circle-outline',
|
||
3 years ago
|
},
|
||
2 years ago
|
color: 'primary',
|
||
2 years ago
|
...(column?.value?.meta || {}),
|
||
2 years ago
|
}
|
||
|
})
|
||
2 years ago
|
|
||
|
function onClick() {
|
||
2 years ago
|
if (!readOnly) {
|
||
2 years ago
|
vModel = !vModel
|
||
|
}
|
||
|
}
|
||
3 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<template>
|
||
2 years ago
|
<div
|
||
|
class="flex"
|
||
|
:class="{ 'justify-center': !isForm, 'nc-cell-hover-show': !vModel && !readOnly, 'opacity-0': readOnly && !vModel }"
|
||
|
>
|
||
2 years ago
|
<div class="px-1 pt-1 rounded-full items-center" :class="{ 'bg-gray-100': !vModel }" @click="onClick">
|
||
2 years ago
|
<component
|
||
2 years ago
|
:is="getMdiIcon(vModel ? checkboxMeta.icon.checked : checkboxMeta.icon.unchecked)"
|
||
2 years ago
|
:style="{
|
||
|
color: checkboxMeta.color,
|
||
|
}"
|
||
|
/>
|
||
|
</div>
|
||
2 years ago
|
</div>
|
||
|
</template>
|
||
2 years ago
|
|
||
|
<style scoped lang="scss">
|
||
|
.nc-cell-hover-show {
|
||
|
opacity: 0;
|
||
|
transition: 0.3s opacity;
|
||
|
&:hover {
|
||
|
opacity: 0.7;
|
||
|
}
|
||
|
}
|
||
|
</style>
|