@@ -4,24 +4,38 @@ import { withComponentFactory } from '../enhancers/withComponentFactory';
4
4
import { ComponentRendering , HtmlElementRendering } from '@sitecore-jss/sitecore-jss' ;
5
5
6
6
export interface PlaceholderComponentProps extends PlaceholderProps {
7
+ /**
8
+ * Render props function that is called when the placeholder contains no content components.
9
+ * Can be used to wrap the Sitecore EE empty placeholder markup in something that's visually correct
10
+ */
11
+ renderEmpty ?: (
12
+ components : React . ReactNode [ ]
13
+ ) => React . ComponentClass < any > | React . SFC < any > | React . ReactNode ;
7
14
/**
8
15
* Render props function that enables control over the rendering of the components in the placeholder.
9
16
* Useful for techniques like wrapping each child in a wrapper component.
10
17
*/
11
- render ?: ( components : React . ReactNode [ ] , data : ( ComponentRendering | HtmlElementRendering ) [ ] , props : PlaceholderProps ) => React . ComponentClass < any > | React . SFC < any > ;
18
+ render ?: (
19
+ components : React . ReactNode [ ] ,
20
+ data : ( ComponentRendering | HtmlElementRendering ) [ ] ,
21
+ props : PlaceholderProps
22
+ ) => React . ComponentClass < any > | React . SFC < any > | React . ReactNode ;
12
23
13
24
/**
14
25
* Render props function that is called for each non-system component added to the placeholder.
15
26
* Mutually exclusive with `render`. System components added during Experience Editor are automatically rendered as-is.
16
27
*/
17
- renderEach ?: ( components : React . ReactNode [ ] , data : ( ComponentRendering | HtmlElementRendering ) [ ] , props : PlaceholderProps ) => React . ComponentClass < any > | React . SFC < any > ;
28
+ renderEach ?: (
29
+ component : React . ReactNode ,
30
+ index : number
31
+ ) => React . ComponentClass < any > | React . SFC < any > | React . ReactNode ;
18
32
}
19
33
20
34
function isRawRendering ( rendering : HtmlElementRendering | ComponentRendering ) : rendering is HtmlElementRendering {
21
35
return ! ( rendering as ComponentRendering ) . componentName && ( rendering as HtmlElementRendering ) . name !== undefined ;
22
36
}
23
37
24
- class PlaceholderComponent extends PlaceholderCommon {
38
+ class PlaceholderComponent extends PlaceholderCommon < PlaceholderComponentProps > {
25
39
static propTypes = PlaceholderCommon . propTypes ;
26
40
27
41
constructor ( props : PlaceholderComponentProps ) {
@@ -48,19 +62,21 @@ class PlaceholderComponent extends PlaceholderCommon {
48
62
const renderingData = childProps . rendering ;
49
63
50
64
const placeholderData = PlaceholderCommon . getPlaceholderDataFromRenderingData ( renderingData , this . props . name ) ;
51
- const components = this . getComponentsForRenderingData ( placeholderData ) ;
65
+ const components = this . getComponentsForRenderingData ( placeholderData ) ;
52
66
53
67
if ( this . props . renderEmpty && placeholderData . every ( ( rendering : ComponentRendering | HtmlElementRendering ) => isRawRendering ( rendering ) ) ) {
54
- return this . props . renderEmpty ( components , placeholderData , childProps ) ;
68
+ return this . props . renderEmpty ( components ) ;
55
69
} else if ( this . props . render ) {
56
70
return this . props . render ( components , placeholderData , childProps ) ;
57
71
} else if ( this . props . renderEach ) {
72
+ const renderEach = this . props . renderEach ;
73
+
58
74
return components . map ( ( component , index ) => {
59
75
if ( component && component . props && component . props . type === 'text/sitecore' ) {
60
76
return component ;
61
77
}
62
78
63
- return this . props . renderEach ( component , index ) ;
79
+ return renderEach ( component , index ) ;
64
80
} ) ;
65
81
} else {
66
82
return components ;
0 commit comments