Skip to content

Commit a5ff6d2

Browse files
committed
feat: hide adminbar on small screens and simplify navigation
1 parent 6f70415 commit a5ff6d2

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

src/my-account/v1/_navigation.scss

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,34 @@
33
*/
44

55
.newspack-my-account {
6+
&--logged-in.admin-bar {
7+
html:has(&) {
8+
margin-top: 0 !important;
9+
10+
@media ( min-width: 601px ) {
11+
margin-top: var(--wp-admin--admin-bar--height) !important;
12+
}
13+
}
14+
15+
#wpadminbar {
16+
display: none;
17+
18+
@media ( min-width: 601px ) {
19+
display: block;
20+
}
21+
}
22+
}
623
.woocommerce-MyAccount-navigation,
724
.woocommerce-MyAccount-content {
825
transition: transform 125ms ease-in-out;
926
}
1027
&.navigation-open {
1128
overflow: hidden;
1229

30+
@media ( min-width: 768px ) {
31+
overflow: visible;
32+
}
33+
1334
.woocommerce-MyAccount-navigation,
1435
.woocommerce-MyAccount-content {
1536
transform: translateX(-100vw);
@@ -105,7 +126,7 @@
105126
width: 301px;
106127
}
107128
@at-root .admin-bar#{&} {
108-
top: calc(var(--wp-admin--admin-bar--height) - var(--wp-admin--admin-bar--scroll, var(--wp-admin--admin-bar--height)));
129+
top: 0;
109130

110131
@media ( min-width: 601px ) {
111132
top: var(--wp-admin--admin-bar--height);

src/my-account/v1/navigation.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,6 @@
88
import { domReady } from '../../utils';
99

1010
domReady( () => {
11-
const adminBar = document.getElementById( 'wpadminbar' );
12-
13-
const updateAdminBarScrolled = () => {
14-
const hasAdminBar = !! adminBar;
15-
const isSmallScreen = window.innerWidth < 601;
16-
const adminBarHeight = hasAdminBar ? adminBar.offsetHeight : 0;
17-
const scrollTop = Math.max( window.scrollY, document.documentElement.scrollTop );
18-
const adminBarScroll = hasAdminBar && isSmallScreen ? Math.min( scrollTop, adminBarHeight ) : 0;
19-
20-
document.body.style.setProperty( '--wp-admin--admin-bar--scroll', `${ adminBarScroll }px` );
21-
};
22-
23-
const debounce = ( callback, wait = 100 ) => {
24-
let timeoutId;
25-
26-
return ( ...args ) => {
27-
window.clearTimeout( timeoutId );
28-
timeoutId = window.setTimeout( () => callback( ...args ), wait );
29-
};
30-
};
31-
32-
const handleScrollOrResize = debounce( updateAdminBarScrolled, 100 );
33-
34-
window.addEventListener( 'scroll', handleScrollOrResize );
35-
window.addEventListener( 'resize', handleScrollOrResize );
36-
3711
// Open and close navigation menu.
3812
const openNavigationButton = document.querySelector( '.newspack-my-account__navigation-topbar__button .newspack-ui__button' );
3913
let setButtonState;
@@ -51,7 +25,6 @@ domReady( () => {
5125
openNavigationButton.addEventListener( 'click', () => {
5226
const isOpen = document.body.classList.toggle( 'navigation-open' );
5327
setButtonState( isOpen );
54-
updateAdminBarScrolled();
5528
} );
5629
}
5730

@@ -62,9 +35,6 @@ domReady( () => {
6235
if ( setButtonState ) {
6336
setButtonState( false );
6437
}
65-
updateAdminBarScrolled();
6638
}
6739
} );
68-
69-
updateAdminBarScrolled();
7040
} );

0 commit comments

Comments
 (0)