Initial commit
This commit is contained in:
53
src/components/FloatingButton/FloatingButton.tsx
Normal file
53
src/components/FloatingButton/FloatingButton.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Button, Grid } from "antd";
|
||||
import TopIcon from "components/Icons/TopIcon";
|
||||
import { useScrollHandler } from "contexts/ScrollHandlerContext";
|
||||
import { useCallback } from "react";
|
||||
import { useAppSelector } from "redux/hooks";
|
||||
import { colors } from "ThemeConstants";
|
||||
import styles from "./FloatingButton.module.css";
|
||||
|
||||
const { useBreakpoint } = Grid;
|
||||
|
||||
export function FloatingButton() {
|
||||
const { isRTL } = useAppSelector((state) => state.locale);
|
||||
const { themeName } = useAppSelector((state) => state.theme);
|
||||
const { xs } = useBreakpoint();
|
||||
const isMobile = xs;
|
||||
|
||||
const { showScrollTop } = useScrollHandler();
|
||||
|
||||
const scrollToTop = useCallback(() => {
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: "smooth",
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Floating Scroll to Top Button */}
|
||||
{showScrollTop && (
|
||||
<Button
|
||||
type="primary"
|
||||
shape="circle"
|
||||
size={isMobile ? "large" : "large"}
|
||||
icon={<TopIcon />}
|
||||
onClick={scrollToTop}
|
||||
className={`${styles.scrollToTopButton}`}
|
||||
style={{
|
||||
position: "fixed",
|
||||
bottom: isMobile ? "100px" : "120px",
|
||||
right: isRTL ? "auto" : isMobile ? "20px" : "32px",
|
||||
left: isRTL ? (isMobile ? "20px" : "32px") : "auto",
|
||||
zIndex: 1000,
|
||||
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
||||
backgroundColor: themeName === "dark" ? colors.primary : colors.primary,
|
||||
borderColor: themeName === "dark" ? colors.primary : colors.primary,
|
||||
width: isMobile ? 48 : 56,
|
||||
height: isMobile ? 48 : 56,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user