-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vara-ui): add
ScrollArea
component (#1713)
- Loading branch information
1 parent
a8916b2
commit 5dc800c
Showing
8 changed files
with
115 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,5 @@ | ||
import { ScrollArea, ScrollAreaProps } from './scroll-area'; | ||
import scrollAreaStyles from './scroll-area.module.scss'; | ||
|
||
export { ScrollArea, scrollAreaStyles }; | ||
export type { ScrollAreaProps }; |
38 changes: 38 additions & 0 deletions
38
utils/vara-ui/src/components/scroll-area/scroll-area.module.scss
This file contains 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,38 @@ | ||
@use '../../utils' as *; | ||
|
||
.container { | ||
@include lightDark(--thumb-color, #e5e5e7, rgba(255, 255, 255, 0.1)); | ||
|
||
overflow: auto; | ||
|
||
/* firefox */ | ||
@-moz-document url-prefix() { | ||
scrollbar-color: var(--thumb-color) transparent; | ||
scrollbar-width: thin; | ||
} | ||
|
||
/* chrome */ | ||
&::-webkit-scrollbar { | ||
height: 16px; | ||
width: 16px; | ||
} | ||
|
||
&::-webkit-scrollbar-corner { | ||
background-color: transparent; | ||
} | ||
|
||
&::-webkit-scrollbar-track, | ||
&::-webkit-scrollbar-thumb { | ||
background-clip: padding-box; | ||
border: 4px solid transparent; | ||
} | ||
|
||
&::-webkit-scrollbar-thumb { | ||
background-color: var(--thumb-color); | ||
border-radius: 8px; | ||
|
||
&:hover { | ||
@include lightDark(--thumb-color, rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.15)); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
utils/vara-ui/src/components/scroll-area/scroll-area.stories.tsx
This file contains 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,22 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { ScrollArea } from './scroll-area'; | ||
|
||
type Type = typeof ScrollArea; | ||
type Story = StoryObj<Type>; | ||
|
||
const LONG_TEXT = | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nec purus nec nunc ultricies ultricies. Nullam nec purus nec nunc ultricies ultricies. Nullam nec purus nec nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nec purus nec nunc ultricies ultricies. Nullam nec purus nec nunc ultricies ultricies. Nullam nec purus nec nunc. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nec purus nec nunc ultricies ultricies. Nullam nec purus nec nunc ultricies ultricies. Nullam nec purus nec nunc. Loremipsumdolorsitamet.'; | ||
|
||
const meta: Meta<Type> = { | ||
title: 'ScrollArea', | ||
component: () => <ScrollArea style={{ maxWidth: '512px', maxHeight: '128px' }}>{LONG_TEXT}</ScrollArea>, | ||
args: {}, | ||
}; | ||
|
||
const Default: Story = { | ||
args: {}, | ||
}; | ||
|
||
export default meta; | ||
export { Default }; |
This file contains 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,23 @@ | ||
import cx from 'clsx'; | ||
import { ComponentPropsWithoutRef, ElementType, PropsWithChildren } from 'react'; | ||
|
||
import styles from './scroll-area.module.scss'; | ||
|
||
type Props<T extends ElementType> = PropsWithChildren & | ||
ComponentPropsWithoutRef<T> & { | ||
as?: T; | ||
className?: string; | ||
}; | ||
|
||
function ScrollArea<T extends ElementType = 'div'>({ as, children, className, ...attrs }: Props<T>) { | ||
const Element = as || 'div'; | ||
|
||
return ( | ||
<Element className={cx(styles.container, className)} {...attrs}> | ||
{children} | ||
</Element> | ||
); | ||
} | ||
|
||
export { ScrollArea }; | ||
export type { Props as ScrollAreaProps }; |