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, } from '@ant-design/icons'; import classnames from 'classnames'; import omit from 'omit.js'; import { getProducts } from './getProducts'; import { useChinaMirrorHost } from '../hooks'; 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; const [isChinaMirrorHost] = useChinaMirrorHost(); const products = getProducts({ t, language: lang, rootDomain, isChinaMirrorHost, }); 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: ( yunfengdie ), title: t('云凤蝶'), url: 'https://yunfengdie.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, }, ], }; const defaultColumns = products .filter((product) => product.category !== 'ecology') .map((product) => ({ title: ( {product.title} {product.slogan} ), items: product.links, })); 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 = () => { if (products.length % 2 !== 0) { return [...defaultColumns]; } return [...defaultColumns]; }; return (
{more.title} {more.items.map((item: any) => (
{item.icon} {item.title} {item.description && {`- ${item.description}`}}
))}
{t('关于我们')} {t('返回旧版')}
© {new Date().getFullYear()} Made with ❤ by{' '} XTech
) } {...omit(restProps, ['githubUrl'])} /> ); }; export default Footer;