Skip to content
Closed
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
17 changes: 14 additions & 3 deletions src/overridable.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,20 @@

if (id in overriddenComponents) {
// If there's an override, we replace the component's content with the override + props
const Overridden = overriddenComponents[id];
const element = React.createElement(Overridden, {...childProps, ...restProps});
return <DevModeWrapper id={id}>{element}</DevModeWrapper>;

if (Array.isArray(overriddenComponents[id])) {
// if the override is an array we display all of them instead of the possible default children
const overrides = overriddenComponents[id];
const elements = overrides.map((overridden, i) =>
React.createElement(overridden, {...childProps, ...restProps, key: `${id}-${i}`})

Check warning on line 51 in src/overridable.js

View workflow job for this annotation

GitHub Actions / Tests

Do not use Array index in keys
);
return <DevModeWrapper id={id}>{elements}</DevModeWrapper>;
} else {
// if it is not an array if will be used to replace it the possible default child
const Overridden = overriddenComponents[id];
const element = React.createElement(Overridden, {...childProps, ...restProps});
return <DevModeWrapper id={id}>{element}</DevModeWrapper>;
}
} else if (child) {
// No override? Clone the Overridable component's original children
const element = React.cloneElement(child, childProps);
Expand Down
7 changes: 7 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export class OverriddenComponentRepository {
this.components[id] = Component;
};

append = (id, Component) => {
if (!Array.isArray(this.components[id])) {
this.components[id] = [];
}
this.components[id].push(Component);
};

get = id => {
return this.components[id];
};
Expand Down