From 14e1b26b6116308f1fa16350ad564b9077426c49 Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Mon, 7 May 2018 11:56:31 -0700 Subject: [PATCH] Update fancyscrollbars to use new ref api --- .../{FancyScrollbar.js => FancyScrollbar.tsx} | 66 +++++++++---------- .../shared/components/MultiGrid/MultiGrid.tsx | 2 +- 2 files changed, 32 insertions(+), 36 deletions(-) rename ui/src/shared/components/{FancyScrollbar.js => FancyScrollbar.tsx} (62%) diff --git a/ui/src/shared/components/FancyScrollbar.js b/ui/src/shared/components/FancyScrollbar.tsx similarity index 62% rename from ui/src/shared/components/FancyScrollbar.js rename to ui/src/shared/components/FancyScrollbar.tsx index e62122ab85..fed1c9e66e 100644 --- a/ui/src/shared/components/FancyScrollbar.js +++ b/ui/src/shared/components/FancyScrollbar.tsx @@ -1,49 +1,59 @@ import _ from 'lodash' import React, {Component} from 'react' -import PropTypes from 'prop-types' import classnames from 'classnames' import {Scrollbars} from 'react-custom-scrollbars' import {ErrorHandling} from 'src/shared/decorators/errors' -@ErrorHandling -class FancyScrollbar extends Component { - constructor(props) { - super(props) - } +interface Props { + autoHide?: boolean + autoHeight?: boolean + maxHeight?: number + className?: string + setScrollTop?: (value: React.MouseEvent) => void + style?: React.CSSProperties + scrollTop?: number + scrollLeft?: number +} - static defaultProps = { +@ErrorHandling +class FancyScrollbar extends Component { + public static defaultProps = { autoHide: true, autoHeight: false, setScrollTop: () => {}, } - updateScroll() { - if (this.ref && _.isNumber(this.props.scrollTop)) { - this.ref.scrollTop(this.props.scrollTop) + private ref: React.RefObject + + constructor(props) { + super(props) + this.ref = React.createRef() + } + + public updateScroll() { + const ref = this.ref.current + if (ref && _.isNumber(this.props.scrollTop)) { + ref.scrollTop(this.props.scrollTop) } - if (this.ref && _.isNumber(this.props.scrollLeft)) { - this.ref.scrollLeft(this.props.scrollLeft) + if (ref && _.isNumber(this.props.scrollLeft)) { + ref.scrollLeft(this.props.scrollLeft) } } - componentDidMount() { + public componentDidMount() { this.updateScroll() } - componentDidUpdate() { + public componentDidUpdate() { this.updateScroll() } - handleMakeDiv = className => props => { + public handleMakeDiv = (className: string) => (props): JSX.Element => { return
} - onRef = ref => { - this.ref = ref - } - - render() { + public render() { const { autoHide, autoHeight, @@ -59,7 +69,7 @@ class FancyScrollbar extends Component { className={classnames('fancy-scroll--container', { [className]: className, })} - ref={this.onRef} + ref={this.ref} style={style} onScroll={setScrollTop} autoHide={autoHide} @@ -79,18 +89,4 @@ class FancyScrollbar extends Component { } } -const {bool, func, node, number, string, object} = PropTypes - -FancyScrollbar.propTypes = { - children: node.isRequired, - className: string, - autoHide: bool, - autoHeight: bool, - maxHeight: number, - setScrollTop: func, - style: object, - scrollTop: number, - scrollLeft: number, -} - export default FancyScrollbar diff --git a/ui/src/shared/components/MultiGrid/MultiGrid.tsx b/ui/src/shared/components/MultiGrid/MultiGrid.tsx index f7c65906b3..f90619e4eb 100644 --- a/ui/src/shared/components/MultiGrid/MultiGrid.tsx +++ b/ui/src/shared/components/MultiGrid/MultiGrid.tsx @@ -400,7 +400,7 @@ class MultiGrid extends React.PureComponent { return this.topGridHeight } - private onScrollbarsScroll = e => { + private onScrollbarsScroll = (e: React.MouseEvent) => { const {target} = e this.onScroll(target) }