Skip to content

Infra/live code playground device wrapper #3298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a81b463
Support live code for components
M-i-k-e-l Sep 24, 2024
ef6563e
Add ActionBar
M-i-k-e-l Sep 24, 2024
9ff281e
Add Checkbox
M-i-k-e-l Sep 24, 2024
df6576b
Add Chip
M-i-k-e-l Sep 24, 2024
848bf96
Add RadioButton
M-i-k-e-l Sep 24, 2024
6b92c29
Add RadioGroup
M-i-k-e-l Sep 24, 2024
855ec96
Remove (regular) Slider
M-i-k-e-l Sep 24, 2024
662ee98
Add Switch
M-i-k-e-l Sep 24, 2024
f4097f8
Add Incubator.Slider (add incubator package)
M-i-k-e-l Sep 24, 2024
2516613
Add SortableList and Icon (add assets package and add a couple of ass…
M-i-k-e-l Sep 24, 2024
75eebd0
Merge branch 'master' into infra/live-code-add-more-components-1
M-i-k-e-l Sep 24, 2024
d5890f0
Merge branch 'infra/live-code-add-more-components-1' into infra/live-…
M-i-k-e-l Sep 24, 2024
dca31c1
Add flexMigration to SortableList
M-i-k-e-l Sep 24, 2024
6def866
Add SortableGridList and Card (add Assets.data.products)
M-i-k-e-l Sep 24, 2024
614b937
Add MaskedInput
M-i-k-e-l Sep 24, 2024
7c07714
Add Carousel
M-i-k-e-l Sep 24, 2024
454cfbf
Add Drawer
M-i-k-e-l Sep 25, 2024
5268e7f
Add usesAnimated to the API
M-i-k-e-l Sep 25, 2024
bb4e4ee
Merge branch 'master' into infra/live-code-add-more-components-2
M-i-k-e-l Sep 25, 2024
33ee7f8
Fix assets (and relevant examples)
M-i-k-e-l Sep 25, 2024
6497c43
Fix some review notes
M-i-k-e-l Sep 26, 2024
5278f72
Merge branch 'master' into infra/live-code-add-more-components-2
M-i-k-e-l Sep 30, 2024
2f7617f
Merge branch 'master' into infra/live-code-add-more-components-2
M-i-k-e-l Oct 7, 2024
1f6b492
Remove usesAnimated and drawer's snippet
M-i-k-e-l Oct 7, 2024
a8600f5
Move to Data and Playground
M-i-k-e-l Oct 7, 2024
576cf22
live-code Playground - MobileDeviceWrapper
adids1221 Oct 7, 2024
35cde61
Merge branch 'master' into infra/live-code-playground-device-wrapper
adids1221 Oct 8, 2024
4b4f0b0
Merge branch 'master' into infra/live-code-playground-device-wrapper
adids1221 Oct 8, 2024
a3ec311
MobileDeviceWrapper renderHeader
adids1221 Oct 8, 2024
f29b16e
processSnippet
adids1221 Oct 8, 2024
04ca2c1
Merge branch 'master' into infra/live-code-playground-device-wrapper
adids1221 Oct 9, 2024
0bf7b9b
yarn.lock update
adids1221 Oct 9, 2024
ab92a65
chevronRight icon fix
adids1221 Oct 13, 2024
8c22b0e
moved MobileDeviceWrapper out from Playground
adids1221 Oct 13, 2024
7e03467
SegmentedControl findSelectedIndex by type
adids1221 Oct 13, 2024
bf89d1a
code refactor - renaming
adids1221 Oct 15, 2024
73266fa
Merge branch 'master' into infra/live-code-playground-device-wrapper
adids1221 Oct 29, 2024
1cb0411
Merge branch 'master' into infra/live-code-playground-device-wrapper
adids1221 Oct 30, 2024
96d6df3
react-live, iframe for live code playground
adids1221 Oct 31, 2024
03c8695
Merge branch 'master' into infra/live-code-playground-device-wrapper
adids1221 Oct 31, 2024
73e1294
livePreview overflow style
adids1221 Oct 31, 2024
ee688b9
hide scrollbar
adids1221 Oct 31, 2024
11d0d01
sortable grid list exmaple fix
adids1221 Oct 31, 2024
bbb0450
ReactLiveScope - UILivePreview export
adids1221 Nov 3, 2024
0d243cc
UILivePreview scope change
adids1221 Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions docs/getting-started/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ title: 'Usage'
# path: "/getting-started/usage"
---

import UILivePreview from '@site/src/components/UILivePreview';

This is a quick example of how to use our basic components, modifiers and presets to generate a good looking screen.
For detailed information please go over the other sections: [Style](../foundation/style.md), [Modifiers](../foundation/modifiers.md), Components...

<!-- ![basic showcase](basic-showcase.png). -->

```jsx live
function Example(props) {
return (
<div>
<View flex center>
<Text blue50 text20 marginB-s5>
<UILivePreview code={`function Example(props) {
return (

<div>
<View flex center>
<Text blue50 text20 marginB-s5>
Welcome
</Text>
<SegmentedControl segments={[{label: 'Register'}, {label: 'Login'}]} />

<View marginT-s5>
<TextField preset="outline" placeholder="username" />
<TextField preset="outline" placeholder="password" secureTextEntry grey10 />
</View>
<SegmentedControl segments={[{label: 'Register'}, {label: 'Login'}]} />
<View marginT-s5>
<TextField preset="outline" placeholder="username" />
<TextField preset="outline" placeholder="password" secureTextEntry grey10 />
</View>
<View row marginT-s5 centerV>
<Button link text70 orange30 label="Sign Up" marginR-s5 />
<Button text70 white background-orange30 label="Login" />
</View>
</View>

<View row marginT-s5 centerV>
<Button link text70 orange30 label="Sign Up" marginR-s5 />
<Button text70 white background-orange30 label="Login" />
</View>
</View>
</div>
);
}
```
</div>
);
}`}/>
1 change: 1 addition & 0 deletions docuilib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"file-loader": "^6.2.0",
"prism-react-renderer": "^2.1.0",
"react-html-parser": "^2.0.2",
"react-live": "^4.1.7",
"react-native-web": "^0.19.12",
"sass": "^1.39.0",
"showdown": "^2.1.0",
Expand Down
Binary file modified docuilib/src/assets/icons/chevronRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docuilib/src/assets/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docuilib/src/assets/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions docuilib/src/components/UILivePreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, {useEffect, useRef, useState} from 'react';
import {StyleSheet} from 'react-native';
import {LiveProvider, LiveEditor} from 'react-live';
import {View, Colors} from 'react-native-ui-lib/core';
import ReactLiveScope from '../theme/ReactLiveScope';

