Reddot UI Library
Docs
Scroll Area
Scroll Area
Augments native scroll functionality for custom, cross-browser styling.
Installation
$npx shadcn@latest add https://reddot.dottools.xyz/r/scroll-area.json
Utilisation
import { ScrollArea } from "@/components/ui/scroll-area"
<ScrollArea className="h-[200px] w-[350px] rounded-md border p-4">
Content that may overflow the scroll area
</ScrollArea>Exemples
Défilement vertical
import * as React from "react"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Separator } from "@/components/ui/separator"
const tags = Array.from({ length: 50 }).map(
(_, i, a) => `v1.2.0-beta.${a.length - i}`
)
export function ScrollAreaDemo() {
return (
<ScrollArea className="h-72 w-48 rounded-md border">
<div className="p-4">
<h4 className="mb-4 text-sm leading-none font-medium">Tags</h4>
{tags.map((tag) => (
<React.Fragment key={tag}>
<div className="text-sm">{tag}</div>
<Separator className="my-2" />
</React.Fragment>
))}
</div>
</ScrollArea>
)
}Défilement horizontal
import * as React from "react"
import Image from "next/image"
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"
const works = [
{ artist: "Artist 1", art: "/image1.jpg" },
{ artist: "Artist 2", art: "/image2.jpg" },
// Plus d'éléments...
]
export function ScrollAreaHorizontalDemo() {
return (
<ScrollArea className="w-96 rounded-md border whitespace-nowrap">
<div className="flex w-max space-x-4 p-4">
{works.map((artwork) => (
<figure key={artwork.artist} className="shrink-0">
<Image
src={artwork.art}
alt={`Photo par ${artwork.artist}`}
width={300}
height={400}
className="aspect-[3/4] h-fit w-fit object-cover"
/>
<figcaption className="pt-2 text-xs text-muted-foreground">
Photo par{" "}
<span className="font-semibold text-foreground">
{artwork.artist}
</span>
</figcaption>
</figure>
))}
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
)
}API Reference
ScrollArea
Le composant principal de la zone de défilement.
| Prop | Type | Default | Description |
|---|---|---|---|
type | "auto" | "always" | "scroll" | "hover" | "hover" | Décrit la nature de la barre de défilement. |
scrollHideDelay | number | 600 | Si type est défini sur "hover", détermine la durée avant que la barre de défilement se cache après que l'utilisateur arrête d'interagir avec les barres de défilement. |
dir | "ltr" | "rtl" | - | La direction de lecture de la zone de défilement. |
ScrollBar
La barre de défilement visible. Vous devez passer un ScrollBar par orientation que vous souhaitez afficher.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | "vertical" | L'orientation de la barre de défilement. |
forceMount | boolean | false | Utilisé pour forcer le montage lorsque plus de contrôle est nécessaire. |