Spaces:
Running
Running
File size: 5,815 Bytes
45b3fab 3b8892c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | /*
* ReferenceLayout.tsx
* Purpose: Implements one of the generic fallback slide layouts used when a template-specific renderer is unavailable.
* Used by: components/slides/SlideFactory.
* Depends on: Template styling props and inline field-edit callbacks.
*/
'use client';
import React, { useState } from 'react';
import { TemplateStyles } from '@/data/templates';
export interface ReferenceLayoutProps {
title: string;
items: Array<{ text: string }>;
styles: TemplateStyles;
slideId?: string;
isEditable?: boolean;
onFieldUpdate?: (slideId: string, field: string, value: string, index?: number) => void;
}
export default function ReferenceLayout({
title,
items,
styles,
slideId,
isEditable = false,
onFieldUpdate,
}: ReferenceLayoutProps) {
const [editingField, setEditingField] = useState<{ field: string; index?: number } | null>(null);
const [tempTitle, setTempTitle] = useState(title);
const [tempItems, setTempItems] = useState(items.map((i) => i.text));
const handleBlur = (field: string, index?: number) => {
if (!slideId || !onFieldUpdate) return;
if (field === 'title' && tempTitle !== title) onFieldUpdate(slideId, 'title', tempTitle);
if (field === 'items' && index !== undefined && tempItems[index] !== items[index]?.text)
onFieldUpdate(slideId, 'items', tempItems[index], index);
setEditingField(null);
};
const handleKeyDown = (e: React.KeyboardEvent, field: string, index?: number) => {
if (e.key === 'Enter') { e.preventDefault(); handleBlur(field, index); }
if (e.key === 'Escape') {
setEditingField(null);
setTempTitle(title);
setTempItems(items.map((i) => i.text));
}
};
return (
<div
className="w-full h-full flex flex-col relative overflow-hidden p-10"
style={{ backgroundColor: styles.colors.background, color: styles.colors.text }}
>
{styles.dotPattern && (
<div aria-hidden className="absolute inset-0 opacity-30" style={{ background: styles.dotPattern }} />
)}
<div className="relative z-10 flex flex-col h-full">
{/* Title */}
{editingField?.field === 'title' ? (
<input
type="text"
value={tempTitle}
onChange={(e) => setTempTitle(e.target.value)}
onBlur={() => handleBlur('title')}
onKeyDown={(e) => handleKeyDown(e, 'title')}
className="bg-transparent outline-none mb-8"
style={{
fontFamily: styles.fonts.heading,
fontSize: '40px',
fontWeight: 'bold',
textTransform: 'uppercase',
backgroundColor: styles.colors.accent,
border: `${styles.border.width} solid ${styles.colors.border}`,
boxShadow: styles.border.shadow,
padding: '8px 24px',
color: styles.colors.text,
}}
autoFocus
/>
) : (
<h2
className={`mb-8 ${isEditable ? 'cursor-pointer' : ''}`}
style={{
fontFamily: styles.fonts.heading,
fontSize: '40px',
fontWeight: 'bold',
textTransform: 'uppercase',
display: 'inline-block',
alignSelf: 'flex-start',
backgroundColor: styles.colors.accent,
border: `${styles.border.width} solid ${styles.colors.border}`,
boxShadow: styles.border.shadow,
padding: '8px 24px',
color: styles.colors.text,
}}
onClick={() => { if (isEditable) { setEditingField({ field: 'title' }); setTempTitle(title); } }}
>
{title}
</h2>
)}
{/* Reference Items */}
<div className="flex flex-col gap-3 flex-1">
{items.map((item, i) => (
<div
key={i}
className="flex items-start gap-4 py-3"
style={{ borderBottom: `1px solid ${styles.colors.border}20` }}
>
<span
className="shrink-0 mt-1"
style={{
fontFamily: styles.fonts.heading,
fontSize: '13px',
fontWeight: 'bold',
color: styles.colors.accent,
backgroundColor: styles.colors.text,
padding: '2px 8px',
borderRadius: styles.border.radius,
}}
>
[{i + 1}]
</span>
{editingField?.field === 'items' && editingField?.index === i ? (
<input
type="text"
value={tempItems[i] || ''}
onChange={(e) => {
const next = [...tempItems];
next[i] = e.target.value;
setTempItems(next);
}}
onBlur={() => handleBlur('items', i)}
onKeyDown={(e) => handleKeyDown(e, 'items', i)}
className="flex-1 bg-transparent outline-none"
style={{ fontFamily: styles.fonts.body, fontSize: '16px', color: styles.colors.text }}
autoFocus
/>
) : (
<span
className={`flex-1 ${isEditable ? 'cursor-pointer hover:opacity-70' : ''}`}
style={{ fontFamily: styles.fonts.body, fontSize: '16px', color: styles.colors.text, opacity: 0.85, lineHeight: 1.6 }}
onClick={() => { if (isEditable) { setEditingField({ field: 'items', index: i }); setTempItems(items.map((x) => x.text)); } }}
>
{item.text}
</span>
)}
</div>
))}
</div>
</div>
</div>
);
}
|