|
1 |
| -import { DeclarationReflection, ReflectionType } from "../../../../models"; |
| 1 | +import type { DeclarationReflection, ReflectionType } from "../../../../models"; |
2 | 2 | import { JSX } from "../../../../utils";
|
3 | 3 | import { getKindClass, hasTypeParameters, renderTypeParametersSignature, wbr } from "../../lib";
|
4 | 4 | import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
|
5 | 5 |
|
6 |
| -export const memberDeclaration = (context: DefaultThemeRenderContext, props: DeclarationReflection) => ( |
7 |
| - <> |
8 |
| - <div class="tsd-signature"> |
9 |
| - <span class={getKindClass(props)}>{wbr(props.name)}</span> |
10 |
| - {renderTypeParametersSignature(context, props.typeParameters)} |
11 |
| - {props.type && ( |
12 |
| - <> |
13 |
| - <span class="tsd-signature-symbol">{!!props.flags.isOptional && "?"}:</span>{" "} |
14 |
| - {context.type(props.type)} |
15 |
| - </> |
16 |
| - )} |
17 |
| - {!!props.defaultValue && ( |
18 |
| - <> |
19 |
| - <span class="tsd-signature-symbol"> |
20 |
| - {" = "} |
21 |
| - {props.defaultValue} |
22 |
| - </span> |
23 |
| - </> |
24 |
| - )} |
25 |
| - </div> |
26 |
| - |
27 |
| - {context.commentSummary(props)} |
28 |
| - |
29 |
| - {hasTypeParameters(props) && context.typeParameters(props.typeParameters)} |
30 |
| - |
31 |
| - {props.type instanceof ReflectionType && ( |
| 6 | +export function memberDeclaration(context: DefaultThemeRenderContext, props: DeclarationReflection) { |
| 7 | + function renderTypeDeclaration(type: ReflectionType) { |
| 8 | + return ( |
32 | 9 | <div class="tsd-type-declaration">
|
33 | 10 | <h4>Type declaration</h4>
|
34 |
| - {context.parameter(props.type.declaration)} |
| 11 | + {context.parameter(type.declaration)} |
35 | 12 | </div>
|
36 |
| - )} |
| 13 | + ); |
| 14 | + } |
37 | 15 |
|
38 |
| - {context.commentTags(props)} |
| 16 | + const visitor = { reflection: renderTypeDeclaration }; |
39 | 17 |
|
40 |
| - {context.memberSources(props)} |
41 |
| - </> |
42 |
| -); |
| 18 | + return ( |
| 19 | + <> |
| 20 | + <div class="tsd-signature"> |
| 21 | + <span class={getKindClass(props)}>{wbr(props.name)}</span> |
| 22 | + {renderTypeParametersSignature(context, props.typeParameters)} |
| 23 | + {props.type && ( |
| 24 | + <> |
| 25 | + <span class="tsd-signature-symbol">{!!props.flags.isOptional && "?"}:</span>{" "} |
| 26 | + {context.type(props.type)} |
| 27 | + </> |
| 28 | + )} |
| 29 | + {!!props.defaultValue && ( |
| 30 | + <> |
| 31 | + <span class="tsd-signature-symbol"> |
| 32 | + {" = "} |
| 33 | + {props.defaultValue} |
| 34 | + </span> |
| 35 | + </> |
| 36 | + )} |
| 37 | + </div> |
| 38 | + |
| 39 | + {context.commentSummary(props)} |
| 40 | + |
| 41 | + {hasTypeParameters(props) && context.typeParameters(props.typeParameters)} |
| 42 | + |
| 43 | + {props.type?.visit<JSX.Children>({ |
| 44 | + reflection: renderTypeDeclaration, |
| 45 | + array: (arr) => arr.elementType.visit(visitor), |
| 46 | + intersection: (int) => int.types.map((t) => t.visit(visitor)), |
| 47 | + union: (union) => union.types.map((t) => t.visit(visitor)), |
| 48 | + reference: (ref) => ref.typeArguments?.map((t) => t.visit(visitor)), |
| 49 | + tuple: (ref) => ref.elements.map((t) => t.visit(visitor)), |
| 50 | + })} |
| 51 | + |
| 52 | + {context.commentTags(props)} |
| 53 | + |
| 54 | + {context.memberSources(props)} |
| 55 | + </> |
| 56 | + ); |
| 57 | +} |
0 commit comments