Skip to content

Commit

Permalink
🌷 UI: alway set theme (#9458)
Browse files Browse the repository at this point in the history
* 🌷 UI: alway set theme

* 🌷 UI: support dynamic theme

* merge master
  • Loading branch information
chenshuai2144 authored Dec 22, 2021
1 parent a2d8f88 commit 645d6ed
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: yarn

- name: plugins
run: yarn add umi-plugin-antd-theme umi-plugin-pro umi-plugin-setting-drawer
run: yarn add umi-plugin-pro

- name: fetch-blocks
run: yarn run pro fetch-blocks
Expand Down
3 changes: 1 addition & 2 deletions config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export default defineConfig({
routes,
// Theme for antd: https://ant.design/docs/react/customize-theme-cn
theme: {
'primary-color': defaultSettings.primaryColor,
'root-entry-name': 'default',
'root-entry-name': 'variable',
},
// esbuild is father build tools
// https://umijs.org/plugins/plugin-esbuild
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ant-design-pro",
"version": "5.1.0",
"version": "5.2.0",
"private": true,
"description": "An out-of-box UI solution for enterprise applications",
"scripts": {
Expand Down Expand Up @@ -57,10 +57,10 @@
"@ant-design/icons": "^4.5.0",
"@ant-design/pro-descriptions": "^1.9.0",
"@ant-design/pro-form": "^1.43.0",
"@ant-design/pro-layout": "^6.26.0",
"@ant-design/pro-layout": "^6.32.0-beta.4",
"@ant-design/pro-table": "^2.56.0",
"@umijs/route-utils": "^2.0.3",
"antd": "4.16.13",
"@umijs/route-utils": "^2.0.4",
"antd": "^4.17.0",
"classnames": "^2.2.6",
"lodash": "^4.17.11",
"moment": "^2.25.3",
Expand Down
28 changes: 23 additions & 5 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Settings as LayoutSettings } from '@ant-design/pro-layout';
import { SettingDrawer } from '@ant-design/pro-layout';
import { PageLoading } from '@ant-design/pro-layout';
import type { RunTimeLayoutConfig } from 'umi';
import { history, Link } from 'umi';
Expand All @@ -21,6 +22,7 @@ export const initialStateConfig = {
export async function getInitialState(): Promise<{
settings?: Partial<LayoutSettings>;
currentUser?: API.CurrentUser;
loading?: boolean;
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
}> {
const fetchUserInfo = async () => {
Expand Down Expand Up @@ -48,7 +50,7 @@ export async function getInitialState(): Promise<{
}

// ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState }) => {
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
return {
rightContentRender: () => <RightContent />,
disableContentMargin: false,
Expand Down Expand Up @@ -79,10 +81,26 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
// 自定义 403 页面
// unAccessible: <div>unAccessible</div>,
// 增加一个 loading 的状态
// childrenRender: (children) => {
// if (initialState.loading) return <PageLoading />;
// return children;
// },
childrenRender: (children, props) => {
// if (initialState?.loading) return <PageLoading />;
return (
<>
{children}
{!props.location?.pathname?.includes('/login') && (
<SettingDrawer
enableDarkTheme
settings={initialState?.settings}
onSettingChange={(settings) => {
setInitialState((preInitialState) => ({
...preInitialState,
settings,
}));
}}
/>
)}
</>
);
},
...initialState?.settings,
};
};
2 changes: 1 addition & 1 deletion src/components/HeaderDropdown/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

.container > * {
background-color: @popover-bg;
Expand Down
2 changes: 1 addition & 1 deletion src/components/HeaderSearch/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

.headerSearch {
display: inline-flex;
Expand Down
2 changes: 1 addition & 1 deletion src/components/NoticeIcon/NoticeList.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

.list {
max-height: 400px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/NoticeIcon/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

.popover {
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion src/components/RightContent/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

@pro-header-hover-bg: rgba(0, 0, 0, 0.025);

Expand Down
2 changes: 1 addition & 1 deletion src/global.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import '~antd/es/style/variable.less';

html,
body,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Welcome.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/lib/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

.pre {
margin: 12px 0;
Expand Down
1 change: 1 addition & 0 deletions src/pages/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const CodePreview: React.FC = ({ children }) => (

const Welcome: React.FC = () => {
const intl = useIntl();

return (
<PageContainer>
<Card>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/user/Login/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less';
@import (reference) '~antd/es/style/themes/index';

.container {
display: flex;
Expand Down

0 comments on commit 645d6ed

Please sign in to comment.