UNPKG

1.15 kBTypeScriptView Raw
1import { jsx } from '../../jsx';
2import { px } from '../../types';
3import Zoom, { ZoomProps } from '../zoom';
4
5export interface ScrollBarProps extends ZoomProps {
6 /**
7 * 显示滚动条
8 */
9 visible?: boolean;
10 /**
11 * 滚动条显示位置
12 */
13 position?: 'bottom' | 'top' | 'left' | 'right';
14 /**
15 * 间距
16 */
17 margin?: px;
18}
19
20export default (View) => {
21 return class ScrollBar extends Zoom<ScrollBarProps> {
22 willMount() {
23 super.willMount();
24 const { context, props } = this;
25 const { visible, position = 'bottom', margin = '16px', chart } = props;
26 const marginNumber = context.px2hd(margin);
27
28 if (visible === false) {
29 return null;
30 }
31
32 chart.updateCoordFor(this, {
33 position,
34 width: position === 'left' || position === 'right' ? marginNumber : 0,
35 height: position === 'bottom' || position === 'top' ? marginNumber : 0,
36 });
37 }
38
39 render() {
40 const { props, state } = this;
41 const { visible } = props;
42 if (visible === false) {
43 return null;
44 }
45 return <View position="bottom" {...props} {...state} />;
46 }
47 };
48};