forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlaygroundArticle.tsx
104 lines (90 loc) · 3.06 KB
/
PlaygroundArticle.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react'
import cx from 'classnames'
import { CheckIcon, SearchIcon } from '@primer/octicons-react'
import { PlaygroundContentBlock } from './PlaygroundContentBlock'
import { ArticleMarkdown } from 'components/playground/ArticleMarkdown'
import { getAnchorLink } from 'components/lib/getAnchorLink'
import { usePlaygroundContext } from 'components/context/PlaygroundContext'
export const PlaygroundArticle = () => {
const { article } = usePlaygroundContext()
if (!article) {
return null
}
return (
<div>
{/* article header */}
<div className="border-bottom py-5">
<h1>{article.title}</h1>
<h2 className="h3 my-3 text-normal text-gray border-bottom-0">
<ArticleMarkdown className="markdown-body">{article.intro}</ArticleMarkdown>
</h2>
{article.prerequisites && (
<div className="mt-4 d-flex">
<div className="pr-3 mt-1">
<Circle className="color-bg-info-inverse">
<CheckIcon className="color-text-white" size={15} />
</Circle>
</div>
<div className="">
<h3>Prerequisites</h3>
<ArticleMarkdown className="markdown-body playground">
{article.prerequisites}
</ArticleMarkdown>
</div>
</div>
)}
{/* toc */}
<div className="mt-4 d-flex">
<div className="pr-3 mt-1">
<Circle className="color-bg-info-inverse">
<SearchIcon className="color-text-white" size={15} />
</Circle>
</div>
<div>
<h3>In this Article</h3>
<ul className="list-style-none ml-3 mt-2">
{article.contentBlocks.map((block) => {
if (!block.title || block.type === 'sub-section-2') {
return null
}
const anchor = getAnchorLink(block.title)
if (block.type === 'sub-section') {
return (
<li key={anchor} className="pointer ml-4 my-1">
<a href={`#${anchor}`}>{block.title}</a>
</li>
)
}
return (
<li key={anchor} className="pointer text-bold text-blue my-2">
<a href={`#${anchor}`}>{block.title}</a>
</li>
)
})}
</ul>
</div>
</div>
</div>
{/* body */}
{article.contentBlocks.map((block, index) => (
<PlaygroundContentBlock
key={`section-${index}`}
contentBlock={block}
sectionIndex={index}
/>
))}
{/* spacer for end of article */}
<div style={{ minHeight: '75vh' }} />
</div>
)
}
const Circle = ({ className, children }: { className?: string; children?: React.ReactNode }) => {
return (
<div
className={cx('circle d-flex flex-justify-center flex-items-center', className)}
style={{ width: 24, height: 24 }}
>
{children}
</div>
)
}