mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 21:30:24 +08:00
feat: support changing theme in antd 5 (#1430)
* feat: add global theme change function * feat: add icons * feat: in app theme changer * feat: use antd built-in themes * fix: multiple styling problem * fix: theme init from localstorage * feat: dark mode footer * feat: casdoor logo color theme * feat: select theme box icon adaptive to theme * fix: menu bar style * fix: language box style * feat: translation * feat: update translation of select theme box without reloading * fix: mobile view * fix: better structured select theme box * feat: add compact icon * fix: redundant theme fetch * fix: redundant theme fetch * fix: various styling problems
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
|
||||
import React from "react";
|
||||
import {Link} from "react-router-dom";
|
||||
import {Tag, Tooltip, message} from "antd";
|
||||
import {Tag, Tooltip, message, theme} from "antd";
|
||||
import {QuestionCircleTwoTone} from "@ant-design/icons";
|
||||
import {isMobile as isMobileDevice} from "react-device-detect";
|
||||
import "./i18n";
|
||||
@ -43,6 +43,13 @@ export const Countries = [{label: "English", key: "en", country: "US", alt: "Eng
|
||||
{label: "Русский", key: "ru", country: "RU", alt: "Русский"},
|
||||
];
|
||||
|
||||
const {defaultAlgorithm, darkAlgorithm, compactAlgorithm} = theme;
|
||||
|
||||
export const Themes = [{label: "Dark", key: "Dark", style: darkAlgorithm, selectThemeLogo: `${StaticBaseUrl}/img/dark.svg`},
|
||||
{label: "Compact", key: "Compact", style: compactAlgorithm, selectThemeLogo: `${StaticBaseUrl}/img/compact.svg`},
|
||||
{label: "Default", key: "Default", style: defaultAlgorithm, selectThemeLogo: `${StaticBaseUrl}/img/light.svg`},
|
||||
];
|
||||
|
||||
export const OtherProviderInfo = {
|
||||
SMS: {
|
||||
"Aliyun SMS": {
|
||||
@ -562,6 +569,14 @@ export function getAvatarColor(s) {
|
||||
return colorList[hash % 4];
|
||||
}
|
||||
|
||||
export function getLogo(theme) {
|
||||
if (theme === "Dark") {
|
||||
return `${StaticBaseUrl}/img/casdoor-logo_1185x256_dark.png`;
|
||||
} else {
|
||||
return `${StaticBaseUrl}/img/casdoor-logo_1185x256.png`;
|
||||
}
|
||||
}
|
||||
|
||||
export function getLanguageText(text) {
|
||||
if (!text.includes("|")) {
|
||||
return text;
|
||||
@ -587,6 +602,11 @@ export function setLanguage(language) {
|
||||
i18next.changeLanguage(language);
|
||||
}
|
||||
|
||||
export function setTheme(themeKey) {
|
||||
localStorage.setItem("theme", themeKey);
|
||||
dispatchEvent(new Event("themeChange"));
|
||||
}
|
||||
|
||||
export function getAcceptLanguage() {
|
||||
if (i18next.language === null || i18next.language === "") {
|
||||
return "en;q=0.9,en;q=0.8";
|
||||
|
Reference in New Issue
Block a user