feat: make tryIt presets, limits, badges and buttons completely dynamic from JSON configs
This commit is contained in:
@@ -25,7 +25,8 @@ interface TryItWidgetProps {
|
||||
variants?: VariantSpec[];
|
||||
locale?: string;
|
||||
className?: string;
|
||||
onSwitchToCompare?: () => void;
|
||||
samplePresets?: Array<{ label: string; url: string; resultUrl?: string }>;
|
||||
ctaText?: string;
|
||||
}
|
||||
|
||||
export function TryItWidget({
|
||||
@@ -34,7 +35,8 @@ export function TryItWidget({
|
||||
variants = [],
|
||||
locale = 'en',
|
||||
className = '',
|
||||
onSwitchToCompare,
|
||||
samplePresets,
|
||||
ctaText,
|
||||
}: TryItWidgetProps) {
|
||||
const [selectedFile, setSelectedFile] = useState<File | null>(null);
|
||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||
@@ -48,20 +50,22 @@ export function TryItWidget({
|
||||
const [isDragOver, setIsDragOver] = useState<boolean>(false);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const samplePresets = [
|
||||
{
|
||||
label: 'Sample Photo',
|
||||
url: (tool as any).media?.before || '/management/pages/home/media/sample_portrait_1.jpg',
|
||||
},
|
||||
{
|
||||
label: 'Natural Studio Model',
|
||||
url: '/management/pages/home/media/sample_portrait_2.jpg',
|
||||
},
|
||||
{
|
||||
label: 'Vintage Archival Shot',
|
||||
url: '/management/pages/home/media/sample_portrait_3.jpg',
|
||||
},
|
||||
];
|
||||
const activePresets = samplePresets && samplePresets.length > 0
|
||||
? samplePresets
|
||||
: [
|
||||
{
|
||||
label: 'Sample Photo',
|
||||
url: (tool as any).media?.before || '/management/pages/home/media/sample_portrait_1.jpg',
|
||||
},
|
||||
{
|
||||
label: 'Natural Studio Model',
|
||||
url: '/management/pages/home/media/sample_portrait_2.jpg',
|
||||
},
|
||||
{
|
||||
label: 'Vintage Archival Shot',
|
||||
url: '/management/pages/home/media/sample_portrait_3.jpg',
|
||||
},
|
||||
];
|
||||
|
||||
const handleFileChange = (file: File) => {
|
||||
const maxMB = tool.tryIt?.limits?.maxMB || 12;
|
||||
@@ -250,7 +254,7 @@ export function TryItWidget({
|
||||
Or test instantly with a sample photo:
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2.5">
|
||||
{samplePresets.map((preset, idx) => (
|
||||
{activePresets.map((preset, idx) => (
|
||||
<button
|
||||
key={idx}
|
||||
onClick={() => loadSamplePreset(preset.url)}
|
||||
@@ -262,20 +266,6 @@ export function TryItWidget({
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mobile Link to Preview Comparison */}
|
||||
{onSwitchToCompare && (
|
||||
<div className="pt-2 md:hidden">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSwitchToCompare}
|
||||
className="w-full py-2.5 px-3 rounded-xl text-xs font-semibold text-slate-600 bg-slate-50 hover:bg-slate-100 border border-slate-200 flex items-center justify-center gap-2 transition-colors"
|
||||
>
|
||||
<SlidersHorizontal className="w-3.5 h-3.5 text-blue-600" />
|
||||
<span>View Model Transformation Preview</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -341,7 +331,7 @@ export function TryItWidget({
|
||||
className="w-full py-4 px-6 rounded-2xl font-bold text-xs sm:text-sm text-white bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-700 hover:to-indigo-700 shadow-md shadow-blue-500/25 transition-all flex items-center justify-center gap-2 active:scale-98"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 text-white" />
|
||||
<span>Run {resolveLocalised(tool.name, locale)}</span>
|
||||
<span>{ctaText || `Run ${resolveLocalised(tool.name, locale)}`}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user