@cmpsr/contentful-core
Advanced tools
Comparing version 0.1.1 to 0.1.2
# @cmpsr/contentful-core | ||
## 0.1.2 | ||
### Patch Changes | ||
- b3bdc01: Add componentMap prop to ComponentRenderer component | ||
## 0.1.1 | ||
@@ -4,0 +10,0 @@ |
declare type Props = { | ||
componentMap?: any; | ||
data?: any; | ||
@@ -7,4 +8,4 @@ index?: number; | ||
}; | ||
export declare const ComponentRenderer: ({ data, index, parentId, ...rest }: Props) => any; | ||
export declare const ComponentRenderer: ({ componentMap: componentMapOverrides, data, index, parentId, ...rest }: Props) => any; | ||
export {}; | ||
//# sourceMappingURL=ComponentRenderer.d.ts.map |
@@ -28,2 +28,3 @@ "use strict"; | ||
let { | ||
componentMap: componentMapOverrides, | ||
data, | ||
@@ -33,8 +34,11 @@ index, | ||
} = _ref, | ||
rest = _objectWithoutProperties(_ref, ["data", "index", "parentId"]); | ||
rest = _objectWithoutProperties(_ref, ["componentMap", "data", "index", "parentId"]); | ||
const contentfulContext = (0, _react.useContext)(_context.ContentfulContext); | ||
const componentMap = Object.assign({}, contentfulContext.componentMap, componentMapOverrides); | ||
if (Array.isArray(data)) { | ||
return data.map((item, index) => (0, _renderers.renderFromContentfulModel)(contentfulContext, _objectSpread(_objectSpread({}, item), rest), index, parentId)); | ||
return data.map((item, index) => (0, _renderers.renderFromContentfulModel)({ | ||
componentMap | ||
}, _objectSpread(_objectSpread({}, item), rest), index, parentId)); | ||
} | ||
@@ -44,8 +48,12 @@ | ||
const collectionKey = Object.keys(data)[0]; | ||
return data[collectionKey].items.map((item, index) => (0, _renderers.renderFromContentfulModel)(contentfulContext, _objectSpread(_objectSpread({}, item), rest), index, parentId)); | ||
return data[collectionKey].items.map((item, index) => (0, _renderers.renderFromContentfulModel)({ | ||
componentMap | ||
}, _objectSpread(_objectSpread({}, item), rest), index, parentId)); | ||
} | ||
return (0, _renderers.renderFromContentfulModel)(contentfulContext, data, index, parentId); | ||
return (0, _renderers.renderFromContentfulModel)({ | ||
componentMap | ||
}, data, index, parentId); | ||
}; | ||
exports.ComponentRenderer = ComponentRenderer; |
@@ -30,2 +30,8 @@ "use strict"; | ||
const HeroOverride = ({ | ||
title | ||
}) => /*#__PURE__*/_react.default.createElement("div", { | ||
className: "hero" | ||
}, /*#__PURE__*/_react.default.createElement("h2", null, title)); | ||
const HeaderData = { | ||
@@ -140,2 +146,36 @@ __typename: 'Header', | ||
}); | ||
it('renders override components', () => { | ||
const { | ||
container | ||
} = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_context.ContentfulProvider, { | ||
componentMap: componentMap | ||
}, /*#__PURE__*/_react.default.createElement(_ComponentRenderer.ComponentRenderer, { | ||
componentMap: { | ||
Hero: HeroOverride | ||
}, | ||
data: [HeaderData, HeroData, FooterData] | ||
}))); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<header> | ||
<a | ||
href="/" | ||
> | ||
Home | ||
</a> | ||
</header> | ||
<div | ||
class="hero" | ||
> | ||
<h2> | ||
Hero Title | ||
</h2> | ||
</div> | ||
<footer> | ||
© | ||
2020 | ||
</footer> | ||
</div> | ||
`); | ||
}); | ||
}); |
{ | ||
"name": "@cmpsr/contentful-core", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Base Composer components for standing up a React/NextJS app that can dynamically render components based on Contentful Model types mapped to components and queries.", | ||
@@ -42,3 +42,3 @@ "author": "Ryan Hefner <hi@ryanhefner.com>", | ||
}, | ||
"gitHead": "1ca1fe23c26a3ea99dcc591431cb4f862f441310" | ||
"gitHead": "6fe0df0dfc20459a6a21246d346df61da62411ab" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36526
703