-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathScrollBar.tsx
110 lines (98 loc) · 2.76 KB
/
ScrollBar.tsx
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
101
102
103
104
105
106
107
108
109
110
import React from "react";
import SimpleBar from "simplebar-react";
import styled from "styled-components";
import { DebouncedFunc } from 'lodash'; // Assuming you're using lodash's DebouncedFunc type
// import 'simplebar-react/dist/simplebar.min.css';
const ScrollBarWrapper = styled.div<{
$hideplaceholder?: boolean;
$overflow?: string;
}>`
min-height: 0;
height: ${props => props.$overflow? props.$overflow === 'scroll' ? '300px' : '100%':'100%'
};
width: 100%;
overflow:${props=>props.$overflow};
.simplebar-scrollbar::before {
background: rgba(139, 143, 163, 0.5) !important;
right: 4px !important;
left: 1px !important;
}
.simplebar-hover::before {
background: rgba(139, 143, 163, 0.5) !important;
right: 4px !important;
left: 1px !important;
opacity: 1 !important;
}
.simplebar-content-wrapper {
height: 100% !important;
outline: none !important;
}
.simplebar-offset {
width: 100% !important;
}
.simplebar-track.simplebar-vertical .simplebar-scrollbar:before {
top: 10px;
bottom: 10px;
}
${(props) =>
Boolean(props.$hideplaceholder) &&
`
.simplebar-placeholder {
display: none !important;
}
`}
`;
// .simplebar-placeholder { added by Falk Wolsky to hide the placeholder - as it doubles the vertical space of a Module on a page
interface IProps {
children: React.ReactNode;
className?: string;
height?: string;
overflow?:string,
style?: React.CSSProperties; // Add this line to include a style prop
scrollableNodeProps?: {
onScroll: DebouncedFunc<(e: any) => void>;
};
$hideplaceholder?: boolean;
hideScrollbar?: boolean;
prefixNode?: React.ReactNode;
suffixNode?: React.ReactNode;
}
export const ScrollBar = ({
className,
children,
style,
overflow,
scrollableNodeProps,
hideScrollbar = false,
$hideplaceholder = false,
prefixNode,
suffixNode,
...otherProps
}: IProps) => {
const height = style?.height ?? '100%';
// You can now use the style prop directly or pass it to SimpleBar
const combinedStyle = { ...style, height }; // Example of combining height with passed style
return hideScrollbar ? (
<ScrollBarWrapper className={className}>
{prefixNode}
{children}
{suffixNode}
</ScrollBarWrapper>
) : (
<ScrollBarWrapper className={className}>
<SimpleBar style={combinedStyle} scrollableNodeProps={scrollableNodeProps} {...otherProps}>
{({ scrollableNodeProps, contentNodeProps }) => {
return (
<div {...scrollableNodeProps as any}>
{prefixNode}
<div {...contentNodeProps as any}>
{children}
</div>
{suffixNode}
</div>
);
}}
</SimpleBar>
</ScrollBarWrapper>
);
};