Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit fbad2ee

Browse files
ryelleAljullu
andauthored
Product Categories List: add a placeholder on save (#650)
* Product Categories List: add a placeholder on save This is saved to the database so that we have a placeholder view while waiting for the categories component to render. * Use `classList.remove` for better readability Co-Authored-By: Albert Juhé Lluveras <[email protected]>
1 parent cc6277f commit fbad2ee

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

assets/js/blocks/product-categories/frontend.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if ( containers.length ) {
2222
isDropdown: data.isDropdown === 'true',
2323
isHierarchical: data.isHierarchical === 'true',
2424
};
25+
el.classList.remove( 'is-loading' );
2526

2627
render( <Block attributes={ attributes } />, el );
2728
} );

assets/js/blocks/product-categories/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,31 @@ registerBlockType( 'woocommerce/product-categories', {
8181
*/
8282
save( { attributes } ) {
8383
const { hasCount, hasEmpty, isDropdown, isHierarchical } = attributes;
84-
const props = {};
84+
const data = {};
8585
if ( hasCount ) {
86-
props[ 'data-has-count' ] = true;
86+
data[ 'data-has-count' ] = true;
8787
}
8888
if ( hasEmpty ) {
89-
props[ 'data-has-empty' ] = true;
89+
data[ 'data-has-empty' ] = true;
9090
}
9191
if ( isDropdown ) {
92-
props[ 'data-is-dropdown' ] = true;
92+
data[ 'data-is-dropdown' ] = true;
9393
}
9494
if ( isHierarchical ) {
95-
props[ 'data-is-hierarchical' ] = true;
95+
data[ 'data-is-hierarchical' ] = true;
9696
}
97-
return <div { ...props }>LOADING</div>;
97+
return (
98+
<div className="is-loading" { ...data }>
99+
{ isDropdown ? (
100+
<span aria-hidden className="wc-block-product-categories__placeholder" />
101+
) : (
102+
<ul aria-hidden>
103+
<li><span className="wc-block-product-categories__placeholder" /></li>
104+
<li><span className="wc-block-product-categories__placeholder" /></li>
105+
<li><span className="wc-block-product-categories__placeholder" /></li>
106+
</ul>
107+
) }
108+
</div>
109+
);
98110
},
99111
} );

assets/js/blocks/product-categories/style.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@
99
margin-right: 0.5em;
1010
}
1111
}
12+
13+
.wp-block-woocommerce-product-categories.is-loading .wc-block-product-categories__placeholder {
14+
display: inline-block;
15+
height: 1em;
16+
width: 50%;
17+
min-width: 200px;
18+
background: currentColor;
19+
opacity: 0.2;
20+
}

0 commit comments

Comments
 (0)