From dded8af07bad08409e4771a7ad6c2cbbb5f787f3 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Thu, 9 Jan 2025 04:31:17 +1030 Subject: [PATCH] feat: implement FloatingBar component for improved DataBar scrolling behavior --- .../src/components/ui/DataBar/DataBar.jsx | 114 +++++++++--------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/frontend/src/components/ui/DataBar/DataBar.jsx b/frontend/src/components/ui/DataBar/DataBar.jsx index b595971..fedb1ce 100644 --- a/frontend/src/components/ui/DataBar/DataBar.jsx +++ b/frontend/src/components/ui/DataBar/DataBar.jsx @@ -5,6 +5,17 @@ import {SortDropdown} from './SortDropdown'; import ToggleSelectButton from './ToggleSelectButton'; import AddButton from './AddButton'; +const FloatingBar = ({children}) => ( + <> +
+
+
{children}
+
+
+
+ +); + const DataBar = ({ onSearch, searchPlaceholder = 'Search by name or tag...', @@ -19,82 +30,67 @@ const DataBar = ({ toggleSelectionMode, onAdd, addButtonLabel = 'Add New', - showAddButton = true + showAddButton = true, + className }) => { const [isFloating, setIsFloating] = useState(false); - const [isVisible, setIsVisible] = useState(true); - const [lastScrollY, setLastScrollY] = useState(0); useEffect(() => { const handleScroll = () => { - const currentScrollY = window.scrollY; - - // Show/hide based on scroll direction - setIsVisible(currentScrollY <= 0 || currentScrollY < lastScrollY); - - // Start floating once we scroll past the initial position - setIsFloating(currentScrollY > 64); // Approximately the height of the bar - - setLastScrollY(currentScrollY); + setIsFloating(window.scrollY > 64); }; window.addEventListener('scroll', handleScroll, {passive: true}); return () => window.removeEventListener('scroll', handleScroll); - }, [lastScrollY]); + }, []); - return ( -
-
- + + +
+ setSortBy(key)} /> -
- setSortBy(key)} - /> -
+ -
- -
- -
- -
+ {showAddButton && !isSelectionMode && ( -
- -
+ )}
+ + ); + + if (isFloating) { + return {controls}; + } + + return ( +
+
{controls}
); };