import { ActionIcon, Tabs } from '@lobehub/ui'; import { type IPreviewerProps, openCodeSandbox, openStackBlitz, useIntl } from 'dumi'; import { Code, Code2, Codesandbox, MonitorUp, Zap } from 'lucide-react'; import { type FC, type ReactNode, useState } from 'react'; import SourceCode from '@/builtins/SourceCode'; import { useStyles } from './style'; export interface PreviewerActionsProps extends IPreviewerProps { demoContainer: HTMLDivElement | HTMLIFrameElement; /** * disabled actions */ disabledActions?: ('CSB' | 'STACKBLITZ' | 'EXTERNAL' | 'HTML2SKETCH')[]; extra?: ReactNode; forceShowCode?: boolean; } const PreviewerActions: FC = (props) => { const intl = useIntl(); const files = Object.entries(props.asset.dependencies).filter(([, { type }]) => type === 'FILE'); const [activeKey, setActiveKey] = useState(0); const [showCode, setShowCode] = useState(props.forceShowCode || props.defaultShowCode); const isSingleFile = files.length === 1; const lang = (files[activeKey][0].match(/\.([^.]+)$/)?.[1] || 'text') as any; const { styles } = useStyles(); return ( <>
{!props.disabledActions?.includes('CSB') && ( openCodeSandbox(props)} size={'small'} title={intl.formatMessage({ id: 'previewer.actions.codesandbox', })} /> )} {!props.disabledActions?.includes('STACKBLITZ') && ( openStackBlitz(props)} size={'small'} title={intl.formatMessage({ id: 'previewer.actions.stackblitz', })} /> )} {!props.disabledActions?.includes('EXTERNAL') && ( )} {!props.forceShowCode && ( setShowCode((previous) => !previous)} size={'small'} title={intl.formatMessage({ id: `previewer.actions.code.${showCode ? 'shrink' : 'expand'}`, })} /> )}
{showCode && ( <>
{!isSingleFile && ( ({ key: String(index), label: filename, }))} onChange={(key) => setActiveKey(Number(key))} /> )}
{files[activeKey][1].value} )} ); }; export default PreviewerActions;