Skip to content

Commit ee3d178

Browse files
committed
fix preview of designs
1 parent 7044dab commit ee3d178

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
8787
const newCardHeight = { ...cardHeight }
8888
const cardRect = ref.current.getBoundingClientRect()
8989

90-
const cardWidth = cardRect.width // Get width of the card
91-
const scaleFactor = cardWidth > 0 ? cardWidth / 1200 : 1 // Divide by 1200, which is the width of preview in the shadow DOM
92-
newPreviewSize.scale = scaleFactor
93-
9490
const shadowBody = hostRef.current.shadowRoot.querySelector( 'body' )
9591
if ( shadowBody ) {
92+
const cardWidth = cardRect.width // Get width of the card
93+
const scaleFactor = cardWidth > 0 ? cardWidth / shadowBody.offsetWidth : 1 // Divide by 1200, which is the width of preview in the shadow DOM
94+
newPreviewSize.scale = scaleFactor
95+
9696
const _height = parseFloat( shadowBody.offsetHeight ) * scaleFactor // Also adjust the height
9797

9898
const heightKey = enableBackground ? 'heightBackground' : 'heightNoBackground'
@@ -127,7 +127,6 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
127127
previewRef.current.render( <DesignPreview
128128
blocks={ cleanedBlock }
129129
adjustScale={ adjustScale }
130-
prevEnableBackground={ prevEnableBackgroundRef.current }
131130
enableBackground={ enableBackground }
132131
designId={ designId }
133132
/> )
@@ -193,6 +192,7 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
193192
hostStyles.innerHTML = ! hasBackgroundTargetRef.current
194193
? `body > .stk-block-columns { padding: 75px; } body > .stk-block-background:not(.stk--no-padding) { padding: calc(75px + var(--stk-block-background-padding)); }`
195194
: `[stk-design-library__bg-target="true"] { padding: 25px; } [stk-design-library__bg-target="true"].stk-block-background:not(.stk--no-padding) { padding: calc(25px + var(--stk-block-background-padding)); }`
195+
hostStyles.innerHTML += `.stk-block-count-up__text:not(.stk--count-up-active) { opacity: 1; }`
196196
styleNodes.push( hostStyles )
197197

198198
styleNodes.forEach( node => {
@@ -212,7 +212,9 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
212212
}, [ content, containerScheme, backgroundScheme, enableBackground ] )
213213

214214
useEffect( () => {
215-
setTimeout( adjustScale, 50 )
215+
if ( selectedNum === 0 && content ) {
216+
setTimeout( adjustScale, 50 )
217+
}
216218
}, [ forceUpdate ] )
217219

218220
useEffect( () => {
@@ -307,13 +309,12 @@ DesignLibraryListItem.defaultProps = {
307309
export default DesignLibraryListItem
308310

309311
const DesignPreview = ( {
310-
blocks, adjustScale, prevEnableBackground, enableBackground,
312+
blocks, adjustScale, enableBackground,
311313
} ) => {
312314
useEffect( () => {
313-
if ( prevEnableBackground !== enableBackground ) {
314-
// Adjust scale if the background was toggled
315-
adjustScale()
316-
}
315+
// Adjust scale if the background was toggled
316+
adjustScale()
317+
setTimeout( adjustScale, 50 )
317318
}, [ blocks, enableBackground ] )
318319

319320
return (

0 commit comments

Comments
 (0)