Skip to content

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

feat(frontend): configured theme for naive-ui (#229)

Luke Zhou81981668abf3
diff --git a/frontend/naive-ui.config.ts b/frontend/naive-ui.config.ts
new file mode 100644
index 0000000000..8c4d420563
--- /dev/null
+++ b/frontend/naive-ui.config.ts
@@ -0,0 +1,45 @@
+import {
+ GlobalThemeOverrides,
+ zhCN,
+ dateZhCN,
+ NLocale,
+ NDateLocale,
+} from "naive-ui";
+
+import { curLocale } from "./src/plugins/i18n";
+
+import { computed } from "vue";
+
+const callVar = (css: string) => {
+ return getComputedStyle(document.documentElement).getPropertyValue(css);
+};
+
+export const themeOverrides = computed((): GlobalThemeOverrides => {
+ return {
+ common: {
+ primaryColor: callVar("--color-accent"),
+ primaryColorHover: callVar("--color-accent-hover"),
+
+ successColor: callVar("--color-success"),
+ successColorHover: callVar("--color-success-hover"),
+
+ warningColor: callVar("--color-warning"),
+ warningColorHover: callVar("--color-warning-hover"),
+
+ errorColor: callVar("--color-error"),
+ errorColorHover: callVar("--color-error-hover"),
+ },
+ };
+});
+
+const isZhCn = (): boolean => {
+ return curLocale.value === "zh-CN";
+};
+
+export const dateLang = computed((): NDateLocale | null => {
+ return isZhCn() ? dateZhCN : null;
+});
+
+export const generalLang = computed((): NLocale | null => {
+ return isZhCn() ? zhCN : null;
+});
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 1868d3d47b..347ceb71e8 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -1,8 +1,9 @@
<template>
<!-- it is recommended by naive-ui that we leave the local to null when the language is en -->
<n-config-provider
- :locale="isZhCn ? zhCN : null"
- :date-locale="isZhCn ? dateZhCN : null"
+ :locale="generalLang"
+ :date-locale="dateLang"
+ :theme-overrides="themeOverrides"
>
<BBModalStack>
<KBarWrapper>
@@ -20,7 +21,7 @@
</template>
<script lang="ts">
-import { reactive, watchEffect, onErrorCaptured, computed } from "vue";
+import { reactive, watchEffect, onErrorCaptured } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { isDev } from "./utils";
@@ -28,9 +29,8 @@ import { Notification } from "./types";
import { BBNotificationItem } from "./bbkit/types";
import KBarWrapper from "./components/KBar/KBarWrapper.vue";
import BBModalStack from "./bbkit/BBModalStack.vue";
-import { useLanguage } from "./composables/useLanguage";
-import { NConfigProvider, zhCN, dateZhCN } from "naive-ui";
-
+import { NConfigProvider } from "naive-ui";
+import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
// Show at most 3 notifications to prevent excessive notification when shit hits the fan.
const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
@@ -55,18 +55,12 @@ export default {
setup() {
const store = useStore();
const router = useRouter();
- const { locale } = useLanguage();
const state = reactive<LocalState>({
notificationList: [],
prevLoggedIn: store.getters["auth/isLoggedIn"](),
});
- // for now, we only support two languages
- const isZhCn = computed(() => {
- return locale.value === "zh-CN";
- });
-
setInterval(() => {
const loggedIn = store.getters["auth/isLoggedIn"]();
if (state.prevLoggedIn != loggedIn) {
@@ -139,9 +133,9 @@ export default {
return {
state,
- isZhCn,
- zhCN,
- dateZhCN,
+ dateLang,
+ generalLang,
+ themeOverrides,
removeNotification,
};
},
diff --git a/frontend/src/plugins/i18n.ts b/frontend/src/plugins/i18n.ts
index ad91d53100..956f95a8ab 100644
--- a/frontend/src/plugins/i18n.ts
+++ b/frontend/src/plugins/i18n.ts
@@ -27,6 +27,8 @@ const i18n = createI18n({
export const t = i18n.global.t;
+export const curLocale = i18n.global.locale;
+
const install = (app: App) => {
app.use(i18n);
};