import { InboxOutlined } from '@ant-design/icons'; import { useIntl } from 'dumi'; import React from 'react'; import styles from './SearchResult.module.less'; export type ITextSegment = { text: string; highlighted?: boolean; }; export type ISearchResult = { /** * 搜索结果的主题,显示在最左边,一般是页面的标题。 */ subject: string; title: ITextSegment[]; description?: ITextSegment[]; link: string; }; const getHighlightInfo = (textSegments: ITextSegment[]) => { return ( <> {textSegments.map((segment) => ( {segment.text} ))} ); }; /** * 展示搜索结果 * @returns */ export const SearchResult: React.FC<{ results: ISearchResult[] }> = ({ results }) => { const intl = useIntl(); return (
{results?.length ? ( results.map((r) => { return (
{r.subject}
{getHighlightInfo(r.title)}
{getHighlightInfo(r.description)}
); }) ) : (
{intl.formatMessage({ id: '没有找到查询结果' })}
)}
); };