scroll-fade-effect
delta-components/scroll-fade-effectFreeComponent
delta-components publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by delta-components on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://deltacomponents.dev/r/scroll-fade-effect.jsonSource
1"use client"23import * as React from "react"45import { cn } from "@/lib/utils"67export interface ScrollFadeEffectProps8 extends React.ComponentPropsWithoutRef<"div"> {9 /**10 * The orientation of the scroll container.11 * @default "vertical"12 */13 orientation?: "horizontal" | "vertical"14 /**15 * Controls the fade size in pixels.16 * Higher values create a more prominent fade effect.17 * @default 6418 */19 intensity?: number20}2122export function ScrollFadeEffect({23 className,24 orientation = "vertical",25 intensity = 64,26 style,27 children,28 ...props29}: ScrollFadeEffectProps) {30 const ref = React.useRef<HTMLDivElement>(null)31 const [isScrollable, setIsScrollable] = React.useState(false)3233 React.useEffect(() => {34 const element = ref.current35 if (!element) return3637 const checkScrollable = () => {38 if (orientation === "vertical") {39 setIsScrollable(element.scrollHeight > element.clientHeight)40 } else {41 setIsScrollable(element.scrollWidth > element.clientWidth)42 }43 }4445 checkScrollable()4647 const resizeObserver = new ResizeObserver(checkScrollable)48 resizeObserver.observe(element)4950 // Also observe content changes51 const mutationObserver = new MutationObserver(checkScrollable)52 mutationObserver.observe(element, { childList: true, subtree: true })5354 return () => {55 resizeObserver.disconnect()56 mutationObserver.disconnect()57 }58 }, [orientation])5960 const fadeSize = `${Math.max(intensity, 0)}px`6162 return (63 <div64 ref={ref}65 data-orientation={orientation}66 data-scrollable={isScrollable}67 className={cn(68 "data-[orientation=horizontal]:overflow-x-auto data-[orientation=vertical]:overflow-y-auto",69 "data-[scrollable=true]:data-[orientation=horizontal]:scroll-fade-effect-x data-[scrollable=true]:data-[orientation=vertical]:scroll-fade-effect-y",70 className71 )}72 style={73 {74 "--mask-height": fadeSize,75 "--mask-width": fadeSize,76 "--bottom-mask-height": fadeSize,77 "--right-mask-width": fadeSize,78 ...style,79 } as React.CSSProperties80 }81 {...props}82 >83 {children}84 </div>85 )86}
Files it writes
More from delta-components
All 93 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| admonitionadmonition | delta-components | Components | Free | 1 dep | |
| cambio-imagecambio-image | delta-components | Components | Free | 2 deps | |
| card-deckcard-deck | delta-components | Components | Free | 3 deps | |
| chatchat | delta-components | Components | Free | 3 deps | |
| code-blockcode-block | delta-components | Components | Free | 3 deps | |
| code-block-iconscode-block-icons | delta-components | Components | Free | no deps | |
| copy-buttoncopy-button | delta-components | Components | Free | 1 dep | |
| input-otpinput-otp | delta-components | Components | Free | 1 dep |
