Skip to content

Commit af07564

Browse files
authored
Add gatsby doc site (reactjs#91)
1 parent bd21f42 commit af07564

File tree

7 files changed

+561
-0
lines changed

7 files changed

+561
-0
lines changed

www/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.cache
2+
public

www/gatsby-config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
siteMetadata: {
5+
title: 'React Transition Group Documentation',
6+
author: 'Jason Quense',
7+
},
8+
plugins: [
9+
{
10+
resolve: 'gatsby-source-filesystem',
11+
options: {
12+
path: path.join(__dirname, 'src/pages'),
13+
name: 'pages',
14+
},
15+
},
16+
{
17+
resolve: 'gatsby-source-filesystem',
18+
options: {
19+
path: path.join(__dirname, '../src'),
20+
name: 'components',
21+
},
22+
},
23+
{
24+
resolve: 'gatsby-transformer-remark',
25+
options: {
26+
plugins: [
27+
'gatsby-remark-prismjs',
28+
],
29+
},
30+
},
31+
'gatsby-transformer-react-docgen',
32+
'gatsby-plugin-sass'
33+
],
34+
}

www/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "react-transition-group-docs",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "gatsby build",
9+
"deploy": "npm run build && gh-pages -d public",
10+
"develop": "gatsby develop"
11+
},
12+
"author": "",
13+
"license": "MIT",
14+
"dependencies": {
15+
"bootstrap": "^4.0.0-alpha.6",
16+
"gatsby": "^1.0.0-beta.7",
17+
"gatsby-link": "^1.0.0-beta.6",
18+
"gatsby-plugin-sass": "^1.0.0-beta.1",
19+
"gatsby-remark-prismjs": "^1.0.0-beta.6",
20+
"gatsby-source-filesystem": "^1.0.0-beta.6",
21+
"gatsby-transformer-react-docgen": "^1.0.0-beta.6",
22+
"gatsby-transformer-remark": "^1.0.0-beta.6",
23+
"graphql-type-json": "^0.1.4",
24+
"lodash": "^4.17.4"
25+
},
26+
"devDependencies": {
27+
"gh-pages": "^1.0.0"
28+
}
29+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
2+
import React from 'react';
3+
import transform from 'lodash/transform';
4+
5+
6+
function displayObj(obj){
7+
return JSON.stringify(obj, null, 2).replace(/"|'/g, '')
8+
}
9+
10+
let capitalize = str => str[0].toUpperCase() + str.substr(1);
11+
let cleanDocletValue = str => str.trim().replace(/^\{/, '').replace(/\}$/, '');
12+
13+
const extractMarkdown = ({ description }) => (
14+
description &&
15+
description.childMarkdownRemark &&
16+
description.childMarkdownRemark.html
17+
);
18+
19+
class ComponentPage extends React.Component {
20+
render() {
21+
const { metadata, ...props } = this.props;
22+
23+
return (
24+
<div {...this.props}>
25+
<h2 id={metadata.displayName}><a href={`#${metadata.displayName}`}>
26+
{metadata.displayName}</a>
27+
</h2>
28+
<p dangerouslySetInnerHTML={{ __html: extractMarkdown(metadata) }} />
29+
30+
<h3>Props</h3>
31+
{metadata.props.map(p =>
32+
this.renderProp(p, metadata.displayName
33+
))}
34+
</div>
35+
)
36+
}
37+
38+
renderProp = (prop, componentName) => {
39+
const { defaultValue, name, required } = prop
40+
let typeInfo = this.renderType(prop);
41+
let id = `${componentName}-prop-${name}`;
42+
43+
return (
44+
<section key={name}>
45+
<h4 id={id}>
46+
<a href={`#${id}`}><code>{name}</code></a>
47+
{required && (
48+
<strong>{' required'}</strong>
49+
)}
50+
</h4>
51+
<div dangerouslySetInnerHTML={{ __html: extractMarkdown(prop) }} />
52+
53+
<div style={{ paddingLeft: 0 }}>
54+
<div>
55+
{'type: '}
56+
{ typeInfo && typeInfo.type === 'pre' ? typeInfo : <code>{typeInfo}</code> }
57+
</div>
58+
{defaultValue &&
59+
<div>default: <code>{defaultValue.value.trim()}</code></div>
60+
}
61+
</div>
62+
</section>
63+
)
64+
}
65+
66+
renderType(prop) {
67+
let type = prop.type || {};
68+
let name = getDisplayTypeName(type.name);
69+
let doclets = prop.doclets || {};
70+
71+
switch (name) {
72+
case 'node':
73+
return 'any';
74+
case 'function':
75+
return 'Function';
76+
case 'elementType':
77+
return 'ReactClass<any>';
78+
case 'dateFormat':
79+
return 'string | (date: Date, culture: ?string, localizer: Localizer) => string';
80+
case 'dateRangeFormat':
81+
return '(range: { start: Date, end: Date }, culture: ?string, localizer: Localizer) => string';
82+
case 'object':
83+
case 'Object':
84+
if (type.value)
85+
return (
86+
<pre className='shape-prop'>
87+
{displayObj(renderObject(type.value))}
88+
</pre>
89+
)
90+
91+
return name;
92+
case 'union':
93+
return type.value.reduce((current, val, i, list) => {
94+
val = typeof val === 'string' ? { name: val } : val;
95+
let item = this.renderType({ type: val });
96+
97+
if (React.isValidElement(item)) {
98+
item = React.cloneElement(item, {key: i});
99+
}
100+
101+
current = current.concat(item);
102+
103+
return i === (list.length - 1) ? current : current.concat(' | ');
104+
}, []);
105+
case 'array':
106+
case 'Array': {
107+
let child = this.renderType({ type: type.value });
108+
109+
return <span>{'Array<'}{ child }{'>'}</span>;
110+
}
111+
case 'enum':
112+
return this.renderEnum(type);
113+
case 'custom':
114+
return cleanDocletValue(doclets.type || name);
115+
default:
116+
return name;
117+
}
118+
}
119+
120+
renderEnum(enumType) {
121+
const enumValues = enumType.value || [];
122+
return <code>{enumValues.join(' | ')}</code>;
123+
}
124+
}
125+
126+
function getDisplayTypeName(typeName) {
127+
if (typeName === 'func') {
128+
return 'function';
129+
} else if (typeName === 'bool') {
130+
return 'boolean';
131+
} else if (typeName === 'object') {
132+
return 'Object';
133+
}
134+
135+
return typeName;
136+
}
137+
138+
function renderObject(props){
139+
return transform(props, (obj, val, key) => {
140+
obj[val.required ? key : key + '?'] = simpleType(val)
141+
142+
}, {})
143+
}
144+
145+
function simpleType(prop) {
146+
let type = prop.type || {};
147+
let name = getDisplayTypeName(type.name);
148+
let doclets = prop.doclets || {};
149+
150+
switch (name) {
151+
case 'node':
152+
return 'any';
153+
case 'function':
154+
return 'Function';
155+
case 'elementType':
156+
return 'ReactClass<any>';
157+
case 'object':
158+
case 'Object':
159+
if (type.value)
160+
return renderObject(type.value)
161+
return name;
162+
case 'array':
163+
case 'Array': {
164+
let child = simpleType({ type: type.value });
165+
166+
return 'Array<' + child + '>';
167+
}
168+
case 'custom':
169+
return cleanDocletValue(doclets.type || name);
170+
default:
171+
return name;
172+
}
173+
}
174+
export default ComponentPage;
175+
176+
export const descFragment = graphql`
177+
fragment ComponentPage_desc on ComponentDescription {
178+
childMarkdownRemark {
179+
html
180+
}
181+
}
182+
`;
183+
184+
export const propsFragment = graphql`
185+
fragment ComponentPage_prop on ComponentProp {
186+
name
187+
required
188+
type {
189+
name
190+
value
191+
raw
192+
}
193+
defaultValue {
194+
value
195+
computed
196+
}
197+
description {
198+
...ComponentPage_desc
199+
}
200+
doclets { type }
201+
}
202+
`;
203+
204+
export const query = graphql`
205+
fragment ComponentPage_metadata on ComponentMetadata {
206+
displayName
207+
composes
208+
description {
209+
...ComponentPage_desc
210+
}
211+
props {
212+
...ComponentPage_prop
213+
}
214+
}
215+
`;

www/src/css/bootstrap.scss

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
3+
$syntax-hue: 230;
4+
$syntax-saturation: 1%;
5+
$syntax-brightness: 98%;
6+
7+
8+
// Monochrome -----------------------------------
9+
$mono-1: hsl($syntax-hue, 8%, 24%);
10+
$mono-2: hsl($syntax-hue, 6%, 44%);
11+
$mono-3: hsl($syntax-hue, 4%, 64%);
12+
13+
$hue-1: hsl(198, 99%, 37%); // <-cyan
14+
$hue-2: hsl(221, 87%, 60%); // <-blue
15+
$hue-3: hsl(301, 63%, 40%); // <-purple
16+
$hue-4: hsl(119, 34%, 47%); // <-green
17+
18+
$hue-5: hsl( 5, 74%, 59%); // <-red 1
19+
$hue-5-2: hsl(344, 84%, 43%); // <-red 2
20+
21+
$hue-6: hsl(41, 99%, 30%); // <-orange 1
22+
$hue-6-2: hsl(41, 99%, 38%); // <-orange 2
23+
24+
$syntax-fg: $mono-1;
25+
$syntax-bg: hsl($syntax-hue, $syntax-saturation, $syntax-brightness);
26+
$syntax-gutter: darken($syntax-bg, 36%);
27+
$syntax-guide: fade($syntax-fg, 20%);
28+
$syntax-accent: hsl($syntax-hue, 100%, 66% );
29+
30+
31+
$body-bg: $syntax-bg;
32+
$code-bg: $syntax-bg;
33+
$code-color: $hue-3;
34+
35+
@import '~bootstrap/scss/bootstrap.scss';
36+
37+
38+
section {
39+
margin-bottom: 2rem;
40+
}
41+
42+
h1, h2, h3,h4, h5 {
43+
& > a {
44+
&,
45+
&:hover {
46+
color: $mono-2;
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)