File size: 4,004 Bytes
7fab18f | 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 | import React from 'react';
import { DYNASTY_OPTIONS, CUSTOMIZATION_OPTIONS } from '../constants';
import { Dynasty } from '../types';
import { Check } from 'lucide-react';
interface OptionsPanelProps {
selectedDynasty: Dynasty;
onSelectDynasty: (d: Dynasty) => void;
selectedCustomizations: string[];
onToggleCustomization: (id: string) => void;
isGenerating: boolean;
onGenerate: () => void;
hasImage: boolean;
}
export const OptionsPanel: React.FC<OptionsPanelProps> = ({
selectedDynasty,
onSelectDynasty,
selectedCustomizations,
onToggleCustomization,
isGenerating,
onGenerate,
hasImage
}) => {
return (
<div className="space-y-8">
{/* Dynasty Selection */}
<section>
<h3 className="text-lg font-bold text-stone-800 mb-4 flex items-center gap-2">
<span className="w-1 h-6 bg-red-800 rounded-full"></span>
选择朝代 (Select Dynasty)
</h3>
<div className="grid grid-cols-1 gap-3">
{DYNASTY_OPTIONS.map((option) => (
<button
key={option.id}
onClick={() => onSelectDynasty(option.id)}
disabled={isGenerating}
className={`
relative p-4 rounded-xl text-left border-2 transition-all duration-200
${selectedDynasty === option.id
? 'border-red-800 bg-red-50'
: 'border-stone-200 hover:border-red-200 bg-white'}
`}
>
<div className="flex items-start justify-between">
<div>
<div className={`font-bold ${selectedDynasty === option.id ? 'text-red-900' : 'text-stone-700'}`}>
{option.name}
</div>
<div className="text-sm text-stone-500 mt-1">
{option.description}
</div>
</div>
{selectedDynasty === option.id && (
<div className="bg-red-800 text-white p-1 rounded-full">
<Check size={14} />
</div>
)}
</div>
</button>
))}
</div>
</section>
{/* Customization Selection */}
<section>
<h3 className="text-lg font-bold text-stone-800 mb-4 flex items-center gap-2">
<span className="w-1 h-6 bg-red-800 rounded-full"></span>
妆容与配饰 (Customization)
</h3>
<div className="grid grid-cols-2 gap-3">
{CUSTOMIZATION_OPTIONS.map((option) => {
const isSelected = selectedCustomizations.includes(option.id);
return (
<button
key={option.id}
onClick={() => onToggleCustomization(option.id)}
disabled={isGenerating}
className={`
p-3 rounded-lg text-sm font-medium border transition-all duration-200
${isSelected
? 'bg-stone-800 text-white border-stone-800'
: 'bg-white text-stone-600 border-stone-200 hover:border-stone-400'}
`}
>
{option.label}
</button>
);
})}
</div>
</section>
{/* Action Button */}
<button
onClick={onGenerate}
disabled={!hasImage || isGenerating}
className={`
w-full py-4 rounded-xl font-bold text-lg shadow-lg transform transition-all
${!hasImage || isGenerating
? 'bg-stone-300 text-stone-500 cursor-not-allowed'
: 'bg-red-800 text-white hover:bg-red-900 hover:-translate-y-1 hover:shadow-xl'}
`}
>
{isGenerating ? '制作中... (Generating)' : '一键换装 (Try On Hanfu)'}
</button>
{!hasImage && (
<p className="text-center text-sm text-red-500 mt-2">
请先上传照片 (Please upload a photo first)
</p>
)}
</div>
);
};
|