MSP-3074 ThemeProvider change to ConfigProvider
This commit is contained in:
1 parent
7ac446d783
commit
c598e0dde8
11 files changed
+34
-30
No files matched your search
File renamed without changes.
@@ -1,19 +1,19 @@
|
||||
import {useState} from 'react';
|
||||
import {ThemeAppearance, ThemeProvider} from 'antd-style';
|
||||
import {ConfigProvider} from "antd";
|
||||
import {Context} from "../store";
|
||||
import Routers from "./Routers/Routers.tsx";
|
||||
import Routers from "./Routers";
|
||||
import {lightTheme} from "../constants/theme.ts";
|
||||
import './app.scss'
|
||||
|
||||
|
||||
function App() {
|
||||
const [theme, setTheme] = useState<ThemeAppearance>('light');
|
||||
const [themes, setTheme] = useState(lightTheme);
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<Context.Provider value={{setTheme}}>
|
||||
<ThemeProvider appearance={theme}>
|
||||
<ConfigProvider theme={themes}>
|
||||
<Routers/>
|
||||
</ThemeProvider>
|
||||
</ConfigProvider>
|
||||
</Context.Provider>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import {useContext} from "react";
|
||||
import {ThemeAppearance, useTheme} from "antd-style";
|
||||
import {Segmented} from "antd";
|
||||
import {Segmented, theme} from "antd";
|
||||
import {Context} from "../../store";
|
||||
import {darkTheme, lightTheme} from "../../constants/theme.ts";
|
||||
import './header.scss'
|
||||
|
||||
|
||||
const options = [
|
||||
{label: 'Light', value: 'light'},
|
||||
{label: 'Light', value: 'light' },
|
||||
{label: 'Dark', value: 'dark'},
|
||||
];
|
||||
|
||||
function Header() {
|
||||
const theme = useTheme();
|
||||
const {setTheme} = useContext(Context)
|
||||
const { useToken } = theme;
|
||||
const { token } = useToken();
|
||||
|
||||
return <header className='header' style={{
|
||||
background: theme.colorBgLayout
|
||||
}}><Segmented onChange={(v) => setTheme(v as ThemeAppearance)} options={options}/></header>;
|
||||
backgroundColor: token.colorBgLayout
|
||||
}}><Segmented onChange={(v) => setTheme(v === 'light' ? lightTheme : darkTheme)} options={options}/></header>;
|
||||
}
|
||||
|
||||
export default Header;
|
||||
@@ -1,19 +1,17 @@
|
||||
import {Button} from 'antd';
|
||||
import {useTheme} from 'antd-style';
|
||||
import {Button, theme} from 'antd';
|
||||
import {PermissionKeys} from "../../types/roles.type.ts";
|
||||
import useRole from "../../hooks/useRole.tsx";
|
||||
import './main.scss'
|
||||
|
||||
|
||||
const Main = () => {
|
||||
const theme = useTheme();
|
||||
const {hasPermission} = useRole();
|
||||
|
||||
const { useToken } = theme;
|
||||
const { token } = useToken();
|
||||
const isPageAvailable = hasPermission(PermissionKeys.user_view);
|
||||
|
||||
return (
|
||||
<div className='main' style={{
|
||||
background: theme.colorBgLayout
|
||||
backgroundColor: token.colorBgLayout
|
||||
}}>
|
||||
|
||||
{isPageAvailable && <Button ghost type={'primary'}>
|
||||
|
||||
@@ -5,7 +5,6 @@ import HomePages from "../../pages/HomePage";
|
||||
import Test from "../Test/Test.tsx";
|
||||
import PrivateRoute from "../PrivateRoute";
|
||||
|
||||
|
||||
function Routers() {
|
||||
|
||||
return (
|
||||
@@ -6,3 +6,6 @@
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
.ant-space-item {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import {theme} from "antd";
|
||||
|
||||
export const darkTheme = {algorithm: theme.darkAlgorithm}
|
||||
|
||||
export const lightTheme = {algorithm: theme.defaultAlgorithm}
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import {BrowserRouter} from 'react-router-dom';
|
||||
import {setupListeners} from "@reduxjs/toolkit/query";
|
||||
import {Provider} from 'react-redux';
|
||||
import App from './components/App.tsx'
|
||||
import './index.css'
|
||||
import {setupStore} from "./store";
|
||||
import {setupListeners} from "@reduxjs/toolkit/query";
|
||||
|
||||
import './index.css'
|
||||
|
||||
const store = setupStore();
|
||||
setupListeners(store.dispatch);
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import {Navigate, Outlet, useNavigate} from 'react-router-dom';
|
||||
import {Menu} from 'antd';
|
||||
import Header from "../../components/Header";
|
||||
import useRole from "../../hooks/useRole.tsx";
|
||||
import {PermissionKeys} from "../../types/roles.type.ts";
|
||||
import {Menu} from 'antd';
|
||||
import {useEffect, useState} from "react";
|
||||
import {MenuItemKeys, menuKeys} from "../../types/layout.type.ts";
|
||||
import {routePaths} from "../../constants/routes.ts";
|
||||
import {StateProfileStatus} from "../../redusers/ProfileSlice.ts";
|
||||
import {useAppSelector} from "../../hooks/redux.ts";
|
||||
import './layout.scss'
|
||||
|
||||
|
||||
function Layout() {
|
||||
const {hasPermission} = useRole();
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
.layout {
|
||||
min-height: calc(100vh - 96px)
|
||||
min-height: calc(100vh - 96px);
|
||||
width: 100%;
|
||||
}
|
||||
+3
-3
@@ -1,16 +1,16 @@
|
||||
import {Dispatch, SetStateAction, createContext} from 'react'
|
||||
import {combineReducers, configureStore} from '@reduxjs/toolkit';
|
||||
import {theme} from "antd";
|
||||
import profileReducer from '../redusers/ProfileSlice.ts';
|
||||
|
||||
export interface ContextProps {
|
||||
setTheme: Dispatch<SetStateAction<'dark' | 'light' | string>>
|
||||
setTheme: Dispatch<SetStateAction<any>>
|
||||
}
|
||||
|
||||
export const Context = createContext<ContextProps>({
|
||||
setTheme: () => 'light'
|
||||
setTheme: () => theme.defaultAlgorithm
|
||||
})
|
||||
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profileReducer
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user