Skip to content

Commit

Permalink
Make top margin of container configurable via theme.json
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwoodnz committed Oct 19, 2023
1 parent 1c4013e commit 7930f56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion mu-plugins/blocks/sidebar-container/postcss/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* Right offset should be "edge spacing" at minimum, otherwise calculate it to be centered. */
right: max(var(--wp--preset--spacing--edge-space), calc((100% - var(--wp--style--global--wide-size)) / 2));
width: var(--local--block-end-sidebar--width);
margin-top: var(--wp--preset--spacing--edge-space) !important;
margin-top: var(--wp--custom--wporg-sidebar-container--spacing--margin--top) !important;

&.is-fixed-sidebar {
position: fixed;
Expand All @@ -44,3 +44,8 @@
scroll-margin-top: var(--wp-local-header-offset, 0);
}
}

/* Set up the custom properties. These can be overridden by settings in theme.json. */
:where(body) {
--wp--custom--wporg-sidebar-container--spacing--margin--top: var(--wp--preset--spacing--edge-space);
}
4 changes: 2 additions & 2 deletions mu-plugins/blocks/sidebar-container/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function onScroll() {
const mainEl = document.getElementById( 'wp--skip-link--target' );
const footerStart = mainEl.offsetTop + mainEl.offsetHeight;

const gap = getCustomPropValue( '--wp--preset--spacing--edge-space' );
const gap = parseInt( window.getComputedStyle( sidebarContainer ).marginTop, 10 );
const viewportYOffset = window
.getComputedStyle( document.documentElement )
.getPropertyValue( 'margin-top' )
Expand Down Expand Up @@ -71,7 +71,7 @@ function onScroll() {

function isSidebarWithinViewport( container ) {
// Margin offset from the top of the sidebar.
const gap = getCustomPropValue( '--wp--preset--spacing--edge-space' );
const gap = parseInt( window.getComputedStyle( container ).marginTop, 10 );
// Usable viewport height.
const viewHeight = window.innerHeight - FIXED_HEADER_HEIGHT;
// Get the height of the sidebar, plus the top margin and 50px for the
Expand Down

0 comments on commit 7930f56

Please sign in to comment.