@rspress/core 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -10
- package/dist/index.js +189 -234
- package/dist/index.js.map +1 -1
- package/dist/loader.js +1 -3
- package/dist/loader.js.map +1 -1
- package/dist/theme/bundle.css +96 -159
- package/dist/theme/bundle.d.ts +1 -1
- package/dist/theme/bundle.js +930 -926
- package/dist/theme/bundle.js.map +1 -1
- package/package.json +14 -13
- package/runtime.ts +1 -1
- package/src/theme-default/components/Aside/index.css +23 -0
- package/src/theme-default/components/Aside/index.tsx +7 -13
- package/src/theme-default/components/EditLink/index.module.scss +3 -3
- package/src/theme-default/components/EditLink/index.tsx +0 -5
- package/src/theme-default/components/HomeHero/index.module.scss +6 -0
- package/src/theme-default/components/HomeHero/index.tsx +4 -4
- package/src/theme-default/components/Nav/index.module.scss +0 -1
- package/src/theme-default/components/Nav/index.tsx +3 -3
- package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +1 -2
- package/src/theme-default/components/Sidebar/SidebarGroup.tsx +180 -0
- package/src/theme-default/components/Sidebar/SidebarItem.tsx +60 -0
- package/src/theme-default/components/Sidebar/index.module.scss +22 -5
- package/src/theme-default/components/Sidebar/index.tsx +39 -248
- package/src/theme-default/components/Tabs/index.module.scss +11 -18
- package/src/theme-default/components/Tabs/index.tsx +1 -1
- package/src/theme-default/layout/DocLayout/index.module.scss +17 -18
- package/src/theme-default/layout/Layout/index.tsx +0 -1
- package/src/theme-default/logic/sideEffects.ts +3 -1
- package/src/theme-default/logic/useEditLink.ts +6 -3
- package/src/theme-default/styles/{doc/code.css → code.css} +4 -1
- package/src/theme-default/styles/index.ts +1 -3
- package/src/theme-default/styles/vars.css +2 -2
- package/src/theme-default/assets/edit.svg +0 -1
- package/src/theme-default/styles/doc/container.css +0 -103
- package/src/theme-default/styles/doc/index.css +0 -6
- /package/dist/theme/{index.ts → index.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"@mdx-js/loader": "2.2.1",
|
|
42
42
|
"@mdx-js/mdx": "2.2.1",
|
|
43
43
|
"@mdx-js/react": "2.2.1",
|
|
44
|
-
"@modern-js/builder": "2.
|
|
45
|
-
"@modern-js/builder-rspack-provider": "2.
|
|
44
|
+
"@modern-js/builder": "2.34.0",
|
|
45
|
+
"@modern-js/builder-rspack-provider": "2.34.0",
|
|
46
46
|
"@modern-js/mdx-rs-binding": "0.2.5",
|
|
47
|
-
"@modern-js/utils": "2.
|
|
47
|
+
"@modern-js/utils": "2.34.0",
|
|
48
48
|
"@types/compression": "^1.7.2",
|
|
49
49
|
"@types/polka": "^0.5.4",
|
|
50
50
|
"acorn": "^8.8.1",
|
|
@@ -91,20 +91,21 @@
|
|
|
91
91
|
"unist-util-visit": "^4.1.1",
|
|
92
92
|
"unist-util-visit-children": "^2.0.1",
|
|
93
93
|
"yaml-front-matter": "^4.1.1",
|
|
94
|
-
"
|
|
95
|
-
"@rspress/
|
|
96
|
-
"@rspress/plugin-
|
|
97
|
-
"@rspress/plugin-
|
|
98
|
-
"@rspress/
|
|
94
|
+
"rspack-plugin-virtual-module": "0.1.11",
|
|
95
|
+
"@rspress/shared": "0.0.10",
|
|
96
|
+
"@rspress/plugin-medium-zoom": "0.0.10",
|
|
97
|
+
"@rspress/plugin-last-updated": "0.0.10",
|
|
98
|
+
"@rspress/plugin-auto-nav-sidebar": "0.0.10",
|
|
99
|
+
"@rspress/plugin-container-syntax": "0.0.10"
|
|
99
100
|
},
|
|
100
101
|
"peerDependencies": {
|
|
101
102
|
"react": ">=17"
|
|
102
103
|
},
|
|
103
104
|
"devDependencies": {
|
|
104
|
-
"@modern-js/plugin-tailwindcss": "2.
|
|
105
|
-
"@modern-js/plugin-testing": "2.
|
|
106
|
-
"@modern-js/tsconfig": "2.
|
|
107
|
-
"@modern-js/types": "2.
|
|
105
|
+
"@modern-js/plugin-tailwindcss": "2.34.0",
|
|
106
|
+
"@modern-js/plugin-testing": "2.34.0",
|
|
107
|
+
"@modern-js/tsconfig": "2.34.0",
|
|
108
|
+
"@modern-js/types": "2.34.0",
|
|
108
109
|
"@types/body-scroll-lock": "^3.1.0",
|
|
109
110
|
"@types/fs-extra": "^9.0.13",
|
|
110
111
|
"@types/hast": "^2.3.4",
|
package/runtime.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './dist/runtime';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.aside-link {
|
|
2
|
+
padding-bottom: 1px;
|
|
3
|
+
}
|
|
4
|
+
.aside-link-text {
|
|
5
|
+
padding: 0px 12px;
|
|
6
|
+
white-space: nowrap;
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
text-overflow: ellipsis;
|
|
9
|
+
transition: all 0.2s ease-in-out;
|
|
10
|
+
border-radius: 10px 0 0 10px;
|
|
11
|
+
font-size: 13px;
|
|
12
|
+
line-height: 1.75rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.aside-link-text:hover {
|
|
16
|
+
background-color: var(--rp-c-bg-mute);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.aside-active,
|
|
20
|
+
.aside-active:hover {
|
|
21
|
+
color: var(--rp-c-brand-dark) !important;
|
|
22
|
+
background-color: var(--rp-c-brand-tint);
|
|
23
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
|
-
import { Header } from '@rspress/shared
|
|
2
|
+
import { Header } from '@rspress/shared';
|
|
3
3
|
import { bindingAsideScroll, scrollToTarget } from '../../logic';
|
|
4
|
+
import './index.css';
|
|
4
5
|
|
|
5
6
|
export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
6
7
|
const { headers } = props;
|
|
@@ -33,22 +34,15 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
33
34
|
};
|
|
34
35
|
}, [headers]);
|
|
35
36
|
|
|
36
|
-
// const handleHeaderClick = e => {};
|
|
37
|
-
|
|
38
37
|
const renderHeader = (header: Header) => {
|
|
39
38
|
return (
|
|
40
39
|
<li key={header.id}>
|
|
41
40
|
<a
|
|
42
41
|
href={`#${header.id}`}
|
|
43
|
-
className="
|
|
42
|
+
className="aside-link transition-all duration-300 hover:text-text-1 text-text-2 block"
|
|
44
43
|
style={{
|
|
45
|
-
fontSize: '13px',
|
|
46
44
|
paddingLeft: (header.depth - baseHeaderLevel) * 12,
|
|
47
|
-
|
|
48
|
-
overflow: 'hidden',
|
|
49
|
-
textOverflow: 'ellipsis',
|
|
50
|
-
fontWeight:
|
|
51
|
-
header.depth === baseHeaderLevel ? 'semibold' : 'normal',
|
|
45
|
+
fontWeight: 'semibold',
|
|
52
46
|
}}
|
|
53
47
|
onClick={e => {
|
|
54
48
|
e.preventDefault();
|
|
@@ -59,7 +53,7 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
59
53
|
}
|
|
60
54
|
}}
|
|
61
55
|
>
|
|
62
|
-
{header.text}
|
|
56
|
+
<span className="aside-link-text block">{header.text}</span>
|
|
63
57
|
</a>
|
|
64
58
|
</li>
|
|
65
59
|
);
|
|
@@ -68,8 +62,8 @@ export function Aside(props: { headers: Header[]; outlineTitle: string }) {
|
|
|
68
62
|
return (
|
|
69
63
|
<div className="flex flex-col">
|
|
70
64
|
<div className={hasOutline ? `<lg:hidden` : 'hidden'}>
|
|
71
|
-
<div id="aside-container" className="relative
|
|
72
|
-
<div className="leading-7 block text-sm font-semibold">
|
|
65
|
+
<div id="aside-container" className="relative text-sm font-medium">
|
|
66
|
+
<div className="leading-7 block text-sm font-semibold pl-3">
|
|
73
67
|
{props.outlineTitle}
|
|
74
68
|
</div>
|
|
75
69
|
<nav className="mt-1">
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
.editLink {
|
|
2
2
|
color: var(--rp-c-brand);
|
|
3
3
|
text-decoration: none;
|
|
4
|
-
font-size:
|
|
4
|
+
font-size: 15px;
|
|
5
5
|
font-weight: 500;
|
|
6
6
|
margin: 20px 0;
|
|
7
|
-
|
|
7
|
+
transition: all 0.2s ease-in-out;
|
|
8
8
|
&:hover {
|
|
9
|
-
|
|
9
|
+
color: var(--rp-c-brand-dark);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEditLink } from '../../logic';
|
|
2
|
-
import Edit from '../../assets/edit.svg';
|
|
3
2
|
import styles from './index.module.scss';
|
|
4
3
|
|
|
5
4
|
export default function EditLink() {
|
|
@@ -13,10 +12,6 @@ export default function EditLink() {
|
|
|
13
12
|
|
|
14
13
|
return (
|
|
15
14
|
<a href={link} target="_blank" className={styles.editLink}>
|
|
16
|
-
<Edit
|
|
17
|
-
className="h-5.5 mr-2 inline-block"
|
|
18
|
-
style={{ verticalAlign: '-5px' }}
|
|
19
|
-
/>
|
|
20
15
|
{text}
|
|
21
16
|
</a>
|
|
22
17
|
);
|
|
@@ -24,8 +24,8 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
24
24
|
></div>
|
|
25
25
|
<div className="m-auto flex flex-col md:flex-row max-w-6xl min-h-[50vh]">
|
|
26
26
|
<div className="flex flex-col justify-center text-center max-w-xl sm:max-w-4xl m-auto order-2 md:order-1">
|
|
27
|
-
<h1 className="font-bold text-3xl sm:text-6xl md:text-7xl m-auto sm:m-4 md:m-0 md:pb-3 lg:pb-
|
|
28
|
-
<span className={styles.clip} style={{ lineHeight: '1.
|
|
27
|
+
<h1 className="font-bold text-3xl sm:text-6xl md:text-7xl m-auto sm:m-4 md:m-0 md:pb-3 lg:pb-2 leading-tight z-10">
|
|
28
|
+
<span className={styles.clip} style={{ lineHeight: '1.3' }}>
|
|
29
29
|
{hero.name}
|
|
30
30
|
</span>
|
|
31
31
|
</h1>
|
|
@@ -34,7 +34,7 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
34
34
|
className={`mx-auto md:m-0 text-3xl sm:text-5xl md:text-6xl pb-2 font-bold z-10 max-w-392px ${
|
|
35
35
|
hasImage ? 'sm:max-w-xl' : 'sm:max-w-4xl'
|
|
36
36
|
}`}
|
|
37
|
-
style={{ lineHeight: '1.
|
|
37
|
+
style={{ lineHeight: '1.2' }}
|
|
38
38
|
>
|
|
39
39
|
{hero.text}
|
|
40
40
|
</p>
|
|
@@ -58,7 +58,7 @@ export function HomeHero({ frontmatter }: { frontmatter: FrontMatterMeta }) {
|
|
|
58
58
|
</div>
|
|
59
59
|
|
|
60
60
|
{hasImage ? (
|
|
61
|
-
<div className="rspress-home-hero-image
|
|
61
|
+
<div className="rspress-home-hero-image md:flex-center m-auto order-1 md:order-2 sm:flex md:none lg:flex">
|
|
62
62
|
<img src={hero.image?.src} alt={hero.image?.alt} />
|
|
63
63
|
</div>
|
|
64
64
|
) : null}
|
|
@@ -100,7 +100,7 @@ export function Nav(props: NavProps) {
|
|
|
100
100
|
|
|
101
101
|
const NavMenu = ({ menuItems }: { menuItems: NavItem[] }) => {
|
|
102
102
|
return (
|
|
103
|
-
<div className="menu h-14">
|
|
103
|
+
<div className="rspress-nav-menu menu h-14">
|
|
104
104
|
{menuItems.map(item => {
|
|
105
105
|
return 'items' in item || Array.isArray(item) ? (
|
|
106
106
|
<div key={item.text} className="mx-3 last:mr-0">
|
|
@@ -140,11 +140,11 @@ export function Nav(props: NavProps) {
|
|
|
140
140
|
const hasAppearanceSwitch = siteData.themeConfig.darkMode !== false;
|
|
141
141
|
|
|
142
142
|
const leftNav = () => {
|
|
143
|
-
return (
|
|
143
|
+
return leftMenuItems.length > 0 ? (
|
|
144
144
|
<div className={styles.leftNav}>
|
|
145
145
|
<NavMenu menuItems={leftMenuItems} />
|
|
146
146
|
</div>
|
|
147
|
-
);
|
|
147
|
+
) : null;
|
|
148
148
|
};
|
|
149
149
|
|
|
150
150
|
const rightNav = () => {
|
|
@@ -27,8 +27,7 @@ export class LocalProvider implements Provider {
|
|
|
27
27
|
|
|
28
28
|
async #getPages(lang: string): Promise<PageIndexInfo[]> {
|
|
29
29
|
const result = await fetch(
|
|
30
|
-
|
|
31
|
-
`${__ASSET_PREFIX__}/static/${SEARCH_INDEX_NAME}.${lang}.${searchIndexHash[lang]}.json`,
|
|
30
|
+
`${process.env.__ASSET_PREFIX__}/static/${SEARCH_INDEX_NAME}.${lang}.${searchIndexHash[lang]}.json`,
|
|
32
31
|
);
|
|
33
32
|
return result.json();
|
|
34
33
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { NormalizedSidebarGroup } from '@rspress/shared';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import ArrowRight from '../../assets/arrow-right.svg';
|
|
5
|
+
import { Tag } from '../Tag';
|
|
6
|
+
import styles from './index.module.scss';
|
|
7
|
+
import { SidebarItem } from './SidebarItem';
|
|
8
|
+
import { highlightTitleStyle, matchCache, type SidebarItemProps } from '.';
|
|
9
|
+
import { normalizeHref, withBase } from '@/runtime';
|
|
10
|
+
|
|
11
|
+
export function SidebarGroup(props: SidebarItemProps) {
|
|
12
|
+
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
|
|
13
|
+
const navigate = useNavigate();
|
|
14
|
+
const isGroupMatched = matchCache.get(item);
|
|
15
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
16
|
+
const transitionRef = useRef<any>(null);
|
|
17
|
+
const innerRef = useRef<HTMLDivElement>(null);
|
|
18
|
+
const initialRender = useRef(true);
|
|
19
|
+
const initialState = useRef((item as NormalizedSidebarGroup).collapsed);
|
|
20
|
+
const active = item.link && activeMatcher(item.link);
|
|
21
|
+
const { collapsed, collapsible = true } = item as NormalizedSidebarGroup;
|
|
22
|
+
const collapsibleIcon = (
|
|
23
|
+
<div
|
|
24
|
+
style={{
|
|
25
|
+
cursor: 'pointer',
|
|
26
|
+
transition: 'transform 0.2s ease-out',
|
|
27
|
+
transform: collapsed ? 'rotate(0deg)' : 'rotate(90deg)',
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
<ArrowRight />
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (initialRender.current) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!containerRef.current || !innerRef.current) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (transitionRef.current) {
|
|
44
|
+
clearTimeout(transitionRef.current);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const container = containerRef.current;
|
|
48
|
+
const inner = innerRef.current;
|
|
49
|
+
// We should add the margin-top(4px) of first item in list, which is a part of the height of the container
|
|
50
|
+
const contentHeight = inner.clientHeight + 4;
|
|
51
|
+
if (collapsed) {
|
|
52
|
+
container.style.maxHeight = `${contentHeight}px`;
|
|
53
|
+
container.style.transitionDuration = '0.5s';
|
|
54
|
+
inner.style.opacity = '0';
|
|
55
|
+
|
|
56
|
+
transitionRef.current = setTimeout(() => {
|
|
57
|
+
if (containerRef.current) {
|
|
58
|
+
containerRef.current.style.maxHeight = '0px';
|
|
59
|
+
}
|
|
60
|
+
}, 0);
|
|
61
|
+
} else {
|
|
62
|
+
container.style.maxHeight = `${contentHeight}px`;
|
|
63
|
+
container.style.transitionDuration = '0.3s';
|
|
64
|
+
inner.style.opacity = '1';
|
|
65
|
+
|
|
66
|
+
transitionRef.current = setTimeout(() => {
|
|
67
|
+
if (containerRef.current) {
|
|
68
|
+
containerRef.current.style.removeProperty('max-height');
|
|
69
|
+
}
|
|
70
|
+
}, 300);
|
|
71
|
+
}
|
|
72
|
+
}, [collapsed]);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
initialRender.current = false;
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
const toggleCollapse: React.MouseEventHandler<HTMLDivElement> = (e): void => {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
// update collapsed state
|
|
81
|
+
setSidebarData(sidebarData => {
|
|
82
|
+
const newSidebarData = [...sidebarData];
|
|
83
|
+
const indexes = id.split('-').map(Number);
|
|
84
|
+
const initialIndex = indexes.shift()!;
|
|
85
|
+
const root = newSidebarData[initialIndex];
|
|
86
|
+
let current = root;
|
|
87
|
+
for (const index of indexes) {
|
|
88
|
+
current = (current as NormalizedSidebarGroup).items[index];
|
|
89
|
+
}
|
|
90
|
+
if ('items' in current) {
|
|
91
|
+
current.collapsed = !current.collapsed;
|
|
92
|
+
}
|
|
93
|
+
return newSidebarData;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<section
|
|
99
|
+
key={id}
|
|
100
|
+
className="mt-0.5 block"
|
|
101
|
+
style={{
|
|
102
|
+
marginLeft: depth === 0 ? 0 : '18px',
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
<div
|
|
106
|
+
className={`flex justify-between items-center ${
|
|
107
|
+
isGroupMatched && !active ? styles.menuGroupActive : ''
|
|
108
|
+
} ${
|
|
109
|
+
// eslint-disable-next-line no-nested-ternary
|
|
110
|
+
active
|
|
111
|
+
? styles.menuItemActive
|
|
112
|
+
: collapsible || item.link
|
|
113
|
+
? styles.menuItem
|
|
114
|
+
: styles.menuItemStatic
|
|
115
|
+
}`}
|
|
116
|
+
onMouseEnter={() => item.link && props.preloadLink(item.link)}
|
|
117
|
+
onClick={e => {
|
|
118
|
+
if (item.link) {
|
|
119
|
+
navigate(withBase(normalizeHref(item.link)));
|
|
120
|
+
collapsed && toggleCollapse(e);
|
|
121
|
+
} else {
|
|
122
|
+
collapsible && toggleCollapse(e);
|
|
123
|
+
}
|
|
124
|
+
}}
|
|
125
|
+
style={{
|
|
126
|
+
borderRadius: depth === 0 ? '0 1rem 1rem 0' : undefined,
|
|
127
|
+
cursor: collapsible || item.link ? 'pointer' : 'normal',
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
<h2
|
|
131
|
+
className="py-2.5 px-3 text-sm font-medium flex"
|
|
132
|
+
style={{
|
|
133
|
+
...(depth === 0 ? highlightTitleStyle : {}),
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<Tag tag={item.tag} />
|
|
137
|
+
{item.text}
|
|
138
|
+
</h2>
|
|
139
|
+
{collapsible && (
|
|
140
|
+
<div
|
|
141
|
+
className={`${styles.collapseContainer} p-2 rounded-xl`}
|
|
142
|
+
onClick={toggleCollapse}
|
|
143
|
+
>
|
|
144
|
+
{collapsibleIcon}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
148
|
+
<div
|
|
149
|
+
ref={containerRef}
|
|
150
|
+
className="transition-all duration-300 ease-in-out"
|
|
151
|
+
style={{
|
|
152
|
+
overflow: 'hidden',
|
|
153
|
+
maxHeight: initialState.current ? 0 : undefined,
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<div
|
|
157
|
+
ref={innerRef}
|
|
158
|
+
className="rspress-sidebar-group transition-opacity duration-500 ease-in-out"
|
|
159
|
+
style={{
|
|
160
|
+
opacity: initialState.current ? 0 : 1,
|
|
161
|
+
marginLeft: depth === 0 ? '12px' : 0,
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
{(item as NormalizedSidebarGroup)?.items?.map((item, index) => (
|
|
165
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
166
|
+
<div key={index}>
|
|
167
|
+
<SidebarItem
|
|
168
|
+
{...props}
|
|
169
|
+
item={item}
|
|
170
|
+
depth={depth + 1}
|
|
171
|
+
id={`${id}-${index}`}
|
|
172
|
+
preloadLink={props.preloadLink}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
))}
|
|
176
|
+
</div>
|
|
177
|
+
</div>
|
|
178
|
+
</section>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { Link } from '../Link';
|
|
3
|
+
import { Tag } from '../Tag';
|
|
4
|
+
import styles from './index.module.scss';
|
|
5
|
+
import { SidebarGroup } from './SidebarGroup';
|
|
6
|
+
import { SidebarItemProps, highlightTitleStyle } from '.';
|
|
7
|
+
import { normalizeHref } from '@/runtime';
|
|
8
|
+
|
|
9
|
+
export function SidebarItem(props: SidebarItemProps) {
|
|
10
|
+
const { item, depth = 0, activeMatcher, id, setSidebarData } = props;
|
|
11
|
+
const active = item.link && activeMatcher(item.link);
|
|
12
|
+
|
|
13
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (active) {
|
|
16
|
+
ref.current?.scrollIntoView({
|
|
17
|
+
block: 'center',
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
const { text } = item;
|
|
23
|
+
|
|
24
|
+
if ('items' in item) {
|
|
25
|
+
return (
|
|
26
|
+
<SidebarGroup
|
|
27
|
+
id={id}
|
|
28
|
+
key={`${item.text}-${id}`}
|
|
29
|
+
item={item}
|
|
30
|
+
depth={depth}
|
|
31
|
+
activeMatcher={activeMatcher}
|
|
32
|
+
collapsed={item.collapsed}
|
|
33
|
+
setSidebarData={setSidebarData}
|
|
34
|
+
preloadLink={props.preloadLink}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
} else {
|
|
38
|
+
return (
|
|
39
|
+
<Link href={normalizeHref(item.link)} className={styles.menuLink}>
|
|
40
|
+
<div
|
|
41
|
+
ref={ref}
|
|
42
|
+
onMouseEnter={() => props.preloadLink(item.link)}
|
|
43
|
+
className={`${
|
|
44
|
+
active ? styles.menuItemActive : styles.menuItem
|
|
45
|
+
} mt-0.5 py-2 px-3 font-medium flex`}
|
|
46
|
+
style={{
|
|
47
|
+
// The first level menu item will have the same font size as the sidebar group
|
|
48
|
+
fontSize: depth === 0 ? '14px' : '13px',
|
|
49
|
+
marginLeft: depth === 0 ? 0 : '18px',
|
|
50
|
+
borderRadius: '0 1rem 1rem 0',
|
|
51
|
+
...(depth === 0 ? highlightTitleStyle : {}),
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<Tag tag={item.tag} />
|
|
55
|
+
{text}
|
|
56
|
+
</div>
|
|
57
|
+
</Link>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
bottom: 0;
|
|
5
5
|
left: 0;
|
|
6
6
|
z-index: var(--rp-z-index-sidebar);
|
|
7
|
-
padding: 12px 12px 96px
|
|
7
|
+
padding: 12px 12px 96px 0;
|
|
8
8
|
width: calc(100vw - 64px);
|
|
9
9
|
max-width: 320px;
|
|
10
10
|
background-color: var(--rp-c-bg);
|
|
@@ -46,9 +46,8 @@
|
|
|
46
46
|
|
|
47
47
|
@media (min-width: 1440px) {
|
|
48
48
|
.sidebar {
|
|
49
|
-
padding-left:
|
|
49
|
+
padding-left: 0;
|
|
50
50
|
width: var(--rp-sidebar-width);
|
|
51
|
-
margin-left: calc((100vw - 1440px) / 2);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -82,18 +81,36 @@
|
|
|
82
81
|
.menuItemActive {
|
|
83
82
|
font-size: 13px;
|
|
84
83
|
line-height: 19px;
|
|
84
|
+
border-radius: 0 1rem 1rem 0;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
.menuItem,
|
|
88
88
|
.menuItemStatic {
|
|
89
89
|
color: var(--rp-c-text-2);
|
|
90
|
-
transition:
|
|
90
|
+
transition: color 0.2s;
|
|
91
|
+
font-weight: 500;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
.menuItemActive {
|
|
94
95
|
background-color: var(--rp-c-brand-tint);
|
|
95
96
|
color: var(--rp-c-brand);
|
|
96
97
|
font-weight: bolder;
|
|
98
|
+
position: relative;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.menuItemActive::before {
|
|
102
|
+
content: '';
|
|
103
|
+
position: absolute;
|
|
104
|
+
top: 0;
|
|
105
|
+
left: 0;
|
|
106
|
+
width: 1px;
|
|
107
|
+
height: 100%;
|
|
108
|
+
background-color: var(--rp-c-brand);
|
|
109
|
+
transition: all 0.2s ease;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.menuGroupActive {
|
|
113
|
+
background-color: var(--rp-c-bg-mute);
|
|
97
114
|
}
|
|
98
115
|
|
|
99
116
|
:global(.rspress-sidebar-group) {
|
|
@@ -102,7 +119,7 @@
|
|
|
102
119
|
content: '';
|
|
103
120
|
position: absolute;
|
|
104
121
|
top: 0;
|
|
105
|
-
left:
|
|
122
|
+
left: 18px;
|
|
106
123
|
width: 1px;
|
|
107
124
|
height: 100%;
|
|
108
125
|
background-color: var(--rp-c-gray-light-4);
|