Appearance
ScrollFadeContainer API
All-in-one wrapper component that combines scroll detection with fade overlays. Simply wrap your scrollable content and it handles the rest.
Import
tsx
import { ScrollFadeContainer, type ScrollFadeContainerProps } from '@/shared/ui/components/scroll/ScrollFadeContainer'Props
ScrollFadeContainerProps
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Required | Child content (should include scrollable element) |
fades | 'top' | 'bottom' | 'both' | 'both' | Which fades to show |
fadeSize | 'sm' | 'md' | 'lg' | 'md' | Size of fade gradients |
className | string | - | Additional CSS classes for container |
scrollOptions | UseScrollFadeOptions | - | Options for scroll detection hook |
fadeZIndex | number | 10 | Z-index for fade overlays |
fadeGradient | GradientConfig | - | Custom gradient configuration |
fadeClassName | string | - | Additional CSS classes for fade elements |
Related Types
UseScrollFadeOptions
ts
interface UseScrollFadeOptions {
/** Threshold in pixels before showing fade (default: 10) */
threshold?: number
/** Debounce delay in ms (default: 50) */
debounce?: number
/** Enable debug logging */
debug?: boolean
}GradientConfig
ts
interface GradientConfig {
/** Starting color (e.g., 'rgb(255 255 255)', 'hsl(var(--card))') */
from: string
/** Middle color (optional, defaults to from with 80% opacity) */
via?: string
}Features
- Automatic detection: Uses
useScrollFadehook internally - Ref management: Handles container ref automatically
- Flexible fades: Show top, bottom, or both
- Pass-through props: All fade customization options available
- Works with: SimpleBar, ScrollArea, native overflow
Examples
Basic Usage
tsx
import { ScrollFadeContainer } from '@/shared/ui/components/scroll/ScrollFadeContainer'
import SimpleBar from 'simplebar-react'
<ScrollFadeContainer>
<SimpleBar className="h-[400px]">
<div className="space-y-2 p-4">
{items.map((item) => (
<div key={item.id}>{item.name}</div>
))}
</div>
</SimpleBar>
</ScrollFadeContainer>Custom Fade Size
tsx
<ScrollFadeContainer fadeSize="sm">
<div className="h-[300px] overflow-y-auto">
{content}
</div>
</ScrollFadeContainer>Top or Bottom Only
tsx
// Only show top fade
<ScrollFadeContainer fades="top">
{content}
</ScrollFadeContainer>
// Only show bottom fade
<ScrollFadeContainer fades="bottom">
{content}
</ScrollFadeContainer>Custom Gradient
Match the fade to your background color:
tsx
<ScrollFadeContainer
fadeGradient={{
from: 'hsl(var(--card))',
via: 'hsl(var(--card) / 0.8)',
}}
>
<div className="bg-card rounded-lg">
{content}
</div>
</ScrollFadeContainer>Custom Scroll Options
tsx
<ScrollFadeContainer
scrollOptions={{
threshold: 20, // Show fade when 20px from edge
debounce: 150, // Debounce scroll events by 150ms
debug: true, // Enable console logging
}}
>
{content}
</ScrollFadeContainer>Complete Example
tsx
import { ScrollFadeContainer } from '@/shared/ui/components/scroll/ScrollFadeContainer'
import { Card, CardHeader, CardTitle, CardContent } from '@/shadcn/components/ui/card'
import SimpleBar from 'simplebar-react'
function ActivityFeed({ activities }) {
return (
<Card>
<CardHeader>
<CardTitle>Recent Activity</CardTitle>
</CardHeader>
<CardContent>
<ScrollFadeContainer
fadeSize="md"
fadeGradient={{
from: 'hsl(var(--card))',
via: 'hsl(var(--card) / 0.8)',
}}
scrollOptions={{
threshold: 15,
debounce: 100,
}}
>
<SimpleBar className="h-[400px]">
<div className="space-y-3 pr-4">
{activities.map((activity) => (
<div
key={activity.id}
className="p-3 bg-muted rounded-md"
>
<p className="text-sm font-medium">
{activity.user}
</p>
<p className="text-sm text-muted-foreground">
{activity.message}
</p>
<p className="text-xs text-muted-foreground mt-1">
{activity.timestamp}
</p>
</div>
))}
</div>
</SimpleBar>
</ScrollFadeContainer>
</CardContent>
</Card>
)
}How It Works
- Creates a container with
position: relative - Attaches a ref to detect scroll events
- Uses
useScrollFadehook to monitor scroll position - Renders two
ScrollFadecomponents (top and bottom) - Automatically shows/hides fades based on scroll position
Type Definition
ts
interface ScrollFadeContainerProps {
children: ReactNode
fades?: 'top' | 'bottom' | 'both'
fadeSize?: 'sm' | 'md' | 'lg'
className?: string
scrollOptions?: UseScrollFadeOptions
fadeZIndex?: number
fadeGradient?: {
from: string
via?: string
}
fadeClassName?: string
}Related
- ScrollFade API - Low-level fade component
- useScrollFade Hook - Scroll detection hook
- ScrollFade Component Guide - Usage guide
- Scroll Patterns - Common patterns