Skip to content

Commit 9186e77

Browse files
committed
Layout: Added scroll fade to the sidebars
1 parent 6045aff commit 9186e77

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

resources/js/components/tri-layout.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export class TriLayout extends Component {
55
setup() {
66
this.container = this.$refs.container;
77
this.tabs = this.$manyRefs.tab;
8+
this.sidebarScrollContainers = this.$manyRefs.sidebarScrollContainer;
89

910
this.lastLayoutType = 'none';
1011
this.onDestroy = null;
@@ -22,6 +23,8 @@ export class TriLayout extends Component {
2223
window.addEventListener('resize', () => {
2324
this.updateLayout();
2425
}, {passive: true});
26+
27+
this.setupSidebarScrollHandlers();
2528
}
2629

2730
updateLayout() {
@@ -108,4 +111,28 @@ export class TriLayout extends Component {
108111
this.lastTabShown = tabName;
109112
}
110113

114+
setupSidebarScrollHandlers() {
115+
for (const sidebar of this.sidebarScrollContainers) {
116+
sidebar.addEventListener('scroll', () => this.handleSidebarScroll(sidebar), {
117+
passive: true,
118+
});
119+
this.handleSidebarScroll(sidebar);
120+
}
121+
122+
window.addEventListener('resize', () => {
123+
for (const sidebar of this.sidebarScrollContainers) {
124+
this.handleSidebarScroll(sidebar);
125+
}
126+
});
127+
}
128+
129+
handleSidebarScroll(sidebar) {
130+
const scrollable = sidebar.clientHeight !== sidebar.scrollHeight;
131+
const atTop = sidebar.scrollTop === 0;
132+
const atBottom = (sidebar.scrollTop + sidebar.clientHeight) === sidebar.scrollHeight;
133+
134+
sidebar.parentElement.classList.toggle('scroll-away-from-top', !atTop && scrollable);
135+
sidebar.parentElement.classList.toggle('scroll-away-from-bottom', !atBottom && scrollable);
136+
}
137+
111138
}

resources/sass/_layout.scss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,12 @@ body.flexbox {
389389
.tri-layout-right {
390390
grid-area: c;
391391
min-width: 0;
392+
position: relative;
392393
}
393394
.tri-layout-left {
394395
grid-area: a;
395396
min-width: 0;
397+
position: relative;
396398
}
397399

398400
@include mixins.larger-than(vars.$bp-xxl) {
@@ -523,4 +525,26 @@ body.flexbox {
523525
margin-inline-start: 0;
524526
margin-inline-end: 0;
525527
}
528+
}
529+
530+
/**
531+
* Scroll Indicators
532+
*/
533+
.scroll-away-from-top:before,
534+
.scroll-away-from-bottom:after {
535+
content: '';
536+
display: block;
537+
position: absolute;
538+
@include mixins.lightDark(color, #F2F2F2, #111);
539+
left: 0;
540+
top: 0;
541+
width: 100%;
542+
height: 50px;
543+
background: linear-gradient(to bottom, currentColor, transparent);
544+
z-index: 2;
545+
}
546+
.scroll-away-from-bottom:after {
547+
top: auto;
548+
bottom: 0;
549+
background: linear-gradient(to top, currentColor, transparent);
526550
}

resources/views/layouts/tri.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class="tri-layout-mobile-tab px-m py-m text-link active">
2828
<div refs="tri-layout@container" class="tri-layout-container" @yield('container-attrs') >
2929

3030
<div class="tri-layout-sides print-hidden">
31-
<div class="tri-layout-sides-content">
31+
<div refs="tri-layout@sidebar-scroll-container" class="tri-layout-sides-content">
3232
<div class="tri-layout-right print-hidden">
33-
<aside class="tri-layout-right-contents">
33+
<aside refs="tri-layout@sidebar-scroll-container" class="tri-layout-right-contents">
3434
@yield('right')
3535
</aside>
3636
</div>
3737

3838
<div class="tri-layout-left print-hidden" id="sidebar">
39-
<aside class="tri-layout-left-contents">
39+
<aside refs="tri-layout@sidebar-scroll-container" class="tri-layout-left-contents">
4040
@yield('left')
4141
</aside>
4242
</div>

0 commit comments

Comments
 (0)