const messageType = 'LIVE_PREVIEW_CODE_UPDATE_MESSAGE';

export default function UILivePreview({code: codeProp}) {
const [code, setCode] = useState(codeProp);
const [iframeLoaded, setIframeLoaded] = useState(false);
const iframeRef = useRef(null);

useEffect(() => {
if (iframeRef.current && iframeLoaded) {
setTimeout(() => {
sendMessageToIframe(code);
}, 100);
}
}, [iframeRef, iframeLoaded, code]);

const sendMessageToIframe = code => {
const message = {type: messageType, code};
iframeRef.current.contentWindow.postMessage(message, '*');
};

return (
<View row gap-s2 style={styles.liveCodeWrapper}>
<LiveProvider code={code} scope={ReactLiveScope}>
<View flex style={{maxHeight: 700, padding: 10, borderRadius: 20, overflow: 'hidden'}}>
<LiveEditor
className="font-mono"
onChange={setCode}
style={{
overflowY: 'scroll',
scrollbarWidth: 'none' // For Firefox
}}
/>
</View>
<View
bg-$backgroundDefault
margin-s2
style={{
alignSelf: 'center',
borderRadius: 40,
borderWidth: 4,
borderColor: Colors.$outlineDisabledHeavy,
width: 320,
height: 700
}}
>
<iframe
ref={iframeRef}
style={{padding: 10, height: 720, width: 320}}
src="http://localhost:3000/react-native-ui-lib/livePreview"
title="Simulator"
onLoad={() => setIframeLoaded(true)}
/>
</View>
</LiveProvider>
</View>
);
}

const styles = StyleSheet.create({
liveCodeWrapper: {
borderRadius: 20,
borderWidth: 1,
backgroundColor: '#011627',
height: 725,
width: 900
}
});
24 changes: 24 additions & 0 deletions docuilib/src/pages/livePreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {useEffect, useState} from 'react';
import {LiveProvider, LivePreview} from 'react-live';
import ReactLiveScope from '../theme/ReactLiveScope';

const messageType = 'LIVE_PREVIEW_CODE_UPDATE_MESSAGE';

export default function UILivePreview() {
const [code, setCode] = useState(``);

useEffect(() => {
window.addEventListener('message', (e: MessageEvent) => {
if (e.data.type === messageType) {
console.log(e.data.code);
}
setCode(e.data.code);
});
}, []);

return (
<LiveProvider code={code} scope={ReactLiveScope}>
<LivePreview style={{overflow: 'hidden'}}/>
</LiveProvider>
);
}
2 changes: 2 additions & 0 deletions docuilib/src/theme/ReactLiveScope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import SortableGridList from 'react-native-ui-lib/sortableGridList';
import SortableList from 'react-native-ui-lib/sortableList';
import Switch from 'react-native-ui-lib/switch';
import TextField from 'react-native-ui-lib/textField';
import UILivePreview from '@site/src/components/UILivePreview';
import * as Playground from './Playground';

