now using data for every type of Elements (no more node for custom type) and fixed child keys warning

This commit is contained in:
Clément Le Bihan
2023-04-10 21:16:45 +02:00
parent 9d5060fc31
commit 87fecb7522
+19 -7
View File
@@ -81,7 +81,11 @@ const getElementDropdownNode = (
isDisabled={disabled} isDisabled={disabled}
> >
{options.map((option) => ( {options.map((option) => (
<Select.Item label={option.label} value={option.value} /> <Select.Item
key={option.label}
label={option.label}
value={option.value}
/>
))} ))}
</Select> </Select>
); );
@@ -95,9 +99,11 @@ type ElementProps = {
description?: string; description?: string;
disabled?: boolean; disabled?: boolean;
onPress?: () => void; onPress?: () => void;
// node is only used if type is "custom" data?:
node?: React.ReactNode; | ElementTextProps
data?: ElementTextProps | ElementToggleProps | ElementDropdownProps; | ElementToggleProps
| ElementDropdownProps
| React.ReactNode;
}; };
const Element = ({ const Element = ({
@@ -200,7 +206,7 @@ const Element = ({
disabled ?? false disabled ?? false
); );
case "custom": case "custom":
return node; return data as React.ReactNode;
default: default:
return <Text>Unknown type</Text>; return <Text>Unknown type</Text>;
} }
@@ -227,9 +233,15 @@ const ElementList = ({ elements, style }: ElementListProps) => {
{(() => { {(() => {
const elementsWithDividers = []; const elementsWithDividers = [];
for (let i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {
elementsWithDividers.push(<Element {...elements[i]} />); elementsWithDividers.push(
<Box key={elements[i]?.title}>
<Element {...elements[i]} />
</Box>
);
if (i < elements.length - 1) { if (i < elements.length - 1) {
elementsWithDividers.push(<Divider />); elementsWithDividers.push(
<Divider key={elements[i]?.title + "Divider"} />
);
} }
} }
return elementsWithDividers; return elementsWithDividers;