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 31 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
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 added 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.
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 added docuilib/src/assets/icons/[email protected]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these changes of the icons 🙏

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 97 additions & 2 deletions docuilib/src/theme/ReactLiveScope/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import {Text, View} from 'react-native-ui-lib/core';
import React, {useState, useEffect} from 'react';
import {StyleSheet} from 'react-native';
import {Text, View, Colors, Image} from 'react-native-ui-lib/core';
import Switch from 'react-native-ui-lib/switch';
import SegmentedControl from 'react-native-ui-lib/segmentedControl';

interface ControlBaseProps<S> {
state: S;
Expand All @@ -13,6 +15,21 @@ interface ToggleControlProps extends ControlBaseProps<boolean> {
spread?: boolean;
}

interface SimulatorSize {
width: number | undefined;
height: number | undefined;
}

enum SimulatorTypes {
MOBILE = 'MOBILE',
TABLET = 'TABLET'
}

const simulatorOptions = [
{label: 'Mobile', value: SimulatorTypes.MOBILE},
{label: 'Tablet', value: SimulatorTypes.TABLET}
];

export function ToggleControl(props: ToggleControlProps) {
const {state, setState, title, spread = false, key = 'does not change'} = props;
return (
Expand All @@ -24,3 +41,81 @@ export function ToggleControl(props: ToggleControlProps) {
</View>
);
}

export function MobileDeviceWrapper({children}) {
const [simulatorSize, setSimulatorSize] = useState<SimulatorSize>({width: 340, height: 754});
const [type, setType] = useState<SimulatorTypes>(SimulatorTypes.MOBILE);

useEffect(() => {
changeType();
}, [type]);

function changeType() {
switch (type) {
case SimulatorTypes.MOBILE:
default:
setSimulatorSize({width: 340, height: 754});
break;
case SimulatorTypes.TABLET:
setSimulatorSize({width: 900, height: 754});
break;
}
}

const onPress = (type: SimulatorTypes) => {
setType?.(type);
};

const renderHeader = () => {
return (
<View center padding-s2 row>
<Image
marginH-s1
source={{
uri: 'https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png'
}}
style={{width: 40, height: 40}}
/>
<Text text60 marginV-s1>
Wix React Native UILIB
</Text>
</View>
);
};

return (
<View gap-s3>
<View gap-s1 marginV-s1 center>
<Text marginR-s3 style={styles.typesTitle}>
Choose Type
</Text>
<SegmentedControl
initialIndex={0}
segments={simulatorOptions}
onChangeIndex={index => {
onPress(simulatorOptions[index].value);
}}
backgroundColor={Colors.$backgroundDefault}
/>
</View>
<View style={[styles.simulatorWrapper, simulatorSize]} gap-s2>
{renderHeader()}
<div>{children}</div>
</View>
</View>
);
}

const styles = StyleSheet.create({
typesTitle: {
fontWeight: 'bold',
textAlign: 'center'
},
simulatorWrapper: {
alignSelf: 'center',
borderRadius: 40,
borderWidth: 4,
borderColor: Colors.$outlineDisabledHeavy,
overflow: 'hidden'
}
});
2 changes: 1 addition & 1 deletion docuilib/src/theme/ReactLiveScope/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ReactLiveScope = {
...React,
/* Docs' utils and components */
Data,
Playground,
...Playground,
/* UI Lib's components */
ActionBar,
Assets,
Expand Down
25 changes: 24 additions & 1 deletion scripts/buildDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ fs.mkdirSync(COMPONENTS_DOCS_DIR);

const compoundComponents = components.filter(c => c.name.includes('.'));
const parentComponents = _.flow(components => _.map(components, c => c.name.split('.')[0]), _.uniq)(compoundComponents);
const processSnippet = snippet => {
//Replace placeholder texts
const processedSnippet = snippet.map(item => item.replace(new RegExp(/\$[1-9]/g), ''));
//Check if the snippet is a function or plain JSX
const isFunction = processedSnippet[0].trim().startsWith('function');

if (isFunction) {
//Check if <div> tag is immediately after return statement
const divTagIndex = processedSnippet.findIndex(line =>
line.trim().startsWith('return (') && processedSnippet[processedSnippet.indexOf(line) + 1]?.includes('<div>'));

if (divTagIndex !== -1) {
//If <div> tag is found, replace <div> and </div> with <MobileDeviceWrapper> and </MobileDeviceWrapper>
return processedSnippet
.map(line => line.replace('<div>', '<MobileDeviceWrapper>').replace('</div>', '</MobileDeviceWrapper>'))
.join('\n');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has a few assumptions, hopefully they don't break; we can try to fins a better solution with a convention we can set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's sync about it.
Iv'e tried to implement it as HOC but I had some issues.

} else {
//Wrap the snippet with <MobileDeviceWrapper>
return ['<MobileDeviceWrapper>', ...processedSnippet, '</MobileDeviceWrapper>'].join('\n');
}
};

components.forEach(component => {
const [componentName, componentParentName] = getComponentNameParts(component.name);
Expand Down Expand Up @@ -157,7 +179,8 @@ function getFirstTab(component) {
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';
content += processSnippet(component.snippet);
content += '\n```\n';
} else {
console.warn(`${component.name} does not have a snippet`);
Expand Down