1
1
import { useViewport } from '@1hive/1hive-ui' ;
2
2
import React , { useEffect , useRef , useState } from 'react' ;
3
- import { GUpx } from 'src/utils/css.util' ;
4
3
import styled from 'styled-components' ;
5
4
import { BREAKPOINTS } from '../styles/breakpoints' ;
6
5
7
6
const WrapperStyled = styled . div `
8
7
display: grid;
9
8
grid-template-areas: ${ ( props : any ) =>
10
- props . twoCol ? "'m m s'\n'm m s '\n'f f f'" : "'s s s'\n'm m m '\n'f f f'" } ;
9
+ props . isOneCol ? "'s s s'\n'm m m '\n'f f f'" : "'m m s'\n'm m s '\n'f f f'" } ;
11
10
height: calc(100vh - 64px);
12
11
overflow-y: auto;
13
12
grid-template-columns: 1fr auto;
14
13
scroll-behavior: smooth;
14
+ ::-webkit-scrollbar {
15
+ display: none;
16
+ }
17
+ -ms-overflow-style: none;
18
+ scrollbar-width: none;
15
19
` ;
16
20
17
21
const SideBlockStyled = styled . div `
@@ -20,6 +24,7 @@ const SideBlockStyled = styled.div`
20
24
21
25
const FooterStyled = styled . div `
22
26
grid-area: f;
27
+ transition: all 5s linear;
23
28
` ;
24
29
25
30
const ScrollViewStyled = styled . div `
@@ -36,53 +41,71 @@ const ScrollViewStyled = styled.div`
36
41
`
37
42
: '' }
38
43
39
- ${ ( props : any ) => ( props . twoCol ? `padding: ${ GUpx ( 1 ) } ${ GUpx ( 4 ) } ;` : `padding: ${ GUpx ( 1 ) } ` ) } ;
40
44
grid-area: m;
41
45
` ;
42
46
43
47
type Props = {
44
48
main : React . ReactNode ;
45
49
side ?: React . ReactNode ;
46
50
footer : React . ReactNode ;
47
- mainScrollable ?: boolean ;
48
51
} ;
49
52
50
- function SideContentLayout ( { main, side, footer, mainScrollable = true } : Props ) {
53
+ function SideContentLayout ( { main, side, footer } : Props ) {
51
54
const { width : vw } = useViewport ( ) ;
55
+ const wrapperElement = document . getElementById ( 'main-scroll' ) ;
52
56
const scrollRef = useRef < HTMLDivElement > ( ) ;
53
57
const footerRef = useRef < HTMLDivElement > ( ) ;
54
- const [ twoCol , setTwoCol ] = useState ( true ) ;
58
+ const [ isOneCol , setIsOneCol ] = useState ( false ) ;
55
59
56
60
useEffect ( ( ) => {
57
61
const handleWheelOnMain = ( e : WheelEvent ) => {
58
62
const scrollElement = scrollRef . current as HTMLElement ;
59
- const wrapperElement = document . getElementById ( 'main-scroll' ) ;
60
- const footerElement = footerRef . current as HTMLElement ;
61
- // scroll is bottom
62
- if ( wrapperElement && scrollElement ) {
63
- if ( Math . round ( wrapperElement . scrollTop ) >= footerElement . clientHeight && e . deltaY < 0 ) {
64
- e . preventDefault ( ) ;
65
- wrapperElement . scroll ( { top : e . deltaY , behavior : 'smooth' } ) ;
63
+ if ( scrollElement && wrapperElement ) {
64
+ if (
65
+ Math . round ( scrollElement . scrollHeight - scrollElement . scrollTop ) >=
66
+ Math . round ( scrollElement . clientHeight ) &&
67
+ e . deltaY < 0
68
+ ) {
69
+ requestAnimationFrame ( ( ) =>
70
+ wrapperElement . scroll ( {
71
+ top : - footerRef . current ! . clientHeight ,
72
+ left : 0 ,
73
+ behavior : 'auto' ,
74
+ } ) ,
75
+ ) ;
76
+ }
77
+ if (
78
+ Math . round ( scrollElement . scrollHeight - scrollElement . scrollTop ) ===
79
+ Math . round ( scrollElement . clientHeight ) &&
80
+ wrapperElement . scrollTop - scrollElement . scrollTop <= 0 &&
81
+ e . deltaY > 0
82
+ ) {
83
+ requestAnimationFrame ( ( ) =>
84
+ wrapperElement . scroll ( {
85
+ top : footerRef . current ! . clientHeight ,
86
+ left : 0 ,
87
+ behavior : 'auto' ,
88
+ } ) ,
89
+ ) ;
66
90
}
67
91
}
68
92
} ;
69
-
70
- if ( scrollRef . current && footerRef . current && side ) {
93
+ if ( scrollRef . current && footerRef . current && ! isOneCol ) {
71
94
scrollRef . current ?. addEventListener ( 'wheel' , handleWheelOnMain ) ;
72
95
} else {
73
96
scrollRef . current ?. removeEventListener ( 'wheel' , handleWheelOnMain ) ;
74
97
}
75
98
return ( ) => scrollRef . current ?. removeEventListener ( 'wheel' , handleWheelOnMain ) ;
76
- } , [ scrollRef . current , footerRef . current , side ] ) ;
99
+ } , [ scrollRef . current , footerRef . current , isOneCol ] ) ;
77
100
78
101
useEffect ( ( ) => {
79
- setTwoCol ( vw >= BREAKPOINTS . large ) ;
80
- } , [ vw ] ) ;
102
+ setIsOneCol ( ! side || vw < BREAKPOINTS . large ) ;
103
+ } , [ vw , side ] ) ;
81
104
82
105
return (
83
106
< >
84
- < WrapperStyled twoCol = { twoCol && side } id = "main-scroll" >
85
- < ScrollViewStyled scrollable = { mainScrollable } id = "scroll-view" ref = { scrollRef } >
107
+ < WrapperStyled isOneCol = { isOneCol } id = "main-scroll" >
108
+ < ScrollViewStyled scrollable = { ! isOneCol } id = "scroll-view" ref = { scrollRef } >
86
109
{ main }
87
110
</ ScrollViewStyled >
88
111
{ side && < SideBlockStyled > { side } </ SideBlockStyled > }
0 commit comments