-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscroll-view.tsx
53 lines (47 loc) · 1.65 KB
/
scroll-view.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) 2011-2020 Genestack Limited
* All Rights Reserved
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF GENESTACK LIMITED
* The copyright notice above does not evidence any
* actual or intended publication of such source code.
*/
import classNames from 'classnames';
import * as React from 'react';
import SimpleBar, {Props as SimpleBarProps} from 'simplebar-react';
import 'simplebar/dist/simplebar.min.css';
import {DarkContext} from '../../utils';
import * as styles from './scroll-view.module.css';
/** Props of ScrollView component */
export interface Props extends SimpleBarProps {
/**
* Defines when and how to show scrollbars. Possible values:
*
* `auto` — scrollbars show up on hover or drag
*
* `always` — scrollbars are always shown
*/
showScrollbars?: 'auto' | 'always';
/** Props of SimpleBarReact's scrollableNodeProps */
scrollableNodeProps?: {ref: React.RefObject<HTMLDivElement>};
}
const simplebarOptions = {
autoHide: false
};
/**
* A wrapper component over [SimpleBar](https://github.com/Grsmto/simplebar/tree/master/packages/simplebar-react) that provides crossplatform experience for scrollable views.
*/
export const ScrollView = ({className, showScrollbars = 'auto', ...rest}: Props) => {
const inverted = React.useContext(DarkContext);
return (
<SimpleBar
{...rest}
className={classNames(
styles.root,
{[styles.inverted]: inverted},
{[styles.scrollbarsAlwaysShown]: showScrollbars === 'always'},
className
)}
{...simplebarOptions}
/>
);
};