Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repeater-native): add empty content #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export function getPreview(values: RepeaterPreviewProps, isDarkMode: boolean): S
type: "DropZone",
placeholder: "Content",
property: values.content
},
{
type: "Container",
borders: true,
children: [
{
type: "DropZone",
placeholder: "No items placeholder: Place widgets here",
property: values.emptyPlaceholder
}
]
}
]
};
Expand Down
11 changes: 4 additions & 7 deletions packages/pluggableWidgets/repeater-native/src/Repeater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ import { mergeNativeStyles } from "@mendix/pluggable-widgets-tools";

export function Repeater(props: RepeaterProps<RepeaterStyle>): ReactElement {
const styles = mergeNativeStyles(defaultRepeaterStyle, props.style);
if (
props.datasource.status === ValueStatus.Loading ||
!props.datasource.items ||
props.datasource.items.length === 0
) {
if (props.datasource.status === ValueStatus.Loading || !props.datasource.items) {
return <View />;
}

const emptyPlaceholder = props.datasource.items.length === 0 ? props.emptyPlaceholder : null;
return (
<View style={styles.container}>
{props.datasource.items?.map((item, index) => (
{props.datasource.items.map((item, index) => (
<Fragment key={`item_${index}`}>{props.content.get(item)}</Fragment>
))}
{emptyPlaceholder}
</View>
);
}
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/repeater-native/src/Repeater.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<property key="content" type="widgets" dataSource="datasource">
<caption>Content</caption>
<description/>
</property>
<property key="emptyPlaceholder" type="widgets" required="false">
<caption>Empty placeholder</caption>
<description/>
</property>
</propertyGroup>
<propertyGroup caption="Common">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* WARNING: All changes made to this file will be overwritten
* @author Mendix Widgets Framework Team
*/
import { ComponentType, CSSProperties } from "react";
import { ComponentType, CSSProperties, ReactNode } from "react";
import { ListValue, ListWidgetValue } from "mendix";

export interface RepeaterProps<Style> {
name: string;
style: Style[];
datasource: ListValue;
content: ListWidgetValue;
emptyPlaceholder?: ReactNode;
}

export interface RepeaterPreviewProps {
Expand All @@ -24,4 +25,5 @@ export interface RepeaterPreviewProps {
readOnly: boolean;
datasource: {} | { type: string } | null;
content: { widgetCount: number; renderer: ComponentType<{ caption?: string }> };
emptyPlaceholder: { widgetCount: number; renderer: ComponentType<{ caption?: string }> };
}
Loading