Skip to content

Commit

Permalink
fix: allow undefined SliceZone slices and components
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Sep 15, 2021
1 parent 43c5274 commit a44bebf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/SliceZone.tsx
Expand Up @@ -88,29 +88,6 @@ export type SliceZoneComponents<
>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>>, TContext>;
};

/**
* React props for the `<SliceZone>` component.
*
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
* @typeParam TContext - Arbitrary data made available to all Slice components.
*/
export type SliceZoneProps<
TSlice extends SliceLike = SliceLike,
TContext = unknown,
> = {
/** List of Slice data from the Slice Zone. */
slices: SliceZoneLike<TSlice>;

/** A record mapping Slice types to React components. */
components: SliceZoneComponents<TSlice, TContext>;

/** The React component rendered if a component mapping from the `components` prop cannot be found. */
defaultComponent?: SliceComponentType<TSlice, TContext>;

/** Arbitrary data made available to all Slice components. */
context?: TContext;
};

/**
* This Slice component can be used as a reminder to provide a proper implementation.
*
Expand Down Expand Up @@ -139,6 +116,29 @@ export const TODOSliceComponent = __PRODUCTION__
);
};

/**
* React props for the `<SliceZone>` component.
*
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
* @typeParam TContext - Arbitrary data made available to all Slice components.
*/
export type SliceZoneProps<
TSlice extends SliceLike = SliceLike,
TContext = unknown,
> = {
/** List of Slice data from the Slice Zone. */
slices?: SliceZoneLike<TSlice>;

/** A record mapping Slice types to React components. */
components?: SliceZoneComponents<TSlice, TContext>;

/** The React component rendered if a component mapping from the `components` prop cannot be found. */
defaultComponent?: SliceComponentType<TSlice, TContext>;

/** Arbitrary data made available to all Slice components. */
context?: TContext;
};

/**
* Renders content from a Prismic Slice Zone using React components for each type of Slice.
*
Expand Down
6 changes: 6 additions & 0 deletions test/SliceZone.test.tsx
Expand Up @@ -28,6 +28,12 @@ const StringifySliceComponent = ({
</div>
);

test("renders null by default", (t) => {
const actual = renderJSON(<SliceZone />);

t.is(actual, null);
});

test("renders null if an empty Slice Zone is provided", (t) => {
const actual = renderJSON(<SliceZone slices={[]} components={{}} />);

Expand Down

0 comments on commit a44bebf

Please sign in to comment.