├── .babelrc
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── example
├── example.js
├── example.scss
├── index.html
├── index.js
├── shin-chan.jpg
└── webpack.config.js
├── jsconfig.json
├── package-lock.json
├── package.json
├── postcss.config.js
├── src
├── index.d.ts
├── index.js
├── scrollbar.js
└── styles.scss
└── webpack.config.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "env",
4 | "react",
5 | "stage-2"
6 | ],
7 | "plugins": [
8 | "add-module-exports"
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.{js,jsx,ts,html,css,less,scss,json,xml}]
13 | indent_style = space
14 | indent_size = 2
15 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | *.d.ts
2 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | 'extends': 'airbnb',
3 | 'parser': 'babel-eslint',
4 |
5 | 'rules': {
6 | 'indent': [2, 2, {
7 | SwitchCase: 1,
8 | }],
9 | 'prefer-const': 0,
10 | 'no-param-reassign': [2, { props: false }],
11 | 'no-underscore-dangle': [2, {
12 | allowAfterThis: true,
13 | allowAfterSuper: true,
14 | }],
15 | 'react/jsx-filename-extension': 0,
16 | 'react/jsx-indent': [2, 2],
17 | 'react/jsx-indent-props': [2, 2],
18 | 'class-methods-use-this': "off",
19 | // concerned
20 | 'react/forbid-prop-types': "off",
21 | 'react/no-unused-prop-types': "off",
22 | 'no-plusplus': "off",
23 | 'no-bitwise': "off",
24 | 'react/destructuring-assignment': "off"
25 | },
26 |
27 | 'globals': {
28 | 'document': false,
29 | },
30 | }
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | lib/
3 | dist/
4 | .idea/
5 | typings/
6 |
7 | npm-*.log
8 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "8"
4 | script:
5 | - npm run build
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Allen Yang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React-Perfect-Scrollbar [](https://travis-ci.org/goldenyz/react-perfect-scrollbar) [](https://www.npmjs.com/package/react-perfect-scrollbar) [](https://www.npmjs.com/package/react-perfect-scrollbar)
2 |
3 | This is a wrapper to allow use [perfect-scrollbar](https://github.com/noraesae/perfect-scrollbar) in React.
4 |
5 | ***To read documentation for versions < 1.0, please visit [`v0.2.5`](https://github.com/goldenyz/react-perfect-scrollbar/tree/v0.2.5).***
6 |
7 | ### Usage
8 | Install the package `npm install react-perfect-scrollbar -S`
9 | Import the css file if you have loader for css files:
10 | ```js
11 | import 'react-perfect-scrollbar/dist/css/styles.css';
12 | ```
13 |
14 | Import the module in the place you want to use:
15 | ```js
16 | import PerfectScrollbar from 'react-perfect-scrollbar'
17 | ```
18 |
19 | Wrap you content in this component:
20 | ```jsx
21 |
22 | ... SCROLLBAR CONTENT HERE ...
23 |
24 | ```
25 |
26 | ### Props
27 | The following props are accepted:
28 | #### options
29 | The optional parameters used to initialize [perfect-scrollbar](https://github.com/utatti/perfect-scrollbar).
30 | For more info, please refer to https://github.com/utatti/perfect-scrollbar#options
31 |
32 | This prop previously was called "option", but has since been renamed.
33 | If you provide "option" as a prop, it will be used unless "options" is also passed.
34 |
35 | #### containerRef
36 | Return the container ref: (ref) => void;
37 | If you want to scroll to somewhere, just update scrollTop/scrollLeft by the ref:
38 | ```js
39 | // Suppose you have save the containerRef to this._scrollRef
40 | // change scroll top
41 | this._scrollRef.scrollTop = 0;
42 |
43 | // change scroll left
44 | this._scrollRef.scrollLeft = 0;
45 | ```
46 |
47 | #### component
48 | The container component type. Default to "div". Only string is allowed.
49 | #### className
50 | The className added to container.
51 | #### style
52 | The style added to container.
53 | #### onScrollY
54 | Invoked when the y-axis is scrolled in either direction.
55 | #### onScrollX
56 | Invoked when the x-axis is scrolled in either direction.
57 | #### onScrollUp
58 | Invoked when scrolling upwards.
59 | #### onScrollDown
60 | Invoked when scrolling downwards.
61 | #### onScrollLeft
62 | Invoked when scrolling to the left.
63 | #### onScrollRight
64 | Invoked when scrolling to the right.
65 | #### onYReachStart
66 | Invoked when scrolling reaches the start of the y-axis.
67 | #### onYReachEnd
68 | Invoked when scrolling reaches the end of the y-axis (useful for infinite scroll).
69 | #### onXReachStart
70 | Invoked when scrolling reaches the start of the x-axis.
71 | #### onXReachEnd
72 | Invoked when scrolling reaches the end of the x-axis.
73 |
74 | All the callback 'onXXXX' can accept a parameter: the ref to the scrollbar container. You can get the current `scrollTop` and `scrollLeft` from it:
75 | ```jsx
76 | console.log(`scrolled to: ${container.scrollTop}.`)}>
78 | ... SCROLLBAR CONTENT HERE ...
79 |
80 | ```
81 |
82 | #### onSync
83 | Invoked when `PerfectScrollbar` comp needs to sync the scrollbar container by invoking `ps.update()`(Basically, it is invoked in CDU lifecycle) and receive the internal `perfect-scroll` instance `ps` as parameter.
84 |
85 | It is useful when you want to customize the sync logic in some scenarios, eg: debounce the invocation of `ps.update()`.
86 |
87 | For more detail, please refer to [issue#87](https://github.com/goldenyz/react-perfect-scrollbar/issues/87) and the example directory.
88 |
89 | #### React.HTMLAttributes
90 | Any attributes defined in [React.HTMLAttributes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L1689) can be used for the component.
91 |
92 | ### Methods
93 | The following method can be called by the component ref:
94 | #### updateScroll
95 | Update the scrollbar(e.g. recalculate the size) manually.
96 | In the following case, the scrollbar will not update automatically, which cause the scrollbar size incorrect.
97 | ```js
98 | class Container extends Component {
99 | ...
100 | render() {
101 | return (
102 |
103 | ...
104 |
105 | ...
106 |
107 | );
108 | }
109 | }
110 |
111 | class ChildComponent extends Component {
112 | handleClick = () => {
113 | this.setState({
114 | show: !this.state.show,
115 | });
116 | }
117 |
118 | render () {
119 | return (
120 |