Skip to content

Commit

Permalink
feat: move config for 'img' and 'a' into named interface
Browse files Browse the repository at this point in the history
This makes it possible for library users to use TypeScript module augmentation to extend these types
  • Loading branch information
TuurDutoit authored and jsamr committed Dec 23, 2022
1 parent 7c79513 commit 2bd0ba1
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions packages/render-html/src/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,52 @@ export interface ListElementConfig {
markerTextStyle?: TextStyle;
}

/**
* Configuration for img.
*
* @public
*/
export interface ImgElementConfig {
/**
* Support for relative percent-widths.
*
* @defaultValue false
*/
enableExperimentalPercentWidth?: boolean;
/**
* Default width and height to display while image's dimensions are being retrieved.
*
* @remarks Changes to this prop will cause a react tree update. Always
* memoize it.
*/
initialDimensions?: ImageDimensions;
}

/**
* Configuration for a.
*
* @public
*/
export interface AElementConfig {
/**
* A callback to handle anchors presses.
*
* @remarks The `href` argument has been normalized, see {@link useNormalizedUrl}.
*
* @defaultValue A function using React Native `Linking.onpenUrl`.
* @param event - The {@link GestureResponderEvent} event.
* @param href - The normalized href, see {@link useNormalizedUrl}.
* @param htmlAttribs - The attributes of the underlying {@link Element}.
* @param target - The normalized `target` for this hyperlink.
*/
onPress?: (
event: GestureResponderEvent,
href: string,
htmlAttribs: Record<string, string>,
target: '_blank' | '_self' | '_parent' | '_top'
) => void;
}

/**
* Props for custom renderers. The convention is to declare a field per tag name.
* In doing so, you can benefit from `useRendererProps('tagname')` in custom renderers.
Expand All @@ -163,40 +209,8 @@ export interface ListElementConfig {
* @public
*/
export interface RenderersProps extends Record<string, any> {
a: {
/**
* A callback to handle anchors presses.
*
* @remarks The `href` argument has been normalized, see {@link useNormalizedUrl}.
*
* @defaultValue A function using React Native `Linking.onpenUrl`.
* @param event - The {@link GestureResponderEvent} event.
* @param href - The normalized href, see {@link useNormalizedUrl}.
* @param htmlAttribs - The attributes of the underlying {@link Element}.
* @param target - The normalized `target` for this hyperlink.
*/
onPress?: (
event: GestureResponderEvent,
href: string,
htmlAttribs: Record<string, string>,
target: '_blank' | '_self' | '_parent' | '_top'
) => void;
};
img: {
/**
* Support for relative percent-widths.
*
* @defaultValue false
*/
enableExperimentalPercentWidth?: boolean;
/**
* Default width and height to display while image's dimensions are being retrieved.
*
* @remarks Changes to this prop will cause a react tree update. Always
* memoize it.
*/
initialDimensions?: ImageDimensions;
};
a: AElementConfig;
img: ImgElementConfig;
ol: ListElementConfig;
ul: ListElementConfig;
}
Expand Down

0 comments on commit 2bd0ba1

Please sign in to comment.