Skip to content

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

Create BBTextField which shows red focus ring if the value is required and is empty

天舟2866b823a6e8
diff --git a/frontend/src/bbkit/BBTextField.vue b/frontend/src/bbkit/BBTextField.vue
new file mode 100644
index 0000000000..4156f902bb
--- /dev/null
+++ b/frontend/src/bbkit/BBTextField.vue
@@ -0,0 +1,54 @@
+<template>
+ <input
+ type="text"
+ ref="inputField"
+ autocomplete="off"
+ class="text-main sm:text-sm rounded-md focus:ring-control focus:border-control"
+ :class="hasError ? 'border-error' : 'border-control-border'"
+ v-model="value"
+ :placeholder="placeholder"
+ @blur="onBlur"
+ @input="hasError = false"
+ />
+</template>
+
+<script lang="ts">
+import { ref } from "vue";
+import isEmpty from "lodash-es/isEmpty";
+
+export default {
+ name: "BBTextField",
+ emits: ["end-editing"],
+ props: {
+ required: {
+ default: false,
+ type: Boolean,
+ },
+ value: {
+ default: "",
+ type: String,
+ },
+ placeholder: {
+ type: String,
+ },
+ },
+ setup(props, { emit }) {
+ const inputField = ref<HTMLInputElement>();
+ let hasError = ref(false);
+
+ const onBlur = () => {
+ if (props.required && isEmpty(props.value!.trim())) {
+ hasError.value = true;
+ } else {
+ emit("end-editing", props.value);
+ }
+ };
+
+ return {
+ onBlur,
+ inputField,
+ hasError,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index c6cd83f7a8..c6bc83aa85 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -11,6 +11,7 @@ import BBSelect from "./BBSelect.vue";
import BBStepBar from "./BBStepBar.vue";
import BBTab from "./BBTab.vue";
import BBTabPanel from "./BBTabPanel.vue";
+import BBTextField from "./BBTextField.vue";
import {
BBTable,
BBTableCell,
@@ -38,4 +39,5 @@ export {
BBTableHeaderCell,
BBTableSearch,
BBTableTabFilter,
+ BBTextField,
};
diff --git a/frontend/src/main.js b/frontend/src/main.js
index e090a6c9c8..3529ee9949 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -26,6 +26,7 @@ import {
BBTableHeaderCell,
BBTableSearch,
BBTableTabFilter,
+ BBTextField,
} from "./bbkit";
import dataSourceType from "./directives/data-source-type";
import highlight from "./directives/highlight";
@@ -84,4 +85,5 @@ app
.component("BBTableHeaderCell", BBTableHeaderCell)
.component("BBTableSearch", BBTableSearch)
.component("BBTableTabFilter", BBTableTabFilter)
+ .component("BBTextField", BBTextField)
.mount("#app");