@prismicio/react 3.2.1 → 3.2.2-pr.236.d65a0c3

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/src/SliceZone.tsx CHANGED
@@ -5,7 +5,7 @@ import { DEV } from "esm-env";
5
5
  /**
6
6
  * Returns the type of a `SliceLike` type.
7
7
  *
8
- * @typeParam Slice - The Slice from which the type will be extracted.
8
+ * @typeParam TSlice - The slice from which the type will be extracted.
9
9
  */
10
10
  type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
11
11
  ? TSlice["slice_type"]
@@ -14,10 +14,10 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
14
14
  : never;
15
15
 
16
16
  /**
17
- * The minimum required properties to represent a Prismic Slice from the Prismic
18
- * Rest API V2 for the `unstable_mapSliceZone()` helper.
17
+ * The minimum required properties to represent a Prismic slice from the Prismic
18
+ * Content API for the `mapSliceZone()` helper.
19
19
  *
20
- * @typeParam SliceType - Type name of the Slice.
20
+ * @typeParam SliceType - Type name of the slice.
21
21
  */
22
22
  export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
23
23
  Slice<TSliceType>,
@@ -25,30 +25,30 @@ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
25
25
  >;
26
26
 
27
27
  /**
28
- * The minimum required properties to represent a Prismic Slice from the Prismic
29
- * GraphQL API for the `unstable_mapSliceZone()` helper.
28
+ * The minimum required properties to represent a Prismic slice from the Prismic
29
+ * GraphQL API for the `mapSliceZone()` helper.
30
30
  *
31
- * @typeParam SliceType - Type name of the Slice.
31
+ * @typeParam SliceType - Type name of the slice.
32
32
  */
33
33
  export type SliceLikeGraphQL<TSliceType extends string = string> = {
34
34
  type: Slice<TSliceType>["slice_type"];
35
35
  };
36
36
 
37
37
  /**
38
- * The minimum required properties to represent a Prismic Slice for the
39
- * `unstable_mapSliceZone()` helper.
38
+ * The minimum required properties to represent a Prismic slice for the
39
+ * `mapSliceZone()` helper.
40
40
  *
41
- * If using Prismic's Rest API V2, use the `Slice` export from
41
+ * If using Prismic's Content API, use the `Slice` export from
42
42
  * `@prismicio/client` for a full interface.
43
43
  *
44
- * @typeParam SliceType - Type name of the Slice.
44
+ * @typeParam SliceType - Type name of the slice.
45
45
  */
46
46
  export type SliceLike<TSliceType extends string = string> = (
47
47
  | SliceLikeRestV2<TSliceType>
48
48
  | SliceLikeGraphQL<TSliceType>
49
49
  ) & {
50
50
  /**
51
- * If `true`, this Slice has been modified from its original value using a
51
+ * If `true`, this slice has been modified from its original value using a
52
52
  * mapper and `@prismicio/client`'s `mapSliceZone()`.
53
53
  *
54
54
  * @internal
@@ -60,21 +60,21 @@ export type SliceLike<TSliceType extends string = string> = (
60
60
  * A looser version of the `SliceZone` type from `@prismicio/client` using
61
61
  * `SliceLike`.
62
62
  *
63
- * If using Prismic's Rest API V2, use the `SliceZone` export from
63
+ * If using Prismic's Content API, use the `SliceZone` export from
64
64
  * `@prismicio/client` for the full type.
65
65
  *
66
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
66
+ * @typeParam TSlice - The type(s) of a slice in the slice zone.
67
67
  */
68
68
  export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
69
69
  readonly TSlice[];
70
70
 
71
71
  /**
72
- * React props for a component rendering content from a Prismic Slice using the
72
+ * React props for a component rendering content from a Prismic slice using the
73
73
  * `<SliceZone>` component.
74
74
  *
75
- * @typeParam TSlice - The Slice passed as a prop.
75
+ * @typeParam TSlice - The slice passed as a prop.
76
76
  * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
77
- * available to all Slice components.
77
+ * available to all slice components.
78
78
  */
79
79
  export type SliceComponentProps<
80
80
  TSlice extends SliceLike = SliceLike,
@@ -83,30 +83,30 @@ export type SliceComponentProps<
83
83
  /** Slice data for this component. */
84
84
  slice: TSlice;
85
85
 
86
- /** The index of the Slice in the Slice Zone. */
86
+ /** The index of the slice in the slice zone. */
87
87
  index: number;
88
88
 
89
- /** All Slices from the Slice Zone to which the Slice belongs. */
90
- // TODO: We have to keep this list of Slices general due to circular
89
+ /** All slices from the slice zone to which the slice belongs. */
90
+ // TODO: We have to keep this list of slices general due to circular
91
91
  // reference limtiations. If we had another generic to determine the full
92
- // union of Slice types, it would include TSlice. This causes TypeScript to
92
+ // union of slice types, it would include TSlice. This causes TypeScript to
93
93
  // throw a compilation error.
94
94
  slices: SliceZoneLike<
95
95
  TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2
96
96
  >;
97
97
 
98
98
  /**
99
- * Arbitrary data passed to `<SliceZone>` and made available to all Slice
99
+ * Arbitrary data passed to `<SliceZone>` and made available to all slice
100
100
  * components.
101
101
  */
102
102
  context: TContext;
103
103
  };
