Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] Enable customising the Nav block breakpoint #45274

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
},
"mobileBreakpoint": {
"type": "string",
"default": "782px"
}
},
"providesContext": {
Expand Down
13 changes: 13 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalInputControl as InputControl,
Button,
Spinner,
} from '@wordpress/components';
Expand Down Expand Up @@ -94,6 +95,7 @@ function Navigation( {
} = {},
hasIcon,
icon = 'handle',
mobileBreakpoint,
} = attributes;

const ref = attributes.ref;
Expand Down Expand Up @@ -561,6 +563,15 @@ function Navigation( {
label={ __( 'Always' ) }
/>
</ToggleGroupControl>

<InputControl
value={ mobileBreakpoint }
onChange={ ( nextValue ) =>
setAttributes( {
mobileBreakpoint: nextValue,
} )
}
/>
{ hasSubmenus && (
<>
<h3>{ __( 'Submenus' ) }</h3>
Expand Down Expand Up @@ -701,6 +712,7 @@ function Navigation( {
isHiddenByDefault={ 'always' === overlayMenu }
overlayBackgroundColor={ overlayBackgroundColor }
overlayTextColor={ overlayTextColor }
mobileBreakpoint={ mobileBreakpoint }
>
<UnsavedInnerBlocks
blocks={ uncontrolledInnerBlocks }
Expand Down Expand Up @@ -937,6 +949,7 @@ function Navigation( {
isHiddenByDefault={ 'always' === overlayMenu }
overlayBackgroundColor={ overlayBackgroundColor }
overlayTextColor={ overlayTextColor }
mobileBreakpoint={ mobileBreakpoint }
>
{ isEntityAvailable && (
<NavigationInnerBlocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { close, Icon } from '@wordpress/icons';
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { getColorClassName } from '@wordpress/block-editor';
import { useMediaQuery } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -27,7 +28,14 @@ export default function ResponsiveWrapper( {
overlayTextColor,
hasIcon,
icon,
mobileBreakpoint,
} ) {
const isMobileBreakPoint = useMediaQuery(
`(max-width: ${ mobileBreakpoint })`
);

console.log( { mobileBreakpoint, isMobileBreakPoint } );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove


if ( ! isResponsive ) {
return children;
}
Expand All @@ -48,6 +56,7 @@ export default function ResponsiveWrapper( {
) ]: !! overlayBackgroundColor?.slug,
'is-menu-open': isOpen,
'hidden-by-default': isHiddenByDefault,
'is-mobile-breakpoint': isMobileBreakPoint,
}
);

Expand All @@ -61,7 +70,10 @@ export default function ResponsiveWrapper( {

const openButtonClasses = classnames(
'wp-block-navigation__responsive-container-open',
{ 'always-shown': isHiddenByDefault }
{
'always-shown': isHiddenByDefault,
'is-mobile-breakpoint': isMobileBreakPoint,
}
);

const modalId = `${ id }-modal`;
Expand Down
20 changes: 14 additions & 6 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ $color-control-label-height: 20px;
// These needs extra specificity in the editor.
.wp-block-navigation__responsive-container:not(.is-menu-open) {
.components-button.wp-block-navigation__responsive-container-close {
@include break-small {
// @include break-small {
&.is-mobile-breakpoint {
display: none;
}
}
Expand All @@ -448,21 +449,26 @@ $color-control-label-height: 20px;
$admin-bar-height-big + $header-height + $block-toolbar-height +
$border-width;

@include break-medium() {
// @include break-medium() {
&.is-mobile-breakpoint {
top: $admin-bar-height + $header-height + $border-width;
}


// Navigation sidebar rules.
@include break-medium() {
// @include break-medium() {
&.is-mobile-breakpoint {
left: $admin-sidebar-width-collapsed;
}

@include break-large() {
left: $admin-sidebar-width;
}
}

.has-fixed-toolbar .wp-block-navigation__responsive-container.is-menu-open {
@include break-medium() {
// @include break-medium() {
&.is-mobile-breakpoint {
top:
$admin-bar-height + $header-height + $block-toolbar-height +
$border-width;
Expand All @@ -488,13 +494,15 @@ $color-control-label-height: 20px;
$admin-bar-height-big + $header-height + $block-toolbar-height +
$border-width;

@include break-medium() {
// @include break-medium() {
&.is-mobile-breakpoint {
top: $header-height + $border-width;
}
}

.has-fixed-toolbar .wp-block-navigation__responsive-container.is-menu-open {
@include break-medium() {
// @include break-medium() {
&.is-mobile-breakpoint {
top: $header-height + $block-toolbar-height + $border-width;
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// Size of burger and close icons.
$navigation-icon-size: 24px;



.wp-block-navigation {
position: relative;

Expand Down Expand Up @@ -591,7 +593,8 @@ button.wp-block-navigation-item__content {
}
}

@include break-small() {
// @include break-small() {
&:not(.is-mobile-breakpoint) {
&:not(.hidden-by-default) {
&:not(.is-menu-open) {
display: block;
Expand Down Expand Up @@ -654,7 +657,8 @@ button.wp-block-navigation-item__content {
display: flex;

&:not(.always-shown) {
@include break-small {
// @include break-small {
&:not(.is-mobile-breakpoint) {
display: none;
}
}
Expand Down