-
Notifications
You must be signed in to change notification settings - Fork 13
Feat: add scroll-area component #555
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 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8a8b0a9
feat: add scroll area component
paanSinghCoder f81a9dc
style: add transition
paanSinghCoder 598c89d
style: simplify styling
paanSinghCoder 85071a2
fix: className not found
paanSinghCoder bf4b930
fix: remove redundant prop
paanSinghCoder 9d45f65
fix: hidden by default
paanSinghCoder 1cc4051
style: faster transition
paanSinghCoder 63bdffa
style: overscroll auto and vars
paanSinghCoder 07e93ae
docs: add mdx
paanSinghCoder dc5ac25
fix: bg color
paanSinghCoder 9d55a56
test: add unit tests
paanSinghCoder 1416b4b
feat: simplify scrollarea API
paanSinghCoder 09748b7
docs: update docs
paanSinghCoder 441bd17
tests: update unit tests
paanSinghCoder 13a45aa
chore: copy in docs
paanSinghCoder 282afd7
tests: update unit tests
paanSinghCoder ca2a2cd
chore: update comment
paanSinghCoder 7b46fb9
Update apps/www/src/content/docs/components/scroll-area/index.mdx
paanSinghCoder a7a7314
feat: add scroll area playground
paanSinghCoder 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
152 changes: 152 additions & 0 deletions
152
apps/www/src/content/docs/components/scroll-area/demo.ts
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,152 @@ | ||
| 'use client'; | ||
|
|
||
| export const preview = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '100%' }}> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| </ScrollArea>` | ||
| }; | ||
|
|
||
| export const verticalDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }}> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 30 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| </ScrollArea>` | ||
| }; | ||
|
|
||
| export const horizontalDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '150px', width: '300px' }}> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="row" gap={4} style={{ width: '600px' }}> | ||
| {Array.from({ length: 10 }, (_, i) => ( | ||
| <Flex key={i} direction="column" gap={2} style={{ minWidth: '150px' }}> | ||
| <Text weight="medium" size="small"> | ||
| Column {i + 1} | ||
| </Text> | ||
| <Text size="small" variant="secondary"> | ||
| Content here | ||
| </Text> | ||
| </Flex> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="horizontal" /> | ||
| </ScrollArea>` | ||
| }; | ||
|
|
||
| export const bothScrollbarsDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }}> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="row" gap={4} style={{ width: '800px' }}> | ||
| {Array.from({ length: 15 }, (_, i) => ( | ||
| <Flex key={i} direction="column" gap={2} style={{ minWidth: '180px' }}> | ||
| <Text weight="medium" size="small"> | ||
| Column {i + 1} | ||
| </Text> | ||
| {Array.from({ length: 20 }, (_, j) => ( | ||
| <Text key={j} size="small" variant="secondary"> | ||
| Row {j + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| <ScrollArea.Scrollbar orientation="horizontal" /> | ||
| </ScrollArea>` | ||
| }; | ||
|
|
||
| export const typeDemo = { | ||
| type: 'code', | ||
| tabs: [ | ||
| { | ||
| name: 'Auto (default)', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="auto"> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| </ScrollArea>` | ||
| }, | ||
| { | ||
| name: 'Always', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="always"> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| </ScrollArea>` | ||
| }, | ||
| { | ||
| name: 'Hover', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="hover"> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| </ScrollArea>` | ||
| }, | ||
| { | ||
| name: 'Scroll', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="scroll"> | ||
| <ScrollArea.Viewport> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea.Viewport> | ||
| <ScrollArea.Scrollbar orientation="vertical" /> | ||
| </ScrollArea>` | ||
| } | ||
| ] | ||
| }; |
97 changes: 97 additions & 0 deletions
97
apps/www/src/content/docs/components/scroll-area/index.mdx
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,97 @@ | ||
| --- | ||
| title: ScrollArea | ||
| description: A customizable scrollable container component with smooth scrolling, hover effects, and automatic corner handling for both vertical and horizontal scrollbars. | ||
| --- | ||
|
|
||
| import { | ||
| preview, | ||
| verticalDemo, | ||
| horizontalDemo, | ||
| bothScrollbarsDemo, | ||
| typeDemo, | ||
| } from "./demo.ts"; | ||
|
|
||
| <Demo data={preview} /> | ||
paanSinghCoder marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Usage | ||
|
|
||
| ```tsx | ||
| import { ScrollArea } from "@raystack/apsara"; | ||
| ``` | ||
|
|
||
| ## Component Structure | ||
|
|
||
| The ScrollArea component uses a composite pattern, providing modular sub-components for flexible scrollable containers: | ||
|
|
||
| - `ScrollArea` - Root container that manages scrolling state | ||
| - `ScrollArea.Viewport` - The scrollable content area | ||
| - `ScrollArea.Scrollbar` - The scrollbar track and thumb (vertical or horizontal) | ||
| - `ScrollArea.Corner` - The corner element (automatically added when both scrollbars are present) | ||
|
|
||
| ## ScrollArea Props | ||
|
|
||
| The ScrollArea root component extends standard HTML div attributes, so you can use props like `style`, `id`, `onClick`, and other standard HTML attributes in addition to the props listed below. | ||
|
|
||
| <auto-type-table path="./props.ts" name="ScrollAreaRootProps" /> | ||
|
|
||
| ### ScrollArea.Viewport Props | ||
|
|
||
| The viewport is the scrollable content container. It extends standard HTML div attributes, so you can use props like `style`, `id`, `onClick`, and other standard HTML attributes in addition to the props listed below. | ||
|
|
||
| <auto-type-table path="./props.ts" name="ScrollAreaViewportProps" /> | ||
|
|
||
| ### ScrollArea.Scrollbar Props | ||
|
|
||
| The scrollbar component renders the scrollbar track and thumb. When both vertical and horizontal scrollbars are present, the Corner component is automatically added. It extends standard HTML div attributes, so you can use props like `style`, `id`, and other standard HTML attributes. | ||
|
|
||
| <auto-type-table path="./props.ts" name="ScrollAreaScrollbarProps" /> | ||
|
|
||
| ### ScrollArea.Corner Props | ||
|
|
||
| The corner component fills the space where vertical and horizontal scrollbars meet. It's automatically added when both scrollbars are present, but you can also add it manually if needed. It extends standard HTML div attributes, so you can use props like `style`, `id`, and other standard HTML attributes. | ||
|
|
||
| <auto-type-table path="./props.ts" name="ScrollAreaCornerProps" /> | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Vertical Scrolling | ||
|
|
||
| A basic vertical scroll area with a list of items. | ||
|
|
||
| <Demo data={verticalDemo} /> | ||
|
|
||
| ### Horizontal Scrolling | ||
|
|
||
| A horizontal scroll area for wide content like tables or card grids. | ||
|
|
||
| <Demo data={horizontalDemo} /> | ||
|
|
||
| ### Both Scrollbars | ||
|
|
||
| When both vertical and horizontal scrollbars are present, the Corner component is automatically added to fill the intersection. | ||
|
|
||
| <Demo data={bothScrollbarsDemo} /> | ||
|
|
||
| ### Scrollbar Type | ||
|
|
||
| Control when the scrollbar appears using the `type` prop. | ||
|
|
||
| <Demo data={typeDemo} /> | ||
|
|
||
| ## Features | ||
|
|
||
| - **Smooth Scrolling**: Custom scrollbar with smooth transitions | ||
| - **Hover Effects**: Scrollbar expands from 4px to 6px on hover | ||
| - **Auto Corner**: Automatically adds corner element when both scrollbars are present | ||
| - **Scroll Chaining**: Scroll continues to parent page when reaching container boundaries | ||
| - **Customizable**: Full control over scrollbar visibility and behavior | ||
|
|
||
| ## Accessibility | ||
|
|
||
| The ScrollArea component is built on Radix UI primitives and provides: | ||
|
|
||
| - Keyboard navigation support | ||
| - Screen reader compatibility | ||
| - Proper ARIA attributes | ||
| - Focus management | ||
|
|
||
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.