-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function MaterialSymbolsProgressActivity(props: { progress: number }) { | ||
const offset = 87.92 * ((100 - props.progress) / 100); | ||
|
||
return ( | ||
<svg style={{ transform: 'rotate(-90deg)' }} width="1em" height="1em" viewBox="0 0 36 36"> | ||
{/* 第一圈 */} | ||
<circle r="14" cx="18" cy="18" fill="transparent" stroke="#e0e0e0" strokeWidth="4"></circle> | ||
{/* 第二圈,进度条 */} | ||
<circle | ||
r="14" | ||
cx="18" | ||
cy="18" | ||
fill="transparent" | ||
stroke="var(--accent-color)" | ||
strokeWidth="4" | ||
strokeDasharray="87.92" | ||
strokeDashoffset={`${offset}`} | ||
></circle> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
|
||
import { MaterialSymbolsProgressActivity } from '@/components/icons/Progress'; | ||
import { MotionButtonBase } from '@/components/ui/button'; | ||
import { cn } from '@/lib/helper'; | ||
import { springScrollToTop } from '@/lib/scroller'; | ||
import { useMainArticleStore } from '@/store/mainArticleStore'; | ||
|
||
export const ReadIndicator = () => { | ||
const { Element } = useMainArticleStore(); | ||
const [readPercent, setReadPercent] = useState(0); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
if (!Element) return; | ||
|
||
const elementTop = Element.getBoundingClientRect().top + window.scrollY; | ||
const scrollTop = window.scrollY; | ||
const winHeight = window.innerHeight; | ||
const elementHeight = Element.offsetHeight; | ||
// 为了解决一开始进度不为0的问题 | ||
const readHeight = scrollTop > winHeight ? scrollTop + winHeight - elementTop : scrollTop; | ||
const scrollPosition = (readHeight / elementHeight) * 100; | ||
setReadPercent(Math.floor(Math.min(Math.max(0, scrollPosition), 100))); | ||
}; | ||
|
||
window.addEventListener('scroll', handleScroll); | ||
handleScroll(); | ||
|
||
return () => { | ||
window.removeEventListener('scroll', handleScroll); | ||
}; | ||
}, [Element]); | ||
|
||
return ( | ||
<div className="text-gray-800 dark:text-neutral-300"> | ||
<div className="flex items-center gap-2"> | ||
<MaterialSymbolsProgressActivity progress={readPercent} /> | ||
{readPercent}%<br /> | ||
</div> | ||
<MotionButtonBase | ||
onClick={springScrollToTop} | ||
className={cn( | ||
'mt-1 flex flex-nowrap items-center gap-2 opacity-50 transition-all duration-500 hover:opacity-100', | ||
readPercent > 10 ? '' : 'pointer-events-none opacity-0', | ||
)} | ||
> | ||
<i className="i-mingcute-arrow-up-circle-line" /> | ||
<span className="whitespace-nowrap">回到顶部</span> | ||
</MotionButtonBase> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,7 @@ export const DividerVertical: FC< | |
className, | ||
)} | ||
{...rest} | ||
> | ||
w | ||
</span> | ||
></span> | ||
); | ||
}; | ||
|
||
|