Skip to content

Commit

Permalink
feat: implemented/added scroll-area component to design-system (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
babblebey authored Jun 26, 2023
1 parent 520b5c6 commit b7280ab
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 10 deletions.
68 changes: 68 additions & 0 deletions components/atoms/ScrollArea/scroll-area.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as React from "react";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";

import clsx from "clsx";

const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollAreaPrimitive.Root
ref={ref}
className={clsx(
"relative overflow-hidden",
className
)}
{...props}
>
<ScrollViewport>
{children}
</ScrollViewport>
</ScrollAreaPrimitive.Root>
));
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;

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

const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Scrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Scrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.Scrollbar
ref={ref}
className={clsx(
"flex touch-none select-none p-0.5 transition-colors duration-[160ms] ease-out",
orientation === "vertical" &&
"h-full w-2 border-l border-l-transparent",
orientation === "horizontal" &&
"h-2 border-t border-t-transparent",
className
)}
orientation={orientation}
{...props}
>
<ScrollAreaPrimitive.Thumb className="relative bg-light-slate-5 flex-1 rounded-full bg-border" />
</ScrollAreaPrimitive.Scrollbar>
));
ScrollBar.displayName = ScrollAreaPrimitive.Scrollbar.displayName;

export { ScrollArea, ScrollViewport, ScrollBar };
27 changes: 17 additions & 10 deletions components/atoms/Select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from "react";
import * as SelectPrimitive from "@radix-ui/react-select";
import clsx from "clsx";

import { ScrollArea, ScrollViewport } from "components/atoms/ScrollArea/scroll-area";

const Select = SelectPrimitive.Root;

const SelectGroup = SelectPrimitive.Group;
Expand Down Expand Up @@ -43,15 +45,20 @@ const SelectContent = React.forwardRef<
position={position}
{...props}
>
<SelectPrimitive.Viewport
className={clsx(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
)}
>
{children}
</SelectPrimitive.Viewport>
<ScrollArea type="auto">
<SelectPrimitive.Viewport
asChild
className={clsx(
"p-1",
position === "popper" &&
"max-h-[var(--radix-select-content-available-height)] w-full min-w-[var(--radix-select-trigger-width)]"
)}
>
<ScrollViewport className="max-h-[var(--radix-select-content-available-height)] w-full">
{children}
</ScrollViewport>
</SelectPrimitive.Viewport>
</ScrollArea>
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
));
Expand Down Expand Up @@ -96,4 +103,4 @@ const SelectSeparator = React.forwardRef<
));
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;

export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator };
export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator };
198 changes: 198 additions & 0 deletions npm-shrinkwrap.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 @@ -59,6 +59,7 @@
"@radix-ui/react-dropdown-menu": "^1.0.0",
"@radix-ui/react-hover-card": "^1.0.3",
"@radix-ui/react-popover": "^1.0.5",
"@radix-ui/react-scroll-area": "^1.0.4",
"@radix-ui/react-select": "^1.2.1",
"@radix-ui/react-switch": "^1.0.1",
"@radix-ui/react-tabs": "^1.0.2",
Expand Down
61 changes: 61 additions & 0 deletions stories/atoms/scroll-area.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ComponentStory } from "@storybook/react";
import { ScrollArea } from "components/atoms/ScrollArea/scroll-area";

import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "components/atoms/Select/select";

const storyConfig = {
title: "Design System/Atoms/ScrollArea",
component: "ScrollArea"
};

export default storyConfig;
const ScrollTemplate: ComponentStory<typeof ScrollArea> = (args) => (
<ScrollArea
className="rounded-md border p-4"
{...args}
>
Jokester began sneaking into the castle in the middle of the night and leaving
jokes all over the place: under the king's pillow, in his soup, even in the
royal toilet. The king was furious, but he couldn't seem to stop Jokester. And
then, one day, the people of the kingdom discovered that the jokes left by
Jokester were so funny that they couldn't help but laugh. And once they
started laughing, they couldn't stop.
</ScrollArea>
)

export const Default = ScrollTemplate.bind({});

Default.argTypes = {
type: {
options: ["auto", "always", "scroll", "hover"],
control: { type: "select" },
}
}
Default.args = {
type: "auto",
style: {
height: "200px",
width: "350px"
}
}

const SelectOptions = Array.from({ length: 50 }).map((value, index, array) => `v1.2.0-beta.${array.length - index}`);



const ScrollInSelectTemplate: ComponentStory<typeof Select> = (args) => (
<Select {...args}>
<SelectTrigger>
<SelectValue placeholder="Select a Version" />
</SelectTrigger>
<SelectContent>
{SelectOptions.map((option, i) => (
<SelectItem value={option} key={i}>
{option}
</SelectItem>
))}
</SelectContent>
</Select>
);

export const WithSelect = ScrollInSelectTemplate.bind({});

0 comments on commit b7280ab

Please sign in to comment.