WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f060db8

Browse files
docs: improve TSDoc comments across codebase (#233)
* docs: simplify component descriptions * docs: refine all TSDocs * docs: clean up TSDocs * style: run Prettier * test: fix some ci error? * test: fix imports
1 parent 9c11500 commit f060db8

File tree

9 files changed

+124
-167
lines changed

9 files changed

+124
-167
lines changed

src/PrismicImage.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type PrismicImageProps = Omit<
2929
ComponentProps<"img">,
3030
"src" | "srcset" | "alt"
3131
> & {
32-
/** The Prismic Image field or thumbnail to render. */
32+
/** The Prismic image field or thumbnail to render. */
3333
field: ImageFieldImage | null | undefined;
3434

3535
/**
@@ -48,7 +48,7 @@ export type PrismicImageProps = Omit<
4848
alt?: "";
4949

5050
/**
51-
* Declare an image as decorative only if the Image field does not have
51+
* Declare an image as decorative only if the image field does not have
5252
* alternative text by providing `fallbackAlt=""`.
5353
*
5454
* See:
@@ -64,13 +64,13 @@ export type PrismicImageProps = Omit<
6464
} & (
6565
| {
6666
/**
67-
* Widths used to build a `srcset` value for the Image field.
67+
* Widths (in pixels) used to build a `srcset` value for the image
68+
* field.
6869
*
69-
* If a `widths` prop is not given or `"defaults"` is passed, the
70-
* following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,
71-
* 3840.
70+
* If omitted or set to `"defaults"`, the following widths will be used:
71+
* 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
7272
*
73-
* If the Image field contains responsive views, each responsive view
73+
* If the image field contains responsive views, each responsive view
7474
* can be used as a width in the resulting `srcset` by passing
7575
* `"thumbnails"` as the `widths` prop.
7676
*/
@@ -84,7 +84,7 @@ export type PrismicImageProps = Omit<
8484
/** Not used when the `widths` prop is used. */
8585
widths?: never;
8686
/**
87-
* Pixel densities used to build a `srcset` value for the Image field.
87+
* Pixel densities used to build a `srcset` value for the image field.
8888
*
8989
* If a `pixelDensities` prop is passed `"defaults"`, the following
9090
* pixel densities will be used: 1, 2, 3.
@@ -98,23 +98,15 @@ export type PrismicImageProps = Omit<
9898
);
9999

100100
/**
101-
* React component that renders an image from a Prismic Image field or one of
102-
* its thumbnails. It will automatically set the `alt` attribute using the Image
103-
* field's `alt` property.
101+
* Renders an optimized image from a Prismic image field.
104102
*
105-
* By default, a widths-based srcset will be used to support responsive images.
106-
* This ensures only the smallest image needed for a browser is downloaded.
103+
* @example
107104
*
108-
* To use a pixel-density-based srcset, use the `pixelDensities` prop. Default
109-
* pixel densities can be used by using `pixelDensities="defaults"`.
105+
* ```tsx
106+
* <PrismicImage field={slice.primary.photo} />;
107+
* ```
110108
*
111-
* **Note**: If you are using a framework that has a native image component,
112-
* such as Next.js and Gatsby, prefer using those image components instead. They
113-
* can provide deeper framework integration than `<PrismicImage>`.
114-
*
115-
* @param props - Props for the component.
116-
*
117-
* @returns A responsive image component for the given Image field.
109+
* @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
118110
*/
119111
export const PrismicImage: FC<PrismicImageProps> = forwardRef(
120112
function PrismicImage(

src/PrismicLink.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface LinkProps {
3737
*/
3838
rel?: string;
3939

40-
/** Children for the component. * */
40+
/** Children for the component. */
4141
children?: ReactNode;
4242
}
4343

@@ -56,13 +56,13 @@ export type PrismicLinkProps<
5656
rel?: string | AsLinkAttrsConfig["rel"];
5757

5858
/**
59-
* The Link Resolver used to resolve links.
59+
* The link resolver used to resolve links.
6060
*
6161
* @remarks
62-
* If your app uses Route Resolvers when querying for your Prismic
63-
* repository's content, a Link Resolver does not need to be provided.
62+
* If your app uses route resolvers when querying for your Prismic
63+
* repository's content, a link resolver does not need to be provided.
6464
*
65-
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
65+
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
6666
*/
6767
linkResolver?: LinkResolverFunction;
6868

@@ -100,6 +100,17 @@ export type PrismicLinkProps<
100100
}
101101
);
102102

103+
/**
104+
* Renders a link from a Prismic link field or page.
105+
*
106+
* @example
107+
*
108+
* ```tsx
109+
* <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;
110+
* ```
111+
*
112+
* @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}
113+
*/
103114
export const PrismicLink = forwardRef(function PrismicLink<
104115
InternalComponentProps = ComponentProps<typeof defaultComponent>,
105116
ExternalComponentProps = ComponentProps<typeof defaultComponent>,

src/PrismicRichText.tsx

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,39 @@ import { devMsg } from "./lib/devMsg.js";
2626
import { LinkProps, PrismicLink } from "./PrismicLink.js";
2727

2828
/**
29-
* A function mapping Rich Text block types to React Components. It is used to
30-
* render Rich Text or Title fields.
29+
* A function mapping rich text block types to React Components. It is used to
30+
* render rich text fields.
3131
*
32-
* @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
32+
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
3333
*/
3434
export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
3535

3636
/**
37-
* A map of Rich Text block types to React Components. It is used to render Rich
38-
* Text or Title fields.
37+
* A map of rich text block types to React Components. It is used to render rich
38+
* text fields.
3939
*
40-
* @see Templating Rich Text and Title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
40+
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
4141
*/
4242
export type JSXMapSerializer = RichTextMapSerializer<ReactNode>;
4343

4444
/** Props for `<PrismicRichText>`. */
4545
export type PrismicRichTextProps = {
46-
/** The Prismic Rich Text field to render. */
46+
/** The Prismic rich text field to render. */
4747
field: RichTextField | null | undefined;
4848

4949
/**
50-
* The Link Resolver used to resolve links.
50+
* The link resolver used to resolve links.
5151
*
5252
* @remarks
53-
* If your app uses Route Resolvers when querying for your Prismic
54-
* repository's content, a Link Resolver does not need to be provided.
53+
* If your app uses route resolvers when querying for your Prismic
54+
* repository's content, a link resolver does not need to be provided.
5555
*
56-
* @see Learn about Link Resolvers and Route Resolvers {@link https://io/docs/core-concepts/link-resolver-route-resolver}
56+
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
5757
*/
5858
linkResolver?: LinkResolverFunction;
5959

6060
/**
61-
* A map or function that maps a Rich Text block to a React component.
61+
* A map or function that maps a rich text block to a React component.
6262
*
6363
* @remarks
6464
* Prefer using a map serializer over the function serializer when possible.
@@ -243,42 +243,15 @@ const createDefaultSerializer = (
243243
});
244244

245245
/**
246-
* React component that renders content from a Prismic Rich Text field. By
247-
* default, HTML elements are rendered for each piece of content. A `heading1`
248-
* block will render an `<h1>` HTML element, for example. Links will use
249-
* `<PrismicLink>` by default which can be customized using the
250-
* `internalLinkComponent` and `externalLinkComponent` props.
246+
* Renders content from a Prismic rich text field as React components.
251247
*
252-
* To customize the components that are rendered, provide a map or function
253-
* serializer to the `components` prop.
248+
* @example
254249
*
255-
* @remarks
256-
* This component returns a React fragment with no wrapping element around the
257-
* content. If you need a wrapper, add a component around `<PrismicRichText>`.
258-
*
259-
* @example Rendering a Rich Text field using the default HTMl elements.
260-
*
261-
* ```jsx
262-
* <PrismicRichText field={document.data.content} />;
250+
* ```tsx
251+
* <PrismicRichText field={slice.primary.text} />;
263252
* ```
264253
*
265-
* @example Rendering a Rich Text field using a custom set of React components.
266-
*
267-
* ```jsx
268-
* <PrismicRichText
269-
* field={document.data.content}
270-
* components={{
271-
* heading1: ({ children }) => <Heading>{children}</Heading>,
272-
* }}
273-
* />;
274-
* ```
275-
*
276-
* @param props - Props for the component.
277-
*
278-
* @returns The Rich Text field's content as React components.
279-
*
280-
* @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
281-
* @see Learn about Rich Text serializers {@link https://io/docs/core-concepts/html-serializer}
254+
* @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
282255
*/
283256
export const PrismicRichText: FC<PrismicRichTextProps> = (props) => {
284257
const {

src/PrismicTable.tsx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,15 @@ export type PrismicTableProps = {
6060
};
6161

6262
/**
63-
* React component that renders content from a Prismic table field. By default,
64-
* HTML elements are rendered for each piece of content. A `tbody` block will
65-
* render a `<tbody>` HTML element, for example.
63+
* Renders content from a Prismic table field as React components.
6664
*
67-
* To customize the components that are rendered, provide a map serializer to
68-
* the `components` prop.
65+
* @example
6966
*
70-
* @example Rendering a table field using the default HTMl elements.
71-
*
72-
* ```jsx
73-
* <PrismicTable field={document.data.my_table} />;
74-
* ```
75-
*
76-
* @example Rendering a table field using a custom set of React components.
77-
*
78-
* ```jsx
79-
* <PrismicTable
80-
* field={document.data.my_table}
81-
* components={{
82-
* tbody: ({ children }) => (
83-
* <tbody className="my-class">{children}</tbody>
84-
* ),
85-
* }}
86-
* />;
67+
* ```tsx
68+
* <PrismicTable field={slice.primary.pricing_table} />;
8769
* ```
8870
*
89-
* @param props - Props for the component.
90-
*
91-
* @returns The table field's content as React components.
92-
*
93-
* @see Learn about table fields {@link https://prismic.io/docs/core-concepts/table}
71+
* @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
9472
*/
9573
export const PrismicTable: FC<PrismicTableProps> = (props) => {
9674
const { field, components, fallback = null } = props;

src/PrismicText.tsx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { devMsg } from "./lib/devMsg.js";
66

77
/** Props for `<PrismicText>`. */
88
export type PrismicTextProps = {
9-
/** The Prismic Rich Text field to render. */
9+
/** The Prismic rich text field to render. */
1010
field: RichTextField | null | undefined;
1111

1212
/**
@@ -20,24 +20,15 @@ export type PrismicTextProps = {
2020
};
2121

2222
/**
23-
* React component that renders content from a Prismic Rich Text field as plain
24-
* text.
23+
* Renders content from a Prismic rich text field as plain text (no HTML).
2524
*
26-
* @remarks
27-
* This component returns a React fragment with no wrapping element around the
28-
* content. If you need a wrapper, add a component around `<PrismicText>`.
25+
* @example
2926
*
30-
* @example Rendering a Rich Text field as plain text.
31-
*
32-
* ```jsx
33-
* <PrismicText field={document.data.content} />;
27+
* ```tsx
28+
* <PrismicText field={slice.primary.text} />;
3429
* ```
3530
*
36-
* @param props - Props for the component.
37-
*
38-
* @returns The Rich Text field's content as plain text.
39-
*
40-
* @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
31+
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
4132
*/
4233
export const PrismicText: FC<PrismicTextProps> = (props) => {
4334
const { field, fallback, separator } = props;
@@ -56,7 +47,7 @@ export const PrismicText: FC<PrismicTextProps> = (props) => {
5647
if (typeof props.field === "string") {
5748
if (DEV) {
5849
console.error(
59-
`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
50+
`[PrismicText] The "field" prop only accepts a rich text field's value but was provided a different type of field instead (e.g. a key text or select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
6051
"prismictext-works-only-with-rich-text-and-title-fields",
6152
)}`,
6253
props.field,

src/PrismicToolbar.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ export type PrismicToolbarProps = {
1313
};
1414

1515
/**
16-
* React component that injects the Prismic Toolbar into the app. This component
17-
* can be placed anywhere in the React tree.
16+
* Renders the Prismic Toolbar script to support draft previews.
17+
*
18+
* @example
19+
*
20+
* ```tsx
21+
* <PrismicToolbar repositoryName="my-repo" />;
22+
* ```
23+
*
24+
* @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
1825
*/
1926
export const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {
2027
const { repositoryName } = props;

0 commit comments

Comments
 (0)