Skip to content

Commit 4d0b3de

Browse files
committed
show spinner
1 parent 03079c4 commit 4d0b3de

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/components/design-library-list/design-library-list-item.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ const DesignLibraryListItem = props => {
5656
} = useAutoScroll( hostRef, shadowBodySizeRef, selectedTab )
5757

5858
const getDesignPreviewSize = () => {
59-
if ( ! shadowRoot || isLoading ) {
60-
return 0
61-
}
62-
6359
return selectedNum && selectedData ? selectedData.selectedPreviewSize.preview
6460
: ( enableBackground ? previewSize.heightBackground : previewSize.heightNoBackground )
6561
}
@@ -109,21 +105,22 @@ const DesignLibraryListItem = props => {
109105
) }
110106
{ isLoading && <div className="stk-spinner-container"><Spinner /></div> }
111107
<div
112-
className="stk-block-design__host-container"
108+
className={ `stk-block-design__host-container ${ ! shadowRoot || isLoading ? 'stk-is-loading' : 'stk-show' }` }
113109
style={ {
114110
transform: `scale(${ selectedNum && selectedData ? selectedData.selectedPreviewSize.scale : previewSize?.scale })`,
115111
transformOrigin: 'top left',
116112
height: getDesignPreviewSize(),
117113
} }
118114
>
119115
<div className="stk-block-design__host" ref={ hostRef }>
120-
{ shadowRoot && ! isLoading && <DesignPreview
116+
{ shadowRoot && <DesignPreview
121117
blocks={ blocks }
122118
shadowRoot={ shadowRoot }
123119
selectedTab={ selectedTab }
124120
designIndex={ props.designIndex }
125121
onMouseDown={ onMouseDown }
126122
updateShadowBodySize={ updateShadowBodySize }
123+
setIsLoading={ setIsLoading }
127124
/> }
128125
</div>
129126
</div>

src/components/design-library-list/design-preview.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const DesignPreview = ( {
1616
designIndex,
1717
onMouseDown = NOOP,
1818
updateShadowBodySize = NOOP,
19+
setIsLoading,
1920
} ) => {
2021
const ref = useRef( null )
2122
const wrapperRef = useRef( null )
@@ -96,10 +97,15 @@ export const DesignPreview = ( {
9697
return
9798
}
9899

100+
setIsLoading( true )
101+
99102
requestAnimationFrame( () => {
100103
ric( () => {
101104
wrapper.innerHTML = sanitizedHTML
102105
updateShadowBodySize()
106+
requestAnimationFrame( () => {
107+
ric( () => setIsLoading( false ) )
108+
} )
103109
} )
104110
} )
105111
}, [ blocks ] )

src/components/design-library-list/editor.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@
188188

189189
.stk-block-design__host-container {
190190
position: relative;
191+
transition: opacity 0.3s cubic-bezier(0.2, 0.6, 0.4, 1);
192+
will-change: opacity;
193+
&.stk-is-loading {
194+
opacity: 0;
195+
}
196+
&.stk-show {
197+
opacity: 1;
198+
}
191199
}
192200

193201
.stk--design-preview-large {
@@ -233,7 +241,7 @@
233241
}
234242

235243
&.stk-design-library__item-pages .stk-spinner-container {
236-
height: 343px;
244+
height: 100%;
237245
display: flex;
238246
.components-spinner {
239247
margin: auto;

0 commit comments

Comments
 (0)