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 all 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 @@ -705,6 +705,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 @@ -1721,6 +1728,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" />
53 changes: 53 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,53 @@
import * as React from "react"
import Image from "next/image"

import { ScrollArea, ScrollBar } from "@/registry/default/ui/scroll-area"

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 w-max space-x-4 p-4">
{works.map((artwork) => (
<figure key={artwork.artist} className="shrink-0">
<div className="overflow-hidden rounded-md">
<Image
src={artwork.art}
alt={`Photo by ${artwork.artist}`}
className="aspect-[3/4] h-fit w-fit object-cover"
width={300}
height={400}
/>
</div>
<figcaption className="pt-2 text-xs text-muted-foreground">
Photo by{" "}
<span className="font-semibold text-foreground">
{artwork.artist}
</span>
</figcaption>
</figure>
))}
</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
53 changes: 53 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,53 @@
import * as React from "react"
import Image from "next/image"

import { ScrollArea, ScrollBar } from "@/registry/new-york/ui/scroll-area"

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 w-max space-x-4 p-4">
{works.map((artwork) => (
<figure key={artwork.artist} className="shrink-0">
<div className="overflow-hidden rounded-md">
<Image
src={artwork.art}
alt={`Photo by ${artwork.artist}`}
className="aspect-[3/4] h-fit w-fit object-cover"
width={300}
height={400}
/>
</div>
<figcaption className="pt-2 text-xs text-muted-foreground">
Photo by{" "}
<span className="font-semibold text-foreground">
{artwork.artist}
</span>
</figcaption>
</figure>
))}
</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 @@ -611,6 +611,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