Skip to content

Commit f78d06c

Browse files
committed
improve scrolling
1 parent 5cc8b75 commit f78d06c

File tree

6 files changed

+131
-138
lines changed

6 files changed

+131
-138
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ import { Tooltip } from '~stackable/components'
1919
/**
2020
* WordPress dependencies.
2121
*/
22-
import { forwardRef, useState } from '@wordpress/element'
22+
import { useState, useRef } from '@wordpress/element'
2323
import { Dashicon, Spinner } from '@wordpress/components'
2424
import { __ } from '@wordpress/i18n'
2525

26-
const DesignLibraryListItem = forwardRef( ( props, ref ) => {
26+
const DesignLibraryListItem = props => {
2727
const {
28-
label,
29-
plan,
30-
selectedNum = false,
31-
selectedData = null,
32-
previewSize,
33-
previewProps,
3428
selectedTab,
29+
plan, label,
30+
selectedNum,
31+
selectedData,
3532
isMultiSelectBusy,
33+
shouldRender,
3634
} = props
3735

3836
const presetMarks = usePresetControls( 'spacingSizes' )?.getPresetMarks() || null
@@ -41,17 +39,16 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
4139

4240
const [ isLoading, setIsLoading ] = useState( true )
4341

44-
const { hostRef, shadowRoot } = useShadowRoot()
42+
const { hostRef, shadowRoot } = useShadowRoot( shouldRender )
43+
44+
const ref = useRef( null )
4545

4646
const {
4747
blocks, enableBackground,
4848
shadowBodySizeRef, blocksForSubstitutionRef,
49-
onClickDesign,
50-
} = usePreviewRenderer(
51-
previewProps, previewSize, plan, spacingSize,
52-
selectedTab, selectedNum, selectedData,
53-
ref, hostRef, shadowRoot, setIsLoading,
54-
)
49+
previewSize, cardHeight, onClickDesign,
50+
} = usePreviewRenderer( props, shouldRender, spacingSize,
51+
ref, hostRef, shadowRoot, setIsLoading )
5552

5653
const {
5754
onMouseOut, onMouseOver, onMouseDown,
@@ -66,6 +63,15 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
6663
: ( enableBackground ? previewSize.heightBackground : previewSize.heightNoBackground )
6764
}
6865

66+
const getCardHeight = () => {
67+
const key = props.enableBackground ? 'background' : 'noBackground'
68+
return cardHeight?.[ key ] || props.selectedTab === 'pages' ? 413 : 250
69+
}
70+
71+
if ( ! shouldRender && ! props.selectedNum ) {
72+
return <div style={ { height: `${ getCardHeight() }px` } } />
73+
}
74+
6975
const mainClasses = classnames( [
7076
'ugb-design-library-item',
7177
'ugb-design-library-item--toggle',
@@ -155,7 +161,7 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
155161
</footer>
156162
</button>
157163
)
158-
} )
164+
}
159165

160166
DesignLibraryListItem.defaultProps = {
161167
designId: '',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
}
234234

235235
&.stk-design-library__item-pages .stk-spinner-container {
236-
height: 400px;
236+
height: 343px;
237237
display: flex;
238238
.components-spinner {
239239
margin: auto;

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

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DesignLibraryList = props => {
2626
onSelectMulti,
2727
selectedDesigns = [],
2828
selectedDesignData = [],
29+
selectedTab,
2930
} = props
3031
const containerRef = useRef( null )
3132

@@ -45,7 +46,7 @@ const DesignLibraryList = props => {
4546
{ isBusy && <Spinner style={ { display: 'block', margin: '0 auto' } } /> }
4647
{ ! isBusy && <>
4748
<div className={ listClasses }>
48-
{ ( designs || [] ).map( ( design, i ) => {
49+
{ ( designs || [] ).map( design => {
4950
const selectedNum = selectedDesigns.indexOf( design.id || design.designId ) + 1
5051
const selectedData = selectedNum ? selectedDesignData[ selectedNum - 1 ] : null
5152

@@ -61,14 +62,13 @@ const DesignLibraryList = props => {
6162

6263
return (
6364
<DesignLibraryItem
64-
key={ i }
65+
key={ design.id || design.designId }
6566
plan={ design.plan }
6667
label={ design.label || design.title }
67-
previewProps={ previewProps }
6868
selectedNum={ selectedNum }
6969
selectedData={ selectedData }
70-
selectedTab={ props.selectedTab }
71-
designKey={ i }
70+
selectedTab={ selectedTab }
71+
{ ...previewProps }
7272
/>
7373
)
7474
} ) }
@@ -91,22 +91,8 @@ DesignLibraryList.defaultProps = {
9191
export default DesignLibraryList
9292

9393
const DesignLibraryItem = props => {
94-
const {
95-
previewProps: _previewProps, ...propsToPass
96-
} = props
97-
9894
const wrapperRef = useRef( null )
99-
const itemRef = useRef( null )
100-
const [ cardHeight, setCardHeight ] = useState( {} )
101-
const [ previewSize, setPreviewSize ] = useState( {} )
102-
const [ shouldRender, setShouldRender ] = useState( props.designKey < 9 )
103-
104-
const previewProps = {
105-
..._previewProps,
106-
setPreviewSize: previewSize => setPreviewSize( previewSize ),
107-
setCardHeight: height => setCardHeight( height ),
108-
cardHeight,
109-
}
95+
const [ shouldRender, setShouldRender ] = useState( false )
11096

11197
useEffect( () => {
11298
const rootEl = document.querySelector( '.ugb-modal-design-library__designs' )
@@ -121,31 +107,17 @@ const DesignLibraryItem = props => {
121107
} )
122108
}, {
123109
root: rootEl,
124-
rootMargin: '500px',
110+
rootMargin: '500px 0px',
125111
threshold: 0,
126112
} )
127113

128114
observer.observe( wrapperRef.current )
129115
return () => observer.disconnect()
130116
}, [] )
131117

132-
const getCardHeight = () => {
133-
const key = _previewProps.enableBackground ? 'background' : 'noBackground'
134-
return props.selectedTab === 'pages' ? 472 : cardHeight?.[ key ] || 250
135-
}
136-
137118
return (
138119
<div ref={ wrapperRef }>
139-
{ ! shouldRender && ! props.selectedNum ? (
140-
<div ref={ itemRef } style={ { height: `${ getCardHeight() }px` } } />
141-
) : (
142-
<DesignLibraryListItem
143-
ref={ itemRef }
144-
previewSize={ previewSize }
145-
previewProps={ previewProps }
146-
{ ...propsToPass }
147-
/>
148-
) }
120+
<DesignLibraryListItem { ...props } shouldRender={ shouldRender } />
149121
</div>
150122
)
151123
}

0 commit comments

Comments
 (0)