-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(scroll-area): add example for horizontal scroll area #1515
Changes from 2 commits
5025ffc
7f1b09a
32d9d23
9311cf5
611c7cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as React from "react" | ||
import Image from "next/image" | ||
|
||
import { ScrollArea, ScrollBar } from "@/registry/default/ui/scroll-area" | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
} from "@/registry/default/ui/tooltip" | ||
|
||
export interface Artwork { | ||
artist: string | ||
art: string | ||
} | ||
|
||
export const works: Artwork[] = [ | ||
{ | ||
artist: "Ornella Binni", | ||
art: "https://images.unsplash.com/photo-1465869185982-5a1a7522cbcb?auto=format&fit=crop&w=300&q=80", | ||
}, | ||
{ | ||
artist: "Tom Byrom", | ||
art: "https://images.unsplash.com/photo-1548516173-3cabfa4607e9?auto=format&fit=crop&w=300&q=80", | ||
}, | ||
{ | ||
artist: "Vladimir Malyavko", | ||
art: "https://images.unsplash.com/photo-1494337480532-3725c85fd2ab?auto=format&fit=crop&w=300&q=80", | ||
}, | ||
] | ||
|
||
export default function ScrollAreaHorizontalDemo() { | ||
return ( | ||
<ScrollArea className="w-96 whitespace-nowrap rounded-md border"> | ||
<div className="flex space-x-4 pb-4"> | ||
{works.map((artwork) => ( | ||
<div | ||
key={artwork.artist} | ||
className="h-[400px] w-[300px] overflow-hidden rounded-md" | ||
> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<Image | ||
src={artwork.art} | ||
alt={`Photo by ${artwork.artist}`} | ||
width={300} | ||
height={400} | ||
/> | ||
</TooltipTrigger> | ||
<TooltipContent>Photo by {artwork.artist}</TooltipContent> | ||
</Tooltip> | ||
</div> | ||
))} | ||
</div> | ||
<ScrollBar orientation="horizontal" /> | ||
</ScrollArea> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ const ScrollBar = React.forwardRef< | |
orientation === "vertical" && | ||
"h-full w-2.5 border-l border-l-transparent p-[1px]", | ||
orientation === "horizontal" && | ||
"h-2.5 border-t border-t-transparent p-[1px]", | ||
"h-2.5 flex-col border-t border-t-transparent p-[1px]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this issue will be seen on all implementations of horizontal scroll bars, so I added it here since it seemed like bug. For a live reproduction of this issue, https://ui.shadcn.com/examples/music under |
||
className | ||
)} | ||
{...props} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as React from "react" | ||
import Image from "next/image" | ||
|
||
import { ScrollArea, ScrollBar } from "@/registry/new-york/ui/scroll-area" | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipTrigger, | ||
} from "@/registry/new-york/ui/tooltip" | ||
|
||
export interface Artwork { | ||
artist: string | ||
art: string | ||
} | ||
|
||
export const works: Artwork[] = [ | ||
{ | ||
artist: "Ornella Binni", | ||
art: "https://images.unsplash.com/photo-1465869185982-5a1a7522cbcb?auto=format&fit=crop&w=300&q=80", | ||
}, | ||
{ | ||
artist: "Tom Byrom", | ||
art: "https://images.unsplash.com/photo-1548516173-3cabfa4607e9?auto=format&fit=crop&w=300&q=80", | ||
}, | ||
{ | ||
artist: "Vladimir Malyavko", | ||
art: "https://images.unsplash.com/photo-1494337480532-3725c85fd2ab?auto=format&fit=crop&w=300&q=80", | ||
}, | ||
] | ||
|
||
export default function ScrollAreaHorizontalDemo() { | ||
return ( | ||
<ScrollArea className="w-96 whitespace-nowrap rounded-md border"> | ||
<div className="flex space-x-4 pb-4"> | ||
{works.map((artwork) => ( | ||
<div | ||
key={artwork.artist} | ||
className="h-[400px] w-[300px] overflow-hidden rounded-md" | ||
> | ||
<Tooltip> | ||
<TooltipTrigger> | ||
<Image | ||
src={artwork.art} | ||
alt={`Photo by ${artwork.artist}`} | ||
width={300} | ||
height={400} | ||
/> | ||
</TooltipTrigger> | ||
<TooltipContent>Photo by {artwork.artist}</TooltipContent> | ||
</Tooltip> | ||
</div> | ||
))} | ||
</div> | ||
<ScrollBar orientation="horizontal" /> | ||
</ScrollArea> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the toolip and add the credit under the images as caption. This makes the code simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated! This is the new visual:
20230918_143546.mp4