-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4729] dev: propel scrollarea #7748
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./scrollarea"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { ScrollArea } from "./scrollarea"; | ||
|
|
||
| const meta: Meta<typeof ScrollArea> = { | ||
| title: "Components/ScrollArea", | ||
| component: ScrollArea, | ||
| parameters: { | ||
| layout: "padded", | ||
| docs: { | ||
| description: { | ||
| component: | ||
| "A customizable scroll area component with multiple size variants, scroll behaviors, and orientations.", | ||
| }, | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| orientation: { | ||
| control: { type: "select" }, | ||
| options: ["vertical", "horizontal"], | ||
| description: "Orientation of the scrollbar", | ||
| table: { | ||
| type: { summary: "ScrollAreaOrientation" }, | ||
| defaultValue: { summary: "vertical" }, | ||
| }, | ||
| }, | ||
| size: { | ||
| control: { type: "select" }, | ||
| options: ["sm", "md", "lg"], | ||
| description: "Size variant of the scrollbar", | ||
| table: { | ||
| type: { summary: "ScrollAreaSize" }, | ||
| defaultValue: { summary: "md" }, | ||
| }, | ||
| }, | ||
| scrollType: { | ||
| control: { type: "select" }, | ||
| options: ["always", "scroll", "hover"], | ||
| description: "When to show the scrollbar", | ||
| table: { | ||
| type: { summary: "ScrollAreaScrollType" }, | ||
| defaultValue: { summary: "always" }, | ||
| }, | ||
| }, | ||
| className: { | ||
| control: { type: "text" }, | ||
| description: "Additional CSS classes", | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof ScrollArea>; | ||
|
|
||
| // Sample content components for stories | ||
| const LongTextContent = () => ( | ||
| <div className="p-4 space-y-4"> | ||
| <h3 className="text-lg font-semibold">Long Text Content</h3> | ||
| <p> | ||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore | ||
| magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo | ||
| consequat. | ||
| </p> | ||
| <p> | ||
| Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur | ||
| sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
| </p> | ||
| <p> | ||
| Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem | ||
| aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. | ||
| </p> | ||
| <p> | ||
| Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores | ||
| eos qui ratione voluptatem sequi nesciunt. | ||
| </p> | ||
| <p> | ||
| Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam | ||
| eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. | ||
| </p> | ||
| <p> | ||
| Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea | ||
| commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae | ||
| consequatur. | ||
| </p> | ||
| </div> | ||
| ); | ||
|
|
||
| // Default story | ||
| export const Default: Story = { | ||
| args: { | ||
| className: "h-64 w-80 border rounded-lg", | ||
| size: "md", | ||
| scrollType: "always", | ||
| orientation: "vertical", | ||
| }, | ||
| render: (args) => ( | ||
| <ScrollArea {...args}> | ||
| <LongTextContent /> | ||
| </ScrollArea> | ||
| ), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import * as React from "react"; | ||
| import { ScrollArea as BaseScrollArea } from "@base-ui-components/react/scroll-area"; | ||
|
|
||
| import { cn } from "../utils/classname"; | ||
|
|
||
| type ScrollAreaOrientation = "horizontal" | "vertical"; | ||
| type ScrollAreaScrollType = "always" | "scroll" | "hover"; | ||
| type ScrollAreaSize = "sm" | "md" | "lg"; | ||
|
|
||
| interface ScrollAreaProps extends React.ComponentProps<typeof BaseScrollArea.Root> { | ||
| orientation?: ScrollAreaOrientation; | ||
| scrollType?: ScrollAreaScrollType; | ||
| size?: ScrollAreaSize; | ||
| } | ||
|
|
||
| function ScrollArea({ className, children, orientation, scrollType, size = "md", ...props }: ScrollAreaProps) { | ||
| return ( | ||
| <BaseScrollArea.Root data-slot="scroll-area" className={cn("relative", className)} {...props}> | ||
| <BaseScrollArea.Viewport | ||
| data-slot="scroll-area-viewport" | ||
| className="focus-visible:ring-ring/50 size-full overscroll-contain rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline" | ||
| > | ||
| {children} | ||
| </BaseScrollArea.Viewport> | ||
| <ScrollBar orientation={orientation} scrollType={scrollType} size={size} /> | ||
| <BaseScrollArea.Corner /> | ||
| </BaseScrollArea.Root> | ||
| ); | ||
| } | ||
|
|
||
| const horizontalSizeStyles = { | ||
| sm: "p-[0.112rem] h-2.5", | ||
| md: "p-[0.112rem] h-3", | ||
| lg: "p-[0.112rem] h-4", | ||
| } as const; | ||
|
|
||
| const verticalSizeStyles = { | ||
| sm: "p-[0.112rem] w-2.5", | ||
| md: "p-[0.112rem] w-3", | ||
| lg: "p-[0.112rem] w-4", | ||
| } as const; | ||
|
|
||
| const thumbSizeStyles = { | ||
| sm: "before:absolute before:left-1/2 before:top-1/2 before:size-full before:min-h-11 before:min-w-11 before:-translate-x-1/2 before:-translate-y-1/2", | ||
| md: "before:absolute before:left-1/2 before:top-1/2 before:size-full before:min-h-14 before:min-w-14 before:-translate-x-1/2 before:-translate-y-1/2", | ||
| lg: "before:absolute before:left-1/2 before:top-1/2 before:size-full before:min-h-17 before:min-w-17 before:-translate-x-1/2 before:-translate-y-1/2", | ||
| } as const; | ||
|
|
||
| interface ScrollBarProps extends React.ComponentProps<typeof BaseScrollArea.Scrollbar> { | ||
| scrollType?: ScrollAreaScrollType; | ||
| size?: ScrollAreaSize; | ||
| } | ||
|
|
||
| const ScrollBar = React.memo(function ScrollBar({ | ||
| className, | ||
| orientation = "vertical", | ||
| scrollType = "always", | ||
| size = "md", | ||
| ...props | ||
| }: ScrollBarProps) { | ||
| return ( | ||
| <BaseScrollArea.Scrollbar | ||
| data-slot="scroll-area-scrollbar" | ||
| orientation={orientation} | ||
| className={cn( | ||
| "group/track mr-1 flex justify-center rounded bg-transparent opacity-0 transition-opacity delay-300 ", | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| orientation === "vertical" && verticalSizeStyles[size], | ||
| orientation === "horizontal" && horizontalSizeStyles[size], | ||
| scrollType === "always" && "opacity-100", | ||
| scrollType === "scroll" && | ||
| "data-[scrolling]:opacity-100 data-[scrolling]:delay-0 data-[scrolling]:duration-75", | ||
| scrollType === "hover" && "data-[hovering]:opacity-100 data-[hovering]:delay-0 data-[hovering]:duration-75", | ||
| className | ||
| )} | ||
| {...props} | ||
| > | ||
| <BaseScrollArea.Thumb | ||
| data-slot="scroll-area-thumb" | ||
| className={cn( | ||
| "relative flex-1 rounded-[10px] bg-custom-scrollbar-neutral group-hover:bg-custom-scrollbar-hover group-active/track:bg-custom-scrollbar-active data-[scrolling]:bg-custom-scrollbar-active", | ||
| thumbSizeStyles[size] | ||
| )} | ||
anmolsinghbhatia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| </BaseScrollArea.Scrollbar> | ||
| ); | ||
| }); | ||
|
|
||
| export { ScrollArea }; | ||
| export type { ScrollAreaProps, ScrollAreaOrientation, ScrollAreaScrollType, ScrollAreaSize }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.