mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 03:14:07 +08:00
docs: fix TOC active (#24426)
* docs: fix TOC active close #23929 * fix footer seeconf logo
This commit is contained in:
parent
e0f57e72e0
commit
0c2eed6866
@ -47,7 +47,7 @@ function fileNameToPath(filename) {
|
|||||||
return snippets[snippets.length - 1];
|
return snippets[snippets.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSideBarOpenKeys = nextProps => {
|
function getSideBarOpenKeys(nextProps) {
|
||||||
const { themeConfig } = nextProps;
|
const { themeConfig } = nextProps;
|
||||||
const { pathname } = nextProps.location;
|
const { pathname } = nextProps.location;
|
||||||
const locale = utils.isZhCN(pathname) ? 'zh-CN' : 'en-US';
|
const locale = utils.isZhCN(pathname) ? 'zh-CN' : 'en-US';
|
||||||
@ -56,7 +56,17 @@ const getSideBarOpenKeys = nextProps => {
|
|||||||
.getMenuItems(moduleData, locale, themeConfig.categoryOrder, themeConfig.typeOrder)
|
.getMenuItems(moduleData, locale, themeConfig.categoryOrder, themeConfig.typeOrder)
|
||||||
.map(m => (m.title && m.title[locale]) || m.title);
|
.map(m => (m.title && m.title[locale]) || m.title);
|
||||||
return shouldOpenKeys;
|
return shouldOpenKeys;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function updateActiveToc(id) {
|
||||||
|
[].forEach.call(document.querySelectorAll('.toc-affix li a'), node => {
|
||||||
|
node.className = '';
|
||||||
|
});
|
||||||
|
const currentNode = document.querySelectorAll(`.toc-affix li a[href="#${id}"]`)[0];
|
||||||
|
if (currentNode) {
|
||||||
|
currentNode.className = 'current';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MainContent extends Component {
|
class MainContent extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -72,6 +82,7 @@ class MainContent extends Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.componentDidUpdate();
|
this.componentDidUpdate();
|
||||||
window.addEventListener('load', this.handleInitialHashOnLoad);
|
window.addEventListener('load', this.handleInitialHashOnLoad);
|
||||||
|
window.addEventListener('hashchange', this.handleHashChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
static getDerivedStateFromProps(props, state) {
|
||||||
@ -103,6 +114,8 @@ class MainContent extends Component {
|
|||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.scroller.destroy();
|
this.scroller.destroy();
|
||||||
window.removeEventListener('load', this.handleInitialHashOnLoad);
|
window.removeEventListener('load', this.handleInitialHashOnLoad);
|
||||||
|
window.removeEventListener('hashchange', this.handleHashChange);
|
||||||
|
clearTimeout(this.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMenuItems(footerNavIcons = {}) {
|
getMenuItems(footerNavIcons = {}) {
|
||||||
@ -188,6 +201,12 @@ class MainContent extends Component {
|
|||||||
}, 0);
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleHashChange = () => {
|
||||||
|
this.timeout = setTimeout(() => {
|
||||||
|
updateActiveToc(window.location.hash.replace(/^#/, ''));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
bindScroller() {
|
bindScroller() {
|
||||||
if (this.scroller) {
|
if (this.scroller) {
|
||||||
this.scroller.destroy();
|
this.scroller.destroy();
|
||||||
@ -206,13 +225,7 @@ class MainContent extends Component {
|
|||||||
offset: 0,
|
offset: 0,
|
||||||
})
|
})
|
||||||
.onStepEnter(({ element }) => {
|
.onStepEnter(({ element }) => {
|
||||||
[].forEach.call(document.querySelectorAll('.toc-affix li a'), node => {
|
updateActiveToc(element.id);
|
||||||
node.className = '';
|
|
||||||
});
|
|
||||||
const currentNode = document.querySelectorAll(`.toc-affix li a[href="#${element.id}"]`)[0];
|
|
||||||
if (currentNode) {
|
|
||||||
currentNode.className = 'current';
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,12 @@ class Footer extends React.Component<WrappedComponentProps> {
|
|||||||
openExternal: true,
|
openExternal: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <ZhihuOutlined style={{ color: '#0084ff' }} />,
|
icon: (
|
||||||
|
<img
|
||||||
|
src="https://gw.alipayobjects.com/zos/rmsportal/mZBWtboYbnMkTBaRIuWQ.png"
|
||||||
|
alt="seeconf"
|
||||||
|
/>
|
||||||
|
),
|
||||||
title: 'SEE Conf',
|
title: 'SEE Conf',
|
||||||
description: <FormattedMessage id="app.footer.seeconf" />,
|
description: <FormattedMessage id="app.footer.seeconf" />,
|
||||||
url: 'https://seeconf.antfin.com/',
|
url: 'https://seeconf.antfin.com/',
|
||||||
|
Loading…
Reference in New Issue
Block a user