-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <tukon479@gmail.com>
- Loading branch information
Showing
4 changed files
with
83 additions
and
11 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
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,28 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
'use client' | ||
|
||
import type { ElementType } from 'react' | ||
|
||
import { | ||
useArticleElementPositsion, | ||
useArticleElementSize, | ||
} from '~/providers/article/article-element-provider' | ||
import { usePageScrollLocationSelector } from '~/providers/root/page-scroll-info-provider' | ||
import { clsxm } from '~/utils/helper' | ||
|
||
export const ReadIndicator: Component<{ | ||
as?: ElementType | ||
}> = ({ className, as }) => { | ||
const { y } = useArticleElementPositsion() | ||
const { h } = useArticleElementSize() | ||
const readPercent = usePageScrollLocationSelector((scrollTop) => { | ||
return Math.floor(Math.min(Math.max(0, ((scrollTop - y) / h) * 100), 100)) | ||
}) | ||
const As = as || 'span' | ||
return ( | ||
<As className={clsxm('text-gray-800 dark:text-neutral-300', className)}> | ||
{readPercent}% | ||
</As> | ||
) | ||
} |
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
30d5395
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
springtide – ./
springtide.vercel.app
springtide-git-main-innei.vercel.app
springtide-innei.vercel.app