Skip to content

Component Utils for docs #3609

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 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 3 additions & 6 deletions docuilib/src/components/UILivePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {StyleSheet} from 'react-native';
import {LiveProvider, LiveEditor} from 'react-live';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import BrowserOnly from '@docusaurus/BrowserOnly';
import CodeBlock from '@theme/CodeBlock';
import {View, Colors} from 'react-native-ui-lib/core';
import ReactLiveScope from '../theme/ReactLiveScope';
import CodeBlock from '@theme/CodeBlock';
import {isComponentSupported} from '../utils/componentUtils';

export const IFRAME_MESSAGE_TYPE = 'LIVE_PREVIEW_CODE_UPDATE_MESSAGE';

Expand All @@ -15,10 +16,6 @@ export default function UILivePreview({code: codeProp, componentName = undefined
const {siteConfig} = useDocusaurusContext();
const iframeRef = useRef(null);

const supportedComponentNames = Object.keys(ReactLiveScope);
const componentLivePlaygroundSupport =
liveScopeSupport || (componentName && supportedComponentNames.includes(componentName));

useEffect(() => {
if (iframeLoaded) {
sendMessageToIframe(code);
Expand All @@ -34,7 +31,7 @@ export default function UILivePreview({code: codeProp, componentName = undefined
return {overflowY: 'scroll', scrollbarWidth: 'none'};
}, []);

if (!componentLivePlaygroundSupport) {
if (!liveScopeSupport && !isComponentSupported(componentName)) {
return <CodeBlock language="jsx">{code}</CodeBlock>;
}

Expand Down
6 changes: 2 additions & 4 deletions docuilib/src/components/pageComponents/Usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import _ from 'lodash';
import React from 'react';
import CodeBlock from '@theme/CodeBlock';
import '../ComponentPage.module.scss';
import ReactLiveScope from '../../theme/ReactLiveScope';
import UILivePreview from '../UILivePreview';
import {isComponentSupported} from '../../utils/componentUtils';

export const Usage = ({component}) => {
const supportedComponentNames = Object.keys(ReactLiveScope);
const componentLivePlaygroundSupport = supportedComponentNames.includes(component.name);
if (component.snippet) {
const code = component.snippet.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), '')).join('\n');
return componentLivePlaygroundSupport ? (
return isComponentSupported(component.name) ? (
<UILivePreview code={code} liveScopeSupport/>
) : (
<CodeBlock language="jsx">{code}</CodeBlock>
Expand Down
7 changes: 7 additions & 0 deletions docuilib/src/utils/componentUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ReactLiveScope from '../theme/ReactLiveScope';

const supportedComponentNames = Object.keys(ReactLiveScope);

export const isComponentSupported = componentName => {
return supportedComponentNames.includes(componentName);
};