fix: theme setting in login
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { createFromIconfontCN } from '@ant-design/icons';
|
import { createFromIconfontCN } from '@ant-design/icons';
|
||||||
import './iconfont/iconfont.js';
|
// import './iconfont/iconfont.js';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: ''
|
scriptUrl: '//at.alicdn.com/t/c/font_4613488_ivhneql6a1f.js'
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import useUserSettings from '@/hooks/use-user-settings';
|
||||||
|
import { MoonOutlined, SunOutlined } from '@ant-design/icons';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { Dropdown } from 'antd';
|
||||||
|
import { createStyles } from 'antd-style';
|
||||||
|
import IconFont from '../icon-font';
|
||||||
|
|
||||||
|
const useStyles = createStyles(({ token, css }) => ({
|
||||||
|
inner: css`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
color: ${token.colorText};
|
||||||
|
font-size: var(--font-size-base);
|
||||||
|
padding: 0 8px;
|
||||||
|
&:hover {
|
||||||
|
color: ${token.colorTextTertiary};
|
||||||
|
}
|
||||||
|
.anticon {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
.icon-auto {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}));
|
||||||
|
|
||||||
|
const ThemeDropActions = () => {
|
||||||
|
const { setTheme, userSettings } = useUserSettings();
|
||||||
|
const { styles } = useStyles();
|
||||||
|
const intl = useIntl();
|
||||||
|
|
||||||
|
const ThemeOptions = [
|
||||||
|
{
|
||||||
|
key: 'light',
|
||||||
|
label: intl.formatMessage({ id: 'common.appearance.light' }),
|
||||||
|
icon: <SunOutlined />
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'realDark',
|
||||||
|
label: intl.formatMessage({ id: 'common.appearance.dark' }),
|
||||||
|
icon: <MoonOutlined />
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'auto',
|
||||||
|
label: intl.formatMessage({ id: 'common.appearance.system' }),
|
||||||
|
icon: <IconFont type="icon-dark_theme" className="icon-auto"></IconFont>
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleOnChange = (item: any) => {
|
||||||
|
const value = item.key as 'light' | 'realDark' | 'auto';
|
||||||
|
setTheme(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dropdown menu={{ items: ThemeOptions, onClick: handleOnChange }}>
|
||||||
|
<div className={styles.inner}>
|
||||||
|
{userSettings.mode === 'auto' ? (
|
||||||
|
<IconFont type="icon-dark_theme" className="icon-auto"></IconFont>
|
||||||
|
) : userSettings.mode === 'realDark' ? (
|
||||||
|
<MoonOutlined />
|
||||||
|
) : (
|
||||||
|
<SunOutlined />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ThemeDropActions;
|
||||||
@@ -2,7 +2,7 @@ import LogoIcon from '@/assets/images/gpustack-logo.png';
|
|||||||
import { initialPasswordAtom, userAtom } from '@/atoms/user';
|
import { initialPasswordAtom, userAtom } from '@/atoms/user';
|
||||||
import LangSelect from '@/components/lang-select';
|
import LangSelect from '@/components/lang-select';
|
||||||
import SealInput from '@/components/seal-form/seal-input';
|
import SealInput from '@/components/seal-form/seal-input';
|
||||||
import ThemeToggle from '@/components/theme-toggle';
|
import ThemeDropActions from '@/components/theme-toggle/theme-drop-actions';
|
||||||
import externalLinks from '@/constants/external-links';
|
import externalLinks from '@/constants/external-links';
|
||||||
import {
|
import {
|
||||||
CRYPT_TEXT,
|
CRYPT_TEXT,
|
||||||
@@ -30,6 +30,7 @@ const useStyles = createStyles(({ token, css }) => ({
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
right: 0;
|
right: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
height: 60px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
.anticon-global {
|
.anticon-global {
|
||||||
color: ${token.colorText};
|
color: ${token.colorText};
|
||||||
@@ -153,7 +154,7 @@ const LoginForm = () => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
<ThemeToggle></ThemeToggle>
|
<ThemeDropActions></ThemeDropActions>
|
||||||
<LangSelect />
|
<LangSelect />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import useUserSettings from '@/hooks/use-user-settings';
|
|||||||
import { MoonOutlined, SunOutlined } from '@ant-design/icons';
|
import { MoonOutlined, SunOutlined } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Select } from 'antd';
|
import { Select } from 'antd';
|
||||||
import React, { useMemo } from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
@@ -56,10 +56,6 @@ const Appearance: React.FC = () => {
|
|||||||
setTheme(value);
|
setTheme(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const theme = useMemo(() => {
|
|
||||||
return userSettings?.theme || 'auto';
|
|
||||||
}, [userSettings?.theme]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<div className="theme">
|
<div className="theme">
|
||||||
|
|||||||
Reference in New Issue
Block a user