Skip to content

Commit 653698e

Browse files
committed
perf: scrollbar
1 parent 598e59f commit 653698e

File tree

11 files changed

+191
-112
lines changed

11 files changed

+191
-112
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
"@typescript-eslint/parser": "^8.48.0",
180180
"@vitejs/plugin-react": "^5.1.1",
181181
"antd-dayjs-webpack-plugin": "^1.0.6",
182+
"archiver": "^5.3.1",
182183
"babel-jest": "^30.2.0",
183184
"babel-loader": "^10.0.0",
184185
"babel-plugin-react-compiler": "latest",
@@ -212,6 +213,7 @@
212213
"eslint-plugin-storybook": "^10.1.7",
213214
"eslint-plugin-unicorn": "^62.0.0",
214215
"eslint-webpack-plugin": "^5.0.2",
216+
"filemanager-webpack-plugin": "^6.0.0",
215217
"fork-ts-checker-webpack-plugin": "^9.1.0",
216218
"gh-pages": "^6.3.0",
217219
"glob": "^13.0.0",
@@ -282,9 +284,7 @@
282284
"webpack-cli": "^6.0.1",
283285
"webpack-dev-server": "^5.2.2",
284286
"webpack-merge": "^6.0.1",
285-
"webpackbar": "^7.0.0",
286-
"filemanager-webpack-plugin": "^6.0.0",
287-
"archiver": "^5.3.1"
287+
"webpackbar": "^7.0.0"
288288
},
289289
"dependencies": {
290290
"@ant-design/cssinjs": "^2.0.1",
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
import React, { useRef, useState, useEffect } from 'react'
1+
/* eslint-disable react/prop-types */
2+
import React, { useRef } from 'react'
23
import { FloatButton } from 'antd'
34
import { VerticalAlignTopOutlined } from '@ant-design/icons'
45
import ScrollProgressBar from '@stateless/ScrollProgressBar'
56

67
const FixTabPanel = React.forwardRef(
78
({ style, children, className, showScrollProgress = true, scrollProgressProps = {}, fill = true, ...rest }, ref) => {
8-
const innerRef = useRef(null)
9-
const [scrollContainer, setScrollContainer] = useState(null)
9+
const wrapperRef = useRef(null)
1010

1111
const setRef = (node) => {
12-
innerRef.current = node
12+
wrapperRef.current = node
1313
if (typeof ref === 'function') {
1414
ref(node)
1515
} else if (ref) {
1616
ref.current = node
1717
}
1818
}
1919

20-
useEffect(() => {
21-
if (innerRef.current) {
22-
setScrollContainer(innerRef.current)
23-
}
24-
}, [])
25-
2620
return (
2721
<div
2822
ref={setRef}
@@ -32,35 +26,42 @@ const FixTabPanel = React.forwardRef(
3226
width: '100%',
3327
height: '100%',
3428
position: 'relative',
35-
overflowX: 'hidden',
3629
overflowY: 'auto',
37-
padding: '5px',
30+
overflowX: 'hidden',
3831
...style,
3932
}}
4033
>
4134
{showScrollProgress && (
4235
<ScrollProgressBar
43-
container={scrollContainer}
36+
container={wrapperRef.current}
4437
position="fixed" // sticky
4538
{...scrollProgressProps}
4639
/>
4740
)}
41+
4842
<div
4943
style={{
5044
position: 'relative',
5145
zIndex: 1,
5246
width: '100%',
47+
maxWidth: '100%',
48+
minWidth: 0,
5349
height: fill ? '100%' : 'auto',
50+
padding: '5px',
51+
boxSizing: 'border-box',
5452
}}
5553
>
5654
{children}
5755
</div>
58-
<FloatButton.BackTop target={() => innerRef.current} style={{ right: 6, bottom: 2 }}>
56+
57+
<FloatButton.BackTop target={() => wrapperRef.current} style={{ right: 6, bottom: 2 }}>
5958
<VerticalAlignTopOutlined style={{ fontSize: 20 }} />
6059
</FloatButton.BackTop>
6160
</div>
6261
)
6362
}
6463
)
6564

65+
FixTabPanel.displayName = 'FixTabPanel'
66+
6667
export default FixTabPanel

