Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d431e86

Browse files
authoredAug 30, 2021
Storybook lite (github#21040)
* Remove storybook * Update index.js * Start a storybook outline * Start a storybook outline * Start showing errors * Update storybook.tsx * Typescript lint * Name field * Responsive * Update storybook.tsx * Update storybook.tsx * Update storybook.tsx * Add BumpLink to storybook * Update storybook.tsx
1 parent 9faab57 commit d431e86

File tree

4 files changed

+83
-4
lines changed

4 files changed

+83
-4
lines changed
 

‎components/ui/BumpLink/BumpLink.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import cx from 'classnames'
33

44
import styles from './BumpLink.module.scss'
55

6-
type Props = {
6+
export type BumpLinkPropsT = {
77
children?: ReactNode
88
title: ReactElement<any> | string
99
href: string
1010
as?: ElementType<{ className?: string; href: string }>
1111
className?: string
1212
}
13-
export const BumpLink = ({ as, children, href, title, className }: Props) => {
13+
14+
export const BumpLink = ({ as, children, href, title, className }: BumpLinkPropsT) => {
1415
const Component = as || 'a'
1516

1617
const symbol = <span className={styles.symbol}></span>

‎components/ui/Callout/Callout.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import { DOMAttributes, ReactNode } from 'react'
22
import cx from 'classnames'
33
import styles from './Callout.module.scss'
44

5-
type Props = {
5+
export type CalloutPropsT = {
66
dangerouslySetInnerHTML?: DOMAttributes<HTMLDivElement>['dangerouslySetInnerHTML']
77
variant: 'success' | 'info' | 'warning'
88
children?: ReactNode
99
className?: string
1010
}
11-
export const Callout = ({ variant, className, dangerouslySetInnerHTML, children }: Props) => {
11+
12+
export const Callout = ({
13+
variant,
14+
className,
15+
dangerouslySetInnerHTML,
16+
children,
17+
}: CalloutPropsT) => {
1218
return (
1319
<div
1420
data-testid="callout"

‎middleware/render-page.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { isConnectionDropped } from './halt-on-dropped-connection.js'
66
import { nextApp, nextHandleRequest } from './next.js'
77

88
export default async function renderPage(req, res, next) {
9+
if (req.path.startsWith('/storybook')) {
10+
return nextHandleRequest(req, res)
11+
}
12+
913
const page = req.context.page
1014
// render a 404 page
1115
if (!page) {

‎pages/storybook.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react'
2+
import { BumpLink, BumpLinkPropsT } from 'components/ui/BumpLink/BumpLink'
3+
import { Callout, CalloutPropsT } from 'components/ui/Callout/Callout'
4+
5+
const stories = [
6+
{
7+
name: 'BumpLink',
8+
component: BumpLink,
9+
variants: [
10+
{ title: 'Think basic', href: 'http://example.com' } as BumpLinkPropsT,
11+
{
12+
title: 'Think different',
13+
href: 'http://example.com',
14+
children: 'This is child text',
15+
} as BumpLinkPropsT,
16+
{
17+
as: 'div',
18+
title: 'Think as div',
19+
href: 'http://example.com',
20+
className: 'color-bg-warning',
21+
} as BumpLinkPropsT,
22+
],
23+
},
24+
{
25+
name: 'Callout', // {component.name} gets optimized away
26+
component: Callout,
27+
variants: [
28+
{ variant: 'success', children: 'Yay you did it!', className: '' } as CalloutPropsT,
29+
{ variant: 'info', children: 'Captain I have information.', className: '' } as CalloutPropsT,
30+
{ variant: 'warning', children: 'Warning... warning...', className: '' } as CalloutPropsT,
31+
{ variant: 'success', children: 'I am a little font', className: 'f6' } as CalloutPropsT,
32+
],
33+
},
34+
]
35+
36+
export default function Storybook() {
37+
return (
38+
<div className="p-4 mx-auto" style={{ maxWidth: 1200 }}>
39+
<h1>GitHub Docs Storybook</h1>
40+
<p className="f3">This page lists React components unique to the GitHub docs.</p>
41+
<div className="my-4 d-lg-flex flex-items-start">
42+
<nav className="menu col-12 col-lg-3 mr-4 color-bg-secondary position-lg-sticky top-0">
43+
{stories.map(({ name }) => (
44+
<a className="menu-item" href={`#${name}`}>
45+
{name}
46+
</a>
47+
))}
48+
</nav>
49+
<div className="col-12 col-lg-9">
50+
{stories.map(({ name, component, variants }) => (
51+
<div id={name} key={name} className="mb-4">
52+
<h2 className="position-sticky top-0 color-bg-primary border-bottom">{name}</h2>
53+
{variants.map((props) => (
54+
<div className="my-4" key={JSON.stringify(props)}>
55+
{/* @ts-ignore */}
56+
{React.createElement(component, props)}
57+
<pre className="mt-2 p-2 color-bg-tertiary border rounded-2">
58+
{JSON.stringify(props, null, 2)}
59+
</pre>
60+
</div>
61+
))}
62+
</div>
63+
))}
64+
</div>
65+
</div>
66+
</div>
67+
)
68+
}

0 commit comments

Comments
 (0)
Please sign in to comment.