104
104
 
105
105
  /**
106
- * A React component to be rendered for each instance of its Slice.
106
+ * A React component to be rendered for each instance of its slice.
107
107
  *
108
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
109
- * @typeParam TContext - Arbitrary data made available to all Slice components.
108
+ * @typeParam TSlice - The type(s) of a slice in the slice zone.
109
+ * @typeParam TContext - Arbitrary data made available to all slice components.
110
110
  */
111
111
  export type SliceComponentType<
112
112
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -115,21 +115,21 @@ export type SliceComponentType<
115
115
  > = ComponentType<SliceComponentProps<TSlice, TContext>>;
116
116
 
117
117
  /**
118
- * A record of Slice types mapped to a React component. The component will be
119
- * rendered for each instance of its Slice.
118
+ * A record of slice types mapped to a React component. The component will be
119
+ * rendered for each instance of its slice.
120
120
  *
121
121
  * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
122
122
  * `Record<string, SliceComponentType<any>>` instead.
123
123
  *
124
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
125
- * @typeParam TContext - Arbitrary data made available to all Slice components.
124
+ * @typeParam TSlice - The type(s) of a slice in the slice zone.
125
+ * @typeParam TContext - Arbitrary data made available to all slice components.
126
126
  */
127
127
  export type SliceZoneComponents<
128
128
  TSlice extends SliceLike = SliceLike,
129
129
  TContext = unknown,
130
130
  > =
131
131
  // This is purposely not wrapped in Partial to ensure a component is provided
132
- // for all Slice types. <SliceZone> will render a default component if one is
132
+ // for all slice types. <SliceZone> will render a default component if one is
133
133
  // not provided, but it *should* be a type error if an explicit component is
134
134
  // missing.
135
135
  //
@@ -149,14 +149,14 @@ export type SliceZoneComponents<
149
149
  /**
150
150
  * React props for the `<SliceZone>` component.
151
151
  *
152
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
153
- * @typeParam TContext - Arbitrary data made available to all Slice components.
152
+ * @typeParam TSlice - The type(s) of a slice in the slice zone.
153
+ * @typeParam TContext - Arbitrary data made available to all slice components.
154
154
  */
155
155
  export type SliceZoneProps<TContext = unknown> = {
156
- /** List of Slice data from the Slice Zone. */
156
+ /** List of slice data from the slice zone. */
157
157
  slices?: SliceZoneLike;
158
158
 
159
- /** A record mapping Slice types to React components. */
159
+ /** A record mapping slice types to React components. */
160
160
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
161
  components?: Record<string, ComponentType<any>>;
162
162
 
@@ -167,12 +167,12 @@ export type SliceZoneProps<TContext = unknown> = {
167
167
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
168
  defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
169
169
 
170
- /** Arbitrary data made available to all Slice components. */
170
+ /** Arbitrary data made available to all slice components. */
171
171
  context?: TContext;
172
172
  };
173
173
 
174
174
  /**
175
- * This Slice component can be used as a reminder to provide a proper
175
+ * This slice component can be used as a reminder to provide a proper
176
176
  * implementation.
177
177
  *
178
178
  * This is also the default React component rendered when a component mapping
@@ -190,32 +190,28 @@ export const TODOSliceComponent = <TSlice extends SliceLike>({
190
190
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
191
191
 
192
192
  console.warn(
193
- `[SliceZone] Could not find a component for Slice type "${type}"`,
193
+ `[SliceZone] Could not find a component for slice type "${type}"`,
194
194
  slice,
195
195
  );
196
196
 
197
197
  return (
198
198
  <section data-slice-zone-todo-component="" data-slice-type={type}>
199
- Could not find a component for Slice type &ldquo;{type}
199
+ Could not find a component for slice type &ldquo;{type}
200
200
  &rdquo;
201
201
  </section>
202
202
  );
203
203
  };
204
204
 
205
205
  /**
206
- * Renders content from a Prismic Slice Zone using React components for each
207
- * type of Slice.
206
+ * Renders slices in a slice zone as React components.
208
207
  *
209
- * If a component is not provided for a type of Slice, a default component can
210
- * be provided. A fallback component is provided by default that will not be
211
- * rendered in a production build of your app.
208
+ * @example
212
209
  *
213
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
214
- * @typeParam TContext - Arbitrary data made available to all Slice components.
210
+ * ```tsx
211
+ * <SliceZone slices={page.data.slices} components={components} />;
212
+ * ```
215
213
  *
216
- * @returns The Slice Zone's content as React components.
217
- *
218
- * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
214
+ * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
219
215
  */
220
216
  export const SliceZone: FC<SliceZoneProps> = (props) => {
221
217
  const {