src/components/stateless/LineBordered/index.module.less

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@
161161

162162
.no-scrollbars {
163163
overflow: auto;
164-
scrollbar-width: none;
165-
}
166-
167-
.no-scrollbars::-webkit-scrollbar {
168-
display: none;
169164
}
170165

171166
.engraved-text {

src/components/stateless/MusicPlayer/index.jsx

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ const MusicPlayer = () => {
103103
if (isReady.current) {
104104
if (isPlaying) {
105105
const playPromise = audio.play()
106-
if (playPromise !== undefined) {
107-
playPromise.catch((error) => {
108-
// 捕获 "The play() request was interrupted" 错误,静默处理
109-
console.log('Playback prevented/interrupted (harmless):', error)
110-
})
111-
}
106+
Promise.resolve(playPromise).catch((error) => {
107+
// 捕获 "The play() request was interrupted" 错误,静默处理
108+
console.log('Playback prevented/interrupted (harmless):', error)
109+
})
112110
}
113111
} else {
114112
// 第一次加载组件时不自动播放
@@ -121,9 +119,7 @@ const MusicPlayer = () => {
121119
const audio = audioRef.current
122120
if (isPlaying) {
123121
const playPromise = audio.play()
124-
if (playPromise !== undefined) {
125-
playPromise.catch((e) => console.log('Play interaction error:', e))
126-
}
122+
Promise.resolve(playPromise).catch((e) => console.log('Play interaction error:', e))
127123
} else {
128124
audio.pause()
129125
}
@@ -250,10 +246,12 @@ const MusicPlayer = () => {
250246
{TRACKS.map((track, index) => {
251247
const isCurrent = index === currentTrackIndex
252248
return (
253-
<div
249+
<button
254250
key={track.id}
255251
onClick={() => playTrack(index)}
256-
className={`group mb-1 flex cursor-pointer items-center rounded-xl p-3 transition-all duration-200 ${isCurrent ? 'bg-gray-800/80' : 'text-gray-400 hover:bg-gray-800/40'} `}
252+
type="button"
253+
aria-label={`Play ${track.title} by ${track.artist}`}
254+
className={`group mb-1 flex w-full items-center rounded-xl p-3 text-left transition-all duration-200 ${isCurrent ? 'bg-gray-800/80' : 'text-gray-400 hover:bg-gray-800/40'} `}
257255
>
258256
{/* 序号 / 动态图标 */}
259257
<div className="mr-2 flex w-10 items-center justify-center">
@@ -284,19 +282,11 @@ const MusicPlayer = () => {
284282
{isCurrent && (
285283
<span className="px-2 text-xs font-medium text-green-500/80">{isPlaying ? 'Playing' : 'Paused'}</span>
286284
)}
287-
</div>
285+
</button>
288286
)
289287
})}
290288
</div>
291289
</div>
292-
293-
{/* 全局样式 (用于滚动条和旋转) */}
294-
<style>{`
295-
.custom-scrollbar::-webkit-scrollbar { width: 4px; }
296-
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
297-
.custom-scrollbar::-webkit-scrollbar-thumb { background: #374151; border-radius: 2px; }
298-
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #4b5563; }
299-
`}</style>
300290
</div>
301291
)
302292
}

src/components/stateless/OrgChart/org-chart/index.module.less

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -178,42 +178,6 @@
178178
overflow: auto visible;
179179
padding-bottom: 10px;
180180
position: relative;
181-
182-
/* 自定义滚动条样式 */
183-
&::-webkit-scrollbar {
184-
height: 8px;
185-
width: 8px;
186-
}
187-
188-
&::-webkit-scrollbar-track {
189-
background: #f1f1f1;
190-
border-radius: 4px;
191-
margin: 0 10px;
192-
}
193-
194-
&::-webkit-scrollbar-thumb {
195-
background: linear-gradient(180deg, #2878ff 0%, #1a68e6 100%);
196-
border-radius: 4px;
197-
border: 1px solid #e0e0e0;
198-
box-shadow: inset 0 0 6px rgb(0 0 0 / 10%);
199-
200-
&:hover {
201-
background: linear-gradient(180deg, #1a68e6 0%, #1558d6 100%);
202-
box-shadow: inset 0 0 8px rgb(0 0 0 / 20%);
203-
}
204-
205-
&:active {
206-
background: linear-gradient(180deg, #1558d6 0%, #1048c6 100%);
207-
}
208-
}
209-
210-
&::-webkit-scrollbar-corner {
211-
background: #f1f1f1;
212-
}
213-
214-
/* Firefox 滚动条样式 */
215-
scrollbar-width: thin;
216-
scrollbar-color: #2878ff #f1f1f1;
217181
}
218182

219183
.childrenWrapper {
@@ -307,10 +271,4 @@
307271
height: 14px;
308272
font-size: 8px;
309273
}
310-
311-
.childrenScroll {
312-
&::-webkit-scrollbar {
313-
height: 6px;
314-
}
315-
}
316274
}

src/components/stateless/PageContainer/index.jsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import PropTypes from 'prop-types'
23
import { theme } from 'antd'
34
import Footer from '@stateless/Footer'
45

@@ -37,32 +38,24 @@ const PageContainer = ({ children, title, footer = <Footer />, className, style
3738
style={{
3839
flex: 1,
3940
overflow: 'auto',
40-
padding: '24px',
4141
position: 'relative',
42+
padding: '24px',
4243
}}
4344
>
4445
{children}
4546
</div>
46-
<style>{`
47-
.page-container-content::-webkit-scrollbar {
48-
width: 6px;
49-
height: 6px;
50-
}
51-
.page-container-content::-webkit-scrollbar-track {
52-
background: transparent;
53-
}
54-
.page-container-content::-webkit-scrollbar-thumb {
55-
background-color: ${token.colorFillSecondary};
56-
border-radius: 3px;
57-
}
58-
.page-container-content::-webkit-scrollbar-thumb:hover {
59-
background-color: ${token.colorFill};
60-
}
61-
`}</style>
6247
</section>
6348
{footer}
6449
</>
6550
)
6651
}
6752

53+
PageContainer.propTypes = {
54+
children: PropTypes.node.isRequired,
55+
title: PropTypes.node,
56+
footer: PropTypes.node,
57+
className: PropTypes.string,
58+
style: PropTypes.object,
59+
}
60+
6861
export default PageContainer

src/pages/mermaid/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
GitBranch,
1717
Activity,
1818
Clock,
19-
Move,
2019
FileCode,
2120
} from 'lucide-react'
2221
import { Button, Tooltip, message, Space, Card, Segmented, theme } from 'antd'

src/pages/portfilo/index.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react'
1+
import React, { useRef, useState, useEffect } from 'react'
22
import PropTypes from 'prop-types'
33
import { useNavigate } from 'react-router-dom'
44
import {
@@ -79,7 +79,8 @@ const MyPortfilo = () => {
7979
const { token, theme: antdTheme } = useToken()
8080
const screens = useBreakpoint()
8181
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
82-
const { scrollYProgress } = useScroll()
82+
const containerRef = useRef(null)
83+
const { scrollYProgress } = useScroll({ container: containerRef })
8384
const scaleX = useSpring(scrollYProgress, {
8485
stiffness: 100,
8586
damping: 30,
@@ -170,12 +171,14 @@ const MyPortfilo = () => {
170171
return (
171172
<div
172173
id="portfolio-container"
174+
ref={containerRef}
173175
style={{
174176
backgroundColor: token.colorBgContainer,
175177
color: token.colorText,
176178
position: 'relative',
177179
height: '100vh',
178180
overflowY: 'auto',
181+
overflowX: 'hidden',
179182
scrollBehavior: 'smooth',
180183
backgroundImage:
181184
antdTheme.id === 1 // Dark mode check approximation or use token
@@ -351,7 +354,7 @@ const MyPortfilo = () => {
351354
>
352355
<Anchor
353356
targetOffset={targetOffset}
354-
getContainer={() => document.getElementById('portfolio-container')}
357+
getContainer={() => containerRef.current || document.getElementById('portfolio-container')}
355358
direction="vertical"
356359
onClick={handleAnchorClick}
357360
items={navItems}

0 commit comments

Comments
 (0)