-
Notifications
You must be signed in to change notification settings - Fork 34
Feat: To add topbar Arrow that auto scroll-up on home page . #56
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
base: main
Are you sure you want to change the base?
Changes from all commits
6dca16a
d00feba
f10fb64
ac9d540
c7839dd
7d94d24
a67442d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ function App() { | |
| <Footer /> | ||
| </div> | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| export default App; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||
| import { useEffect, useState } from "react"; | ||||||||||||||||||||||||||||||||||||
| import { Moon, Sun } from "lucide-react"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const ThemeToggle = () => { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const [isDarkMode, setIsDarkMode] = useState(false); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||
| if( localStorage.getItem('theme') === 'dark' ){ | ||||||||||||||||||||||||||||||||||||
| document.documentElement.classList.add('dark'); | ||||||||||||||||||||||||||||||||||||
| setIsDarkMode(true); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| },[]) | ||||||||||||||||||||||||||||||||||||
| const toggleTheme = () => { | ||||||||||||||||||||||||||||||||||||
| if(isDarkMode){ | ||||||||||||||||||||||||||||||||||||
| document.documentElement.classList.remove('dark'); | ||||||||||||||||||||||||||||||||||||
| localStorage.setItem('theme', 'light'); | ||||||||||||||||||||||||||||||||||||
| setIsDarkMode(false); | ||||||||||||||||||||||||||||||||||||
| }else{ | ||||||||||||||||||||||||||||||||||||
| document.documentElement.classList.add('dark'); | ||||||||||||||||||||||||||||||||||||
| localStorage.setItem('theme', 'dark'); | ||||||||||||||||||||||||||||||||||||
| setIsDarkMode(true); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Normalize toggle semantics and storage values. Ensure the class and localStorage reflect the same meaning. -const toggleTheme = () => {
- if(isDarkMode){
- document.documentElement.classList.remove('dark');
- localStorage.setItem('theme', 'light');
- setIsDarkMode(false);
- }else{
- document.documentElement.classList.add('dark');
- localStorage.setItem('theme', 'dark');
- setIsDarkMode(true);
- }
-}
+const toggleTheme = () => {
+ const next = !isDarkMode;
+ document.documentElement.classList.toggle('dark', next);
+ localStorage.setItem('theme', next ? 'dark' : 'light');
+ setIsDarkMode(next);
+};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||
| <button onClick={toggleTheme} className="p-1 cursor-pointer hover:bg-slate-500 rounded-lg transition-colors duration-300"> | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| {!isDarkMode ? (<Sun className="h-6 w-6 text-yellow-300"/>) : (<Moon className="h-6 w-6 text-blue-700 hover:transform-fill"/>) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| export default ThemeToggle; | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { ArrowBigUp } from "lucide-react"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import Styled from "styled-components"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const OnTopBar = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const [isvisible, setIsVisible] = React.useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| const [scrollProgress, setScrollProgress] = React.useState(0); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const onTopbtn = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| window.scrollTo({ | ||||||||||||||||||||||||||||||||||||||||||||||
| top: 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| left: 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| behavior: "smooth", | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Updated scroll handler to calculate progress | ||||||||||||||||||||||||||||||||||||||||||||||
| const handleScroll = () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const winScroll = document.documentElement.scrollTop; | ||||||||||||||||||||||||||||||||||||||||||||||
| const height = document.documentElement.scrollHeight - document.documentElement.clientHeight; | ||||||||||||||||||||||||||||||||||||||||||||||
| const scrolled = (winScroll / height) * 100; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| setScrollProgress(scrolled); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (window.scrollY > 100) { | ||||||||||||||||||||||||||||||||||||||||||||||
| setIsVisible(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| setIsVisible(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Guard division by zero and clamp progress; improve cross-browser scroll source. Avoid NaN/Infinity when the page isn’t scrollable and support body/html differences. -const handleScroll = () => {
- const winScroll = document.documentElement.scrollTop;
- const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
- const scrolled = (winScroll / height) * 100;
-
- setScrollProgress(scrolled);
-
- if (window.scrollY > 100) {
- setIsVisible(true);
- } else {
- setIsVisible(false);
- }
-};
+const handleScroll = () => {
+ const doc = document.documentElement;
+ const body = document.body;
+ const winScroll = doc.scrollTop || body.scrollTop || 0;
+ const height = (doc.scrollHeight || body.scrollHeight) - doc.clientHeight;
+ const pct = height > 0 ? Math.min(100, Math.max(0, (winScroll / height) * 100)) : 0;
+ setScrollProgress(pct);
+ setIsVisible(window.scrollY > 100);
+};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| window.addEventListener("scroll", handleScroll); | ||||||||||||||||||||||||||||||||||||||||||||||
| return () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| window.removeEventListener("scroll", handleScroll); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| <Container> | ||||||||||||||||||||||||||||||||||||||||||||||
| <div className="progress-bar" style={{ width: `${scrollProgress}%` }} /> | ||||||||||||||||||||||||||||||||||||||||||||||
| {isvisible && ( | ||||||||||||||||||||||||||||||||||||||||||||||
| <div className="on-top-bar" onClick={onTopbtn}> | ||||||||||||||||||||||||||||||||||||||||||||||
| <ArrowBigUp /> | ||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||
| </Container> | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a button for accessibility; add aria-label. Clickable divs are not keyboard-accessible by default. - {isvisible && (
- <div className="on-top-bar" onClick={onTopbtn}>
- <ArrowBigUp />
- </div>
- )}
+ {isVisible && (
+ <button className="on-top-bar" type="button" onClick={onTopbtn} aria-label="Back to top">
+ <ArrowBigUp />
+ </button>
+ )}
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const Container = Styled.section` | ||||||||||||||||||||||||||||||||||||||||||||||
| display: flex; | ||||||||||||||||||||||||||||||||||||||||||||||
| justify-content: center; | ||||||||||||||||||||||||||||||||||||||||||||||
| align-items: center; | ||||||||||||||||||||||||||||||||||||||||||||||
| position: relative; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| .progress-bar { | ||||||||||||||||||||||||||||||||||||||||||||||
| position: fixed; | ||||||||||||||||||||||||||||||||||||||||||||||
| top: 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| left: 0; | ||||||||||||||||||||||||||||||||||||||||||||||
| height: 2px; | ||||||||||||||||||||||||||||||||||||||||||||||
| background: #00abff; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| .on-top-bar { | ||||||||||||||||||||||||||||||||||||||||||||||
| position: fixed; | ||||||||||||||||||||||||||||||||||||||||||||||
| bottom: 20px; | ||||||||||||||||||||||||||||||||||||||||||||||
| right: 18px; | ||||||||||||||||||||||||||||||||||||||||||||||
| background-color: #fff; | ||||||||||||||||||||||||||||||||||||||||||||||
| color: #1a1a1a; | ||||||||||||||||||||||||||||||||||||||||||||||
| border-radius: 50%; | ||||||||||||||||||||||||||||||||||||||||||||||
| width: 40px; | ||||||||||||||||||||||||||||||||||||||||||||||
| height: 40px; | ||||||||||||||||||||||||||||||||||||||||||||||
| display: flex; | ||||||||||||||||||||||||||||||||||||||||||||||
| justify-content: center; | ||||||||||||||||||||||||||||||||||||||||||||||
| align-items: center; | ||||||||||||||||||||||||||||||||||||||||||||||
| cursor: pointer; | ||||||||||||||||||||||||||||||||||||||||||||||
| transition: background-color 0.2s ease-in-out; | ||||||||||||||||||||||||||||||||||||||||||||||
| box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| &:hover { | ||||||||||||||||||||||||||||||||||||||||||||||
| background-color: #0039ff; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default OnTopBar; | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,3 +31,13 @@ html { | |||||||||||||||||
| .custom-scrollbar::-webkit-scrollbar-thumb:hover { | ||||||||||||||||||
| background: #056896; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| :body { | ||||||||||||||||||
| background-color: #1a1a1a; | ||||||||||||||||||
| color: #f3f4f6; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix invalid selector ':body' (lint error).
-:body {
+body {
background-color: #1a1a1a;
color: #f3f4f6;
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (2.1.2)[error] 35-35: Unexpected unknown pseudo-class body See MDN web docs for more details. (lint/correctness/noUnknownPseudoClass) 🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| .dark { | ||||||||||||||||||
| background-color: #f3f4f6; | ||||||||||||||||||
| color: #1a1a1a; | ||||||||||||||||||
| } | ||||||||||||||||||
AayushSahani01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
🛠️ Refactor suggestion
Initialize dark mode from storage or system preference; current logic may show wrong icon on first paint.
Defaulting
isDarkModeto false while the CSS default is dark causes a mismatch.📝 Committable suggestion
🤖 Prompt for AI Agents