@portabletext/react-pdf
Version:
Serialize Portable Text to ReactPDF
119 lines (107 loc) • 4.08 kB
TypeScript
import type { PortableTextProps } from "@portabletext/react"
import { PortableTextBlock, PortableTextReactComponents } from "@portabletext/react"
import { Style } from "@react-pdf/stylesheet"
import type { JSX } from "react"
/**
* This function takes the styles provided as args and merges them into the default styles (in the case of overlapping styles, the user-defined styles will take precedence).
* It also uses the baseFontSizePt to calculate values for the default styles (e.g. line-height, font-size, etc.).
* The result of this factory function is a map of default components whose styles are modified/extended using the user-defined styles.
* That map will be consumed by the mergeAndStyleComponents function.
* @public
*/
export declare const generateStyledDefaultComponentsMap: (styles: PortableTextStyles, baseFontSizePt: number) => PortableTextReactComponents
/**
* Typedef for the list subobject of PortableTextStyles
* @public
*/
declare type ListStyles = {
list?: Style
listDeep?: Style
listItemWrapper?: Style
listItemDecorator?: Style
listItemNumber?: Style
}
/**
* Typedef for the marks subobject of PortableTextStyles
* @public
*/
declare type MarksStyles = {
strong?: Style
em?: Style
link?: Style
underline?: Style
"strike-through"?: Style
code?: Style
superscript?: Style
subscript?: Style
highlight?: Style
}
/**
* This function takes the styles provided as args and merges them into the default styles (in the case of overlapping styles, the user-defined styles will take precedence).
* The result of this style-merge is a set of default components whose styles are modified/extended with the user-defined styles.
* This function then takes the components provided as args and merges them into the default components (in the case of overlapping components, the user-defined components will take precedence).
* The overall result returned is a components map which includes the user-defined components and any user-defined styles for the default components -- this map is
* consumed by the PortableText component.
* @public
*/
export declare const mergeAndStyleComponents: (components: Partial<PortableTextReactComponents> | undefined, styles: PortableTextStyles, baseFontSizePt: number) => PortableTextReactComponents
/**
* PortableText component serializes PortableTextBlock objects to ReactPDF components.
* PortableText component expects to be wrapped a Page(s) wrapped in a Document (Document and Page are components from \@react-pdf/renderer)
* @public
*/
export declare function PortableText<B extends TypedObject = PortableTextBlock>(props: ReactPdfPortableTextProps<B>): JSX.Element
/**
* Typedef for the defaultComponentStyles prop for the ReactPDF PortableText serializer component
* @public
*/
declare type PortableTextStyles = {
block?: TypographyStyles
text?: TypographyStyles
marks?: MarksStyles
list?: ListStyles
image?: Style
}
/**
* Props typedef for the ReactPDF PortableText serializer component
* @public
*/
declare type ReactPdfPortableTextProps<B extends TypedObject = PortableTextBlock> = PortableTextProps<B> & {
defaultComponentStyles?: PortableTextStyles
baseFontSizePt?: number
}
/**
* Any object with an `_type` property (which is required in portable text arrays),
* as well as a _potential_ `_key` (highly encouraged)
* @public
*/
declare interface TypedObject {
/**
* Identifies the type of object/span this is, and is used to pick the correct React components
* to use when rendering a span or inline object with this type.
*/
_type: string
/**
* Uniquely identifies this object within its parent block.
* Not _required_, but highly encouraged.
*/
_key?: string
}
export declare namespace types {
export { TypographyStyles, MarksStyles, ListStyles, PortableTextStyles, ReactPdfPortableTextProps }
}
/**
* Typedef for the block and text subobjects of PortableTextStyles
* @public
*/
declare type TypographyStyles = {
h1?: Style
h2?: Style
h3?: Style
h4?: Style
h5?: Style
h6?: Style
normal?: Style
blockquote?: Style
}
export {}