-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: show back to top button at bottom #4464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
YashSikarwar28
wants to merge
5
commits into
asyncapi:master
from
YashSikarwar28:Fix/Back-To-Top-Button
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
596d044
BUG - Fix Show back to top button at bottom
YashSikarwar28 b3a7576
fix: resolve lint errors in ScrollButton component
YashSikarwar28 64824f9
fix: normalize line endings to LF
YashSikarwar28 fcdd39c
fix: convert line endings from CRLF to LF for lint compliance
YashSikarwar28 083b7f4
Merge branch 'master' into Fix/Back-To-Top-Button
YashSikarwar28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,42 +1,65 @@ | ||
| /// <reference types="node" /> | ||
|
|
||
| import React, { useEffect, useState } from 'react'; | ||
|
|
||
| /** | ||
| * @returns {React.JSX.Element} The ScrollButton component | ||
| * @description The ScrollButton component is a button that scrolls the user to the top of the page. | ||
| * ScrollButton component shows a "Back to Top" button at the bottom of the page. | ||
| * The button is visible only when the user scrolls to the bottom of the page. | ||
| */ | ||
| function ScrollButton() { | ||
| const [backToTopButton, setBackToTopButton] = useState(false); | ||
| const scrollImage = '/img/loaders/scroll.svg'; | ||
| const ScrollButton: React.FC = () => { | ||
| const [isBottom, setIsBottom] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| window.addEventListener('scroll', () => { | ||
| if (window.scrollY > 150) { | ||
| setBackToTopButton(true); | ||
| } else { | ||
| setBackToTopButton(false); | ||
| const handleScroll = () => { | ||
| const scrollPosition = window.innerHeight + window.pageYOffset; | ||
| const pageHeight = document.documentElement.scrollHeight; | ||
|
|
||
| setIsBottom(scrollPosition >= pageHeight); | ||
| }; | ||
|
|
||
| // Initialize the button visibility on mount | ||
| handleScroll(); | ||
|
|
||
YashSikarwar28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let throttleTimeout: NodeJS.Timeout | null = null; | ||
|
|
||
| const throttledHandleScroll = () => { | ||
| if (throttleTimeout === null) { | ||
| throttleTimeout = setTimeout(() => { | ||
| handleScroll(); | ||
| throttleTimeout = null; | ||
| }, 100); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| window.addEventListener('scroll', throttledHandleScroll); | ||
|
|
||
| return () => { | ||
| window.removeEventListener('scroll', throttledHandleScroll); | ||
|
|
||
| if (throttleTimeout) { | ||
| clearTimeout(throttleTimeout); | ||
| } | ||
| }; | ||
| }, []); | ||
|
|
||
| const scrollUp = () => { | ||
| window.scrollTo({ | ||
| top: 0, | ||
| behavior: 'smooth' | ||
| }); | ||
| const scrollToTop = () => { | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
| }; | ||
|
|
||
| if (!isBottom) return null; | ||
|
|
||
| return ( | ||
| <div className='fixed bottom-14 right-4 z-40 h-16 w-12'> | ||
| {backToTopButton && ( | ||
| <button | ||
| className='rounded-full bg-white shadow-md transition-all duration-300 ease-in-out hover:scale-110 hover:bg-[#8851FB]' | ||
| onClick={scrollUp} | ||
| > | ||
| <img src={scrollImage} alt='scroll to top' /> | ||
| </button> | ||
| )} | ||
| </div> | ||
| <button | ||
| onClick={scrollToTop} | ||
| className='fixed bottom-6 right-6 z-50 h-12 w-12 rounded-full bg-purple-600 | ||
| text-white shadow-md hover:bg-purple-700 transition duration-300 | ||
| flex items-center justify-center text-lg' | ||
| aria-label='Scroll to top' | ||
YashSikarwar28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type='button' | ||
| > | ||
| ↑ | ||
| </button> | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| export default ScrollButton; | ||
40 changes: 20 additions & 20 deletions
40
markdown/docs/community/060-meetings-and-communication/docs-community.md
This file contains hidden or 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 |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| --- | ||
| title: 'AsyncAPI docs community' | ||
| weight: 20 | ||
| --- | ||
| [Schedule your own docs meetings](MEETINGS_ORGANIZATION). | ||
| ## AsyncAPI Slack workspace and docs channels | ||
| Join the [AsyncAPI documentation Slack channel](https://join.slack.com/share/enQtNjUxNTY1NTU1MDk0NS1mYjNhODFhZDI3ZDRjODA1ZWRkZTZlYmM4ZTNjNzZjNTg5NTBiYjNmNTkwYzRlYzY4ZjQ4M2RhMDYzMjI3N2U5) to meet other technical writers: | ||
| - **#13_docs:** A space for all technical writers to start discussions, ask questions, share new ideas, and request `good first issues.` | ||
| ## AsyncAPI documentation roadmap 2024 | ||
| Stay tuned for new opportunities on our [Docs’ Community discussions](https://github.com/orgs/asyncapi/discussions/categories/docs-education) or reach out in the AsyncAPI Slack channel **#13_docs**. | ||
| | Docs Roadmap | Ongoing Docs Projects | Timeline | Contribution Type | | ||
| |--------------|-----------------------|----------|---------------------| | ||
| | AsyncAPI Style Guide | [AsyncAPI Style Guide](https://github.com/asyncapi/website/issues/1240) | Ongoing | Regular contribution | | ||
| | AsyncAPI Tools’ Docs | <li>[Modelina Docs](https://github.com/asyncapi/modelina/tree/master/docs) </li> <li>[Parser Docs](https://github.com/asyncapi/parser-js/tree/master/docs) </li> <li>[GitHub Actions Docs](https://github.com/asyncapi/github-action-for-generator)</li> <li>[Studio Docs](https://github.com/asyncapi/studio/tree/master/doc/adr)</li> <li>[Generator Docs](https://github.com/asyncapi/generator/tree/master/docs)</li> <li>[CLI Docs](https://github.com/asyncapi/cli/tree/master/docs)</li> | Ongoing | Regular contribution | | ||
| | Technical Writer Onboarding Guide | Onboarding Guide for new docs contributors | Ongoing | Regular contribution | | ||
| --- | ||
| title: 'AsyncAPI docs community' | ||
| weight: 20 | ||
| --- | ||
|
|
||
| [Schedule your own docs meetings](MEETINGS_ORGANIZATION). | ||
|
|
||
| ## AsyncAPI Slack workspace and docs channels | ||
| Join the [AsyncAPI documentation Slack channel](https://join.slack.com/share/enQtNjUxNTY1NTU1MDk0NS1mYjNhODFhZDI3ZDRjODA1ZWRkZTZlYmM4ZTNjNzZjNTg5NTBiYjNmNTkwYzRlYzY4ZjQ4M2RhMDYzMjI3N2U5) to meet other technical writers: | ||
|
|
||
| - **#13_docs:** A space for all technical writers to start discussions, ask questions, share new ideas, and request `good first issues.` | ||
|
|
||
| ## AsyncAPI documentation roadmap 2024 | ||
| Stay tuned for new opportunities on our [Docs’ Community discussions](https://github.com/orgs/asyncapi/discussions/categories/docs-education) or reach out in the AsyncAPI Slack channel **#13_docs**. | ||
|
|
||
| | Docs Roadmap | Ongoing Docs Projects | Timeline | Contribution Type | | ||
| |--------------|-----------------------|----------|---------------------| | ||
| | AsyncAPI Style Guide | [AsyncAPI Style Guide](https://github.com/asyncapi/website/issues/1240) | Ongoing | Regular contribution | | ||
| | AsyncAPI Tools’ Docs | <li>[Modelina Docs](https://github.com/asyncapi/modelina/tree/master/docs) </li> <li>[Parser Docs](https://github.com/asyncapi/parser-js/tree/master/docs) </li> <li>[GitHub Actions Docs](https://github.com/asyncapi/github-action-for-generator)</li> <li>[Studio Docs](https://github.com/asyncapi/studio/tree/master/doc/adr)</li> <li>[Generator Docs](https://github.com/asyncapi/generator/tree/master/docs)</li> <li>[CLI Docs](https://github.com/asyncapi/cli/tree/master/docs)</li> | Ongoing | Regular contribution | | ||
| | Technical Writer Onboarding Guide | Onboarding Guide for new docs contributors | Ongoing | Regular contribution | |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.