@lonelyplanet/dotcom-core
Version:
This package is meant to house some of our more common UI and shared libs across dotcom applications.
42 lines (32 loc) • 726 B
text/typescript
const templateAreas = (areasArray, children) => {
let areas = {};
areasArray.forEach((area) => {
areas[area] = null;
});
if (children) {
let theChildren = {};
if (Array.isArray(children)) {
theChildren = children.reduce((acc, child) => {
const area = child ? child.props.area : null;
if (area) {
acc[area] = child;
}
return acc;
}, areas);
} else {
if (children.props.area) {
const child = children;
const area = child.props.area;
theChildren = {
[area]: child,
};
}
}
areas = {
...areas,
...theChildren,
};
}
return areas;
};
export default templateAreas;