close
  • 中文
  • 内置图标 theme-only

    Rspress 内置使用图标时,会使用一个 SvgWrapper 组件来渲染图标。支持 icon 为 url 或者 svgr 的 React 组件:

    type Icon = React.FC<React.SVGProps<SVGSVGElement>> | string;

    下面的代码是一个 Rspress 如何使用 IconGithub 的示例:

    import { SvgWrapper, IconGithub } from '@rspress/core/theme-original';
    
    <SvgWrapper icon={IconGithub} width={24} height={24} />

    用法

    当你想更换 Rspress 内置图标时,使用 自定义主题 - 重导出 进行替换。

    theme/index.tsx
    export { IconGithub } from './my-icons';
    export * from '@rspress/core/theme-original';

    所有 Rspress 使用到的图标如下:

    import {
      SvgWrapper,
      IconArrowDown,
      IconArrowRight,
      IconClose,
      IconCopy,
      IconDeprecated,
      IconDown,
      IconEdit,
      IconEmpty,
      IconExperimental,
      IconExternalLink,
      IconFile,
      IconGithub,
      IconGitlab,
      IconHeader,
      IconJump,
      IconLoading,
      IconMenu,
      IconMoon,
      IconScrollToTop,
      IconSearch,
      IconSmallMenu,
      IconSuccess,
      IconSun,
      IconTitle,
      IconWrap,
      IconWrapped,
      IconLink,
    } from '@rspress/core/theme';
    
    export default () => {
      return (
        <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', fontSize: 12 }}>
          {[
            IconArrowDown,
            IconArrowRight,
            IconClose,
            IconCopy,
            IconDeprecated,
            IconDown,
            IconEdit,
            IconEmpty,
            IconExperimental,
            IconExternalLink,
            IconFile,
            IconGithub,
            IconGitlab,
            IconHeader,
            IconJump,
            IconLoading,
            IconMenu,
            IconMoon,
            IconScrollToTop,
            IconSearch,
            IconSmallMenu,
            IconSuccess,
            IconSun,
            IconTitle,
            IconWrap,
            IconWrapped,
            IconLink,
          ].map((Icon, idx) => (
            <SvgWrapper icon={Icon} key={idx} width={24} height={24} />
          ))}
        </div>
      );
    };