Skip to content

Commit badd90b

Browse files
committed
TSDoc -> TypeDoc, constants, latest @date-fns/docs
1 parent 4e6aef1 commit badd90b

File tree

21 files changed

+240
-103
lines changed

21 files changed

+240
-103
lines changed

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"start": "env NODE_ENV=development ts-node -r tsconfig-paths/register devServer.ts"
1515
},
1616
"dependencies": {
17-
"@date-fns/docs": "0.18.0",
17+
"@date-fns/docs": "0.21.1",
1818
"@sentry/browser": "^5.30.0",
1919
"@sentry/tracing": "^5.30.0",
2020
"@switcher/preact": "2.3.0",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ComponentChildren, FunctionComponent, h, Fragment } from 'preact'
2+
import { DocHeaderAnchor } from '~/ui/components/DocHeaderAnchor'
3+
import { Markdown } from '~/ui/components/Markdown'
4+
5+
interface DocDescriptionProps {
6+
description: string
7+
header?: 'h2' | 'h3'
8+
}
9+
10+
export const DocDescription: FunctionComponent<DocDescriptionProps> = ({
11+
description,
12+
header,
13+
}) => {
14+
const headerContent = (
15+
<>
16+
Description
17+
<DocHeaderAnchor anchor="description" />
18+
</>
19+
)
20+
21+
return (
22+
<section>
23+
{header === 'h2' ? (
24+
<h2 id="description">{headerContent}</h2>
25+
) : (
26+
<h3 id="description">{headerContent}</h3>
27+
)}
28+
29+
<Markdown value={description} />
30+
</section>
31+
)
32+
}
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, FunctionComponent } from 'preact'
1+
import { h, Fragment, FunctionComponent } from 'preact'
22
import { Code } from '~/ui/components/Code'
33
import { DocHeaderAnchor } from '~/ui/components/DocHeaderAnchor'
44
import isArray from 'lodash/isArray'
@@ -7,23 +7,34 @@ import * as styles from './styles.css'
77

88
interface Props {
99
examples: string[] | string
10+
header?: 'h2' | 'h3'
1011
}
1112

12-
export const DocExamples: FunctionComponent<Props> = ({ examples }) => (
13-
<section>
14-
<h2 id="examples">
13+
export const DocExamples: FunctionComponent<Props> = ({ examples, header }) => {
14+
const headerContent = (
15+
<>
1516
Examples
1617
<DocHeaderAnchor anchor="examples" />
17-
</h2>
18+
</>
19+
)
1820

19-
{isArray(examples) ? (
20-
examples.map((example, index) => (
21-
<div class={styles.codeContainer} key={index}>
22-
<Code value={example} />
23-
</div>
24-
))
25-
) : (
26-
<Markdown value={examples} />
27-
)}
28-
</section>
29-
)
21+
return (
22+
<section>
23+
{header === 'h2' ? (
24+
<h2 id="examples">{headerContent}</h2>
25+
) : (
26+
<h3 id="description">{headerContent}</h3>
27+
)}
28+
29+
{isArray(examples) ? (
30+
examples.map((example, index) => (
31+
<div class={styles.codeContainer} key={index}>
32+
<Code value={example} />
33+
</div>
34+
))
35+
) : (
36+
<Markdown value={examples} />
37+
)}
38+
</section>
39+
)
40+
}

β€Žsrc/ui/components/DocLinks/index.tsxβ€Ž

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { h } from 'preact'
22
import { useContext } from 'preact/hooks'
33
import { RouterContext, RouterLink } from '~/ui/router'
44
import { bugTemplateText, docIssueTemplateText } from './templateText'
5-
import * as styles from './styles.css'
65

