Skip to content

Commit 4d01488

Browse files
authored
refactor(theme): move LLMs components to Llms directory and support outline placement (#3180)
1 parent dd83352 commit 4d01488

File tree

9 files changed

+51
-30
lines changed

9 files changed

+51
-30
lines changed
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
.rp-edit-link {
2-
color: var(--rp-c-brand);
3-
text-decoration: none;
4-
font-size: 15px;
5-
font-weight: 500;
6-
transition: all 0.2s ease-in-out;
1+
.rp-doc-footer {
2+
.rp-edit-link {
3+
color: var(--rp-c-brand);
4+
text-decoration: none;
5+
font-size: 15px;
6+
font-weight: 500;
7+
transition: all 0.2s ease-in-out;
78

8-
&:hover {
9-
color: var(--rp-c-brand-dark);
9+
&:hover {
10+
color: var(--rp-c-brand-dark);
11+
}
1012
}
1113
}

packages/core/src/theme/components/EditLink/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function EditLink({ isOutline }: { isOutline?: boolean }) {
1313

1414
if (isOutline) {
1515
return (
16-
<Link href={link} className="rp-outline__action-row">
16+
<Link href={link} className="rp-outline__action-row rp-edit-link">
1717
<SvgWrapper icon={IconEdit} width="16" height="16" />
1818
<span>{text}</span>
1919
</Link>

packages/core/src/theme/components/Outline/LlmsCopyRow.tsx renamed to packages/core/src/theme/components/Llms/LlmsCopyRow.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { useI18n } from '@rspress/core/runtime';
2-
import { IconCopy, IconSuccess } from '@theme';
2+
import { IconCopy, IconSuccess, SvgWrapper } from '@theme';
33
import { useCallback, useRef, useState } from 'react';
4-
import { useMdUrl } from '../Llms/useMdUrl';
5-
import { SvgWrapper } from '../SvgWrapper';
4+
import { useMdUrl } from './useMdUrl';
65

76
const cache = new Map<string, string>();
87

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.rp-outline__open-in-wrapper {
2+
position: relative;
3+
4+
.rp-llms-view-options__menu {
5+
bottom: calc(100% + 6px);
6+
top: auto;
7+
left: 0;
8+
transform-origin: bottom left;
9+
}
10+
}

packages/core/src/theme/components/Outline/LlmsOpenRow.tsx renamed to packages/core/src/theme/components/Llms/LlmsOpenRow.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useI18n, useSite } from '@rspress/core/runtime';
2-
import { IconExternalLink } from '@theme';
2+
import { IconExternalLink, SvgWrapper } from '@theme';
33
import { useEffect, useMemo, useRef, useState } from 'react';
4-
import { SvgWrapper } from '../SvgWrapper';
5-
import '../Llms/LlmsViewOptions.scss';
6-
import { useMdUrl } from '../Llms/useMdUrl';
4+
import './LlmsOpenRow.scss';
5+
import './LlmsViewOptions.scss';
6+
import { useMdUrl } from './useMdUrl';
77

88
export function LlmsOpenRow() {
99
const t = useI18n();

packages/core/src/theme/components/Outline/ScrollToTop.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export function ScrollToTop() {
1818
}
1919

2020
return (
21-
<button className="rp-outline__action-row" onClick={scrollToTop}>
21+
<button
22+
className="rp-outline__action-row rp-scroll-to-top"
23+
onClick={scrollToTop}
24+
>
2225
<SvgWrapper icon={IconScrollToTop} width="16" height="16" />
2326
<span>{t('scrollToTopText')}</span>
2427
</button>

packages/core/src/theme/components/Outline/index.scss

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,4 @@
9191
flex-shrink: 0;
9292
}
9393
}
94-
95-
&__open-in-wrapper {
96-
position: relative;
97-
98-
.rp-llms-view-options__menu {
99-
bottom: calc(100% + 6px);
100-
top: auto;
101-
left: 0;
102-
transform-origin: bottom left;
103-
}
104-
}
10594
}

packages/core/src/theme/components/Outline/index.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { useI18n, useSite } from '@rspress/core/runtime';
2-
import { EditLink, ReadPercent, Toc, useDynamicToc } from '@theme';
2+
import {
3+
EditLink,
4+
LlmsCopyRow,
5+
LlmsOpenRow,
6+
ReadPercent,
7+
Toc,
8+
useDynamicToc,
9+
} from '@theme';
310
import './index.scss';
411
import { ScrollToTop } from './ScrollToTop';
512

@@ -9,14 +16,17 @@ export function Outline() {
916
const headers = useDynamicToc();
1017
const {
1118
site: {
12-
themeConfig: { enableScrollToTop = true },
19+
themeConfig: { enableScrollToTop = true, llmsUI },
1320
},
1421
} = useSite();
1522

1623
if (headers.length === 0) {
1724
return <></>;
1825
}
1926

27+
const placement =
28+
typeof llmsUI === 'object' ? (llmsUI?.placement ?? 'title') : 'title';
29+
2030
return (
2131
<div className="rp-outline">
2232
<div className="rp-outline__title">
@@ -29,6 +39,12 @@ export function Outline() {
2939
<div className="rp-outline__divider" />
3040
<div className="rp-outline__bottom">
3141
<EditLink isOutline />
42+
{process.env.ENABLE_LLMS_UI && placement === 'outline' && (
43+
<>
44+
<LlmsCopyRow />
45+
<LlmsOpenRow />
46+
</>
47+
)}
3248
{enableScrollToTop && <ScrollToTop />}
3349
</div>
3450
</div>

packages/core/src/theme/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export {
3838
type LlmsViewOptionsProps,
3939
useMdUrl,
4040
} from './components/Llms/index';
41+
export { LlmsCopyRow } from './components/Llms/LlmsCopyRow';
42+
export { LlmsOpenRow } from './components/Llms/LlmsOpenRow';
4143
export { Nav, type NavProps } from './components/Nav/index';
4244
export { NavHamburger } from './components/NavHamburger/index';
4345
export { NavTitle } from './components/NavTitle/index';

0 commit comments

Comments
 (0)