Skip to content

Commit

Permalink
Custom body scrollbar + disable body scroll when overlay or image vie…
Browse files Browse the repository at this point in the history
…wer opened (#897)
  • Loading branch information
MaxKotlan authored Feb 18, 2022
1 parent 6a69e02 commit 56f8d8b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ui/component/app/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ function App(props: Props) {
document.documentElement.setAttribute('theme', theme);
}, [theme]);

useEffect(() => {
// $FlowFixMe
document.body.style.overflowY = currentModal ? 'hidden' : '';
}, [currentModal]);

useEffect(() => {
if (hasMyChannels && !hasActiveChannelClaim) {
setActiveChannelIfNotSet();
Expand Down
8 changes: 7 additions & 1 deletion ui/component/sideNavigation/view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function SideNavigation(props: Props) {

const showMicroMenu = !sidebarOpen && !menuCanCloseCompletely;
const showPushMenu = sidebarOpen && !menuCanCloseCompletely;
const showOverlay = isAbsolute && sidebarOpen;

const showSubscriptionSection = shouldRenderLargeMenu && isPersonalized && subscriptions && subscriptions.length > 0;
const showTagSection = sidebarOpen && isPersonalized && followedTags && followedTags.length;
Expand Down Expand Up @@ -362,6 +363,11 @@ function SideNavigation(props: Props) {
return null;
}

React.useEffect(() => {
// $FlowFixMe
document.body.style.overflowY = showOverlay ? 'hidden' : '';
}, [showOverlay]);

React.useEffect(() => {
if (purchaseSuccess) {
setPulseLibrary(true);
Expand Down Expand Up @@ -501,7 +507,7 @@ function SideNavigation(props: Props) {
</nav>
<div
className={classnames('navigation__overlay', {
'navigation__overlay--active': isAbsolute && sidebarOpen,
'navigation__overlay--active': showOverlay,
})}
onClick={() => setSidebarOpen(false)}
/>
Expand Down
3 changes: 2 additions & 1 deletion ui/scss/component/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
z-index: 3; // Main content uses z-index: 1, other content uses z-index: 2, this ensures it always scrolls under the header
position: fixed;
top: 0;
width: 100%;
width: 100vw;
background-color: var(--color-header-background);
font-size: var(--font-body);
user-select: none;
Expand Down Expand Up @@ -137,6 +137,7 @@
height: var(--header-height);
padding: var(--spacing-s) var(--spacing-m);
flex-wrap: nowrap;
margin-right: var(--body-scrollbar-width);

.wunderbar__wrapper {
.wunderbar__input {
Expand Down
20 changes: 18 additions & 2 deletions ui/scss/init/_gui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ html {
}

body {
width: calc(100vw - var(--body-scrollbar-width));

font-size: 1em;
cursor: default;
line-height: 1.5;
Expand All @@ -33,11 +35,20 @@ body {
scrollbar-color: var(--color-scrollbar-thumb-bg) var(--color-scrollbar-track-bg);
}

body::-webkit-scrollbar {
width: var(--body-scrollbar-width);
height: 6px;
}

body *::-webkit-scrollbar {
width: 6px;
width: var(--scrollbar-width);
height: 6px;
}

body::-webkit-scrollbar-track {
background: var(--color-body-scrollbar-track-bg);
}

body *::-webkit-scrollbar-track {
background: var(--color-scrollbar-track-bg);
}
Expand All @@ -47,7 +58,12 @@ body *::-webkit-scrollbar-thumb {
// standard currently doesn't support it. Stick with square
// scrollbar for all browsers.
background-color: var(--color-scrollbar-thumb-bg);
border-radius: 4px;
border-radius: var(--scrollbar-radius);
}

body::-webkit-scrollbar-thumb {
background-color: var(--color-scrollbar-thumb-bg);
border-radius: var(--scrollbar-radius);
}

hr {
Expand Down
6 changes: 6 additions & 0 deletions ui/scss/init/_vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@
// Animations
--resizing-animation-function: ease-in;
--resizing-animation-timing: 180ms;

//Scrollbars
--body-scrollbar-width: 12px;
--scrollbar-width: 6px;
--scrollbar-radius: 0.5rem;
}

@media (max-width: $breakpoint-small) {
:root {
--font-body: 0.8rem;
--body-scrollbar-width: 0px;
}
}
1 change: 1 addition & 0 deletions ui/scss/themes/dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
// Scrollbar
--color-scrollbar-thumb-bg: rgba(255, 255, 255, 0.2);
--color-scrollbar-track-bg: transparent;
--color-body-scrollbar-track-bg: rgba(0, 0, 0, 0.5);

--background-shade: linear-gradient(-180deg, rgba(25, 25, 25, 0.2) 2%, #202020),
radial-gradient(circle at 50% 117%, rgba(25, 25, 25, 0.2) 0, #202020 100%);
Expand Down
1 change: 1 addition & 0 deletions ui/scss/themes/light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
// Scrollbar
--color-scrollbar-thumb-bg: rgba(0, 0, 0, 0.2);
--color-scrollbar-track-bg: transparent;
--color-body-scrollbar-track-bg: var(--color-header-button);

--background-shade: linear-gradient(-180deg, rgba(var(--color-background-base), 0.6) 2%, #f1f1f1),
radial-gradient(circle at 50% 217%, rgba(var(--color-background-base), 0.6) 0, #f8f8f8 100%);
Expand Down

0 comments on commit 56f8d8b

Please sign in to comment.