Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add fade to bottom of filter scroll container

Tim Wilsonadb290683eb4
diff --git a/packages/ui/src/animated-size-container.tsx b/packages/ui/src/animated-size-container.tsx
index 561c771b1a..61bfdca1ad 100644
--- a/packages/ui/src/animated-size-container.tsx
+++ b/packages/ui/src/animated-size-container.tsx
@@ -28,6 +28,7 @@ const AnimatedSizeContainer = forwardRef<
className,
transition,
children,
+ ...rest
}: AnimatedSizeContainerProps,
forwardedRef,
) => {
@@ -47,6 +48,7 @@ const AnimatedSizeContainer = forwardRef<
: "auto",
}}
transition={transition ?? { type: "spring", duration: 0.3 }}
+ {...rest}
>
<div
ref={containerRef}
diff --git a/packages/ui/src/filter/filter-select.tsx b/packages/ui/src/filter/filter-select.tsx
index c9714e9a99..ba28342855 100644
--- a/packages/ui/src/filter/filter-select.tsx
+++ b/packages/ui/src/filter/filter-select.tsx
@@ -45,6 +45,8 @@ export function FilterSelect({
height: number;
}>();
+ const [scrollProgress, setScrollProgress] = useState(1);
+
const [isOpen, setIsOpen] = useState(false);
const [search, setSearch] = useState("");
const [selectedFilterKey, setSelectedFilterKey] = useState<
@@ -92,6 +94,21 @@ export function FilterSelect({
[activeFilters, selectedFilter],
);
+ const updateScrollProgress = useCallback(() => {
+ if (!mainListContainer.current) return;
+ const { scrollTop, scrollHeight, clientHeight } = mainListContainer.current;
+
+ setScrollProgress(
+ scrollHeight === clientHeight
+ ? 1
+ : scrollTop / (scrollHeight - clientHeight),
+ );
+ }, []);
+
+ useEffect(() => {
+ updateScrollProgress();
+ }, [selectedFilterKey, updateScrollProgress]);
+
return (
<Popover
openPopover={isOpen}
@@ -100,7 +117,12 @@ export function FilterSelect({
if (selectedFilterKey) e.preventDefault();
}}
content={
- <AnimatedSizeContainer width={!isMobile} height>
+ <AnimatedSizeContainer
+ width={!isMobile}
+ height
+ className="rounded-[inherit]"
+ style={{ transform: "translateZ(0)" }} // Fixes overflow on some browsers
+ >
<Command loop>
<Command.Input
size={1}
@@ -118,6 +140,7 @@ export function FilterSelect({
<div
className="scrollbar-hide max-h-[50vh] w-screen overflow-y-scroll p-2 sm:w-auto"
ref={mainListContainer}
+ onScroll={updateScrollProgress}
>
{!selectedFilter ? (
<Command.List className="flex w-full min-w-[160px] flex-col gap-1">
@@ -171,6 +194,11 @@ export function FilterSelect({
)}
</div>
</Command>
+ {/* Bottom scroll fade */}
+ <div
+ className="pointer-events-none absolute bottom-0 left-0 h-16 w-full bg-gradient-to-t from-white"
+ style={{ opacity: 1 - Math.pow(scrollProgress, 2) }}
+ ></div>
</AnimatedSizeContainer>
}
>