Skip to content

Commit 2bd0ba1

Browse files
TuurDutoitjsamr
authored andcommitted
feat: move config for 'img' and 'a' into named interface
This makes it possible for library users to use TypeScript module augmentation to extend these types
1 parent 7c79513 commit 2bd0ba1

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

packages/render-html/src/shared-types.ts

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,52 @@ export interface ListElementConfig {
145145
markerTextStyle?: TextStyle;
146146
}
147147

148+
/**
149+
* Configuration for img.
150+
*
151+
* @public
152+
*/
153+
export interface ImgElementConfig {
154+
/**
155+
* Support for relative percent-widths.
156+
*
157+
* @defaultValue false
158+
*/
159+
enableExperimentalPercentWidth?: boolean;
160+
/**
161+
* Default width and height to display while image's dimensions are being retrieved.
162+
*
163+
* @remarks Changes to this prop will cause a react tree update. Always
164+
* memoize it.
165+
*/
166+
initialDimensions?: ImageDimensions;
167+
}
168+
169+
/**
170+
* Configuration for a.
171+
*
172+
* @public
173+
*/
174+
export interface AElementConfig {
175+
/**
176+
* A callback to handle anchors presses.
177+
*
178+
* @remarks The `href` argument has been normalized, see {@link useNormalizedUrl}.
179+
*
180+
* @defaultValue A function using React Native `Linking.onpenUrl`.
181+
* @param event - The {@link GestureResponderEvent} event.
182+
* @param href - The normalized href, see {@link useNormalizedUrl}.
183+
* @param htmlAttribs - The attributes of the underlying {@link Element}.
184+
* @param target - The normalized `target` for this hyperlink.
185+
*/
186+
onPress?: (
187+
event: GestureResponderEvent,
188+
href: string,
189+
htmlAttribs: Record<string, string>,
190+
target: '_blank' | '_self' | '_parent' | '_top'
191+
) => void;
192+
}
193+
148194
/**
149195
* Props for custom renderers. The convention is to declare a field per tag name.
150196
* In doing so, you can benefit from `useRendererProps('tagname')` in custom renderers.
@@ -163,40 +209,8 @@ export interface ListElementConfig {
163209
* @public
164210
*/
165211
export interface RenderersProps extends Record<string, any> {
166-
a: {
167-
/**
168-
* A callback to handle anchors presses.
169-
*
170-
* @remarks The `href` argument has been normalized, see {@link useNormalizedUrl}.
171-
*
172-
* @defaultValue A function using React Native `Linking.onpenUrl`.
173-
* @param event - The {@link GestureResponderEvent} event.
174-
* @param href - The normalized href, see {@link useNormalizedUrl}.
175-
* @param htmlAttribs - The attributes of the underlying {@link Element}.
176-
* @param target - The normalized `target` for this hyperlink.
177-
*/
178-
onPress?: (
179-
event: GestureResponderEvent,
180-
href: string,
181-
htmlAttribs: Record<string, string>,
182-
target: '_blank' | '_self' | '_parent' | '_top'
183-
) => void;
184-
};
185-
img: {
186-
/**
187-
* Support for relative percent-widths.
188-
*
189-
* @defaultValue false
190-
*/
191-
enableExperimentalPercentWidth?: boolean;
192-
/**
193-
* Default width and height to display while image's dimensions are being retrieved.
194-
*
195-
* @remarks Changes to this prop will cause a react tree update. Always
196-
* memoize it.
197-
*/
198-
initialDimensions?: ImageDimensions;
199-
};
212+
a: AElementConfig;
213+
img: ImgElementConfig;
200214
ol: ListElementConfig;
201215
ul: ListElementConfig;
202216
}

0 commit comments

Comments
 (0)