Skip to content

Commit

Permalink
switched shadcn ui scrollarea
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgegriff committed Dec 1, 2023
1 parent f92cb1f commit ec6ded1
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 11 deletions.
40 changes: 40 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@dnd-kit/sortable": "^7.0.2",
"@dnd-kit/utilities": "^3.2.1",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-slot": "^1.0.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
Expand Down
26 changes: 15 additions & 11 deletions src/components/BoardColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { cva } from "class-variance-authority";
import { Card, CardContent, CardHeader } from "./ui/card";
import { Button } from "./ui/button";
import { GripVertical } from "lucide-react";
import { ScrollArea, ScrollBar } from "./ui/scroll-area";

export interface Column {
id: UniqueIdentifier;
Expand Down Expand Up @@ -55,7 +56,7 @@ export function BoardColumn({ column, tasks, isOverlay }: BoardColumnProps) {
};

const variants = cva(
"h-[500px] max-h-[500px] w-[350px] max-w-full bg-secondary flex flex-col flex-shrink-0 snap-center",
"h-[500px] max-h-[500px] w-[350px] max-w-full bg-primary-foreground flex flex-col flex-shrink-0 snap-center",
{
variants: {
dragging: {
Expand Down Expand Up @@ -87,21 +88,23 @@ export function BoardColumn({ column, tasks, isOverlay }: BoardColumnProps) {
</Button>
<span className="ml-auto"> {column.title}</span>
</CardHeader>
<CardContent className="flex flex-grow flex-col gap-4 p-2 overflow-y-auto overflow-x-hidden">
<SortableContext items={tasksIds}>
{tasks.map((task) => (
<TaskCard key={task.id} task={task} />
))}
</SortableContext>
</CardContent>
<ScrollArea>
<CardContent className="flex flex-grow flex-col gap-2 p-2">
<SortableContext items={tasksIds}>
{tasks.map((task) => (
<TaskCard key={task.id} task={task} />
))}
</SortableContext>
</CardContent>
</ScrollArea>
</Card>
);
}

export function BoardContainer({ children }: { children: React.ReactNode }) {
const dndContext = useDndContext();

const variations = cva("overflow-x-auto px-2 md:px-0 flex lg:justify-center", {
const variations = cva("px-2 md:px-0 flex lg:justify-center pb-4", {
variants: {
dragging: {
default: "snap-x snap-mandatory",
Expand All @@ -111,14 +114,15 @@ export function BoardContainer({ children }: { children: React.ReactNode }) {
});

return (
<div
<ScrollArea
className={variations({
dragging: dndContext.active ? "active" : "default",
})}
>
<div className="flex gap-4 items-center flex-row justify-center">
{children}
</div>
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
);
}
46 changes: 46 additions & 0 deletions src/components/ui/scroll-area.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from "react"
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"

import { cn } from "@/lib/utils"

const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn("relative overflow-hidden", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
))
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName

const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
))
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName

export { ScrollArea, ScrollBar }

0 comments on commit ec6ded1

Please sign in to comment.