Skip to content

Commit 9b7cd02

Browse files
committed
feat: add get started page
1 parent 70b17c1 commit 9b7cd02

File tree

10 files changed

+167
-92
lines changed

10 files changed

+167
-92
lines changed

docs/app.src.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
33
import RedBox from 'redbox-react';
44
import { rehydrate } from 'glamor';
55
import App from './templates/App';
6-
import pages from './dist/app.data.json'; // eslint-disable-line import/no-unresolved
6+
import { pages, components } from './dist/app.data.json'; // eslint-disable-line import/no-unresolved
77

88
rehydrate(window.__GLAMOR__);
99

@@ -13,6 +13,7 @@ const render = () => {
1313
ReactDOM.render(
1414
<App
1515
pages={pages}
16+
components={components}
1617
name={window.__INITIAL_PATH__}
1718
/>,
1819
root

docs/index.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ if (!fs.existsSync(dist)) {
2020
fs.mkdirSync(dist);
2121
}
2222

23-
let items = [];
23+
let components = [];
2424
let pages = [];
2525

2626
function collectInfo() {
27-
items = [];
28-
pages = [];
27+
components = [];
2928

3029
const files = fs.readFileSync(path.join(__dirname, '../src/index.js'))
3130
.toString()
@@ -48,16 +47,18 @@ function collectInfo() {
4847
const componentName = comp.split('/').pop().split('.')[0];
4948
try {
5049
const componentInfo = parse(fs.readFileSync(comp).toString());
51-
items.push({ name: componentName, info: componentInfo });
52-
pages.push(componentName);
50+
components.push({ name: componentName, info: componentInfo });
5351
} catch (e) {
5452
console.log(`${componentName}: ${e.message}`);
5553
}
5654
});
5755

58-
pages.sort();
56+
pages = fs.readdirSync(path.join(__dirname, 'pages')).filter(name => name.endsWith('.md')).map(name => ({
57+
name: name.replace(/\.md/, ''),
58+
text: fs.readFileSync(path.join(__dirname, 'pages', name)).toString(),
59+
}));
5960

60-
fs.writeFileSync(path.join(dist, 'app.data.json'), JSON.stringify(items));
61+
fs.writeFileSync(path.join(dist, 'app.data.json'), JSON.stringify({ pages, components }));
6162
}
6263

6364
collectInfo();
@@ -66,7 +67,8 @@ function buildHTML({ title, description, name }: any) {
6667
const { html, css, ids } = renderStatic(
6768
() => ReactDOMServer.renderToString(
6869
<App
69-
pages={items}
70+
pages={pages}
71+
components={components}
7072
name={name}
7173
/>
7274
)
@@ -101,7 +103,7 @@ function buildHTML({ title, description, name }: any) {
101103
);
102104
}
103105

104-
buildRoutes(items).forEach(buildHTML);
106+
buildRoutes(pages, components).forEach(buildHTML);
105107

106108
const entry = [ 'app.src.js' ];
107109

docs/pages/Getting Started.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Getting Started
2+
===============
3+
4+
## Installation
5+
6+
Open a Terminal in your project's folder and run,
7+
8+
```sh
9+
npm install --save react-native-paper react-native-vector-icons
10+
```
11+
12+
After installation, you'll need to link [react-native-vector-icons](https://github.com/oblador/react-native-vector-icons).
13+
14+
15+
## Usage
16+
17+
Wrap your root component in `Provider` from `react-native-paper`. It's a good idea to wrap the component which is passed to `AppRegsitry.registerComponent`.
18+
19+
Example:
20+
21+
```js
22+
import React from 'react';
23+
import { AppRegistry } from 'react-native';
24+
import { Provider as PaperProvider } from 'react-native-paper';
25+
import App from './src/App';
26+
27+
function Main() {
28+
return (
29+
<PaperProvider>
30+
<App />
31+
</PaperProvider>
32+
)
33+
}
34+
35+
AppRegistry.registerComponent('main', () => Main);
36+
```
37+
38+
The `PaperProvider` component provides the theme to all the components in the framework. It also acts as a portal to components which need to be rendered at the top level.
39+
40+
41+
## Customization
42+
43+
You can provide a custom theme to customize the colors, fonts etc. with the `Provider` component. Check the [default theme](blob/master/src/styles/DefaultTheme.js) to see what customization options are supported.
44+
45+
Example:
46+
47+
```js
48+
import React from 'react';
49+
import { AppRegistry } from 'react-native';
50+
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
51+
import color from 'color';
52+
import App from './src/App';
53+
54+
const theme = {
55+
...DefaultTheme,
56+
colors: {
57+
...DefaultTheme.colors,
58+
primary: 'tomato',
59+
primaryDark: color('tomato').darken(0.2).rgbaString(),
60+
accent: 'yellow',
61+
},
62+
};
63+
64+
function Main() {
65+
return (
66+
<PaperProvider theme={theme}>
67+
<App />
68+
</PaperProvider>
69+
)
70+
}
71+
```

docs/templates/App.js

+46-7
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,73 @@
11
/* @flow */
22

33
import React from 'react';
4+
import { insertGlobal } from 'glamor';
45
import Router from './Router';
56
import Page from './Page';
67
import Home from './Home';
78
import ComponentDocs from './ComponentDocs';
9+
import Markdown from './Markdown';
810

9-
export const buildRoutes = (pages: Array<*>) =>
10-
pages.map(it => ({
11+
insertGlobal(`
12+
html {
13+
box-sizing: border-box;
14+
}
15+
*, *:before, *:after {
16+
box-sizing: inherit;
17+
}
18+
html, body {
19+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
20+
margin: 0;
21+
padding: 0;
22+
color: #333;
23+
lineHeight: 1.5;
24+
}
25+
code {
26+
font-family: "Roboto Mono", "Operator Mono", "Fira Code", "Ubuntu Mono", "Droid Sans Mono", "Liberation Mono", "Source Code Pro", Menlo, Consolas, Courier, monospace;
27+
color: #000;
28+
line-height: 2;
29+
}
30+
a {
31+
color: #1976D2;
32+
text-decoration: none;
33+
}
34+
a:hover {
35+
color: #2196F3;
36+
}
37+
`);
38+
39+
export const buildRoutes = (pages: Array<*>, components: Array<*>) =>
40+
components.map(it => ({
1141
title: it.name,
1242
name: it.name.toLowerCase(),
1343
description: it.info.description,
1444
component: props => (
15-
<Page {...props} pages={pages}>
45+
<Page {...props} pages={pages} components={components}>
1646
<ComponentDocs {...it} />
1747
</Page>
1848
),
19-
})).concat({
49+
})).concat(pages.map(it => ({
50+
title: it.name,
51+
name: it.name.toLowerCase().replace(/\s+/g, '-'),
52+
description: '',
53+
component: props => (
54+
<Page {...props} pages={pages} components={components}>
55+
<Markdown source={it.text} />
56+
</Page>
57+
),
58+
}))).concat({
2059
title: 'Home',
2160
name: 'index',
2261
description: '',
2362
component: props => (
24-
<Page {...props} pages={pages}>
63+
<Page {...props} pages={pages} components={components}>
2564
<Home />
2665
</Page>
2766
),
2867
});
2968

30-
export default function App({ pages, name }: any) {
31-
const routes = buildRoutes(pages);
69+
export default function App({ pages, components, name }: any) {
70+
const routes = buildRoutes(pages, components);
3271
return (
3372
<Router
3473
name={name}

docs/templates/ComponentDocs.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
import React from 'react';
44
import { style, merge } from 'glamor';
5-
import mono from './styles/mono';
6-
import body from './styles/body';
75
import Markdown from './Markdown';
86

9-
const wrapper = style({
10-
padding: '24px 48px',
11-
});
12-
137
const name = style({
148
fontSize: '36px',
159
margin: '24px 0 8px -24px',
@@ -77,7 +71,7 @@ const propDetails = style({
7771
});
7872

7973
const rest = style({
80-
color: '#2196F3',
74+
color: '#1976D2',
8175
});
8276

8377
export default function ComponentDocs(props: any) {
@@ -96,50 +90,51 @@ export default function ComponentDocs(props: any) {
9690
}).join('\n');
9791

9892
return (
99-
<div {...wrapper}>
100-
<h1 {...mono} {...name}>{`<${props.name} />`}</h1>
93+
<div>
94+
<h1 {...name}><code>{`<${props.name} />`}</code></h1>
10195
<Markdown
102-
{...body}
10396
{...markdown}
10497
source={description} options={{ linkify: true }}
10598
/>
106-
<h2 {...mono} {...propsHeader}>Props</h2>
99+
<h2 {...propsHeader}>Props</h2>
107100
{Object.keys(props.info.props).map(prop => {
108101
const { flowType, type, required } = props.info.props[prop];
109102
return (
110103
<div {...propInfo} key={prop}>
111-
<span {...mono}>
112-
<span
104+
<span>
105+
<code
113106
{...propRequired}
114107
data-hint='required'
115108
>
116109
{required ? '*' : ''}
117-
</span>
110+
</code>
118111
<a
119-
{...mono}
120112
{...propLabel}
121113
name={prop}
122114
href={`#${prop}`}
123115
>
124-
{prop}: {flowType.name === 'any' && type ? (type.raw || type.name) : (flowType.raw || flowType.name)}
116+
<code>
117+
{prop}: {flowType.name === 'any' && type ? (type.raw || type.name) : (flowType.raw || flowType.name)}
118+
</code>
125119
</a>
126120
</span>
127121
<Markdown
128-
{...body} {...propDetails}
122+
{...propDetails}
129123
source={props.info.props[prop].description}
130124
/>
131125
</div>
132126
);
133127
})}
134128
{restProps && restProps.length ? restProps.map(prop => (
135129
<a
136-
{...mono}
137130
{...propLabel}
138131
{...rest}
139132
key={prop.name}
140133
href={prop.link}
141134
>
142-
...{prop.name}
135+
<code>
136+
...{prop.name}
137+
</code>
143138
</a>
144139
)) : null}
145140
</div>

docs/templates/Home.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import React from 'react';
44
import { style } from 'glamor';
5-
import mono from './styles/mono';
6-
import body from './styles/body';
75

86
const wrapper = style({
97
display: 'flex',
@@ -31,8 +29,8 @@ export default function Home() {
3129
return (
3230
<div {...wrapper}>
3331
<div {...inner}>
34-
<h1 {...mono} {...heading}>React Native Paper</h1>
35-
<p {...body} {...description}>Documentation</p>
32+
<h1 {...heading}>React Native Paper</h1>
33+
<p {...description}>Documentation</p>
3634
</div>
3735
</div>
3836
);

docs/templates/Markdown.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const markdown = style({
1414
overflowX: 'auto',
1515
},
1616

17+
'& code': {
18+
fontSize: '.9em',
19+
},
20+
1721
'& .hljs-comment': {
1822
color: '#ABB0B6',
1923
},

0 commit comments

Comments
 (0)