Skip to content

Commit

Permalink
feat(ts): new generic argument for renderers propsFromParent prop
Browse files Browse the repository at this point in the history
This especially improves plugin authors capability to convey information
on custom renderers.
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 230e2c5 commit 6427732
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions packages/render-html/src/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,30 @@ export interface TNodeChildrenRendererProps extends TChildrenBaseProps {
tnode: TNode;
}

export interface TNodeRendererProps<T extends TNode> {
export interface TNodeRendererProps<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> {
tnode: T;
key?: string | number;
markers: Markers;
propsFromParent: PropsFromParent;
propsFromParent: P;
}

export interface TNodeSubRendererProps<T extends TNode>
extends TNodeRendererProps<T> {
export interface TNodeSubRendererProps<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> extends TNodeRendererProps<T, P> {
/**
* Props shared across the whole render tree.
*/
sharedProps: Required<RenderHTMLSharedProps<any>>;
}

export interface TRendererBaseProps<T extends TNode>
extends TNodeRendererProps<T> {
export interface TRendererBaseProps<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> extends TNodeRendererProps<T, P> {
/**
* Any default renderer should be able to handle press.
*/
Expand All @@ -533,8 +540,10 @@ export interface TRendererBaseProps<T extends TNode>
type: 'text' | 'block';
}

export interface TDefaultRendererProps<T extends TNode>
extends TRendererBaseProps<T> {
export interface TDefaultRendererProps<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> extends TRendererBaseProps<T, P> {
/**
* When children is present, renderChildren will not be invoked.
*/
Expand All @@ -555,8 +564,10 @@ export interface TDefaultRendererProps<T extends TNode>
propsForChildren?: Partial<PropsFromParent>;
}

export interface DefaultTagRendererProps<T extends TNode>
extends TRendererBaseProps<T> {
export interface DefaultTagRendererProps<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> extends TRendererBaseProps<T, P> {
/**
* Styles extracted from tnode.style
*/
Expand All @@ -571,8 +582,10 @@ export interface DefaultTagRendererProps<T extends TNode>
TDefaultRenderer: TDefaultRenderer<T>;
}

export interface CustomTagRendererProps<T extends TNode>
extends DefaultTagRendererProps<T> {
export interface CustomTagRendererProps<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> extends DefaultTagRendererProps<T, P> {
/**
* Internal renderer for this _tagName_, not to be confused with
* {@link TDefaultRenderer}, which is the default renderer for the _tnode_.
Expand All @@ -586,17 +599,20 @@ export interface CustomTagRendererProps<T extends TNode>
DefaultTagRenderer: DefaultTagRenderer<T>;
}

export type TDefaultRenderer<T extends TNode> = React.ComponentType<
TDefaultRendererProps<T>
>;
export type TDefaultRenderer<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> = React.ComponentType<TDefaultRendererProps<T, P>>;

export type DefaultTagRenderer<T extends TNode> = React.ComponentType<
DefaultTagRendererProps<T>
>;
export type DefaultTagRenderer<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> = React.ComponentType<DefaultTagRendererProps<T, P>>;

export type CustomTagRenderer<T extends TNode> = React.ComponentType<
CustomTagRendererProps<T>
>;
export type CustomTagRenderer<
T extends TNode,
P extends PropsFromParent = PropsFromParent
> = React.ComponentType<CustomTagRendererProps<T, P>>;

/**
* An object containing meta-data extracted from resource URL and HTML
Expand Down

0 comments on commit 6427732

Please sign in to comment.