Loading...
Loading...
Compare original and translation side by side
theme/index.tsx@rspress/core/*rspress/*theme/index.tsx@rspress/core/*rspress/*| User wants to... | Level | Approach |
|---|---|---|
| Change brand colors, fonts, spacing, shadows | 1 | CSS variables |
| Adjust a specific component's style (borders, padding, etc.) | 2 | BEM class overrides |
| Add content around existing components (banners, footers, logos) | 3 | Layout slots (wrap) |
Override MDX rendering (custom | 3 | |
| Wrap the app in a provider (state, analytics, auth) | 4 | Eject |
| Replace built-in icons (logo, GitHub, search, etc.) | — | Icon re-export |
| Completely replace a built-in component | 4 | Eject that component |
| Add a global floating component (back-to-top, chat widget) | — | |
| Control page layout structure (hide sidebar, blank page) | — | Frontmatter |
| 用户需求 | 层级 | 实现方式 |
|---|---|---|
| 更改品牌颜色、字体、间距、阴影 | 1 | CSS variables |
| 调整特定组件的样式(边框、内边距等) | 2 | BEM 类覆盖 |
| 在现有组件周围添加内容(横幅、页脚、Logo) | 3 | Layout slots(封装) |
覆盖 MDX 渲染逻辑(自定义 | 3 | |
| 用提供者包裹整个应用(状态、统计、权限) | 4 | Eject |
| 替换内置图标(Logo、GitHub、搜索等) | — | 图标重导出 |
| 完全替换内置组件 | 4 | Eject 目标组件 |
| 添加全局悬浮组件(返回顶部、聊天窗口) | — | |
| 控制页面布局结构(隐藏侧边栏、空白页面) | — | Frontmatter |
theme/index.tsxdocs/project/
├── docs/
├── theme/
│ ├── index.tsx # Theme entry — re-exports + overrides
│ ├── index.css # CSS variable / BEM overrides (optional)
│ └── components/ # Ejected components (Level 4)
└── rspress.config.ts// theme/index.tsx
import './index.css'; // optional
export * from '@rspress/core/theme-original';theme/@rspress/core/theme-original@rspress/core/themetheme/index.tsxdocs/@rspress/core/themedocs/theme/index.tsxproject/
├── docs/
├── theme/
│ ├── index.tsx # 主题入口 — 重导出 + 覆盖
│ ├── index.css # CSS 变量 / BEM 覆盖(可选)
│ └── components/ # Eject 出的组件(层级4)
└── rspress.config.ts// theme/index.tsx
import './index.css'; // 可选
export * from '@rspress/core/theme-original';theme/@rspress/core/theme-original@rspress/core/themetheme/index.tsxdocs/@rspress/core/themetheme/index.csstheme/index.tsx/* theme/index.css */
:root {
--rp-c-brand: #7c3aed;
--rp-c-brand-light: #8b5cf6;
--rp-c-brand-dark: #6d28d9;
}
.dark {
--rp-c-brand: #a78bfa;
}globalStyles// rspress.config.ts
export default defineConfig({
globalStyles: path.join(__dirname, 'styles/custom.css'),
});Full variable list: Readfor all available CSS variables with light/dark defaults.references/css-variables.md
theme/index.csstheme/index.tsx/* theme/index.css */
:root {
--rp-c-brand: #7c3aed;
--rp-c-brand-light: #8b5cf6;
--rp-c-brand-dark: #6d28d9;
}
.dark {
--rp-c-brand: #a78bfa;
}globalStyles// rspress.config.ts
export default defineConfig({
globalStyles: path.join(__dirname, 'styles/custom.css'),
});完整变量列表:查看获取所有带亮色/暗色默认值的可用 CSS 变量。references/css-variables.md
.rp-[component]__[element]--[modifier].rp-nav.rp-link.rp-tabs.rp-codeblock.rp-codeblock__title.rp-nav-menu__item--active.rp-[component]__[element]--[modifier].rp-nav.rp-link.rp-tabs.rp-codeblock.rp-codeblock__title.rp-nav-menu__item--activeLayouttheme/index.tsx// theme/index.tsx
import { Layout as OriginalLayout } from '@rspress/core/theme-original';
export * from '@rspress/core/theme-original';
export function Layout() {
return (
<OriginalLayout beforeNavTitle={<MyLogo />} bottom={<CustomFooter />} />
);
}@rspress/core/runtimeuseDark()useLang()useVersion()usePage()useSite()useFrontmatter()useI18n()All slots & examples: Readfor the complete slot list and usage patterns including i18n and MDX component overrides.references/layout-slots.md
theme/index.tsxLayout// theme/index.tsx
import { Layout as OriginalLayout } from '@rspress/core/theme-original';
export * from '@rspress/core/theme-original';
export function Layout() {
return (
<OriginalLayout beforeNavTitle={<MyLogo />} bottom={<CustomFooter />} />
);
}@rspress/core/runtimeuseDark()useLang()useVersion()usePage()useSite()useFrontmatter()useI18n()所有插槽及示例:查看获取完整插槽列表及使用模式,包括国际化和 MDX 组件覆盖。references/layout-slots.md
rspress eject # list available components
rspress eject DocFooter # eject to theme/components/DocFooter/theme/index.tsxexport * from '@rspress/core/theme-original';
export { DocFooter } from './components/DocFooter';Component list & patterns: Readfor available components, workflow, and common patterns.references/eject-components.md
rspress eject # 列出可用组件
rspress eject DocFooter # 导出到 theme/components/DocFooter/theme/index.tsxexport * from '@rspress/core/theme-original';
export { DocFooter } from './components/DocFooter';组件列表及模式:查看获取可用组件、工作流程及常见模式。references/eject-components.md
theme/index.tsximport type { FC, SVGProps } from 'react';
type Icon = FC<SVGProps<SVGSVGElement>> | string;// theme/index.tsx
export * from '@rspress/core/theme-original';
// Named export overrides the wildcard — replaces the GitHub icon site-wide
export const IconGithub = (props: React.SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path d="M12 2C6.477 2 2 6.484 2 12.017c0 ..." fill="currentColor" />
</svg>
);// theme/index.tsx
export * from '@rspress/core/theme-original';
import CustomGithubIcon from './icons/github.svg?react';
export const IconGithub = CustomGithubIcon;SvgWrapperimport { SvgWrapper, IconGithub } from '@rspress/core/theme';
<SvgWrapper icon={IconGithub} width={24} height={24} />IconArrowDownIconArrowRightIconCloseIconCopyIconDeprecatedIconDownIconEditIconEmptyIconExperimentalIconExternalLinkIconFileIconGithubIconGitlabIconHeaderIconJumpIconLinkIconLoadingIconMenuIconMoonIconScrollToTopIconSearchIconSmallMenuIconSuccessIconSunIconTitleIconWrapIconWrappedSource: See the icons source for default implementations.
theme/index.tsximport type { FC, SVGProps } from 'react';
type Icon = FC<SVGProps<SVGSVGElement>> | string;// theme/index.tsx
export * from '@rspress/core/theme-original';
// 命名导出覆盖通配符导出——全站替换 GitHub 图标
export const IconGithub = (props: React.SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path d="M12 2C6.477 2 2 6.484 2 12.017c0 ..." fill="currentColor" />
</svg>
);// theme/index.tsx
export * from '@rspress/core/theme-original';
import CustomGithubIcon from './icons/github.svg?react';
export const IconGithub = CustomGithubIcon;SvgWrapperimport { SvgWrapper, IconGithub } from '@rspress/core/theme';
<SvgWrapper icon={IconGithub} width={24} height={24} />IconArrowDownIconArrowRightIconCloseIconCopyIconDeprecatedIconDownIconEditIconEmptyIconExperimentalIconExternalLinkIconFileIconGithubIconGitlabIconHeaderIconJumpIconLinkIconLoadingIconMenuIconMoonIconScrollToTopIconSearchIconSmallMenuIconSuccessIconSunIconTitleIconWrapIconWrapped源码:查看 图标源码 获取默认实现。
// rspress.config.ts
export default defineConfig({
globalUIComponents: [
path.join(__dirname, 'components', 'BackToTop.tsx'),
[
path.join(__dirname, 'components', 'Analytics.tsx'),
{ trackingId: '...' },
],
],
});// rspress.config.ts
export default defineConfig({
globalUIComponents: [
path.join(__dirname, 'components', 'BackToTop.tsx'),
[
path.join(__dirname, 'components', 'Analytics.tsx'),
{ trackingId: '...' },
],
],
});pageType| Value | Description |
|---|---|
| Home page with navbar |
| Standard doc with sidebar and outline |
| Doc without sidebar/outline |
| Custom content with navbar only |
| Custom content without navbar |
| 404 error page |
navbar: falsesidebar: falseoutline: falsefooter: falsepageType| 值 | 描述 |
|---|---|
| 带导航栏的首页 |
| 带侧边栏和大纲的标准文档页 |
| 无侧边栏/大纲的文档页 |
| 仅带导航栏的自定义内容页 |
| 无导航栏的自定义内容页 |
| 404 错误页 |
navbar: falsesidebar: falseoutline: falsefooter: false@rspress/core/theme@rspress/core/theme-originaltheme/export * from '@rspress/core/theme-original'theme/index.tsxrspress/theme@rspress/theme-default@rspress/core/theme-originaltheme/@rspress/core/theme@rspress/core/theme-originaltheme/index.tsxexport * from '@rspress/core/theme-original'rspress/theme@rspress/theme-default@rspress/core/theme-original