Skip to content
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

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/www/__registry__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,13 @@ export const Index: Record<string, any> = {
component: React.lazy(() => import("@/registry/default/example/scroll-area-demo")),
files: ["registry/default/example/scroll-area-demo.tsx"],
},
"scroll-area-horizontal-demo": {
name: "scroll-area-horizontal-demo",
type: "components:example",
registryDependencies: ["scroll-area"],
component: React.lazy(() => import("@/registry/default/example/scroll-area-horizontal-demo")),
files: ["registry/default/example/scroll-area-horizontal-demo.tsx"],
},
"select-demo": {
name: "select-demo",
type: "components:example",
Expand Down Expand Up @@ -1707,6 +1714,13 @@ export const Index: Record<string, any> = {
component: React.lazy(() => import("@/registry/new-york/example/scroll-area-demo")),
files: ["registry/new-york/example/scroll-area-demo.tsx"],
},
"scroll-area-horizontal-demo": {
name: "scroll-area-horizontal-demo",
type: "components:example",
registryDependencies: ["scroll-area"],
component: React.lazy(() => import("@/registry/new-york/example/scroll-area-horizontal-demo")),
files: ["registry/new-york/example/scroll-area-horizontal-demo.tsx"],
},
"select-demo": {
name: "select-demo",
type: "components:example",
Expand Down
6 changes: 6 additions & 0 deletions apps/www/content/docs/components/scroll-area.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ import { ScrollArea } from "@/components/ui/scroll-area"
started laughing, they couldn't stop.
</ScrollArea>
```

## Examples

### Horizontal Scrolling

<ComponentPreview name="scroll-area-horizontal-demo" />
57 changes: 57 additions & 0 deletions apps/www/registry/default/example/scroll-area-horizontal-demo.tsx
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>
Copy link
Collaborator

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.

Copy link
Contributor Author

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

<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>
)
}
2 changes: 1 addition & 1 deletion apps/www/registry/default/ui/scroll-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the flex-col here? Can this be added via the consumer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 Listen Now has a horizontal scroll bar that goes off screen when scrolling all the way to the right.

className
)}
{...props}
Expand Down
57 changes: 57 additions & 0 deletions apps/www/registry/new-york/example/scroll-area-horizontal-demo.tsx
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>
)
}
2 changes: 1 addition & 1 deletion apps/www/registry/new-york/ui/scroll-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
className
)}
{...props}
Expand Down
6 changes: 6 additions & 0 deletions apps/www/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ const example: Registry = [
registryDependencies: ["scroll-area"],
files: ["example/scroll-area-demo.tsx"],
},
{
name: "scroll-area-horizontal-demo",
type: "components:example",
registryDependencies: ["scroll-area"],
files: ["example/scroll-area-horizontal-demo.tsx"],
},
{
name: "select-demo",
type: "components:example",
Expand Down