-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathUI.tsx
More file actions
100 lines (87 loc) · 2.36 KB
/
UI.tsx
File metadata and controls
100 lines (87 loc) · 2.36 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import * as React from 'react';
import { fullWidthClassName, zeroRightClassName } from 'react-remove-scroll-bar/constants';
import { useMergeRefs } from 'use-callback-ref';
import { SideCarComponent } from 'use-sidecar';
import { effectCar } from './medium';
import {
IRemoveScrollEffectProps,
RemoveScrollEffectCallbacks,
IRemoveScrollUIProps,
RemoveScrollUIType,
IRemoveScrollSelfProps,
} from './types';
export type { IRemoveScrollSelfProps, RemoveScrollUIType };
const nothing = () => {
return;
};
/**
* Removes scrollbar from the page and contain the scroll within the Lock
*/
const RemoveScroll: RemoveScrollUIType = React.forwardRef<HTMLElement, IRemoveScrollUIProps>((props, parentRef) => {
const ref = React.useRef<HTMLElement>(null);
const [callbacks, setCallbacks] = React.useState<RemoveScrollEffectCallbacks>({
onScrollCapture: nothing,
onWheelCapture: nothing,
onTouchMoveCapture: nothing,
});
const {
forwardProps,
children,
className,
removeScrollBar,
enabled,
shards,
sideCar,
noRelative,
noIsolation,
inert,
allowPinchZoom,
as: Container = 'div',
gapMode,
...rest
} = props;
const SideCar: SideCarComponent<IRemoveScrollEffectProps> = sideCar;
const containerRef = useMergeRefs<any>([ref, parentRef as React.MutableRefObject<HTMLElement>]);
const containerProps = {
...rest,
...callbacks,
};
return (
<React.Fragment>
{enabled && (
<SideCar
sideCar={effectCar}
removeScrollBar={removeScrollBar}
shards={shards}
noRelative={noRelative}
noIsolation={noIsolation}
inert={inert}
setCallbacks={setCallbacks}
allowPinchZoom={!!allowPinchZoom}
lockRef={ref}
gapMode={gapMode}
/>
)}
{forwardProps ? (
React.cloneElement(React.Children.only(children as React.ReactElement), {
...containerProps,
ref: containerRef,
})
) : (
<Container {...containerProps} className={className} ref={containerRef}>
{children}
</Container>
)}
</React.Fragment>
);
}) as any;
RemoveScroll.defaultProps = {
enabled: true,
removeScrollBar: true,
inert: false,
};
RemoveScroll.classNames = {
fullWidth: fullWidthClassName,
zeroRight: zeroRightClassName,
};
export { RemoveScroll };