File size: 10,354 Bytes
edb7d3e a72d248 edb7d3e 7c5bb49 edb7d3e | 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | import { useState } from 'react'
import { X, Smile } from 'lucide-react'
import clsx from 'clsx'
/**
* Caption style editor modal
* Props: { isOpen, onClose, clipId, jobId }
*/
function CaptionEditor({ isOpen, onClose, clipId, jobId }) {
const [style, setStyle] = useState('highlight')
const [fontSize, setFontSize] = useState(48)
const [textColor, setTextColor] = useState('#FFFFFF')
const [highlightColor, setHighlightColor] = useState('#E8A020')
const [bgColor, setBgColor] = useState('#000000')
const [bgOpacity, setBgOpacity] = useState(0.5)
const [position, setPosition] = useState('bottom')
const [emoji, setEmoji] = useState(true)
const [language, setLanguage] = useState('en')
if (!isOpen) return null
const styles = [
{ id: 'highlight', label: 'Highlight Word', icon: '✨' },
{ id: 'box', label: 'Box', icon: '📦' },
{ id: 'outline', label: 'Outline', icon: '⭕' },
{ id: 'bold', label: 'Bold', icon: '𝗕' },
{ id: 'none', label: 'None', icon: '—' },
]
const positions = [
{ id: 'top', label: 'Top', pos: 'top-4' },
{ id: 'middle', label: 'Middle', pos: 'top-1/2' },
{ id: 'bottom', label: 'Bottom', pos: 'bottom-4' },
]
const handleSave = () => {
// Mock API call
console.log({
style,
fontSize,
textColor,
highlightColor,
bgColor,
bgOpacity,
position,
emoji,
language,
})
onClose()
}
return (
<>
{/* Overlay */}
<div
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-40 animate-fade-in"
onClick={onClose}
/>
{/* Modal */}
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 animate-scale-in">
<div className="glass-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto rounded-3xl">
{/* Header */}
<div className="flex items-center justify-between p-8 border-b border-white/10 sticky top-0 bg-dark-900/50 backdrop-blur">
<h2 className="text-2xl font-bold text-white">Edit Captions</h2>
<button
onClick={onClose}
className="p-2 hover:bg-white/10 rounded-lg transition-colors"
>
<X className="w-5 h-5 text-white/70" />
</button>
</div>
<div className="p-8 space-y-8">
{/* Caption Style */}
<div>
<label className="block text-sm font-semibold text-white mb-4">Style</label>
<div className="grid grid-cols-5 gap-3">
{styles.map((s) => (
<button
key={s.id}
onClick={() => setStyle(s.id)}
className={clsx(
'p-4 rounded-xl text-center font-semibold transition-all flex flex-col items-center gap-2',
style === s.id
? 'glass-lg bg-primary-500/20 border-primary-500/50 shadow-glow'
: 'glass hover:bg-white/10'
)}
>
<span className="text-2xl">{s.icon}</span>
<span className="text-xs text-white/70">{s.label}</span>
</button>
))}
</div>
</div>
{/* Font Size */}
<div>
<div className="flex justify-between items-center mb-3">
<label className="text-sm font-semibold text-white">Font Size</label>
<span className="text-2xl font-bold text-primary-500">{fontSize}px</span>
</div>
<input
type="range"
min="24"
max="80"
value={fontSize}
onChange={(e) => setFontSize(parseInt(e.target.value))}
className="w-full h-2 bg-white/10 rounded-full accent-primary-500"
/>
</div>
{/* Colors */}
<div className="grid grid-cols-2 gap-6">
<div>
<label className="block text-sm font-semibold text-white mb-3">Text Color</label>
<div className="flex gap-3">
<input
type="color"
value={textColor}
onChange={(e) => setTextColor(e.target.value)}
className="w-16 h-10 rounded-lg cursor-pointer"
/>
<input
type="text"
value={textColor}
onChange={(e) => setTextColor(e.target.value)}
className="input-field flex-1 text-sm font-mono"
/>
</div>
</div>
<div>
<label className="block text-sm font-semibold text-white mb-3">Highlight Color</label>
<div className="flex gap-3">
<input
type="color"
value={highlightColor}
onChange={(e) => setHighlightColor(e.target.value)}
className="w-16 h-10 rounded-lg cursor-pointer"
/>
<input
type="text"
value={highlightColor}
onChange={(e) => setHighlightColor(e.target.value)}
className="input-field flex-1 text-sm font-mono"
/>
</div>
</div>
<div>
<label className="block text-sm font-semibold text-white mb-3">Background</label>
<div className="flex gap-3">
<input
type="color"
value={bgColor}
onChange={(e) => setBgColor(e.target.value)}
className="w-16 h-10 rounded-lg cursor-pointer"
/>
<input
type="text"
value={bgColor}
onChange={(e) => setBgColor(e.target.value)}
className="input-field flex-1 text-sm font-mono"
/>
</div>
</div>
<div>
<label className="block text-sm font-semibold text-white mb-3">
Background Opacity: {Math.round(bgOpacity * 100)}%
</label>
<input
type="range"
min="0"
max="1"
step="0.1"
value={bgOpacity}
onChange={(e) => setBgOpacity(parseFloat(e.target.value))}
className="w-full h-2 bg-white/10 rounded-full accent-primary-500"
/>
</div>
</div>
{/* Position */}
<div>
<label className="block text-sm font-semibold text-white mb-4">Position</label>
<div className="grid grid-cols-3 gap-3">
{positions.map((p) => (
<button
key={p.id}
onClick={() => setPosition(p.id)}
className={clsx(
'p-4 rounded-xl font-semibold transition-all',
position === p.id
? 'glass-lg bg-primary-500/20 border-primary-500/50'
: 'glass hover:bg-white/10'
)}
>
{p.label}
</button>
))}
</div>
</div>
{/* Language */}
<div>
<label className="block text-sm font-semibold text-white mb-3">Language</label>
<select
value={language}
onChange={(e) => setLanguage(e.target.value)}
className="input-field-lg w-full bg-white/5"
>
<option value="en">English</option>
<option value="es">Spanish</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="it">Italian</option>
<option value="pt">Portuguese</option>
<option value="ja">Japanese</option>
<option value="zh">Chinese</option>
<option value="ko">Korean</option>
</select>
</div>
{/* Emoji Captions */}
<label className="flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={emoji}
onChange={(e) => setEmoji(e.target.checked)}
className="w-4 h-4 rounded accent-primary-500"
/>
<span className="text-sm font-semibold text-white flex items-center gap-2">
<Smile className="w-4 h-4" />
Include Emoji Captions
</span>
</label>
{/* Preview */}
<div className="glass-lg p-8 rounded-2xl">
<p className="text-xs text-white/60 mb-4">Preview</p>
<div className="aspect-9-16 bg-dark-850 rounded-xl flex items-end justify-center overflow-hidden relative">
{/* Phone frame mockup */}
<div className="absolute inset-0 bg-gradient-to-b from-transparent via-transparent to-dark-900 pointer-events-none" />
{/* Caption preview */}
<div
className={`${position === 'bottom' ? 'mb-8' : position === 'middle' ? 'my-auto' : 'mt-8'} px-4 text-center transition-all`}
style={{
fontSize: `${fontSize / 2}px`,
color: textColor,
}}
>
<p className="font-bold">Sample caption text</p>
{emoji && <p>✨ 🎬 🔥</p>}
</div>
</div>
</div>
{/* Actions */}
<div className="flex gap-3">
<button onClick={onClose} className="btn-secondary-lg flex-1">
Cancel
</button>
<button onClick={handleSave} className="btn-primary-lg flex-1">
Apply Changes
</button>
</div>
</div>
</div>
</div>
</>
)
}
export default CaptionEditor
|