Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: use naive-ui components to implement DroppableTextarea (#8839)

Liu Ji132b862545d6
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue b/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue
index 52314d128a..30875a6698 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue
@@ -17,8 +17,9 @@
</p>
<DroppableTextarea
:value="value"
- class="block w-full resize-none whitespace-pre-wrap h-24"
+ :resizable="false"
:placeholder="placeholder"
+ class="w-full h-24 whitespace-pre-wrap"
@update:value="$emit('update:value', $event ?? '')"
/>
</div>
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
index 7b19fc09d0..928e356bd3 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
@@ -73,7 +73,8 @@
</label>
<DroppableTextarea
v-model:value="state.value.sshPrivateKey"
- class="block w-full resize-none whitespace-pre-wrap h-24"
+ :resizable="false"
+ class="w-full h-24 whitespace-pre-wrap"
/>
</div>
</div>
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
index 1cea431f66..f2b6f4cb2f 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
@@ -20,7 +20,8 @@
>
<DroppableTextarea
v-model:value="state.value.sslCa"
- class="block w-full resize-none whitespace-pre-wrap h-24"
+ :resizable="false"
+ class="w-full h-24 whitespace-pre-wrap"
placeholder="Input or drag and drop YOUR_CA_CERTIFICATE"
/>
</NTabPane>
@@ -32,7 +33,8 @@
>
<DroppableTextarea
v-model:value="state.value.sslKey"
- class="block w-full resize-none whitespace-pre-wrap h-24"
+ :resizable="false"
+ class="w-full h-24 whitespace-pre-wrap"
placeholder="Input or drag and drop YOUR_CLIENT_KEY"
/>
</NTabPane>
@@ -44,7 +46,8 @@
>
<DroppableTextarea
v-model:value="state.value.sslCert"
- class="block w-full resize-none whitespace-pre-wrap h-24"
+ :resizable="false"
+ class="w-full h-24 whitespace-pre-wrap"
placeholder="Input or drag and drop YOUR_CLIENT_CERT"
/>
</NTabPane>
diff --git a/frontend/src/components/misc/DroppableTextarea.vue b/frontend/src/components/misc/DroppableTextarea.vue
index 0375e80af2..9e90a7eac4 100644
--- a/frontend/src/components/misc/DroppableTextarea.vue
+++ b/frontend/src/components/misc/DroppableTextarea.vue
@@ -1,22 +1,24 @@
<template>
<div
ref="container"
- class="relative"
- :class="[state.reading && 'pointer-events-none']"
+ class="droppable-textarea"
+ :class="{
+ reading: state.reading,
+ 'drop-over': isOverDropZone,
+ }"
>
- <textarea
- ref="textareaRef"
- v-model="state.value"
- class="textarea rounded-[3px]"
+ <NInput
+ ref="inputRef"
+ v-model:value="state.value"
:placeholder="placeholder"
+ type="textarea"
v-bind="$attrs"
/>
<div
v-if="!state.value"
- class="absolute bottom-2 left-[50%] -translate-x-1/2 flex flex-col items-center justify-center border border-control-border hover:border-control-hover border-dashed text-xs text-control-placeholder hover:text-control-hover p-2 rounded-md"
+ class="absolute bottom-2 left-[50%] -translate-x-1/2 flex flex-col items-center justify-center border border-control-border hover:border-accent border-dashed text-xs text-control-placeholder hover:text-accent p-2 rounded-md"
>
- {{ borderRadius }}
Or drag and drop files here.
<input
type="file"
@@ -28,12 +30,12 @@
<div
v-if="isOverDropZone || state.reading"
- class="absolute inset-0 pointer-events-none flex flex-col items-center justify-center bg-white/50 border border-accent border-dashed"
+ class="absolute inset-0 pointer-events-none flex flex-col items-center justify-center bg-white/50 border border-accent border-dashed text-accent"
:style="{
borderRadius,
}"
>
- <heroicons-outline:arrow-up-tray v-if="isOverDropZone" class="w-8 h-8" />
+ <heroicons:arrow-up-tray v-if="isOverDropZone" class="w-8 h-8 color" />
<BBSpin v-if="state.reading" />
</div>
</div>
@@ -46,7 +48,7 @@ export default {
</script>
<script lang="ts" setup>
-import { reactive, ref, watch } from "vue";
+import { computed, reactive, ref, watch } from "vue";
import { useDropZone, useMutationObserver } from "@vueuse/core";
import { head } from "lodash-es";
import { useI18n } from "vue-i18n";
@@ -54,6 +56,7 @@ import { useI18n } from "vue-i18n";
import { pushNotification } from "@/store";
import { BBSpin } from "@/bbkit";
import { onMounted } from "vue";
+import { NInput } from "naive-ui";
type LocalState = {
value: string | undefined;
@@ -82,8 +85,10 @@ const state = reactive<LocalState>({
reading: false,
});
const container = ref<HTMLDivElement>();
-const textareaRef = ref<HTMLTextAreaElement>();
-
+const inputRef = ref<InstanceType<typeof NInput>>();
+const inputWrapperRef = computed(
+ () => inputRef.value?.wrapperElRef as HTMLDivElement | undefined
+);
const borderRadius = ref("");
watch(
@@ -136,13 +141,13 @@ const handleFileChange = (e: Event) => {
const { isOverDropZone } = useDropZone(container, onDrop);
-const updateBorderRadius = (textarea: HTMLTextAreaElement) => {
- borderRadius.value = getComputedStyle(textarea).borderRadius;
+const updateBorderRadius = (element: HTMLElement) => {
+ borderRadius.value = getComputedStyle(element).borderRadius;
};
useMutationObserver(
- textareaRef,
+ inputWrapperRef,
(records) => {
- updateBorderRadius(records[0].target as HTMLTextAreaElement);
+ updateBorderRadius(records[0].target as HTMLElement);
},
{
attributeFilter: ["style", "class"],
@@ -150,9 +155,22 @@ useMutationObserver(
}
);
onMounted(() => {
- const textarea = textareaRef.value;
- if (textarea) {
- updateBorderRadius(textarea);
+ const wrapper = inputWrapperRef.value;
+ if (wrapper) {
+ updateBorderRadius(wrapper);
}
});
</script>
+
+<style lang="postcss" scoped>
+.droppable-textarea {
+ @apply relative;
+}
+.droppable-textarea.reading {
+ @apply pointer-events-none;
+}
+.droppable-textarea.drop-over :deep(.n-input__state-border),
+.droppable-textarea.reading :deep(.n-input__state-border) {
+ border-style: dashed;
+}
+</style>