@prismicio/react 2.5.1 → 2.5.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.
@@ -1,188 +1,188 @@
1
- import * as React from "react";
2
- import * as prismicT from "@prismicio/types";
3
- import { PascalCase } from "./lib/pascalCase";
4
- /**
5
- * Returns the type of a `SliceLike` type.
6
- *
7
- * @typeParam Slice - The Slice from which the type will be extracted.
8
- */
9
- type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ? Slice["slice_type"] : Slice extends SliceLikeGraphQL ? Slice["type"] : never;
10
- /**
11
- * The minimum required properties to represent a Prismic Slice from the Prismic
12
- * Rest API V2 for the `<SliceZone>` component.
13
- *
14
- * If using Prismic's Rest API V2, use the `Slice` export from
15
- * `@prismicio/types` for a full interface.
16
- *
17
- * @typeParam SliceType - Type name of the Slice.
18
- */
19
- export type SliceLikeRestV2<SliceType extends string = string> = {
20
- slice_type: prismicT.Slice<SliceType>["slice_type"];
21
- id?: string;
22
- };
23
- /**
24
- * The minimum required properties to represent a Prismic Slice from the Prismic
25
- * GraphQL API for the `<SliceZone>` component.
26
- *
27
- * @typeParam SliceType - Type name of the Slice.
28
- */
29
- export type SliceLikeGraphQL<SliceType extends string = string> = {
30
- type: prismicT.Slice<SliceType>["slice_type"];
31
- };
32
- /**
33
- * The minimum required properties to represent a Prismic Slice for the
34
- * `<SliceZone>` component.
35
- *
36
- * If using Prismic's Rest API V2, use the `Slice` export from
37
- * `@prismicio/types` for a full interface.
38
- *
39
- * @typeParam SliceType - Type name of the Slice.
40
- */
41
- export type SliceLike<SliceType extends string = string> = SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>;
42
- /**
43
- * A looser version of the `SliceZone` type from `@prismicio/types` using
44
- * `SliceLike`.
45
- *
46
- * If using Prismic's Rest API V2, use the `SliceZone` export from
47
- * `@prismicio/types` for the full type.
48
- *
49
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
50
- */
51
- export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
52
- /**
53
- * React props for a component rendering content from a Prismic Slice using the
54
- * `<SliceZone>` component.
55
- *
56
- * @typeParam TSlice - The Slice passed as a prop.
57
- * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
58
- * available to all Slice components.
59
- */
60
- export type SliceComponentProps<TSlice extends SliceLike = any, TContext = unknown> = {
61
- /**
62
- * Slice data for this component.
63
- */
64
- slice: TSlice;
65
- /**
66
- * The index of the Slice in the Slice Zone.
67
- */
68
- index: number;
69
- /**
70
- * All Slices from the Slice Zone to which the Slice belongs.
71
- */
72
- slices: SliceZoneLike<SliceLike>;
73
- /**
74
- * Arbitrary data passed to `<SliceZone>` and made available to all Slice
75
- * components.
76
- */
77
- context: TContext;
78
- };
79
- /**
80
- * A React component to be rendered for each instance of its Slice.
81
- *
82
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
83
- * @typeParam TContext - Arbitrary data made available to all Slice components.
84
- */
85
- export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;
86
- /**
87
- * A record of Slice types mapped to a React component. The component will be
88
- * rendered for each instance of its Slice.
89
- *
90
- * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
91
- * `Record<string, SliceComponentType<any>>` instead.
92
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
93
- * @typeParam TContext - Arbitrary data made available to all Slice components.
94
- */
95
- export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
96
- [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
97
- };
98
- /**
99
- * This Slice component can be used as a reminder to provide a proper
100
- * implementation.
101
- *
102
- * This is also the default React component rendered when a component mapping
103
- * cannot be found in `<SliceZone>`.
104
- */
105
- export declare const TODOSliceComponent: <TSlice extends SliceLike<string>, TContext>({ slice, }: SliceComponentProps<TSlice, TContext>) => JSX.Element | null;
106
- /**
107
- * Arguments for a `<SliceZone>` `resolver` function.
108
- */
109
- type SliceZoneResolverArgs<TSlice extends SliceLike = any> = {
110
- /**
111
- * The Slice to resolve to a React component.
112
- */
113
- slice: TSlice;
114
- /**
115
- * The name of the Slice.
116
- */
117
- sliceName: PascalCase<ExtractSliceType<TSlice>>;
118
- /**
119
- * The index of the Slice in the Slice Zone.
120
- */
121
- i: number;
122
- };
123
- /**
124
- * A function that determines the rendered React component for each Slice in the
125
- * Slice Zone. If a nullish value is returned, the component will fallback to
126
- * the `components` or `defaultComponent` props to determine the rendered
127
- * component.
128
- *
129
- * @deprecated Use the `components` prop instead.
130
- *
131
- * @param args - Arguments for the resolver function.
132
- *
133
- * @returns The React component to render for a Slice.
134
- */
135
- export type SliceZoneResolver<TSlice extends SliceLike = any, TContext = unknown> = (args: SliceZoneResolverArgs<TSlice>) => SliceComponentType<any, TContext> | undefined | null;
136
- /**
137
- * React props for the `<SliceZone>` component.
138
- *
139
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
140
- * @typeParam TContext - Arbitrary data made available to all Slice components.
141
- */
142
- export type SliceZoneProps<TContext = unknown> = {
143
- /**
144
- * List of Slice data from the Slice Zone.
145
- */
146
- slices?: SliceZoneLike;
147
- /**
148
- * A record mapping Slice types to React components.
149
- */
150
- components?: Record<string, SliceComponentType<any, TContext>>;
151
- /**
152
- * A function that determines the rendered React component for each Slice in
153
- * the Slice Zone.
154
- *
155
- * @deprecated Use the `components` prop instead.
156
- *
157
- * @param args - Arguments for the resolver function.
158
- *
159
- * @returns The React component to render for a Slice.
160
- */
161
- resolver?: SliceZoneResolver<any, TContext>;
162
- /**
163
- * The React component rendered if a component mapping from the `components`
164
- * prop cannot be found.
165
- */
166
- defaultComponent?: SliceComponentType<any, TContext>;
167
- /**
168
- * Arbitrary data made available to all Slice components.
169
- */
170
- context?: TContext;
171
- };
172
- /**
173
- * Renders content from a Prismic Slice Zone using React components for each
174
- * type of Slice.
175
- *
176
- * If a component is not provided for a type of Slice, a default component can
177
- * be provided. A fallback component is provided by default that will not be
178
- * rendered in a production build of your app.
179
- *
180
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
181
- * @typeParam TContext - Arbitrary data made available to all Slice components.
182
- *
183
- * @returns The Slice Zone's content as React components.
184
- *
185
- * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
186
- */
187
- export declare const SliceZone: <TContext>({ slices, components, resolver, defaultComponent, context, }: SliceZoneProps<TContext>) => JSX.Element;
188
- export {};
1
+ import * as React from "react";
2
+ import * as prismicT from "@prismicio/types";
3
+ import { PascalCase } from "./lib/pascalCase";
4
+ /**
5
+ * Returns the type of a `SliceLike` type.
6
+ *
7
+ * @typeParam Slice - The Slice from which the type will be extracted.
8
+ */
9
+ type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ? Slice["slice_type"] : Slice extends SliceLikeGraphQL ? Slice["type"] : never;
10
+ /**
11
+ * The minimum required properties to represent a Prismic Slice from the Prismic
12
+ * Rest API V2 for the `<SliceZone>` component.
13
+ *
14
+ * If using Prismic's Rest API V2, use the `Slice` export from
15
+ * `@prismicio/types` for a full interface.
16
+ *
17
+ * @typeParam SliceType - Type name of the Slice.
18
+ */
19
+ export type SliceLikeRestV2<SliceType extends string = string> = {
20
+ slice_type: prismicT.Slice<SliceType>["slice_type"];
21
+ id?: string;
22
+ };
23
+ /**
24
+ * The minimum required properties to represent a Prismic Slice from the Prismic
25
+ * GraphQL API for the `<SliceZone>` component.
26
+ *
27
+ * @typeParam SliceType - Type name of the Slice.
28
+ */
29
+ export type SliceLikeGraphQL<SliceType extends string = string> = {
30
+ type: prismicT.Slice<SliceType>["slice_type"];
31
+ };
32
+ /**
33
+ * The minimum required properties to represent a Prismic Slice for the
34
+ * `<SliceZone>` component.
35
+ *
36
+ * If using Prismic's Rest API V2, use the `Slice` export from
37
+ * `@prismicio/types` for a full interface.
38
+ *
39
+ * @typeParam SliceType - Type name of the Slice.
40
+ */
41
+ export type SliceLike<SliceType extends string = string> = SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>;
42
+ /**
43
+ * A looser version of the `SliceZone` type from `@prismicio/types` using
44
+ * `SliceLike`.
45
+ *
46
+ * If using Prismic's Rest API V2, use the `SliceZone` export from
47
+ * `@prismicio/types` for the full type.
48
+ *
49
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
50
+ */
51
+ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
52
+ /**
53
+ * React props for a component rendering content from a Prismic Slice using the
54
+ * `<SliceZone>` component.
55
+ *
56
+ * @typeParam TSlice - The Slice passed as a prop.
57
+ * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
58
+ * available to all Slice components.
59
+ */
60
+ export type SliceComponentProps<TSlice extends SliceLike = any, TContext = unknown> = {
61
+ /**
62
+ * Slice data for this component.
63
+ */
64
+ slice: TSlice;
65
+ /**
66
+ * The index of the Slice in the Slice Zone.
67
+ */
68
+ index: number;
69
+ /**
70
+ * All Slices from the Slice Zone to which the Slice belongs.
71
+ */
72
+ slices: SliceZoneLike<SliceLike>;
73
+ /**
74
+ * Arbitrary data passed to `<SliceZone>` and made available to all Slice
75
+ * components.
76
+ */
77
+ context: TContext;
78
+ };
79
+ /**
80
+ * A React component to be rendered for each instance of its Slice.
81
+ *
82
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
83
+ * @typeParam TContext - Arbitrary data made available to all Slice components.
84
+ */
85
+ export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;
86
+ /**
87
+ * A record of Slice types mapped to a React component. The component will be
88
+ * rendered for each instance of its Slice.
89
+ *
90
+ * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
91
+ * `Record<string, SliceComponentType<any>>` instead.
92
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
93
+ * @typeParam TContext - Arbitrary data made available to all Slice components.
94
+ */
95
+ export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
96
+ [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
97
+ };
98
+ /**
99
+ * This Slice component can be used as a reminder to provide a proper
100
+ * implementation.
101
+ *
102
+ * This is also the default React component rendered when a component mapping
103
+ * cannot be found in `<SliceZone>`.
104
+ */
105
+ export declare const TODOSliceComponent: <TSlice extends SliceLike<string>, TContext>({ slice, }: SliceComponentProps<TSlice, TContext>) => JSX.Element | null;
106
+ /**
107
+ * Arguments for a `<SliceZone>` `resolver` function.
108
+ */
109
+ type SliceZoneResolverArgs<TSlice extends SliceLike = any> = {
110
+ /**
111
+ * The Slice to resolve to a React component.
112
+ */
113
+ slice: TSlice;
114
+ /**
115
+ * The name of the Slice.
116
+ */
117
+ sliceName: PascalCase<ExtractSliceType<TSlice>>;
118
+ /**
119
+ * The index of the Slice in the Slice Zone.
120
+ */
121
+ i: number;
122
+ };
123
+ /**
124
+ * A function that determines the rendered React component for each Slice in the
125
+ * Slice Zone. If a nullish value is returned, the component will fallback to
126
+ * the `components` or `defaultComponent` props to determine the rendered
127
+ * component.
128
+ *
129
+ * @deprecated Use the `components` prop instead.
130
+ *
131
+ * @param args - Arguments for the resolver function.
132
+ *
133
+ * @returns The React component to render for a Slice.
134
+ */
135
+ export type SliceZoneResolver<TSlice extends SliceLike = any, TContext = unknown> = (args: SliceZoneResolverArgs<TSlice>) => SliceComponentType<any, TContext> | undefined | null;
136
+ /**
137
+ * React props for the `<SliceZone>` component.
138
+ *
139
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
140
+ * @typeParam TContext - Arbitrary data made available to all Slice components.
141
+ */
142
+ export type SliceZoneProps<TContext = unknown> = {
143
+ /**
144
+ * List of Slice data from the Slice Zone.
145
+ */
146
+ slices?: SliceZoneLike;
147
+ /**
148
+ * A record mapping Slice types to React components.
149
+ */
150
+ components?: Record<string, SliceComponentType<any, TContext>>;
151
+ /**
152
+ * A function that determines the rendered React component for each Slice in
153
+ * the Slice Zone.
154
+ *
155
+ * @deprecated Use the `components` prop instead.
156
+ *
157
+ * @param args - Arguments for the resolver function.
158
+ *
159
+ * @returns The React component to render for a Slice.
160
+ */
161
+ resolver?: SliceZoneResolver<any, TContext>;
162
+ /**
163
+ * The React component rendered if a component mapping from the `components`
164
+ * prop cannot be found.
165
+ */
166
+ defaultComponent?: SliceComponentType<any, TContext>;
167
+ /**
168
+ * Arbitrary data made available to all Slice components.
169
+ */
170
+ context?: TContext;
171
+ };
172
+ /**
173
+ * Renders content from a Prismic Slice Zone using React components for each
174
+ * type of Slice.
175
+ *
176
+ * If a component is not provided for a type of Slice, a default component can
177
+ * be provided. A fallback component is provided by default that will not be
178
+ * rendered in a production build of your app.
179
+ *
180
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
181
+ * @typeParam TContext - Arbitrary data made available to all Slice components.
182
+ *
183
+ * @returns The Slice Zone's content as React components.
184
+ *
185
+ * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
186
+ */
187
+ export declare const SliceZone: <TContext>({ slices, components, resolver, defaultComponent, context, }: SliceZoneProps<TContext>) => JSX.Element;
188
+ export {};