Skip to content

Commit 374218f

Browse files
committed
feat(repeater-native): add empty content
1 parent e19655a commit 374218f

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

packages/pluggableWidgets/repeater-native/src/Repeater.editorConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ export function getPreview(values: RepeaterPreviewProps, isDarkMode: boolean): S
2828
type: "DropZone",
2929
placeholder: "Content",
3030
property: values.content
31+
},
32+
{
33+
type: "Container",
34+
borders: true,
35+
children: [
36+
{
37+
type: "DropZone",
38+
placeholder: "Content when Empty",
39+
property: values.contentEmpty
40+
}
41+
]
3142
}
3243
]
3344
};

packages/pluggableWidgets/repeater-native/src/Repeater.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ import { mergeNativeStyles } from "@mendix/pluggable-widgets-tools";
77

88
export function Repeater(props: RepeaterProps<RepeaterStyle>): ReactElement {
99
const styles = mergeNativeStyles(defaultRepeaterStyle, props.style);
10-
if (
11-
props.datasource.status === ValueStatus.Loading ||
12-
!props.datasource.items ||
13-
props.datasource.items.length === 0
14-
) {
10+
if (props.datasource.status === ValueStatus.Loading || !props.datasource.items) {
1511
return <View />;
1612
}
17-
13+
const contentEmpty = props.datasource.items.length === 0 ? props.contentEmpty : null;
1814
return (
1915
<View style={styles.container}>
20-
{props.datasource.items?.map((item, index) => (
16+
{props.datasource.items.map((item, index) => (
2117
<Fragment key={`item_${index}`}>{props.content.get(item)}</Fragment>
2218
))}
19+
{contentEmpty}
2320
</View>
2421
);
2522
}

packages/pluggableWidgets/repeater-native/src/Repeater.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<property key="content" type="widgets" dataSource="datasource">
1515
<caption>Content</caption>
1616
<description/>
17+
</property>
18+
<property key="contentEmpty" type="widgets" required="false">
19+
<caption>Content empty</caption>
20+
<description/>
1721
</property>
1822
</propertyGroup>
1923
<propertyGroup caption="Common">

packages/pluggableWidgets/repeater-native/typings/RepeaterProps.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* WARNING: All changes made to this file will be overwritten
44
* @author Mendix UI Content Team
55
*/
6-
import { ComponentType, CSSProperties } from "react";
6+
import { ComponentType, CSSProperties, ReactNode } from "react";
77
import { ListValue, ListWidgetValue } from "mendix";
88

99
export interface RepeaterProps<Style> {
1010
name: string;
1111
style: Style[];
1212
datasource: ListValue;
1313
content: ListWidgetValue;
14+
contentEmpty?: ReactNode;
1415
}
1516

1617
export interface RepeaterPreviewProps {
@@ -20,4 +21,5 @@ export interface RepeaterPreviewProps {
2021
readOnly: boolean;
2122
datasource: {} | { type: string } | null;
2223
content: { widgetCount: number; renderer: ComponentType<{ caption?: string }> };
24+
contentEmpty: { widgetCount: number; renderer: ComponentType<{ caption?: string }> };
2325
}

0 commit comments

Comments
 (0)