Skip to content

Commit 30636c4

Browse files
authored
Component Utils for docs (#3609)
1 parent f5af3f1 commit 30636c4

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

docuilib/src/components/UILivePreview.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {StyleSheet} from 'react-native';
33
import {LiveProvider, LiveEditor} from 'react-live';
44
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
55
import BrowserOnly from '@docusaurus/BrowserOnly';
6+
import CodeBlock from '@theme/CodeBlock';
67
import {View, Colors} from 'react-native-ui-lib/core';
78
import ReactLiveScope from '../theme/ReactLiveScope';
8-
import CodeBlock from '@theme/CodeBlock';
9+
import {isComponentSupported} from '../utils/componentUtils';
910

1011
export const IFRAME_MESSAGE_TYPE = 'LIVE_PREVIEW_CODE_UPDATE_MESSAGE';
1112

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

18-
const supportedComponentNames = Object.keys(ReactLiveScope);
19-
const componentLivePlaygroundSupport =
20-
liveScopeSupport || (componentName && supportedComponentNames.includes(componentName));
21-
2219
useEffect(() => {
2320
if (iframeLoaded) {
2421
sendMessageToIframe(code);
@@ -34,7 +31,7 @@ export default function UILivePreview({code: codeProp, componentName = undefined
3431
return {overflowY: 'scroll', scrollbarWidth: 'none'};
3532
}, []);
3633

37-
if (!componentLivePlaygroundSupport) {
34+
if (!liveScopeSupport && !isComponentSupported(componentName)) {
3835
return <CodeBlock language="jsx">{code}</CodeBlock>;
3936
}
4037

docuilib/src/components/pageComponents/Usage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import _ from 'lodash';
22
import React from 'react';
33
import CodeBlock from '@theme/CodeBlock';
44
import '../ComponentPage.module.scss';
5-
import ReactLiveScope from '../../theme/ReactLiveScope';
65
import UILivePreview from '../UILivePreview';
6+
import {isComponentSupported} from '../../utils/componentUtils';
77

88
export const Usage = ({component}) => {
9-
const supportedComponentNames = Object.keys(ReactLiveScope);
10-
const componentLivePlaygroundSupport = supportedComponentNames.includes(component.name);
119
if (component.snippet) {
1210
const code = component.snippet.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), '')).join('\n');
13-
return componentLivePlaygroundSupport ? (
11+
return isComponentSupported(component.name) ? (
1412
<UILivePreview code={code} liveScopeSupport/>
1513
) : (
1614
<CodeBlock language="jsx">{code}</CodeBlock>

docuilib/src/utils/componentUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import ReactLiveScope from '../theme/ReactLiveScope';
2+
3+
const supportedComponentNames = Object.keys(ReactLiveScope);
4+
5+
export const isComponentSupported = componentName => {
6+
return supportedComponentNames.includes(componentName);
7+
};

0 commit comments

Comments
 (0)