import { Box, BoxProps, chakra } from '@chakra-ui/react' import React, { useState } from 'react' import { LiveEditor, LiveError, LivePreview, LiveProvider } from 'react-live' import CodeContainer from './code-container' import CopyButton from './copy-button' import scope from './react-live-scope' import { liveEditorStyle, liveErrorStyle } from './styles' import { t } from 'utils/i18n' const LiveCodePreview = chakra(LivePreview, { baseStyle: { fontFamily: 'body', mt: 5, p: 3, borderWidth: 1, borderRadius: '12px', overflowX: 'auto', }, }) const EditableNotice = (props: BoxProps) => { return ( {t('component.mdx-components.react-live-block.editable-example')} ) } function ReactLiveBlock({ editable, rawCode, ...rest }) { const code = rawCode.trim().replace('// prettier-ignore', '') const [editorCode, setEditorCode] = useState(code.trim()) const onChange = (newCode) => setEditorCode(newCode.trim()) const liveProviderProps = { code: editorCode, scope, ...rest, } return ( {editable && ( )} {editable && } {editable && } ) } export default ReactLiveBlock