import React, { useMemo, useRef, type FC, type PropsWithChildren } from 'react'; import { type IPreviewerProps, useLocation, useLocale } from 'dumi'; import PreviewerActions from 'dumi/theme/slots/PreviewerActions'; import { Stack, HStack, Heading, Text, LinkOverlay, LinkBox, Badge, Box, useColorModeValue } from '@chakra-ui/react'; import { getLocalValue } from '../../factory/tools'; const Previewer: FC> = (props) => { const { asset, iframe, children, className, debug, style, demoUrl, compact } = props; const locale = useLocale(); const { hash } = useLocation(); const demoContainer = useRef(null); const link = `#${asset.id}`; const previewBgColor = useColorModeValue('whiteAlpha.900', 'gray.800'); const headingDefaultBorderColor = useColorModeValue( 'gray.200', 'whiteAlpha.200' ); const title = getLocalValue(locale, props, 'title'); const description = getLocalValue(locale, props, 'description'); const borderColor = useMemo(() => { return link === hash ? 'brand.400' : debug ? 'yellow.300' : 'transparent'; }, [link, hash, debug]); const headingBorderColor = useMemo(() => { return link === hash ? 'brand.400' : debug ? 'yellow.300' : headingDefaultBorderColor; }, [link, hash, debug, headingDefaultBorderColor]); return ( {(title || debug) && ( {title} {debug && DEV ONLY} )} {description && ( )} {iframe ? ( ) : ( children )} ); }; export default Previewer;