Skip to content

Commit

Permalink
fix: use pascalCase Slice type for <SliceZone> resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Jan 13, 2022
1 parent 33dea53 commit dbf6e76
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
48 changes: 40 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"dependencies": {
"@prismicio/helpers": "^2.0.0",
"@prismicio/richtext": "^2.0.0"
"@prismicio/richtext": "^2.0.0",
"tiny-case": "^1.0.2"
},
"devDependencies": {
"@prismicio/client": "^6.0.0",
Expand Down Expand Up @@ -82,6 +83,7 @@
"siroc": "^0.16.0",
"standard-version": "^9.3.2",
"ts-eager": "^2.0.2",
"type-fest": "^2.9.0",
"typescript": "^4.5.4"
},
"peerDependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/SliceZone.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from "react";
import * as prismicT from "@prismicio/types";
import { pascalCase } from "tiny-case";
import { PascalCase } from "type-fest";

import { __PRODUCTION__ } from "./lib/__PRODUCTION__";

Expand Down Expand Up @@ -148,7 +150,7 @@ type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
/**
* The name of the Slice.
*/
sliceName: TSlice["slice_type"];
sliceName: PascalCase<TSlice["slice_type"]>;

/**
* The index of the Slice in the Slice Zone.
Expand Down Expand Up @@ -249,7 +251,9 @@ export const SliceZone = <TSlice extends SliceLike, TContext>({
if (resolver) {
const resolvedComp = resolver({
slice,
sliceName: slice.slice_type,
sliceName: pascalCase(slice.slice_type) as PascalCase<
typeof slice.slice_type
>,
i: index,
});

Expand All @@ -270,7 +274,7 @@ export const SliceZone = <TSlice extends SliceLike, TContext>({
/>
);
});
}, [components, context, defaultComponent, slices]);
}, [components, context, defaultComponent, slices, resolver]);

return <>{renderedSlices}</>;
};
4 changes: 2 additions & 2 deletions test/SliceZone.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ test("renders components from a resolver function for backwards compatibility wi
sliceName,
}) => {
switch (sliceName) {
case "foo": {
case "Foo": {
return (props) => <StringifySliceComponent id="foo" {...props} />;
}

case "bar": {
case "Bar": {
return (props) => <StringifySliceComponent id="bar" {...props} />;
}
}
Expand Down

0 comments on commit dbf6e76

Please sign in to comment.