Skip to content

Commit 8cc671a

Browse files
authored
Add live code playground in uilib docs (#3254)
* Add live code playground in uilib docs * Update live code example
1 parent e3bafc4 commit 8cc671a

File tree

6 files changed

+9264
-8
lines changed

6 files changed

+9264
-8
lines changed

docs/getting-started/usage.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
sidebar_position: 2
33
sidebar_label: Usage
4-
title: "Usage"
4+
title: 'Usage'
55
# path: "/getting-started/usage"
66
---
7+
78
This is a quick example of how to use our basic components, modifiers and presets to generate a good looking screen.
89
For detailed information please go over the other sections: [Style](../foundation/style.md), [Modifiers](../foundation/modifiers.md), Components...
910

@@ -14,19 +15,45 @@ import React, {Component} from 'react';
1415
import {View, TextField, Text, Button} from 'react-native-ui-lib';
1516

1617
export default class Example extends Component {
17-
1818
render() {
1919
return (
2020
<View flex paddingH-25 paddingT-120>
21-
<Text blue50 text20>Welcome</Text>
22-
<TextField text50 placeholder="username" grey10/>
23-
<TextField text50 placeholder="password" secureTextEntry grey10/>
21+
<Text blue50 text20>
22+
Welcome
23+
</Text>
24+
<TextField text50 placeholder="username" grey10 />
25+
<TextField text50 placeholder="password" secureTextEntry grey10 />
2426
<View marginT-100 center>
25-
<Button text70 white background-orange30 label="Login"/>
26-
<Button link text70 orange30 label="Sign Up" marginT-20/>
27+
<Button text70 white background-orange30 label="Login" />
28+
<Button link text70 orange30 label="Sign Up" marginT-20 />
2729
</View>
2830
</View>
2931
);
3032
}
3133
}
3234
```
35+
36+
```jsx live
37+
function Example(props) {
38+
return (
39+
<div>
40+
<View flex center>
41+
<Text blue50 text20 marginB-s5>
42+
Welcome
43+
</Text>
44+
<SegmentedControl segments={[{label: 'Register'}, {label: 'Login'}]} />
45+
46+
<View marginT-s5>
47+
<TextField preset="outline" placeholder="username" />
48+
<TextField preset="outline" placeholder="password" secureTextEntry grey10 />
49+
</View>
50+
51+
<View row marginT-s5 centerV>
52+
<Button link text70 orange30 label="Sign Up" marginR-s5 />
53+
<Button text70 white background-orange30 label="Login" />
54+
</View>
55+
</View>
56+
</div>
57+
);
58+
}
59+
```

docuilib/docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const darkCodeTheme = require('prism-react-renderer/themes/dracula');
2020
expoSnackLink: 'https://snack.expo.io/@ethanshar/rnuilib_snack',
2121
stars: '4.7'
2222
},
23-
plugins: ['docusaurus-plugin-sass'],
23+
plugins: ['docusaurus-plugin-sass', '@docusaurus/theme-live-codeblock', './plugins/uilib.js'],
2424
presets: [
2525
[
2626
'@docusaurus/preset-classic',

docuilib/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@docusaurus/core": "2.3",
1818
"@docusaurus/preset-classic": "2.3",
19+
"@docusaurus/theme-live-codeblock": "2.3",
1920
"@mdx-js/react": "^1.6.21",
2021
"@svgr/webpack": "^5.5.0",
2122
"classnames": "^2.3.1",
@@ -25,6 +26,11 @@
2526
"prism-react-renderer": "^1.2.1",
2627
"react": "^17.0.1",
2728
"react-dom": "^17.0.1",
29+
"react-native-linear-gradient": "2.6.2",
30+
"react-native-reanimated": "^3.15.1",
31+
"react-native-shimmer-placeholder": "^2.0.9",
32+
"react-native-ui-lib": "snapshot",
33+
"react-native-web": "^0.19.12",
2834
"sass": "^1.39.0",
2935
"url-loader": "^4.1.1"
3036
},
@@ -34,6 +40,7 @@
3440
"@types/react": "^17.0.14",
3541
"@types/react-helmet": "^6.1.2",
3642
"@types/react-router-dom": "^5.1.8",
43+
"babel-plugin-react-native-web": "^0.19.12",
3744
"typescript": "^4.3.5"
3845
},
3946
"browserslist": {

docuilib/plugins/uilib.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
4+
module.exports = ({siteDir}, options) => {
5+
const baseProjectSource = [
6+
path.resolve(siteDir, 'src'),
7+
path.resolve(siteDir, 'node_modules/react-native-web'),
8+
path.resolve(siteDir, 'node_modules/react-native-ui-lib'),
9+
// // just for not getting warnings
10+
path.resolve(siteDir, 'node_modules/react-native-shimmer-placeholder'),
11+
path.resolve(siteDir, 'node_modules/react-native-linear-gradient')
12+
// // end just for not getting warnings
13+
// path.resolve(siteDir, 'node_modules/react-native-haptic-feedback'),
14+
// path.resolve(siteDir, 'node_modules/react-native-animatable'),
15+
// path.resolve(siteDir, 'node_modules/react-native-reanimated'),
16+
// path.resolve(siteDir, 'node_modules/react-native-svg'),
17+
// path.resolve(siteDir, 'node_modules/react-native-svg-transformer'),
18+
// path.resolve(siteDir, 'node_modules/@react-native-community/netinfo'),
19+
// path.resolve(siteDir, 'node_modules/@react-native-community/datetimepicker'),
20+
// path.resolve(siteDir, 'node_modules/react-native-color'),
21+
22+
// path.resolve(siteDir, 'node_modules/postcss'),
23+
// path.resolve(siteDir, 'node_modules/postcss-js')
24+
];
25+
26+
const useBabelForRN = {
27+
loader: 'babel-loader',
28+
options: {
29+
cacheDirectory: false,
30+
// The 'react-native' preset is recommended to match React Native's packager
31+
presets: ['module:metro-react-native-babel-preset'],
32+
plugins: ['react-native-web', 'react-native-reanimated/plugin']
33+
}
34+
};
35+
36+
const babelLoaderAppConfiguration = {
37+
test: /\.(js|jsx|ts|tsx)$/,
38+
include: baseProjectSource,
39+
use: useBabelForRN
40+
};
41+
42+
return {
43+
name: 'uilib-plugin',
44+
configureWebpack(config, isServer, utils) {
45+
return {
46+
mergeStrategy: {
47+
'resolve.extensions': 'prepend'
48+
},
49+
plugins: [
50+
new webpack.DefinePlugin({
51+
process: {env: {}},
52+
__DEV__: 'false',
53+
setImmediate: () => {}
54+
})
55+
],
56+
module: {
57+
rules: [babelLoaderAppConfiguration]
58+
},
59+
resolve: {
60+
alias: {
61+
'react-native$': 'react-native-web'
62+
},
63+
extensions: ['.web.js']
64+
}
65+
};
66+
}
67+
};
68+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import Text from 'react-native-ui-lib/text';
3+
import View from 'react-native-ui-lib/view';
4+
import Button from 'react-native-ui-lib/button';
5+
import TextField from 'react-native-ui-lib/textField';
6+
import SegmentedControl from 'react-native-ui-lib/segmentedControl';
7+
8+
// Add react-live imports you need here
9+
const ReactLiveScope = {
10+
React,
11+
...React,
12+
/* uilib components */
13+
View,
14+
Text,
15+
Button,
16+
TextField,
17+
SegmentedControl
18+
};
19+
20+
export default ReactLiveScope;

0 commit comments

Comments
 (0)