mirror of https://github.com/nocodb/nocodb
47 lines
1016 B
47 lines
1016 B
3 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import type { VNodeRef } from '@vue/runtime-core'
|
||
2 years ago
|
import { inject, useVModel } from '#imports'
|
||
|
import { EditModeInj } from '~/context'
|
||
2 years ago
|
|
||
3 years ago
|
interface Props {
|
||
2 years ago
|
modelValue: number | null | undefined
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
2 years ago
|
interface Emits {
|
||
|
(event: 'update:modelValue', model: number): void
|
||
|
}
|
||
|
|
||
|
const props = defineProps<Props>()
|
||
3 years ago
|
|
||
2 years ago
|
const emits = defineEmits<Emits>()
|
||
3 years ago
|
|
||
2 years ago
|
const editEnabled = inject(EditModeInj)
|
||
3 years ago
|
|
||
2 years ago
|
const vModel = useVModel(props, 'modelValue', emits)
|
||
3 years ago
|
|
||
2 years ago
|
const focus: VNodeRef = (el) => (el as HTMLInputElement)?.focus()
|
||
2 years ago
|
|
||
|
function onKeyDown(evt: KeyboardEvent) {
|
||
|
return evt.key === '.' && evt.preventDefault()
|
||
|
}
|
||
3 years ago
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<input
|
||
|
v-if="editEnabled"
|
||
2 years ago
|
:ref="focus"
|
||
2 years ago
|
v-model="vModel"
|
||
2 years ago
|
class="outline-none p-0 border-none w-full h-full prose-sm"
|
||
2 years ago
|
type="number"
|
||
2 years ago
|
@blur="editEnabled = false"
|
||
2 years ago
|
@keydown="onKeyDown"
|
||
|
/>
|
||
|
<span v-else class="prose-sm">{{ vModel }}</span>
|
||
3 years ago
|
</template>
|
||
|
|
||
2 years ago
|
<style scoped lang="scss">
|
||
|
input[type='number']:focus {
|
||
|
@apply ring-transparent;
|
||
|
}
|
||
|
</style>
|