Skip to content

Usage component support live preview for compatible components #3581

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

Merged
merged 6 commits into from
Mar 12, 2025

Conversation

adids1221
Copy link
Contributor

@adids1221 adids1221 commented Mar 10, 2025

Description

Docs - Usage section, should show live playground or code block.
If the component is part of the ReactLiveScope we should show live playground else code block.
Old PR
- closed because of the api files.

Changelog

Docs - Usage section, should show live playground or code block.

Additional info

None

@adids1221
Copy link
Contributor Author

Note:

const code = component.snippet?.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), '')).join('\n');

This line takes the $x and remove it from each line of the snipper.

</CodeBlock>
</div>
return componentLivePlaygroundSupport ? (
<UILivePreview code={code}/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to prettify the code, Nitzan did it in another use case, check with him


export const Usage = ({component}) => {
const componentLivePlaygroundSupport = !!ReactLiveScope[component.name];
const code = component.snippet?.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), '')).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.

Move this line of code to after the check if a snippet exists

</CodeBlock>
</div>
return componentLivePlaygroundSupport ? (
<UILivePreview code={code}/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that the code doesn't update in runtime, it stuck on the snippet
if the user plays with the code it doesn't reflected in the preview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UILivePreview has his own code state management, the LiveProvider handels it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So it works?
If the user changes the code it applies?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see it works for me
So maybe I had another issue, I'll approve
Let's merge this and fix the formatting in another PR

@adids1221
Copy link
Contributor Author

adids1221 commented Mar 11, 2025

Now LivePreview will be shown only for supported components otherwise it will show CodeBlock.

TODO: add useFormattedCode usage for LivePreview

I have some issue with useFormattedCode in some cases when the snippet is functional component with state management.
@nitzanyiz let's sync about it.

Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

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

Approving.
I see it works for me now, we can fix the formatting in another PR

@ethanshar ethanshar merged commit 0950f3e into master Mar 12, 2025
1 check passed
@ethanshar ethanshar deleted the docs/usage_suport_live_playground branch March 12, 2025 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants