import React, { useState, useEffect } from 'react'; import { withPrefix } from 'gatsby'; import { default as RCFooter, FooterProps as RcFooterProps } from 'rc-footer'; import { useTranslation } from 'react-i18next'; import { GithubOutlined, WeiboOutlined, ZhihuOutlined, QuestionCircleOutlined, } from '@ant-design/icons'; import classnames from 'classnames'; import omit from 'omit.js'; import styles from './Footer.module.less'; import 'rc-footer/assets/index.less'; export const OLD_SITE_DOMAIN = 'https://antv-2018.alipay.com'; interface FooterProps extends RcFooterProps { rootDomain?: string; language?: string; githubUrl?: string; location: Location; } const Footer: React.FC = ({ columns, bottom, theme = 'dark', language, rootDomain = '', location, ...restProps }) => { const [withMenu, setWithMenu] = useState(false); const { t, i18n } = useTranslation(); const lang = language || i18n.language; useEffect(() => { // 有 menu 的模版 footer 表现不同,通过 location 判断加载的模版 const pathPrefix = withPrefix('/').replace(/\/$/, ''); const path = location.pathname.replace(pathPrefix, ''); const isExamplePage = path.startsWith(`/zh/examples`) || path.startsWith(`/en/examples`); const isDocsPage = path.startsWith(`/zh/docs`) || path.startsWith(`/en/docs`); // examples 页面里目前只有 gallery 是有 footer 的, // 且 gallery 会出现 `location.key = 'initial'` 逻辑,所以先统一处理为需要 menu if (isExamplePage) { setWithMenu(true); } else if (isDocsPage) { // 文档页为 404 时 footer 没有 menu setWithMenu(!((location as any).key === 'initial')); } else { setWithMenu(false); } }, [location]); const getColums = () => { // 如果外部没有传入 columns,则默认展示 antv footer const col1 = { title: t('Resources'), items: [ { title: 'Ant Design', url: 'https://ant.design', openExternal: true, }, { title: 'Ant Design Mobile', url: 'https://mobile.ant.design', openExternal: true, }, { title: 'Umi', description: t('React 应用开发框架'), url: 'https://umijs.org', openExternal: true, }, { title: 'Dumi', description: t('组件/文档研发工具'), url: 'https://d.umijs.org', openExternal: true, }, { title: 'ahooks', description: t('React Hooks 库'), url: 'https://github.com/alibaba/hooks', openExternal: true, }, { title: t('国内镜像'), url: 'https://antv.gitee.io/', }, ], }; const col2 = { title: t('社区'), items: [ { icon: , title: t('体验科技专栏'), url: 'http://zhuanlan.zhihu.com/xtech', openExternal: true, }, { icon: ( seeconf ), title: 'SEE Conf', description: t('蚂蚁体验科技大会'), url: 'https://seeconf.antfin.com/', openExternal: true, }, ], }; const col3 = { title: t('帮助'), items: [ { icon: , title: 'GitHub', url: 'https://github.com/antvis', openExternal: true, }, { icon: , title: t('StackOverflow'), url: 'http://stackoverflow.com/questions/tagged/antv', openExternal: true, }, ], }; const more = { icon: ( more products ), title: t('更多产品'), items: [ { icon: ( Ant Design ), title: 'Ant Design', url: 'https://ant.design', description: t('企业级 UI 设计语言'), openExternal: true, }, { icon: ( yuque ), title: t('语雀'), url: 'https://yuque.com', description: t('知识创作与分享工具'), openExternal: true, }, { icon: ( Egg ), title: 'Egg', url: 'https://eggjs.org', description: t('企业级 Node 开发框架'), openExternal: true, }, { icon: ( kitchen ), title: 'Kitchen', description: t('Sketch 工具集'), url: 'https://kitchen.alipay.com', openExternal: true, }, { icon: ( xtech ), title: t('蚂蚁体验科技'), url: 'https://xtech.antfin.com/', openExternal: true, }, ], }; return [col1, col2, col3, more]; }; return (
© {new Date().getFullYear()} Made with ❤ by{' '} XTech
) } {...omit(restProps, ['githubUrl'])} /> ); }; export default Footer;