Skip to content

Commit 1ca2565

Browse files
committed
[ui]: theme saver implementation;
1 parent 2abbbcc commit 1ca2565

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/layout/CustomLayout.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useLocation, Link } from 'react-router-dom';
55
import { notification, Input, Select, Form, Button, Affix } from 'antd';
66
import { copyText } from 'copy-clipboard-js';
77
import CopyOutlined from '@ant-design/icons/CopyOutlined';
8-
import { ReloadOutlined, SearchOutlined } from '@ant-design/icons';
8+
import { ReloadOutlined, SearchOutlined, MoonOutlined, SunOutlined } from '@ant-design/icons';
99
import logo from './logo.svg';
1010

1111
const defaultMenus: MenuDataItem[] = [
@@ -169,9 +169,11 @@ const subMenuItemRender = (item: any, dom: React.ReactNode) => <Link to={item.pa
169169

170170
interface ICustomLayoutProps {
171171
children: ReactNode;
172+
isDark: boolean;
173+
toggleTheme: () => void;
172174
}
173175

174-
const CustomLayout = ({ children }: ICustomLayoutProps) => {
176+
const CustomLayout = ({ children, isDark, toggleTheme }: ICustomLayoutProps) => {
175177
const location = useLocation();
176178

177179
const [scrollPercent, setScrollPercent] = useState(0);
@@ -203,6 +205,18 @@ const CustomLayout = ({ children }: ICustomLayoutProps) => {
203205
subMenuItemRender={subMenuItemRender}
204206
// eslint-disable-next-line
205207
menuFooterRender={(props) => <CustomFooterMenu {...props} />}
208+
actionsRender={() => [
209+
<span key="theme-text" style={{ fontSize: '14px', opacity: 0.85, marginRight: '8px' }}>
210+
{isDark ? 'Dark Mode' : 'Light Mode'}
211+
</span>,
212+
<Button
213+
key="theme-button"
214+
type="text"
215+
icon={isDark ? <SunOutlined /> : <MoonOutlined />}
216+
onClick={toggleTheme}
217+
title={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
218+
/>,
219+
]}
206220
>
207221
<PageContainer header={{ title: true }}>
208222
<Affix offsetTop={0}>

0 commit comments

Comments
 (0)