-
Notifications
You must be signed in to change notification settings - Fork 734
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
Changes from 31 commits
a81b463
ef6563e
9ff281e
df6576b
848bf96
6b92c29
855ec96
662ee98
f4097f8
2516613
75eebd0
d5890f0
dca31c1
6def866
614b937
7c07714
454cfbf
5268e7f
bb4e4ee
33ee7f8
6497c43
5278f72
2f7617f
1f6b492
a8600f5
576cf22
35cde61
4b4f0b0
a3ec311
f29b16e
04ca2c1
0bf7b9b
ab92a65
8c22b0e
7e03467
bf89d1a
73266fa
1cb0411
96d6df3
03c8695
73e1294
ee688b9
11d0d01
bbb0450
0d243cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's sync about it. |
||
} else { | ||
//Wrap the snippet with <MobileDeviceWrapper> | ||
return ['<MobileDeviceWrapper>', ...processedSnippet, '</MobileDeviceWrapper>'].join('\n'); | ||
} | ||
}; | ||
|
||
components.forEach(component => { | ||
const [componentName, componentParentName] = getComponentNameParts(component.name); | ||
|
@@ -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`); | ||
|
There was a problem hiding this comment.
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 🙏