x-scrollable
delta-components/x-scrollableFreeComponent
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/x-scrollable.jsonSource
1"use client"23import { useEffect, useRef, useState, type ReactNode } from "react"45import { cn } from "@/lib/utils"67interface XScrollableProps {8 children: ReactNode9 className?: string10 showScrollbar?: boolean11 scrollbarTrackClassName?: string12 scrollbarThumbClassName?: string13 onScroll?: (14 scrollLeft: number,15 scrollWidth: number,16 clientWidth: number17 ) => void18}1920export function XScrollable({21 children,22 className,23 showScrollbar = false,24 scrollbarTrackClassName,25 scrollbarThumbClassName,26 onScroll,27}: XScrollableProps) {28 const scrollContainerRef = useRef<HTMLDivElement>(null)29 const [showLeftShadow, setShowLeftShadow] = useState(false)30 const [showRightShadow, setShowRightShadow] = useState(false)3132 useEffect(() => {33 const scrollContainer = scrollContainerRef.current34 if (!scrollContainer) return3536 const handleScroll = () => {37 const { scrollLeft, scrollWidth, clientWidth } = scrollContainer38 setShowLeftShadow(scrollLeft > 0)39 setShowRightShadow(scrollLeft < scrollWidth - clientWidth)40 onScroll?.(scrollLeft, scrollWidth, clientWidth)41 }4243 handleScroll() // Initial check44 scrollContainer.addEventListener("scroll", handleScroll)4546 return () => {47 scrollContainer.removeEventListener("scroll", handleScroll)48 }49 }, [onScroll])5051 return (52 <div className="relative">53 <div54 ref={scrollContainerRef}55 className={cn(56 "overflow-x-auto overflow-y-hidden",57 showScrollbar58 ? "scrollbar-thin scrollbar-track-transparent scrollbar-thumb-gray-300 hover:scrollbar-thumb-gray-400"59 : "scrollbar-hide",60 className61 )}62 >63 {children}64 </div>65 {showLeftShadow && (66 <div className="from-background pointer-events-none absolute top-0 bottom-0 left-0 w-8 bg-gradient-to-r to-transparent" />67 )}68 {showRightShadow && (69 <div className="from-background pointer-events-none absolute top-0 right-0 bottom-0 w-8 bg-gradient-to-l to-transparent" />70 )}71 {showScrollbar && (72 <div73 className={cn(74 "mt-1 h-1 rounded-full bg-gray-200",75 scrollbarTrackClassName76 )}77 >78 <div79 className={cn(80 "h-full rounded-full bg-gray-400",81 scrollbarThumbClassName82 )}83 style={{84 width: scrollContainerRef.current85// … truncated
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 |
