diff --git a/site/theme/en-US.js b/site/theme/en-US.js index 981a4c553f..e1af295d32 100644 --- a/site/theme/en-US.js +++ b/site/theme/en-US.js @@ -144,5 +144,6 @@ module.exports = { 'app.docs.components.icon.pic-searcher.result-tip': 'Match the following icons for you:', 'app.docs.components.icon.pic-searcher.th-icon': 'Icon', 'app.docs.components.icon.pic-searcher.th-score': 'Probability', + 'app.components.overview.search': 'Search in components', }, }; diff --git a/site/theme/template/Content/ComponentOverview.jsx b/site/theme/template/Content/ComponentOverview.jsx index 6741aa71fa..cfc847ce8a 100644 --- a/site/theme/template/Content/ComponentOverview.jsx +++ b/site/theme/template/Content/ComponentOverview.jsx @@ -1,19 +1,32 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Helmet } from 'react-helmet-async'; import { Link } from 'bisheng/router'; import { useIntl } from 'react-intl'; -import { Divider, Row, Col, Card, Typography, Tag, Space } from 'antd'; +import debounce from 'lodash/debounce'; +import { Input, Divider, Row, Col, Card, Typography, Tag, Space } from 'antd'; +import { SearchOutlined } from '@ant-design/icons'; import { getChildren } from 'jsonml.js/lib/utils'; import { getMetaDescription, getLocalizedPathname, getThemeConfig, getMenuItems } from '../utils'; import './ComponentOverview.less'; const onClickCard = href => { - window.gtag('event', '点击', { - event_category: '组件总览卡片', - event_label: href, - }); + if (window.gtag) { + window.gtag('event', '点击', { + event_category: '组件总览卡片', + event_label: href, + }); + } }; +const reportSearch = debounce(value => { + if (window.gtag) { + window.gtag('event', '搜索', { + event_category: '组件总览卡片', + event_label: value, + }); + } +}, 500); + const { Title } = Typography; const ComponentOverview = ({ componentsData = [], @@ -23,7 +36,7 @@ const ComponentOverview = ({ }, utils: { toReactComponent }, }) => { - const { locale } = useIntl(); + const { locale, formatMessage } = useIntl(); const documentTitle = `${title} - Ant Design`; const contentChild = getMetaDescription(getChildren(content)); const themeConfig = getThemeConfig(); @@ -33,6 +46,7 @@ const ComponentOverview = ({ themeConfig.categoryOrder, themeConfig.typeOrder, ); + const [search, setSearch] = useState(''); return (
@@ -44,47 +58,69 @@ const ComponentOverview = ({

{title}

{toReactComponent(['section', { className: 'markdown' }].concat(getChildren(content)))} + { + setSearch(e.target.value); + reportSearch(e.target.value); + }} + autoFocus // eslint-disable-line jsx-a11y/no-autofocus + suffix={} + /> + {menuItems .filter(i => i.order > -1) - .map(group => ( -
- - <Space align="center"> - {group.title} - <Tag style={{ display: 'block' }}>{group.children.length}</Tag> - </Space> - - - {group.children - .sort((a, b) => a.title.charCodeAt(0) - b.title.charCodeAt(0)) - .map(component => { - const url = `${component.filename - .replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '') - .toLowerCase()}/`; - const href = getLocalizedPathname(url, locale === 'zh-CN'); - return ( - - onClickCard(href)}> - - {component.title} {component.subtitle} + .map(group => { + const components = group.children.filter( + component => + !search.trim() || + component.title.toLowerCase().includes(search.trim().toLowerCase()) || + component.subtitle.toLowerCase().includes(search.trim().toLowerCase()), + ); + return ( +
+ {components.length > 0 && ( + + <Space align="center"> + {group.title} + <Tag style={{ display: 'block' }}>{components.length}</Tag> + </Space> + + )} + + {components + .sort((a, b) => a.title.charCodeAt(0) - b.title.charCodeAt(0)) + .map(component => { + const url = `${component.filename + .replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '') + .toLowerCase()}/`; + const href = getLocalizedPathname(url, locale === 'zh-CN'); + return ( + + onClickCard(href)}> + + {component.title} {component.subtitle} +
+ } + > +
+ {component.title}
- } - > -
- {component.title} -
-
- - - ); - })} -
-
- ))} + + + + ); + })} + + + ); + })}
); }; diff --git a/site/theme/template/Content/ComponentOverview.less b/site/theme/template/Content/ComponentOverview.less index 6171182cd6..e65a7c9908 100644 --- a/site/theme/template/Content/ComponentOverview.less +++ b/site/theme/template/Content/ComponentOverview.less @@ -26,3 +26,20 @@ } } } + +.components-overview-search { + width: 100%; + padding: 0; + font-size: 20px; + border: 0; + box-shadow: none; + + input { + color: rgba(0, 0, 0, 0.85); + font-size: 20px; + } + + .anticon { + color: #bbb; + } +} diff --git a/site/theme/zh-CN.js b/site/theme/zh-CN.js index 5e6e5bfc8a..cbf53d97ad 100644 --- a/site/theme/zh-CN.js +++ b/site/theme/zh-CN.js @@ -140,5 +140,6 @@ module.exports = { 'app.docs.components.icon.pic-searcher.result-tip': '为您匹配到以下图标:', 'app.docs.components.icon.pic-searcher.th-icon': '图标', 'app.docs.components.icon.pic-searcher.th-score': '匹配度', + 'app.components.overview.search': '搜索组件', }, };