Skip to content

Commit 28c0502

Browse files
committed
chore: SidebarMenu animation
1 parent 1e6558e commit 28c0502

File tree

10 files changed

+57
-21
lines changed

10 files changed

+57
-21
lines changed

packages/theme-default/src/components/Aside/ProgressCircle.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/theme-default/src/components/Aside/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { useLocaleSiteData, useLocation, useSite } from '@rspress/runtime';
2-
import { useEffect } from 'react';
3-
4-
import './index.scss';
52
import { Toc } from '@theme';
3+
import { useEffect } from 'react';
64
import { scrollToTarget } from '../../logic/sideEffects';
75
import { useDynamicToc } from '../Toc/useDynamicToc';
8-
import { ProgressCircle } from './ProgressCircle';
6+
import './index.scss';
7+
import { ReadPercent } from '../ReadPercent';
98
import { ScrollToTop } from './ScrollToTop';
10-
import { useReadPercent } from './useReadPercent';
119

1210
export function Aside() {
1311
const localesData = useLocaleSiteData();
@@ -18,7 +16,6 @@ export function Aside() {
1816
localesData?.outlineTitle || themeConfig?.outlineTitle || 'ON THIS PAGE';
1917

2018
const headers = useDynamicToc();
21-
const [readPercent] = useReadPercent();
2219

2320
const { pathname } = useLocation();
2421

@@ -44,7 +41,7 @@ export function Aside() {
4441
<div className="rp-aside">
4542
<div className="rp-aside__title">
4643
{outlineTitle}
47-
<ProgressCircle percent={readPercent} size={14} strokeWidth={2} />
44+
<ReadPercent size={14} strokeWidth={2} />
4845
</div>
4946
<nav className="rp-aside__toc">
5047
<Toc />

packages/theme-default/src/components/NewNav/NavMenu.scss

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
display: inline-flex;
33
align-items: center;
44
height: 100%;
5-
gap: 32px;
6-
75
list-style: none;
86

7+
@media (min-width: 1280px) {
8+
gap: 32px;
9+
}
10+
11+
@media (max-width: 1279px) {
12+
gap: 24px;
13+
}
14+
915
&__others {
1016
display: flex;
1117
align-items: center;

packages/theme-default/src/components/NewNav/index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@
6767
gap: 24px;
6868
display: flex;
6969
align-items: center;
70+
71+
@media (max-width: 767px) {
72+
gap: 4px;
73+
}
7074
}
7175
}

packages/theme-default/src/components/Aside/ProgressCircle.tsx renamed to packages/theme-default/src/components/ReadPercent/ProgressCircle.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import clsx from 'clsx';
22
import type React from 'react';
3-
import './ProgressCircle.scss';
3+
import './index.scss';
44

55
interface CircleProgressProps {
66
percent: number;
@@ -28,7 +28,7 @@ export const ProgressCircle: React.FC<CircleProgressProps> = ({
2828
<svg
2929
width={size}
3030
height={size}
31-
className={clsx('rp-aside__progress-circle', className)}
31+
className={clsx('rp-progress-circle', className)}
3232
>
3333
<circle
3434
cx={size / 2}
@@ -49,7 +49,6 @@ export const ProgressCircle: React.FC<CircleProgressProps> = ({
4949
strokeWidth={strokeWidth}
5050
strokeDasharray={circumference}
5151
strokeDashoffset={offset}
52-
// className="duration-75"
5352
transform={`rotate(-90 ${size / 2} ${size / 2})`}
5453
style={{ transition: 'stroke-dashoffset 0.3s' }}
5554
/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.rp-progress-circle {
2+
display: inline-flex;
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ProgressCircle } from './ProgressCircle';
2+
import { useReadPercent } from './useReadPercent';
3+
4+
export function ReadPercent({
5+
size,
6+
strokeWidth,
7+
}: {
8+
size: number;
9+
strokeWidth: number;
10+
}) {
11+
const [readPercent] = useReadPercent();
12+
return (
13+
<ProgressCircle
14+
percent={readPercent}
15+
size={size}
16+
strokeWidth={strokeWidth}
17+
/>
18+
);
19+
}
File renamed without changes.

packages/theme-default/src/components/SidebarMenu/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useLocaleSiteData, useLocation, useSite } from '@rspress/runtime';
2-
import ArrowRight from '@theme-assets/arrow-right';
32
import MenuIcon from '@theme-assets/menu';
43
import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock';
54
import { forwardRef, useEffect, useRef } from 'react';
65
import { useUISwitch } from '../../layout/Layout/useUISwitch';
76
import { SvgWrapper } from '../SvgWrapper';
87
import { useDynamicToc } from '../Toc/useDynamicToc';
98
import './index.scss';
9+
import { ReadPercent } from '../ReadPercent';
1010

1111
/* Top Menu, only displayed on <1280px screen width */
1212
export const SidebarMenu = forwardRef(
@@ -66,7 +66,7 @@ export const SidebarMenu = forwardRef(
6666
sidebarMenuRef.current &&
6767
(isAsideOpen || isSidebarOpen) &&
6868
disableBodyScroll(sidebarMenuRef.current, {
69-
reserveScrollBarGap: false,
69+
reserveScrollBarGap: true,
7070
});
7171
return () => {
7272
clearAllBodyScrollLocks();
@@ -77,7 +77,7 @@ export const SidebarMenu = forwardRef(
7777
sidebarMenuRef.current &&
7878
isAsideOpen &&
7979
disableBodyScroll(sidebarMenuRef.current, {
80-
reserveScrollBarGap: false,
80+
reserveScrollBarGap: true,
8181
});
8282
return () => {
8383
clearAllBodyScrollLocks();
@@ -121,13 +121,15 @@ export const SidebarMenu = forwardRef(
121121
className="rp-sidebar-menu__right"
122122
>
123123
<span>{outlineTitle}</span>
124-
<SvgWrapper
124+
<ReadPercent size={14} strokeWidth={2} />
125+
{/* TODO: discussion */}
126+
{/* <SvgWrapper
125127
icon={ArrowRight}
126128
style={{
127129
transform: isAsideOpen ? 'rotate(90deg)' : 'rotate(0deg)',
128130
transition: 'transform 0.2s ease-out',
129131
}}
130-
/>
132+
/> */}
131133
</button>
132134
)}
133135
</div>

packages/theme-default/src/layout/DocLayout/index.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
}
152152
.rp-doc-layout {
153153
&__aside {
154-
display: none;
155154
position: fixed;
156155
margin-top: var(--rp-sidebar-menu-height);
157156
background-color: color-mix(in srgb, var(--rp-c-bg) 60%, transparent);
@@ -162,8 +161,18 @@
162161
border-radius: var(--rp-radius-small);
163162
border: 1px solid var(--rp-c-divider-light);
164163

164+
visibility: hidden;
165+
opacity: 0;
166+
transform: translate3d(0, -10px, 0);
167+
transition:
168+
opacity 0.2s,
169+
transform 0.2s cubic-bezier(0.19, 1, 0.22, 1);
170+
165171
&--open {
166172
display: block;
173+
opacity: 1;
174+
visibility: visible;
175+
transform: translate3d(0, 0, 0);
167176
}
168177
}
169178
}

0 commit comments

Comments
 (0)