Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: optimize rename logic
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 14, 2023
1 parent 5877a99 commit 7cba1ba
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/client/src/components/atomic/AutoFocusInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
import { NInput } from 'naive-ui'
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
const props = defineProps<{
value: string
Expand All @@ -13,6 +13,13 @@ const emits = defineEmits<{
}>()
const value = useVModel(props, 'value', emits)
const base = computed(() => {
return /^([\s\S]*?)(?:\.[a-z]+)?$/.exec(value.value)?.[1] ?? value.value
})
const suffix = computed(() => {
return /(\.[a-z]+)$/.exec(value.value)?.[1] ?? ''
})
const el = ref<InstanceType<typeof NInput> | null>(null)
onMounted(() => {
Expand All @@ -23,9 +30,18 @@ onMounted(() => {
<template>
<NInput
ref="el"
v-model:value="value"
:value="base"
@update:value="
v => {
value = `${v}${suffix}`
}
"
size="tiny"
class="outline-none bg-transparent"
@blur="emits('blur')"
></NInput>
>
<template #suffix>
{{ suffix }}
</template>
</NInput>
</template>

0 comments on commit 7cba1ba

Please sign in to comment.