@@ -4,6 +4,7 @@ import {themes} from 'prism-react-renderer';
4
4
import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
5
5
import BrowserOnly from '@docusaurus/BrowserOnly' ;
6
6
import CodeBlock from '@theme/CodeBlock' ;
7
+ import Button from 'react-native-ui-lib/Button' ;
7
8
import ReactLiveScope from '../theme/ReactLiveScope' ;
8
9
import { isComponentSupported } from '../utils/componentUtils' ;
9
10
import useFormattedCode from '../hooks/useFormattedCode' ;
@@ -15,12 +16,8 @@ export default function UILivePreview({code: initialCode, componentName = undefi
15
16
const [ iframeLoaded , setIframeLoaded ] = useState ( false ) ;
16
17
const { siteConfig} = useDocusaurusContext ( ) ;
17
18
const iframeRef = useRef ( null ) ;
18
- const { code : formattedCode } = useFormattedCode ( initialCode , { printWidth : 100 } ) ;
19
- const [ code , setCode ] = useState ( formattedCode ) ;
20
-
21
- useEffect ( ( ) => {
22
- setCode ( formattedCode ) ;
23
- } , [ formattedCode ] ) ;
19
+ const [ code , setCode ] = useState ( initialCode ) ;
20
+ const { code : formattedCode } = useFormattedCode ( code , { printWidth : 100 } ) ;
24
21
25
22
useEffect ( ( ) => {
26
23
if ( iframeLoaded ) {
@@ -33,6 +30,10 @@ export default function UILivePreview({code: initialCode, componentName = undefi
33
30
iframeRef . current ?. contentWindow . postMessage ( message , '*' ) ;
34
31
} ;
35
32
33
+ const handleFormat = ( ) => {
34
+ setCode ( formattedCode ) ;
35
+ } ;
36
+
36
37
if ( ! liveScopeSupport && ! isComponentSupported ( componentName ) ) {
37
38
return < CodeBlock language = "jsx" > { code } </ CodeBlock > ;
38
39
}
@@ -46,6 +47,15 @@ export default function UILivePreview({code: initialCode, componentName = undefi
46
47
< LiveProvider code = { code } scope = { ReactLiveScope } theme = { themes . oceanicNext } >
47
48
< div className = { styles . container } >
48
49
< div className = { styles . codeContainer } >
50
+ < div className = { styles . codeHeader } >
51
+ < Button
52
+ label = "Prettify"
53
+ size = { Button . sizes . small }
54
+ onPress = { handleFormat }
55
+ backgroundColor = "#2d2d2d"
56
+ borderRadius = { 4 }
57
+ />
58
+ </ div >
49
59
< LiveEditor onChange = { setCode } className = { styles . liveEditor } />
50
60
< div className = { styles . errorContainer } >
51
61
< LiveError />
0 commit comments