forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorybook.tsx
199 lines (195 loc) · 6.83 KB
/
storybook.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import React from 'react'
import ReactDomServer from 'react-dom/server'
import { BumpLink, BumpLinkPropsT } from 'components/ui/BumpLink/BumpLink'
import { Callout, CalloutPropsT } from 'components/ui/Callout/Callout'
import { Lead, LeadPropsT } from 'components/ui/Lead/Lead'
import {
MarkdownContent,
MarkdownContentPropsT,
} from 'components/ui/MarkdownContent/MarkdownContent'
import { ScrollButton, ScrollButtonPropsT } from 'components/ui/ScrollButton/ScrollButton'
import { TruncateLines, TruncateLinesPropsT } from 'components/ui/TruncateLines/TruncateLines'
const markdownExample = (
<>
<h1>Header Level 1: Steps example</h1>
<ol>
<li>Start with step 1</li>
<li>Continue with step 2</li>
<li>Finish with step 3</li>
</ol>
<h2>Header Level 2: Highlighted code example</h2>
<pre>
<code className="hljs language-yaml">
<span className="hljs-attr">steps:</span>
{'\n'}
<span className="hljs-bullet">-</span> <span className="hljs-attr">uses:</span>{' '}
<span className="hljs-string">actions/checkout@v2</span>
{'\n'}
<span className="hljs-bullet">-</span> <span className="hljs-attr">uses:</span>{' '}
<span className="hljs-string">actions/setup-java@v2</span>
{'\n '}
<span className="hljs-attr">with:</span>
{'\n '}
<span className="hljs-attr">java-version:</span> <span className="hljs-string">'11'</span>
{'\n '}
<span className="hljs-attr">distribution:</span>{' '}
<span className="hljs-string">'adopt'</span>
</code>
</pre>
<h3>Header Level 3: Table example</h3>
<table>
<thead>
<tr>
<th>Qualifier</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>sort:interactions</code> or <code>sort:interactions-desc</code>
</td>
<td>
<a href="https://github.com/search?q=org%3Agithub+sort%3Ainteractions&type=Issues">
<strong>org:github sort:interactions</strong>
</a>{' '}
matches issues in repositories owned by GitHub, sorted by the highest combined number of
reactions and comments.
</td>
</tr>
<tr>
<td>
<code>sort:interactions-asc</code>
</td>
<td>
<a href="https://github.com/search?utf8=%E2%9C%93&q=org%3Agithub+sort%3Ainteractions-asc&type=Issues">
<strong>org:github sort:interactions-asc</strong>
</a>{' '}
matches issues in repositories owned by GitHub, sorted by the lowest combined number of
reactions and comments.
</td>
</tr>
</tbody>
</table>
<h4>Header Level 4: Procedural image example</h4>
<img
alt="Group assignment"
className="procedural-image-wrapper"
src="/assets/images/help/classroom/assignment-group-hero.png"
/>
</>
)
// Trying to keep these alphabetical order
const stories = [
{
name: 'BumpLink',
component: BumpLink,
variants: [
{ title: 'Think basic', href: 'http://example.com' } as BumpLinkPropsT,
{
title: 'Think different',
href: 'http://example.com',
children: 'This is child text',
} as BumpLinkPropsT,
{
as: 'div',
title: 'Think as div',
href: 'http://example.com',
className: 'color-bg-attention',
} as BumpLinkPropsT,
],
},
{
name: 'Callout',
component: Callout,
variants: [
{ variant: 'success', children: 'Yay you did it!', className: '' } as CalloutPropsT,
{ variant: 'info', children: 'Captain I have information.', className: '' } as CalloutPropsT,
{ variant: 'warning', children: 'Warning... warning...', className: '' } as CalloutPropsT,
{ variant: 'success', children: 'I am a little font', className: 'f6' } as CalloutPropsT,
],
},
{
name: 'Lead',
component: Lead,
variants: [
{ children: 'Lead by example' } as LeadPropsT,
{ children: 'Lead by blue', className: 'color-bg-accent' } as LeadPropsT,
{
children: (
<>
You can personalize Codespaces by using a <code>dotfiles</code> repository on GitHub.
</>
),
} as LeadPropsT,
],
},
{
name: 'MarkdownContent',
component: MarkdownContent,
variants: [{ children: markdownExample } as MarkdownContentPropsT],
},
{
name: 'ScrollButton',
component: ScrollButton,
variants: [{ className: '', ariaLabel: 'Scroll to top' } as ScrollButtonPropsT],
},
{
name: 'TruncateLines',
component: TruncateLines,
variants: [
{
as: 'p',
maxLines: 2,
children:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
className: 'color-bg-subtle',
} as TruncateLinesPropsT,
],
},
]
function displayProps(props: Object) {
const xprops = Object.fromEntries(
Object.entries(props).map(([key, value]) => [
key,
key === 'children' ? ReactDomServer.renderToString(value) : value,
])
)
return JSON.stringify(xprops, null, 2)
}
export default function Storybook() {
return (
<div className="p-4 mx-auto" style={{ maxWidth: 1200 }}>
<h1>GitHub Docs Storybook</h1>
<Lead>This page lists React components unique to the GitHub docs.</Lead>
<div className="my-4 d-lg-flex flex-items-start">
<nav className="menu col-12 col-lg-3 mr-4 color-bg-subtle position-lg-sticky top-0">
{stories.map(({ name }) => (
<a className="menu-item" href={`#${name}`}>
{name}
</a>
))}
</nav>
<div className="col-12 col-lg-9">
{stories.map(({ name, component, variants }) => (
<div id={name} key={name} className="mb-8">
<h2 className="position-sticky top-0 color-bg-default border-bottom z-2">{name}</h2>
{variants.map((props) => (
<div className="my-4" key={JSON.stringify(props)}>
{/* @ts-ignore */}
{React.createElement(component, props)}
<pre
className="mt-2 p-2 color-bg-subtle border rounded-2"
style={{ whiteSpace: 'pre-wrap' }}
>
{displayProps(props)}
</pre>
</div>
))}
</div>
))}
</div>
</div>
</div>
)
}