Skip to content

Commit c62ba82

Browse files
authored
Merge branch 'ant-design:main' into main
2 parents 2e086da + 381b2cf commit c62ba82

File tree

18 files changed

+175
-1079
lines changed

18 files changed

+175
-1079
lines changed

.dumi/theme/SiteThemeProvider.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { ConfigProvider, theme as antdTheme } from 'antd';
21
import type { ThemeConfig } from 'antd';
2+
import { theme as antdTheme, ConfigProvider } from 'antd';
33
import type { ThemeProviderProps } from 'antd-style';
44
import { ThemeProvider } from 'antd-style';
55
import React, { useContext } from 'react';
66

77
interface NewToken {
88
bannerHeight: number;
99
headerHeight: number;
10+
alertHeight: number;
1011
menuItemBorder: number;
1112
mobileMaxWidth: number;
1213
siteMarkdownCodeBg: string;
@@ -27,7 +28,7 @@ interface NewToken {
2728
declare module 'antd-style' {
2829
export interface CustomToken extends NewToken {}
2930
}
30-
31+
const alertHeight = 40;
3132
const headerHeight = 80;
3233
const bannerHeight = 38;
3334
const indexRadius = 24;
@@ -48,6 +49,7 @@ const SiteThemeProvider: React.FC<ThemeProviderProps<any>> = ({ children, theme,
4849
theme={theme}
4950
customToken={{
5051
headerHeight,
52+
alertHeight,
5153
bannerHeight,
5254
indexRadius,
5355
pcMaxWidth,

.dumi/theme/layouts/GlobalLayout.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { MappingAlgorithm } from 'antd';
1111
import { App, theme as antdTheme } from 'antd';
1212
import type { DirectionType, ThemeConfig } from 'antd/es/config-provider';
1313
import { createSearchParams, useOutlet, useSearchParams, useServerInsertedHTML } from 'dumi';
14-
import React, { Suspense, useCallback, useEffect } from 'react';
14+
import React, { Suspense, useCallback, useEffect, useState } from 'react';
1515

1616
import { DarkContext } from '../../hooks/useDark';
1717
import useLayoutState from '../../hooks/useLayoutState';
@@ -23,18 +23,14 @@ import type { SiteContextProps } from '../slots/SiteContext';
2323
import SiteContext from '../slots/SiteContext';
2424

2525
import '@ant-design/v5-patch-for-react-19';
26+
import Alert from '../slots/Alert';
2627

2728
type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][];
2829
type SiteState = Partial<Omit<SiteContextProps, 'updateSiteContext'>>;
2930

3031
const RESPONSIVE_MOBILE = 768;
3132
export const ANT_DESIGN_NOT_SHOW_BANNER = 'ANT_DESIGN_NOT_SHOW_BANNER';
3233

33-
// const styleCache = createCache();
34-
// if (typeof global !== 'undefined') {
35-
// (global as any).styleCache = styleCache;
36-
// }
37-
3834
const getAlgorithm = (themes: ThemeName[] = []) =>
3935
themes
4036
.map((theme) => {
@@ -69,7 +65,6 @@ const GlobalLayout: React.FC = () => {
6965
(props: SiteState) => {
7066
setSiteState((prev) => ({ ...prev, ...props }));
7167

72-
// updating `searchParams` will clear the hash
7368
const oldSearchStr = searchParams.toString();
7469

7570
let nextSearchParams: URLSearchParams = searchParams;
@@ -112,6 +107,8 @@ const GlobalLayout: React.FC = () => {
112107
}
113108
}, [theme.length, isIndexPage]);
114109

110+
const [alertVisible, setAlertVisible] = useState(true);
111+
115112
useEffect(() => {
116113
const _theme = searchParams.getAll('theme') as ThemeName[];
117114
const _direction = searchParams.get('direction') as DirectionType;
@@ -140,8 +137,9 @@ const GlobalLayout: React.FC = () => {
140137
theme: theme!,
141138
isMobile: isMobile!,
142139
bannerVisible,
140+
alertVisible,
143141
}),
144-
[isMobile, direction, updateSiteConfig, theme],
142+
[isMobile, direction, updateSiteConfig, alertVisible, theme],
145143
);
146144

147145
const themeConfig = React.useMemo<ThemeConfig>(
@@ -199,6 +197,11 @@ const GlobalLayout: React.FC = () => {
199197
>
200198
<SiteContext value={siteContextValue}>
201199
<SiteThemeProvider theme={themeConfig}>
200+
<Alert
201+
afterClose={() => {
202+
setAlertVisible(false);
203+
}}
204+
/>
202205
<App>
203206
{outlet}
204207
<Suspense>{pathname.startsWith('/~demos') ? <PeterCat /> : null}</Suspense>

.dumi/theme/layouts/SidebarLayout/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { createStyles } from 'antd-style';
22
import type { PropsWithChildren } from 'react';
33
import React from 'react';
4-
4+
import SiteContext from '../../../pages/index/components/SiteContext';
55
import CommonHelmet from '../../common/CommonHelmet';
66
import Content from '../../slots/Content';
77
import Sidebar from '../../slots/Sidebar';
88

9-
const useStyle = createStyles(({ css, token }) => ({
9+
const useStyle = createStyles(({ css, token }, { alertVisible }: { alertVisible: boolean }) => ({
1010
main: css`
1111
display: flex;
12-
margin-top: ${token.headerHeight}px;
13-
`,
12+
margin-top: ${token.headerHeight + (alertVisible ? 40 : 0)}px;
13+
`,
1414
}));
1515

1616
const SidebarLayout: React.FC<PropsWithChildren> = ({ children }) => {
17-
const { styles } = useStyle();
17+
const { alertVisible } = React.use(SiteContext);
18+
const { styles } = useStyle({ alertVisible });
1819
return (
1920
<main className={styles.main}>
2021
<CommonHelmet />

.dumi/theme/slots/Alert/index.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Alert, Button, Space } from 'antd';
2+
import { createStyles } from 'antd-style';
3+
import React from 'react';
4+
5+
import useLocale from '../../../hooks/useLocale';
6+
7+
const useStyle = createStyles(({ token, css }) => {
8+
return {
9+
alert: css`
10+
height: ${token.alertHeight}px;
11+
width: 100%;
12+
position: fixed;
13+
top: 0px;
14+
z-index: 1000;
15+
border: none;
16+
border-radius: 0;
17+
background: linear-gradient(90deg, #fe8aff 0%, rgb(111, 179, 226) 66%, rgb(108, 87, 255) 100%);
18+
.ant-alert-message{
19+
color: #000;
20+
text-align: center;
21+
}
22+
.ant-btn-color-link.ant-btn-variant-link{
23+
padding: 0;
24+
}
25+
`,
26+
};
27+
});
28+
29+
const locales = {
30+
cn: {
31+
content: '参与 WeaveFox「AI艺术家」大赛,赢 SEE Conf 门票与千元好礼',
32+
link: '立即前往',
33+
},
34+
en: {
35+
content:
36+
'Participate in the WeaveFox "AI Artist" contest to win SEE Conf tickets and thousands of prizes',
37+
link: 'Go to',
38+
},
39+
};
40+
41+
const Index: React.FC<{ afterClose: () => void }> = ({ afterClose }) => {
42+
const { styles } = useStyle();
43+
const [locale] = useLocale(locales);
44+
45+
return (
46+
<Alert
47+
className={styles.alert}
48+
closable
49+
afterClose={afterClose}
50+
message={
51+
<Space>
52+
{' '}
53+
{locale.content}
54+
<Button
55+
type="link"
56+
onClick={() => {
57+
window.open('https://weavefox.cn/?ref=seeconf2025&source=antdx', '_blank');
58+
}}
59+
>
60+
{locale.link}
61+
</Button>
62+
</Space>
63+
}
64+
/>
65+
);
66+
};
67+
68+
export default Index;

.dumi/theme/slots/Header/index.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,26 @@ import { CloseOutlined, MenuOutlined } from '@ant-design/icons';
22
import { Button, Drawer } from 'antd';
33
import { createStyles } from 'antd-style';
44
import classnames from 'classnames';
5+
import { useLocation } from 'dumi';
56
import React, { useEffect } from 'react';
6-
77
import useLocale from '../../../hooks/useLocale';
88
import useScrollY from '../../../hooks/useScrollY';
9+
import type { SiteContextProps } from '../SiteContext';
910
import SiteContext from '../SiteContext';
10-
1111
import HeaderActions from './Actions';
12+
import type { SharedProps } from './interface';
1213
import Logo from './Logo';
1314
import Navigation from './Navigation';
1415

15-
import { useLocation } from 'dumi';
16-
import type { SiteContextProps } from '../SiteContext';
17-
import type { SharedProps } from './interface';
18-
19-
const useStyle = createStyles(({ token, css }) => {
16+
const useStyle = createStyles(({ token, css }, { alertVisible }: { alertVisible: boolean }) => {
2017
return {
2118
header: css`
2219
height: ${token.headerHeight}px;
2320
width: 100%;
2421
box-sizing: border-box;
25-
2622
position: fixed;
27-
top: 0;
23+
top: ${alertVisible ? token.alertHeight : '0'}px;
2824
z-index: 1000;
29-
3025
display: flex;
3126
align-items: center;
3227
justify-content: space-between;
@@ -37,10 +32,8 @@ const useStyle = createStyles(({ token, css }) => {
3732
width: calc(100% - ${token.paddingLG * 2}px);
3833
padding: 0 ${token.paddingLG}px;
3934
margin: 0 ${token.paddingLG}px;
40-
41-
top: ${(token.headerHeight - token.paddingLG * 2) / 2}px;
35+
top: ${(token.headerHeight - token.paddingLG * 2) / 2 + (alertVisible ? token.alertHeight : 0)}px;
4236
overflow: hidden;
43-
4437
border-radius: ${token.indexRadius}px;
4538
`,
4639
mini: css`
@@ -103,9 +96,9 @@ const Header: React.FC = () => {
10396
const [, lang] = useLocale();
10497
const { pathname } = useLocation();
10598

106-
const { direction, isMobile } = React.useContext<SiteContextProps>(SiteContext);
99+
const { direction, isMobile, alertVisible } = React.useContext<SiteContextProps>(SiteContext);
107100

108-
const { styles } = useStyle();
101+
const { styles } = useStyle({ alertVisible });
109102

110103
const { scrollY, scrollYDirection } = useScrollY();
111104

.dumi/theme/slots/Sidebar/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react';
88
import useMenu from '../../../hooks/useMenu';
99
import SiteContext from '../SiteContext';
1010

11-
const useStyle = createStyles(({ token, css }) => {
11+
const useStyle = createStyles(({ token, css }, { alertVisible }: { alertVisible: boolean }) => {
1212
const { antCls, fontFamily, colorSplit, marginXXL, paddingXXS } = token;
1313

1414
return {
@@ -94,9 +94,9 @@ const useStyle = createStyles(({ token, css }) => {
9494
mainMenu: css`
9595
z-index: 1;
9696
position: sticky;
97-
top: ${token.headerHeight}px;
97+
top: ${token.headerHeight + (alertVisible ? token.alertHeight : 0)}px;
9898
width: 100%;
99-
max-height: calc(100vh - ${token.headerHeight}px);
99+
max-height: calc(100vh - ${token.headerHeight + (alertVisible ? token.alertHeight : 0)}px);
100100
overflow: hidden;
101101
scrollbar-width: thin;
102102
scrollbar-gutter: stable;
@@ -110,8 +110,8 @@ const useStyle = createStyles(({ token, css }) => {
110110

111111
const Sidebar: React.FC = () => {
112112
const sidebarData = useSidebarData();
113-
const { isMobile, theme } = React.use(SiteContext);
114-
const { styles } = useStyle();
113+
const { isMobile, theme, alertVisible } = React.use(SiteContext);
114+
const { styles } = useStyle({ alertVisible });
115115

116116
const [menuItems, selectedKey] = useMenu();
117117
const isDark = theme.includes('dark');

.dumi/theme/slots/SiteContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export interface SiteContextProps {
77
isMobile: boolean;
88
bannerVisible: boolean;
99
direction: DirectionType;
10+
alertVisible: boolean;
1011
theme: ThemeName[];
1112
updateSiteConfig: (props: Partial<SiteContextProps>) => void;
1213
}
1314

1415
const SiteContext = React.createContext<SiteContextProps>({
1516
isMobile: false,
17+
alertVisible: true,
1618
bannerVisible: false,
1719
direction: 'ltr',
1820
theme: ['light'],

README-zh_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
</div>
3333

34-
![demos](https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*UAEeSbJfuM8AAAAAAAAAAAAADgCCAQ/fmt.webp)
34+
![demos](https://github.com/user-attachments/assets/8f6b56b9-3619-4ddc-9105-ca0eb7af070f)
3535

3636
## ✨ 特性
3737

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Craft AI-driven interfaces effortlessly.
3131

3232
</div>
3333

34-
![demos](https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*UAEeSbJfuM8AAAAAAAAAAAAADgCCAQ/fmt.webp)
34+
![demos](https://github.com/user-attachments/assets/8f6b56b9-3619-4ddc-9105-ca0eb7af070f)
3535

3636
## ✨ Features
3737

biome.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"!server",
1414
"!coverage",
1515
"!scripts/previewEditor/**/*",
16-
"!package.json"
16+
"!package.json",
17+
"!tests/index.html"
1718
]
1819
},
1920
"formatter": {
@@ -57,7 +58,8 @@
5758
"noArrayIndexKey": "off",
5859
"noConfusingVoidType": "off",
5960
"noThenProperty": "off",
60-
"noTemplateCurlyInString": "off"
61+
"noTemplateCurlyInString": "off",
62+
"noNonNullAssertedOptionalChain": "off"
6163
},
6264
"performance": {
6365
"noDelete": "off",
@@ -81,6 +83,14 @@
8183
"quoteStyle": "single"
8284
}
8385
},
86+
"html": {
87+
"formatter": {
88+
"enabled": true
89+
},
90+
"parser": {
91+
"interpolation": true
92+
}
93+
},
8494
"overrides": [
8595
{
8696
"includes": ["**/*.test.ts", "**/*.test.tsx", "tests/**/*", "scripts/**/*", ".dumi/**/*"],

0 commit comments

Comments
 (0)