@prismicio/react 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -12
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/PrismicLink.tsx +17 -11
- package/src/SliceZone.tsx +36 -22
- package/src/index.ts +2 -0
package/src/SliceZone.tsx
CHANGED
|
@@ -59,7 +59,8 @@ export type SliceLike<SliceType extends string = string> =
|
|
|
59
59
|
*
|
|
60
60
|
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
61
61
|
*/
|
|
62
|
-
export type SliceZoneLike<TSlice extends SliceLike
|
|
62
|
+
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
|
|
63
|
+
readonly TSlice[];
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
* React props for a component rendering content from a Prismic Slice using the
|
|
@@ -70,7 +71,8 @@ export type SliceZoneLike<TSlice extends SliceLike> = readonly TSlice[];
|
|
|
70
71
|
* available to all Slice components.
|
|
71
72
|
*/
|
|
72
73
|
export type SliceComponentProps<
|
|
73
|
-
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
TSlice extends SliceLike = any,
|
|
74
76
|
TContext = unknown,
|
|
75
77
|
> = {
|
|
76
78
|
/**
|
|
@@ -105,7 +107,8 @@ export type SliceComponentProps<
|
|
|
105
107
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
106
108
|
*/
|
|
107
109
|
export type SliceComponentType<
|
|
108
|
-
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
+
TSlice extends SliceLike = any,
|
|
109
112
|
TContext = unknown,
|
|
110
113
|
> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
111
114
|
|
|
@@ -113,6 +116,8 @@ export type SliceComponentType<
|
|
|
113
116
|
* A record of Slice types mapped to a React component. The component will be
|
|
114
117
|
* rendered for each instance of its Slice.
|
|
115
118
|
*
|
|
119
|
+
* @deprecated This type is no longer used by `@prismicio/react`. Prefer using
|
|
120
|
+
* `Record<string, SliceComponentType<any>>` instead.
|
|
116
121
|
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
117
122
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
118
123
|
*/
|
|
@@ -169,7 +174,10 @@ export const TODOSliceComponent = __PRODUCTION__
|
|
|
169
174
|
/**
|
|
170
175
|
* Arguments for a `<SliceZone>` `resolver` function.
|
|
171
176
|
*/
|
|
172
|
-
type SliceZoneResolverArgs<
|
|
177
|
+
type SliceZoneResolverArgs<
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
|
+
TSlice extends SliceLike = any,
|
|
180
|
+
> = {
|
|
173
181
|
/**
|
|
174
182
|
* The Slice to resolve to a React component.
|
|
175
183
|
*/
|
|
@@ -198,11 +206,17 @@ type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
|
|
|
198
206
|
* @returns The React component to render for a Slice.
|
|
199
207
|
*/
|
|
200
208
|
export type SliceZoneResolver<
|
|
201
|
-
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
|
+
TSlice extends SliceLike = any,
|
|
202
211
|
TContext = unknown,
|
|
203
|
-
> = (
|
|
204
|
-
|
|
205
|
-
|
|
212
|
+
> = (args: SliceZoneResolverArgs<TSlice>) =>
|
|
213
|
+
| SliceComponentType<
|
|
214
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
215
|
+
any,
|
|
216
|
+
TContext
|
|
217
|
+
>
|
|
218
|
+
| undefined
|
|
219
|
+
| null;
|
|
206
220
|
|
|
207
221
|
/**
|
|
208
222
|
* React props for the `<SliceZone>` component.
|
|
@@ -210,19 +224,17 @@ export type SliceZoneResolver<
|
|
|
210
224
|
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
211
225
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
212
226
|
*/
|
|
213
|
-
export type SliceZoneProps<
|
|
214
|
-
TSlice extends SliceLike = SliceLike,
|
|
215
|
-
TContext = unknown,
|
|
216
|
-
> = {
|
|
227
|
+
export type SliceZoneProps<TContext = unknown> = {
|
|
217
228
|
/**
|
|
218
229
|
* List of Slice data from the Slice Zone.
|
|
219
230
|
*/
|
|
220
|
-
slices?: SliceZoneLike
|
|
231
|
+
slices?: SliceZoneLike;
|
|
221
232
|
|
|
222
233
|
/**
|
|
223
234
|
* A record mapping Slice types to React components.
|
|
224
235
|
*/
|
|
225
|
-
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
237
|
+
components?: Record<string, SliceComponentType<any>>;
|
|
226
238
|
|
|
227
239
|
/**
|
|
228
240
|
* A function that determines the rendered React component for each Slice in
|
|
@@ -234,13 +246,15 @@ export type SliceZoneProps<
|
|
|
234
246
|
*
|
|
235
247
|
* @returns The React component to render for a Slice.
|
|
236
248
|
*/
|
|
237
|
-
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
|
+
resolver?: SliceZoneResolver<any, TContext>;
|
|
238
251
|
|
|
239
252
|
/**
|
|
240
253
|
* The React component rendered if a component mapping from the `components`
|
|
241
254
|
* prop cannot be found.
|
|
242
255
|
*/
|
|
243
|
-
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
257
|
+
defaultComponent?: SliceComponentType<any, TContext>;
|
|
244
258
|
|
|
245
259
|
/**
|
|
246
260
|
* Arbitrary data made available to all Slice components.
|
|
@@ -263,19 +277,19 @@ export type SliceZoneProps<
|
|
|
263
277
|
*
|
|
264
278
|
* @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
|
|
265
279
|
*/
|
|
266
|
-
export const SliceZone = <
|
|
280
|
+
export const SliceZone = <TContext,>({
|
|
267
281
|
slices = [],
|
|
268
|
-
components = {}
|
|
282
|
+
components = {},
|
|
269
283
|
resolver,
|
|
270
284
|
defaultComponent = TODOSliceComponent,
|
|
271
285
|
context = {} as TContext,
|
|
272
|
-
}: SliceZoneProps<
|
|
286
|
+
}: SliceZoneProps<TContext>): JSX.Element => {
|
|
273
287
|
const renderedSlices = React.useMemo(() => {
|
|
274
288
|
return slices.map((slice, index) => {
|
|
275
289
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
276
290
|
|
|
277
|
-
let Comp =
|
|
278
|
-
|
|
291
|
+
let Comp =
|
|
292
|
+
components[type as keyof typeof components] || defaultComponent;
|
|
279
293
|
|
|
280
294
|
// TODO: Remove `resolver` in v3 in favor of `components`.
|
|
281
295
|
if (resolver) {
|
|
@@ -286,7 +300,7 @@ export const SliceZone = <TSlice extends SliceLike, TContext>({
|
|
|
286
300
|
});
|
|
287
301
|
|
|
288
302
|
if (resolvedComp) {
|
|
289
|
-
Comp = resolvedComp;
|
|
303
|
+
Comp = resolvedComp as typeof Comp;
|
|
290
304
|
}
|
|
291
305
|
}
|
|
292
306
|
|