125 lines
4.4 KiB
TypeScript
125 lines
4.4 KiB
TypeScript
'use client'
|
|
|
|
import { useThemeStyles, cn } from '@/lib/ui-styles'
|
|
import type { UploadTemplateDto } from '../../template-manager/types'
|
|
|
|
interface SaveMessage {
|
|
type: 'success' | 'error'
|
|
text: string
|
|
}
|
|
|
|
interface TemplateEditorFooterProps {
|
|
isPreviewMode: boolean
|
|
saving: boolean
|
|
saveMessage: SaveMessage | null
|
|
previewTemplate: UploadTemplateDto | null
|
|
onClose: () => void
|
|
onSave: () => void
|
|
onExitPreview: () => void
|
|
onCreateFromPreview: () => void
|
|
}
|
|
|
|
export default function TemplateEditorFooter({
|
|
isPreviewMode,
|
|
saving,
|
|
saveMessage,
|
|
previewTemplate,
|
|
onClose,
|
|
onSave,
|
|
onExitPreview,
|
|
onCreateFromPreview,
|
|
}: TemplateEditorFooterProps) {
|
|
const styles = useThemeStyles()
|
|
return (
|
|
<div className="px-6 py-5 border-t border-slate-200/60 dark:border-slate-800/60 bg-slate-50/50 dark:bg-slate-800/30">
|
|
{saveMessage && (
|
|
<div
|
|
className={cn(
|
|
'mb-4 px-4 py-3 rounded-lg flex items-center gap-2 border',
|
|
saveMessage.type === 'success'
|
|
? 'bg-green-50 dark:bg-green-900/30 text-green-700 dark:text-green-300 border-green-200 dark:border-green-800'
|
|
: 'bg-red-50 dark:bg-red-900/30 text-red-700 dark:text-red-300 border-red-200 dark:border-red-800',
|
|
)}
|
|
>
|
|
{saveMessage.type === 'success' ? (
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
</svg>
|
|
) : (
|
|
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
</svg>
|
|
)}
|
|
<span className="text-sm font-medium">{saveMessage.text}</span>
|
|
</div>
|
|
)}
|
|
|
|
<div className="flex justify-end gap-3">
|
|
{isPreviewMode ? (
|
|
<>
|
|
<button
|
|
onClick={onClose}
|
|
className={cn(
|
|
styles.buttonStyles.secondary,
|
|
styles.buttonModifiers.compact,
|
|
'rounded-lg bg-white dark:bg-slate-800 border-slate-300 dark:border-slate-600 text-slate-700 dark:text-slate-200',
|
|
)}
|
|
>
|
|
关闭
|
|
</button>
|
|
<button
|
|
onClick={previewTemplate ? onExitPreview : onCreateFromPreview}
|
|
className={cn(
|
|
styles.buttonStyles.primary,
|
|
styles.buttonModifiers.compact,
|
|
'rounded-lg bg-slate-900 hover:bg-slate-800 text-white dark:bg-slate-100 dark:hover:bg-white dark:text-slate-900',
|
|
)}
|
|
>
|
|
{previewTemplate ? '编辑此模板' : '从此模板新建'}
|
|
</button>
|
|
</>
|
|
) : (
|
|
<>
|
|
<button
|
|
onClick={onClose}
|
|
disabled={saving}
|
|
className={cn(
|
|
styles.buttonStyles.secondary,
|
|
styles.buttonModifiers.compact,
|
|
'rounded-lg bg-white dark:bg-slate-800 border-slate-300 dark:border-slate-600 text-slate-700 dark:text-slate-200',
|
|
saving && 'opacity-60 cursor-not-allowed',
|
|
)}
|
|
>
|
|
取消
|
|
</button>
|
|
<button
|
|
onClick={onSave}
|
|
disabled={saving}
|
|
className={cn(
|
|
styles.buttonStyles.primary,
|
|
styles.buttonModifiers.compact,
|
|
'min-w-[120px]',
|
|
'rounded-lg bg-slate-900 hover:bg-slate-800 text-white dark:bg-slate-100 dark:hover:bg-white dark:text-slate-900',
|
|
)}
|
|
>
|
|
{saving ? (
|
|
<span className="flex items-center justify-center gap-2">
|
|
<svg className="animate-spin h-4 w-4" fill="none" viewBox="0 0 24 24">
|
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
|
</svg>
|
|
保存中...
|
|
</span>
|
|
) : (
|
|
'保存模板'
|
|
)}
|
|
</button>
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
|