Skip to content

Commit

Permalink
docs: render china mirror link before hydration (ant-design#44233)
Browse files Browse the repository at this point in the history
* docs: render china mirror link before hydration

* docs: fix pre render error

* chore: hide first

* chore: show china mirror link always
  • Loading branch information
afc163 authored Aug 16, 2023
1 parent 83e3b52 commit a92a883
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
39 changes: 29 additions & 10 deletions .dumi/theme/slots/Header/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const locales = {

// ============================= Style =============================
const useStyle = createStyles(({ token }) => {
const { antCls, iconCls, fontFamily, headerHeight, menuItemBorder, colorPrimary } = token;
const { antCls, iconCls, fontFamily, headerHeight, menuItemBorder, colorPrimary, colorText } =
token;

return {
nav: css`
Expand All @@ -56,6 +57,17 @@ const useStyle = createStyles(({ token }) => {
left: 12px;
border-width: ${menuItemBorder}px;
}
a {
color: ${colorText};
}
a:before {
position: absolute;
inset: 0;
background-color: transparent;
content: "";
}
}
& ${antCls}-menu-submenu-title ${iconCls} {
Expand Down Expand Up @@ -97,7 +109,6 @@ const useStyle = createStyles(({ token }) => {

export interface NavigationProps extends SharedProps {
isMobile: boolean;
isClient: boolean;
responsive: null | 'narrow' | 'crowded';
directionText: string;
onLangChange: () => void;
Expand All @@ -106,7 +117,6 @@ export interface NavigationProps extends SharedProps {

export default ({
isZhCN,
isClient,
isMobile,
responsive,
directionText,
Expand Down Expand Up @@ -224,16 +234,21 @@ export default ({
),
key: 'docs/resources',
},
isZhCN &&
isClient &&
window.location.host !== 'ant-design.antgroup.com' &&
window.location.host !== 'ant-design.gitee.io'
isZhCN
? {
label: '国内镜像',
label: (
<a href="https://ant-design.antgroup.com" target="_blank" rel="noreferrer">
国内镜像
</a>
),
key: 'mirror',
children: [
{
label: <a href="https://ant-design.antgroup.com">官方镜像</a>,
label: (
<a href="https://ant-design.antgroup.com" target="_blank" rel="noreferrer">
官方镜像
</a>
),
icon: (
<img
alt="logo"
Expand All @@ -245,7 +260,11 @@ export default ({
key: 'antgroup',
},
{
label: <a href="https://ant-design.gitee.io">Gitee 镜像</a>,
label: (
<a href="https://ant-design.gitee.io" target="_blank" rel="noreferrer">
Gitee 镜像
</a>
),
icon: (
<img
alt="gitee"
Expand Down
3 changes: 0 additions & 3 deletions .dumi/theme/slots/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ interface HeaderState {

// ================================= Header =================================
const Header: React.FC = () => {
const [isClient, setIsClient] = React.useState(false);
const [, lang] = useLocale();

const { pkg } = useSiteData();
Expand Down Expand Up @@ -166,7 +165,6 @@ const Header: React.FC = () => {
}, [location]);

useEffect(() => {
setIsClient(typeof window !== 'undefined');
onWindowResize();
window.addEventListener('resize', onWindowResize);
pingTimer.current = ping((status) => {
Expand Down Expand Up @@ -273,7 +271,6 @@ const Header: React.FC = () => {
const sharedProps: SharedProps = {
isZhCN,
isRTL,
isClient,
};

const navigationNode = (
Expand Down
1 change: 0 additions & 1 deletion .dumi/theme/slots/Header/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface SharedProps {
isZhCN: boolean;
isRTL: boolean;
isClient: boolean;
}

0 comments on commit a92a883

Please sign in to comment.