-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathTabPane.tsx
More file actions
47 lines (42 loc) · 1.19 KB
/
TabPane.tsx
File metadata and controls
47 lines (42 loc) · 1.19 KB
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
import * as React from 'react';
import { getPxStyle, getTransformPropValue } from './util';
export interface PropsType {
key?: string;
className?: string;
active: boolean;
fixX?: boolean;
fixY?: boolean;
}
export class TabPane extends React.PureComponent<PropsType, {}> {
static defaultProps = {
fixX: true,
fixY: true,
};
layout: HTMLDivElement;
offsetX = 0;
offsetY = 0;
componentWillReceiveProps(nextProps: PropsType & { children?: React.ReactNode }) {
if (this.props.active !== nextProps.active) {
if (nextProps.active) {
this.offsetX = 0;
this.offsetY = 0;
} else {
this.offsetX = this.layout.scrollLeft;
this.offsetY = this.layout.scrollTop;
}
}
}
setLayout = (div: HTMLDivElement) => {
this.layout = div;
}
render() {
const { active, fixX, fixY, ...props } = this.props;
let style = {
...fixX && this.offsetX ? getTransformPropValue(getPxStyle(-this.offsetX, 'px', false)) : {},
...fixY && this.offsetY ? getTransformPropValue(getPxStyle(-this.offsetY, 'px', true)) : {},
};
return <div {...props} style={style} ref={this.setLayout}>
{props.children}
</div>;
}
}