Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / main / frontend / src / shared / scroll / Scrollbars.js
1 /*
2 * Copyright © 2018 European Support Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import React from 'react';
18 import PropTypes from 'prop-types';
19 import PerfectScrollbar from 'perfect-scrollbar';
20
21 class Scrollbars extends React.Component {
22     containerRef = React.createRef();
23     scrollbars = null;
24
25     componentDidMount() {
26         const container = this.containerRef.current;
27
28         this.scrollbars = new PerfectScrollbar(container);
29     }
30
31     componentDidUpdate() {
32         if (this.scrollbars) {
33             this.scrollbars.update();
34         }
35     }
36
37     componentWillUnmount() {
38         this.scrollbars.destroy();
39         this.scrollbars = null;
40     }
41
42     render() {
43         const { children, className } = this.props;
44
45         return (
46             <div className={className} ref={this.containerRef}>
47                 {children}
48             </div>
49         );
50     }
51 }
52
53 Scrollbars.propTypes = {
54     children: PropTypes.node,
55     className: PropTypes.string
56 };
57
58 export default Scrollbars;