@prismicio/react
Version:
React components and hooks to fetch and present Prismic content
33 lines (32 loc) • 1.3 kB
JavaScript
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
import { DEV } from "esm-env";
const TODOSliceComponent = ({ slice }) => {
if (!DEV) {
return null;
}
const type = "slice_type" in slice ? slice.slice_type : slice.type;
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
return jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: ["Could not find a component for Slice type “", type, "”"] });
};
const SliceZone = (props) => {
const { slices = [], components = {}, defaultComponent, context = {} } = props;
const renderedSlices = slices.map((slice, index) => {
const type = "slice_type" in slice ? slice.slice_type : slice.type;
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
const Comp = components[type] || defaultComponent;
if (!Comp) {
return jsx(TODOSliceComponent, { slice }, key);
}
if (slice.__mapped) {
const { __mapped, ...mappedProps } = slice;
return jsx(Comp, { ...mappedProps }, key);
}
return jsx(Comp, { slice, index, slices, context }, key);
});
return jsx(Fragment, { children: renderedSlices });
};
export {
SliceZone,
TODOSliceComponent
};
//# sourceMappingURL=SliceZone.js.map