Assets.loadAssetsGroup('icons.demo', {
Expand Down Expand Up @@ -56,6 +57,7 @@ const ReactLiveScope = {
/* Docs' utils and components */
Data,
Playground,
UILivePreview,
/* UI Lib's components */
ActionBar,
Assets,
Expand Down
2 changes: 1 addition & 1 deletion docuilib/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8022,7 +8022,7 @@ react-json-view-lite@^1.2.0:
resolved "https://registry.npmjs.org/react-json-view-lite/-/react-json-view-lite-1.5.0.tgz#377cc302821717ac79a1b6d099e1891df54c8662"
integrity sha512-nWqA1E4jKPklL2jvHWs6s+7Na0qNgw9HCP6xehdQJeg6nPBTFZgGwyko9Q0oj+jQWKTTVRS30u0toM5wiuL3iw==

react-live@^4.1.6:
react-live@^4.1.6, react-live@^4.1.7:
version "4.1.7"
resolved "https://registry.npmjs.org/react-live/-/react-live-4.1.7.tgz#a451054bee78e6c9b4410dfc3940b318d9bc7880"
integrity sha512-NTzl0POOAW3dkp7+QL30duOrIu2Vzf2LHdx4TaQ0BqOAtQcSTKEXujfm9jR2VoCHko0oi35PYp38yKQBXz4mrg==
Expand Down
14 changes: 7 additions & 7 deletions scripts/buildDocsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ function resetDocsDir() {
function processComponents(components) {
/** Break into compound components (TabController.TabPage) and parent components (TabController) */
const compoundComponents = components.filter(c => c.name.includes('.'));
const parentComponents = _.flow(
components => _.map(components, c => c.name.split('.')[0]),
_.uniq
)(compoundComponents);
const parentComponents = _.flow(components => _.map(components, c => c.name.split('.')[0]),
_.uniq)(compoundComponents);

components.forEach(component => {
const [componentName, componentParentName] = getComponentNameParts(component.name);
Expand Down Expand Up @@ -114,6 +112,7 @@ function generateExtendsLink(extendsLink) {

function buildOldDocs(component) {
let content = '';
content += `import UILivePreview from '@site/src/components/UILivePreview';\n\n`;

/* General Info */
content += `${component.description} \n`;
Expand Down Expand Up @@ -170,9 +169,10 @@ function buildOldDocs(component) {
/* Snippet */
if (component.snippet) {
content += `### Usage\n`;
content += '``` jsx live\n';
content += component.snippet?.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), '')).join('\n');
content += '\n```\n';
content += `<UILivePreview code={\`${component.snippet
?.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), ''))
.join('\n')
.toString()}\`}/>\n\n`;
} else {
console.warn(`${component.name} does not have a snippet`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/marquee/marquee.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"snippet": [
"<Marquee",
" key={`${index}`$1}",
" key={\\`\\${index}\\`$1}",
" label={'Hey there'$2}",
" direction={directionHorizontal ? MarqueeDirections.LEFT : MarqueeDirections.RIGHT$3}",
" duration={duration$4}",
Expand Down
2 changes: 1 addition & 1 deletion src/components/sortableGridList/sortableGridList.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"",
" return (",
" <div>",
" <View style={{width: 800}}>",
" <View style={{width: 300}}>",
" <Playground.ToggleControl title={'Order by index'} state={shouldOrderByIndex} setState={setShouldOrderByIndex}/>",
" <SortableGridList",
" data={data$1}",
Expand Down
6 changes: 3 additions & 3 deletions src/components/sortableList/SortableList.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
"snippet": [
"function Example(props) {",
" const data = Array.from({length: 10}, (_, index) => {",
" let text = `${index}`;",
" let text = \\`\\${index}\\`;",
" if (index === 3) {",
" text = 'Locked item';",
" }",
" ",
" return {",
" text,",
" id: `${index}`,",
" id: \\`\\${index}\\`,",
" locked: index === 3",
" };",
" });",
Expand All @@ -78,7 +78,7 @@
" }, []);",
"",
" const keyExtractor = useCallback((item: Item) => {",
" return `${item.id}`;",
" return \\`\\${item.id}\\`;",
" }, []);",
"",
" return (",
Expand Down
2 changes: 1 addition & 1 deletion src/incubator/Slider/slider.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
" value={0$1}",
" minimumValue={0$2}",
" maximumValue={10$3}",
" onValueChange={value => console.log(`value changed: ${value}`)$4}",
" onValueChange={value => console.log(\\`value changed: \\${value}\\`)$4}",
"/>"
]
}