76
export const DocLinks = () => {
87
const { location } = useContext(RouterContext)
@@ -19,7 +18,6 @@ export const DocLinks = () => {
1918
<li>
2019
<div>
2120
<RouterLink
22-
class={styles.link}
2321
decorated
2422
to={{
2523
name: 'docs',

β€Žsrc/ui/components/DocLinks/styles.css.tsβ€Ž

Lines changed: 0 additions & 6 deletions
This file was deleted.

β€Žsrc/ui/components/RichText/styles.css.tsβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,10 @@ globalStyle(`${content} ul ul`, {
146146
globalStyle(`${content} ul:last-child`, {
147147
marginBottom: '0',
148148
})
149+
150+
globalStyle(`${content} blockquote`, {
151+
marginBottom: '10px',
152+
borderLeft: '3px solid #b9a2b2',
153+
background: '#faf6f0',
154+
padding: '0.5rem 1rem',
155+
})

β€Žsrc/ui/screens/Docs/Doc/JSDoc/index.tsxβ€Ž

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Returns } from './Returns'
1111
import { Syntax } from './Syntax'
1212
import { DocUsage } from '~/ui/components/DocUsage'
1313
import { DocHeader } from '~/ui/components/DocHeader'
14+
import { DocDescription } from '~/ui/components/DocDescription'
1415

1516
interface Props {
1617
doc: DateFnsDocs.JSDocFunction
@@ -20,14 +21,7 @@ export const JSDoc: FunctionComponent<Props> = ({ doc }) => (
2021
<div>
2122
<DocHeader>{doc.title}</DocHeader>
2223

23-
<section>
24-
<h2 id="description">
25-
Description
26-
<DocHeaderAnchor anchor="description" />
27-
</h2>
28-
29-
<Markdown value={doc.content.description} />
30-
</section>
24+
<DocDescription description={doc.content.description} />
3125

3226
{doc.usage && doc.usageTabs && (
3327
<DocUsage usage={doc.usage} usageTabs={doc.usageTabs} />
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import type { DateFnsDocs } from '@date-fns/docs/types'
2+
import {
3+
findDescription,
4+
findSummary,
5+
findFnDescription,
6+
findFnExamples,
7+
findExamples,
8+
} from '@date-fns/docs/utils'
9+
import { Fragment, FunctionComponent, h } from 'preact'
10+
import { useMemo } from 'preact/hooks'
11+
import type { DeclarationReflection } from 'typedoc'
12+
import { CodeComponent } from '~/ui/components/Code'
13+
import { DocDescription } from '~/ui/components/DocDescription'
14+
import { DocExamples } from '~/ui/components/DocExamples'
15+
import { DocHeader } from '~/ui/components/DocHeader'
16+
import { DocHeaderAnchor } from '~/ui/components/DocHeaderAnchor'
17+
import { DocLinks } from '~/ui/components/DocLinks'
18+
import { extractCodeFromTagString } from '~/utils/docs'
19+
import * as styles from './styles.css'
20+
21+
interface TypeDocConstantsProps {
22+
page: DateFnsDocs.TypeDocPage
23+
doc: DeclarationReflection
24+
}
25+
26+
export const TypeDocConstants: FunctionComponent<TypeDocConstantsProps> = ({
27+
page,
28+
doc,
29+
}) => {
30+
const description = useMemo(() => findDescription(doc), [doc])
31+
32+
return (
33+
<>
34+
<DocHeader>{page.title}</DocHeader>
35+
36+
{description && <DocDescription description={description} />}
37+
38+
{doc.children?.map((constant) => (
39+
<Constant constant={constant} />
40+
))}
41+
42+
<code>
43+
<pre>{JSON.stringify(doc, null, 2)}</pre>
44+
</code>
45+
46+
<DocLinks />
47+
</>
48+
)
49+
}
50+
51+
interface ConstantProps {
52+
constant: DeclarationReflection
53+
}
54+
55+
function Constant({ constant }: ConstantProps) {
56+
if (constant.kindString !== 'Variable') return null
57+
58+
const description = useMemo(
59+
() => findDescription(constant) || findSummary(constant),
60+
[constant]
61+
)
62+
63+
const examples = useMemo(
64+
() => findExamples(constant).map(extractCodeFromTagString),
65+
[constant]
66+
)
67+
68+
return (
69+
<section>
70+
<h2 id={constant.name}>
71+
<span class={styles.name}>{constant.name}</span>
72+
<DocHeaderAnchor anchor={constant.name} />
73+
</h2>
74+
75+
{description && <DocDescription description={description} header="h3" />}
76+
77+
{examples && <DocExamples examples={examples} header="h3" />}
78+
</section>
79+
)
80+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { style } from '@vanilla-extract/css'
2+
3+
export const name = style({
4+
fontFamily: 'monospace',
5+
})
File renamed without changes.

0 commit comments

Comments
Β (0)