Skip to content

Commit ece1821

Browse files
committed
Object reflection, indentation, proper type styling, imports
1 parent 916c8a9 commit ece1821

File tree

15 files changed

+172
-66
lines changed

15 files changed

+172
-66
lines changed

src/ui/components/DocReturns/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentChildren, Fragment, FunctionComponent, h } from 'preact'
22
import { Markdown } from '~/ui/components/Markdown'
3+
import { InlineCode } from '../InlineCode'
34
import { SectionHeader } from '../SectionHeader'
45

56
interface ReturnType {
@@ -33,7 +34,9 @@ export const DocReturns: FunctionComponent<DocReturnsProps> = ({
3334
<tbody>
3435
{returns.map((returnData, index) => (
3536
<tr key={index}>
36-
<td>{returnData.type}</td>
37+
<td>
38+
<InlineCode>{returnData.type}</InlineCode>
39+
</td>
3740
<td>
3841
<Markdown value={returnData.description} />
3942
</td>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ComponentChildren, Fragment, FunctionComponent, h } from 'preact'
2+
import * as styles from './styles.css'
3+
4+
interface InlineCodeProps {
5+
children: ComponentChildren
6+
}
7+
8+
export const InlineCode: FunctionComponent<InlineCodeProps> = ({
9+
children,
10+
}) => <span class={styles.code}>{children}</span>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { style } from '@vanilla-extract/css'
2+
3+
export const code = style({
4+
fontFamily: 'monospace',
5+
display: 'block',
6+
textIndent: '-10px',
7+
paddingLeft: '10px',
8+
})

src/ui/components/TypeDocInterface/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
import { InlineTypeContext } from '~/ui/contexts/InlineTypeContext'
1010
import { findSource, ParentTypesMap } from '~/utils/docs'
1111
import { IdHightlight } from '../IdHighlight'
12+
import { InlineCode } from '../InlineCode'
1213
import { Markdown } from '../Markdown'
1314
import { SourceLink } from '../SourceLink'
1415
import { TypeDocType } from '../TypeDocType'
@@ -58,7 +59,11 @@ export function TypeDocInterface<
5859
</td>
5960

6061
<td style={styles.code}>
61-
{item.type && <TypeDocType type={item.type} />}
62+
{item.type && (
63+
<InlineCode>
64+
<TypeDocType type={item.type} />
65+
</InlineCode>
66+
)}
6267
</td>
6368

6469
<td>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Fragment, FunctionComponent, h } from 'preact'
2+
import { useContext } from 'preact/hooks'
3+
import type { DeclarationReflection } from 'typedoc'
4+
import { TypeIndentContext } from '~/ui/contexts/TypeIndentContext'
5+
import { Debug } from '../../Debug'
6+
import { TypeDocSignature } from '../../TypeDocSignature'
7+
import { TypeDocType } from '../../TypeDocType'
8+
9+
interface TypeDocReflectionObjectProps {
10+
declaration: DeclarationReflection
11+
}
12+
13+
export const TypeDocReflectionObject: FunctionComponent<TypeDocReflectionObjectProps> = ({
14+
declaration,
15+
}) => {
16+
const indent = useContext(TypeIndentContext)
17+
const localIndent = indent + 2
18+
19+
return (
20+
<TypeIndentContext.Provider value={localIndent}>
21+
{'{'}
22+
{declaration.children?.map((child) => (
23+
<>
24+
<br />
25+
{' '.repeat(localIndent)}
26+
{child.name}
27+
{child.flags.isOptional && '?'}: <TypeDocType type={child.type!} />
28+
</>
29+
))}
30+
<br />
31+
{' '.repeat(indent) + '}'}
32+
</TypeIndentContext.Provider>
33+
)
34+
}
File renamed without changes.

src/ui/components/TypeDocReflection/Signature/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Fragment, FunctionComponent, h } from 'preact'
22
import type { SignatureReflection } from 'typedoc'
33
import { TypeDocSignature } from '../../TypeDocSignature'
44

5-
interface TypeDocReflectionProps {
5+
interface TypeDocReflectionSignatureProps {
66
signature: SignatureReflection
77
listed: boolean | undefined
88
}
99

10-
export const TypeDocReflectionSignature: FunctionComponent<TypeDocReflectionProps> = ({
10+
export const TypeDocReflectionSignature: FunctionComponent<TypeDocReflectionSignatureProps> = ({
1111
signature,
1212
listed,
1313
}) => {

src/ui/components/TypeDocReflection/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FunctionComponent, h } from 'preact'
22
import type { ReflectionType } from 'typedoc'
3-
import { ParentTypesMap } from '~/utils/docs'
43
import { Missing } from '../Missing'
4+
import { TypeDocReflectionObject } from './Object'
55
import { TypeDocReflectionSignature } from './Signature'
66

77
interface TypeDocReflection {
@@ -27,5 +27,6 @@ export const TypeDocReflection: FunctionComponent<TypeDocReflection> = ({
2727
/>
2828
)
2929
}
30-
return <Missing data={reflection} />
30+
31+
return <TypeDocReflectionObject declaration={reflection.declaration} />
3132
}

src/ui/components/TypeDocSignature/Arguments/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Fragment, FunctionComponent, h } from 'preact'
2+
import { useContext } from 'preact/hooks'
23
import type { ParameterReflection } from 'typedoc'
4+
import { TypeIndentContext } from '~/ui/contexts/TypeIndentContext'
35
import { ParentTypesMap } from '~/utils/docs'
46
import { TypeDocType } from '../../TypeDocType'
57

@@ -10,13 +12,16 @@ interface TypeDocSignatureArgumentsProps {
1012
export const TypeDocSignatureArguments: FunctionComponent<TypeDocSignatureArgumentsProps> = ({
1113
args,
1214
}) => {
15+
const indent = useContext(TypeIndentContext)
16+
const localIndent = indent + 2
17+
1318
return (
14-
<>
19+
<TypeIndentContext.Provider value={localIndent}>
1520
{args.map((arg, index) => (
1621
<>
1722
<br />
1823
<span>
19-
{' '}
24+
{' '.repeat(localIndent)}
2025
{arg.name}
2126
{arg.flags.isOptional && '?'}
2227
{arg.type && (
@@ -29,6 +34,6 @@ export const TypeDocSignatureArguments: FunctionComponent<TypeDocSignatureArgume
2934
</span>
3035
</>
3136
))}
32-
</>
37+
</TypeIndentContext.Provider>
3338
)
3439
}

src/ui/components/TypeDocSignature/Generics/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FunctionComponent, h } from 'preact'
1+
import { FunctionComponent, h, Fragment } from 'preact'
22
import { useContext } from 'preact/hooks'
33
import type { TypeParameterReflection } from 'typedoc'
44
import { InlineTypeContext } from '~/ui/contexts/InlineTypeContext'
@@ -16,12 +16,12 @@ export const TypeDocSignatureGenerics: FunctionComponent<TypeDocSignatureGeneric
1616
const inline = useContext(InlineTypeContext)
1717

1818
return (
19-
<span>
19+
<>
2020
{'<'}
2121
{params.map((param, index) => {
2222
const id = inline.buildId?.(param)
2323
return (
24-
<span>
24+
<>
2525
{inline ? (
2626
<span id={id}>
2727
<IdHightlight id={id} match={inline.idHighlightMatch}>
@@ -33,22 +33,22 @@ export const TypeDocSignatureGenerics: FunctionComponent<TypeDocSignatureGeneric
3333
)}
3434

3535
{param.type && (
36-
<span>
36+
<>
3737
{' '}
3838
extends <TypeDocType type={param.type} />
39-
</span>
39+
</>
4040
)}
4141
{param.default && (
42-
<span>
42+
<>
4343
{' '}
4444
= <TypeDocType type={param.default} />
45-
</span>
45+
</>
4646
)}
4747
{index < params.length - 1 && ', '}
48-
</span>
48+
</>
4949
)
5050
})}
5151
{'>'}
52-
</span>
52+
</>
5353
)
5454
}

0 commit comments

Comments
 (0)