feat(tool-page): add dynamic support for before/after comparison animations and videos in alternating features

This commit is contained in:
2026-11-11 12:53:39 +05:30
parent e8307fd4bc
commit a372be4578
3 changed files with 56 additions and 33 deletions
@@ -3,6 +3,7 @@
import React from 'react';
import { AlternatingFeature, resolveLocalised } from '@/types';
import { KineticText } from '@/components/magicui/kinetic-text';
import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider';
interface AlternatingFeaturesSectionProps {
features?: AlternatingFeature[];
@@ -35,39 +36,72 @@ export function AlternatingFeaturesSection({
</p>
</div>
{/* Alternating Feature Items: Image at Left - Text at Right, then Text at Left - Image at Right (No cards, pure editorial) */}
{/* Alternating Feature Items: Supports Image, Interactive Before/After Comparison, or Video */}
<div className="space-y-14 sm:space-y-20">
{features.map((feature, idx) => {
const isEven = idx % 2 === 0;
const title = resolveLocalised(feature.title, locale);
const desc = resolveLocalised(feature.description, locale);
// Dynamically detect media format: comparison animation/slider, video, or image
const isComparison = feature.mediaType === 'comparison' || (Boolean(feature.before) && Boolean(feature.after));
const isVideo = feature.mediaType === 'video' || Boolean(feature.videoUrl) || (feature.image ? /\.(mp4|webm|mov)(\?.*)?$/i.test(feature.image) : false);
return (
<div
key={idx}
className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-14 items-center"
>
{/* Visual / Image Block */}
{/* Visual / Media Block */}
<div
className={`lg:col-span-6 ${
isEven ? 'order-1 lg:order-1' : 'order-1 lg:order-2'
}`}
>
<div className="group relative rounded-3xl overflow-hidden bg-paper-2 border border-rule shadow-md transition-all duration-300 hover:shadow-lg">
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={feature.image}
alt={title}
loading="lazy"
decoding="async"
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-[1.02]"
/>
</div>
{/* 1. Comparison Interactive Slider / Animation */}
{isComparison && feature.before && feature.after ? (
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden">
<CardBeforeAfterSlider
beforeUrl={feature.before}
afterUrl={feature.after}
title={title}
aspectRatio="aspect-auto h-full"
beforeLabel="Before"
afterLabel="After"
/>
</div>
) : isVideo ? (
/* 2. Autoplay Looped Video Specimen */
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden bg-paper-2">
<video
src={feature.videoUrl || feature.image}
poster={feature.poster}
muted
loop
autoPlay
playsInline
preload="metadata"
className="w-full h-full object-cover"
/>
</div>
) : (
/* 3. High-Resolution Single Specimen Image */
<div className="aspect-[16/10] sm:aspect-[4/3] w-full overflow-hidden">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={feature.image || '/management/pages/home/sections/our-tools/blemish-remover/after.jpg'}
alt={title}
loading="lazy"
decoding="async"
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-[1.02]"
/>
</div>
)}
</div>
</div>
{/* Text Paragraph Block: Clean Heading + Spacious Paragraph (No cards, no Feature labels, no pills) */}
{/* Text Paragraph Block: Clean Heading + Spacious Paragraph */}
<div
className={`lg:col-span-6 space-y-4 ${
isEven ? 'order-2 lg:order-2' : 'order-2 lg:order-1'