-
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 all 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
155 changes: 155 additions & 0 deletions
155
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,155 @@ | ||
| 'use client'; | ||
|
|
||
| import { getPropsString } from '@/lib/utils'; | ||
|
|
||
| export const getCode = (props: any) => { | ||
| const content = `<Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex>`; | ||
|
|
||
| return `<ScrollArea${getPropsString(props)} style={{ height: '200px', width: '300px' }}> | ||
| ${content} | ||
| </ScrollArea>`; | ||
| }; | ||
|
|
||
| export const playground = { | ||
| type: 'playground', | ||
| controls: { | ||
| type: { | ||
| type: 'select', | ||
| options: ['auto', 'always', 'scroll', 'hover'], | ||
| defaultValue: 'auto' | ||
| } | ||
| }, | ||
| getCode | ||
| }; | ||
|
|
||
| export const preview = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '100%' }}> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea>` | ||
| }; | ||
|
|
||
| export const verticalDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }}> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 30 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea>` | ||
| }; | ||
|
|
||
| export const horizontalDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '150px', width: '300px' }}> | ||
| <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>` | ||
| }; | ||
|
|
||
| export const bothScrollbarsDemo = { | ||
| type: 'code', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }}> | ||
| <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>` | ||
| }; | ||
|
|
||
| export const typeDemo = { | ||
| type: 'code', | ||
| tabs: [ | ||
| { | ||
| name: 'Auto (default)', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="auto"> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea>` | ||
| }, | ||
| { | ||
| name: 'Always', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="always"> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea>` | ||
| }, | ||
| { | ||
| name: 'Hover', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="hover"> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea>` | ||
| }, | ||
| { | ||
| name: 'Scroll', | ||
| code: ` | ||
| <ScrollArea style={{ height: '200px', width: '300px' }} type="scroll"> | ||
| <Flex direction="column" gap={2}> | ||
| {Array.from({ length: 20 }, (_, i) => ( | ||
| <Text key={i} size="small"> | ||
| Item {i + 1} | ||
| </Text> | ||
| ))} | ||
| </Flex> | ||
| </ScrollArea>` | ||
| } | ||
| ] | ||
| }; |
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
| --- | ||
| title: Scroll Area | ||
| description: A customizable scrollable container component with smooth scrolling, hover effects, and automatic scrollbar handling. Both vertical and horizontal scrollbars are automatically rendered and shown based on content overflow. | ||
| tag: new | ||
| --- | ||
|
|
||
| import { | ||
| playground, | ||
| preview, | ||
| verticalDemo, | ||
| horizontalDemo, | ||
| bothScrollbarsDemo, | ||
| typeDemo, | ||
| } from "./demo.ts"; | ||
|
|
||
| <Demo data={playground} /> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```tsx | ||
| import { ScrollArea } from "@raystack/apsara"; | ||
| ``` | ||
|
|
||
| ## Scroll Area Props | ||
|
|
||
| The Scroll Area 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" /> | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Vertical Scrolling | ||
|
|
||
| A basic vertical scroll area with a list of items. The scrollbar automatically appears when content overflows vertically. | ||
|
|
||
| <Demo data={verticalDemo} /> | ||
|
|
||
| ### Horizontal Scrolling | ||
|
|
||
| A horizontal scroll area for wide content like tables or card grids. The scrollbar automatically appears when content overflows horizontally. | ||
|
|
||
| <Demo data={horizontalDemo} /> | ||
|
|
||
| ### Both Scrollbars | ||
|
|
||
| When content overflows both vertically and horizontally, both scrollbars appear automatically along with the corner element. | ||
|
|
||
| <Demo data={bothScrollbarsDemo} /> | ||
|
|
||
| ### Scrollbar Type | ||
|
|
||
| Control when the scrollbar appears using the `type` prop. | ||
|
|
||
| <Demo data={typeDemo} /> | ||
|
|
||
| ## Features | ||
|
|
||
| - **Automatic Scrollbars**: Both vertical and horizontal scrollbars are always rendered and automatically shown when content overflows | ||
| - **Smooth Scrolling**: Custom scrollbar with smooth transitions | ||
| - **Hover Effects**: Scrollbar expands from 4px to 6px on hover | ||
| - **Auto Corner**: Corner element is automatically added when both scrollbars are visible | ||
| - **Scroll Chaining**: Scroll continues to parent page when reaching container boundaries | ||
| - **Customizable Visibility**: Control when scrollbars appear using the `type` prop | ||
|
|
||
| ## Accessibility | ||
|
|
||
| The Scroll Area component is built on Radix UI primitives and provides: | ||
|
|
||
| - Keyboard navigation support | ||
| - Screen reader compatibility | ||
| - Proper ARIA attributes | ||
| - Focus management | ||
|
|
||
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,28 @@ | ||
| import type React from 'react'; | ||
|
|
||
| export interface ScrollAreaRootProps { | ||
| /** | ||
| * Controls when the scrollbar appears. | ||
| * - `auto`: Scrollbar appears only when content overflows (default) | ||
| * - `always`: Scrollbar is always visible | ||
| * - `scroll`: Scrollbar appears during scrolling | ||
| * - `hover`: Scrollbar appears on hover | ||
| * @default 'auto' | ||
| */ | ||
| type?: 'auto' | 'always' | 'scroll' | 'hover'; | ||
|
|
||
| /** | ||
| * Custom className for the root element. | ||
| */ | ||
| className?: string; | ||
|
|
||
| /** | ||
| * Inline styles for the root element. | ||
| */ | ||
| style?: React.CSSProperties; | ||
|
|
||
| /** | ||
| * The content to be scrolled. Both vertical and horizontal scrollbars are automatically rendered and shown when content overflows. | ||
| */ | ||
| children?: React.ReactNode; | ||
| } |
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.