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

Navigation: Remove blobs that look like a loading state #37099

Merged
merged 4 commits into from
Jan 28, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { Icon, search } from '@wordpress/icons';
import { Icon, navigation } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';

const PlaceholderPreview = ( { isLoading } ) => {
return (
<ul
<div
className={ classnames(
'wp-block-navigation-placeholder__preview',
'wp-block-navigation__container',
{ 'is-loading': isLoading }
) }
>
<li className="wp-block-navigation-item">&#8203;</li>
<li className="wp-block-navigation-item">&#8203;</li>
<li className="wp-block-navigation-item">&#8203;</li>
<li className="wp-block-navigation-placeholder__preview-search-icon">
<Icon icon={ search } />
</li>
</ul>
<div className="wp-block-navigation-placeholder__actions__indicator">
<Icon icon={ navigation } />
{ __( 'Navigation' ) }
</div>
</div>
);
};

Expand Down
161 changes: 68 additions & 93 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,23 @@ $color-control-label-height: 20px;
justify-content: flex-start;
}


/**
* Setup state
*/

// Loading state.
@keyframes loadingpulse {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
// Unstyle some inherited placeholder component styles.
.components-placeholder.wp-block-navigation-placeholder {
outline: none;
Expand All @@ -215,118 +228,79 @@ $color-control-label-height: 20px;
// For the placeholder indicators to colorize correctly, colors need to be inherited unless selected.
color: inherit;

.is-selected & {
.wp-block-navigation.is-selected & {
color: $gray-900;
}
}

// Spinner.
.wp-block-navigation-placeholder .components-spinner {
margin-top: -4px;
margin-left: 4px;
vertical-align: middle;
margin-right: 7px;
}

@keyframes loadingpulse {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}

// Unselected state.
.wp-block-navigation-placeholder__preview {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: nowrap;
width: 100%;
overflow: hidden;

&.is-loading {
animation: loadingpulse 1s linear infinite;
animation-delay: 0.5s; // avoid animating for fast network responses
}
min-width: $grid-unit-10 * 12;
font-size: $default-font-size;
font-family: $default-font;

// Style skeleton elements to mostly match the metrics of actual menu items.
// Needs specificity.
.wp-block-navigation-item.wp-block-navigation-item {
position: relative;
min-width: 72px;

&::before {
display: block;
content: "";
border-radius: $radius-block-ui;
background: currentColor;
height: $grid-unit-20;
width: 100%;
}
.wp-block-navigation.is-selected & {
display: none;
}

.wp-block-navigation-placeholder__preview-search-icon {
height: $icon-size;
svg {
fill: currentColor;
}
}
// Draw the dashed outline.
// By setting the dashed border to currentColor, we ensure it's visible
// against any background color.
color: currentColor;
background: transparent;
&::before {
content: "";
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: $border-width dashed currentColor;
opacity: 0.4;
pointer-events: none;

.wp-block-navigation-item.wp-block-navigation-item,
.wp-block-navigation-placeholder__preview-search-icon {
opacity: 0.3;
// Inherit border radius from style variations.
border-radius: inherit;
}

&:not(.is-loading) {
// Don't show the preview boxes for an empty nav block,
// but be technically present to help size the empty state.
.wp-block-navigation.is-selected & {
display: flex;
opacity: 0;
width: 0;
overflow: hidden;
flex-wrap: nowrap;
flex: 0;
}

// Hide entirely when vertical.
.wp-block-navigation.is-selected .is-small &,
.wp-block-navigation.is-selected .is-medium & {
display: none;
}
> svg {
fill: currentColor;
opacity: 0.4;
}
}

// Selected state.
.wp-block-navigation-placeholder__preview,
.wp-block-navigation-placeholder__controls {
padding: ($grid-unit-15 * 0.5) $grid-unit-10;
flex-direction: row;
align-items: center;
}

.wp-block-navigation-placeholder__controls {
border-radius: $radius-block-ui;
background-color: $white;
box-shadow: inset 0 0 0 $border-width $gray-900;
flex-direction: row;
align-items: center;
display: none;
position: relative;
z-index: 1;
padding: $grid-unit-05 $grid-unit-10;

// Show when selected.
.wp-block-navigation.is-selected & {
display: flex;
}

// If an ancestor has a text-decoration property applied, it is inherited regardless of
// the specificity of a child element. Only pulling the child out of the flow fixes it.
// See also https://www.w3.org/TR/CSS21/text.html#propdef-text-decoration.
float: left;
width: 100%;

// Show when selected.
.wp-block-navigation.is-selected & {
display: flex;
}

// Hide a few elements in medium size placeholders.
// @todo: part of the code here will be irrelevant if https://github.com/WordPress/gutenberg/pull/36775 lands.
// Show stacked for the vertical navigation, or small placeholders.
.is-small &,
.is-medium & {
.wp-block-navigation-placeholder__actions__indicator,
.wp-block-navigation-placeholder__actions__indicator + hr,
Expand All @@ -352,22 +326,23 @@ $color-control-label-height: 20px;
margin-right: $grid-unit-15;
height: $button-size; // Prevents jumpiness.
}
}

// Block title
.wp-block-navigation-placeholder__actions__indicator {
display: flex;
padding: 0 ($grid-unit-15 * 0.5) 0 0;
align-items: center;
justify-content: flex-start;
line-height: 0;
min-height: $button-size;
// Block title
.wp-block-navigation-placeholder__actions__indicator {
display: flex;
padding: 0 ($grid-unit-15 * 0.5) 0 0;
align-items: center;
justify-content: flex-start;
line-height: 0;
min-height: $button-size;

// Line up with the icon in the toolbar.
margin-left: $grid-unit-05;
// Line up with the icon in the toolbar.
margin-left: $grid-unit-05;

svg {
margin-right: $grid-unit-05;
}
svg {
margin-right: $grid-unit-05;
fill: currentColor;
}
}

Expand Down