fix(tools): refine tool grid header, mobile touch slider scrolling, and remove duplicates

This commit is contained in:
2026-11-07 12:44:57 +05:30
parent d273fb0489
commit 39fdb0aae1
3 changed files with 214 additions and 163 deletions
+153 -150
View File
@@ -12,10 +12,7 @@ import {
Sparkles, Sparkles,
X, X,
Layers, Layers,
ShieldCheck,
Zap,
Smartphone, Smartphone,
SlidersHorizontal,
ChevronRight, ChevronRight,
RotateCcw, RotateCcw,
} from 'lucide-react'; } from 'lucide-react';
@@ -227,32 +224,60 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
setSplitPos(pct); setSplitPos(pct);
}, []); }, []);
const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => { const startDragging = useCallback((clientX: number, target: HTMLElement, pointerId: number) => {
if (media.type !== 'comparison') return;
isDraggingRef.current = true; isDraggingRef.current = true;
try { try {
e.currentTarget.setPointerCapture(e.pointerId); target.setPointerCapture(pointerId);
} catch {} } catch {}
updatePosition(e.clientX); updatePosition(clientX);
}, [updatePosition]);
// On desktop with mouse, clicking anywhere on the stage moves the slider.
// On phones/touch screens, touching the card does NOT move the slider,
// allowing completely unobstructed vertical page scrolling!
const handleContainerPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (e.pointerType !== 'mouse' || e.button !== 0) return;
startDragging(e.clientX, e.currentTarget, e.pointerId);
}; };
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => { const handleContainerPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return; if (media.type !== 'comparison') return;
if (isDraggingRef.current || e.pointerType === 'mouse') { if (e.pointerType === 'mouse' && !isDraggingRef.current) {
updatePosition(e.clientX); updatePosition(e.clientX);
} }
}; };
const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => { const handleContainerPointerLeave = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.pointerType === 'mouse' && !isDraggingRef.current) {
setSplitPos(50);
}
};
// Dedicated Handle Button Pointer Handlers (Phone Touch & Mouse Dragging)
const handleHandlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
startDragging(e.clientX, e.currentTarget, e.pointerId);
};
const handleHandlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (isDraggingRef.current) {
e.stopPropagation();
updatePosition(e.clientX);
}
};
const handleHandlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (isDraggingRef.current) {
e.stopPropagation();
isDraggingRef.current = false; isDraggingRef.current = false;
try { try {
e.currentTarget.releasePointerCapture(e.pointerId); e.currentTarget.releasePointerCapture(e.pointerId);
} catch {} } catch {}
};
const handlePointerLeave = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.pointerType === 'mouse' && !isDraggingRef.current) {
setSplitPos(50);
} }
}; };
@@ -294,12 +319,11 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
return ( return (
<div <div
ref={containerRef} ref={containerRef}
onPointerDown={handlePointerDown} onPointerDown={handleContainerPointerDown}
onPointerMove={handlePointerMove} onPointerMove={handleContainerPointerMove}
onPointerUp={handlePointerUp} onPointerLeave={handleContainerPointerLeave}
onPointerCancel={handlePointerUp} className="relative w-full aspect-[4/3] rounded-2xl overflow-hidden bg-paper-2 select-none cursor-ew-resize group/img shadow-inner touch-pan-y"
onPointerLeave={handlePointerLeave} style={{ touchAction: 'pan-y' }}
className="relative w-full aspect-[4/3] rounded-2xl overflow-hidden bg-paper-2 select-none cursor-ew-resize group/img shadow-inner touch-none"
> >
{/* Enhanced / After Image (Underneath) */} {/* Enhanced / After Image (Underneath) */}
{/* eslint-disable-next-line @next/next/no-img-element */} {/* eslint-disable-next-line @next/next/no-img-element */}
@@ -329,16 +353,27 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
/> />
</div> </div>
{/* Vertical Slider Divider Line */} {/* Vertical Slider Divider Line (pointer-events-none so it doesn't block vertical scrolling) */}
<div <div
className="absolute top-0 bottom-0 w-[2px] bg-paper-hi shadow-md pointer-events-none z-10" className="absolute top-0 bottom-0 w-[2px] bg-paper-hi shadow-md pointer-events-none z-10"
style={{ left: `${splitPos}%`, transform: 'translateX(-50%)' }} style={{ left: `${splitPos}%`, transform: 'translateX(-50%)' }}
> >
{/* Sleek handle pill */} {/* Dedicated Tactile Handle Button: Phone touch activates ONLY on this button */}
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-6 h-6 rounded-full bg-paper-hi text-ink shadow-md flex items-center justify-center border border-rule"> <div
<div className="flex items-center gap-[2px]"> onPointerDown={handleHandlePointerDown}
<div className="w-0 h-0 border-y-[3px] border-y-transparent border-r-[4px] border-r-ink" /> onPointerMove={handleHandlePointerMove}
<div className="w-0 h-0 border-y-[3px] border-y-transparent border-l-[4px] border-l-ink" /> onPointerUp={handleHandlePointerUp}
onPointerCancel={handleHandlePointerUp}
role="slider"
aria-label="Before and after transformation slider"
aria-valuenow={Math.round(splitPos)}
tabIndex={0}
style={{ touchAction: 'none' }}
className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink shadow-md flex items-center justify-center border border-rule pointer-events-auto cursor-ew-resize touch-none before:absolute before:-inset-3 before:content-['']"
>
<div className="flex items-center gap-[2px] pointer-events-none">
<div className="w-0 h-0 border-y-[3.5px] border-y-transparent border-r-[4.5px] border-r-ink" />
<div className="w-0 h-0 border-y-[3.5px] border-y-transparent border-l-[4.5px] border-l-ink" />
</div> </div>
</div> </div>
</div> </div>
@@ -480,14 +515,6 @@ export function ToolGridSection({
return categorizedTools.find((g) => g.id === selectedCategory); return categorizedTools.find((g) => g.id === selectedCategory);
}, [categorizedTools, selectedCategory]); }, [categorizedTools, selectedCategory]);
// Categories to display
const displayedCategories = useMemo(() => {
if (selectedCategory === 'all') {
return categorizedTools;
}
return categorizedTools.filter((group) => group.id === selectedCategory);
}, [categorizedTools, selectedCategory]);
// If this is a simple embedded grid (e.g., inside an App detail page), render standard container // If this is a simple embedded grid (e.g., inside an App detail page), render standard container
if (!showCategoryFilter) { if (!showCategoryFilter) {
return ( return (
@@ -537,25 +564,11 @@ export function ToolGridSection({
{/* Top: Header, Search, Categories Nav */} {/* Top: Header, Search, Categories Nav */}
<div className="space-y-6"> <div className="space-y-6">
{/* Studio Brand & Directory Identity */} {/* Categories Header */}
<div className="flex items-center justify-between pb-3.5 border-b border-rule"> <div className="pb-3.5 border-b border-rule">
<div className="flex items-center gap-2.5"> <h2 className="text-sm font-bold text-ink font-body">
<div className="w-8 h-8 rounded-xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent shadow-2xs"> Categories
<SlidersHorizontal className="w-4 h-4" /> </h2>
</div>
<div>
<span className="text-xs font-semibold text-ink font-body block leading-tight">
Studio Directory
</span>
<span className="text-[11px] text-muted font-body">
12 neural models
</span>
</div>
</div>
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 text-[10px] font-semibold font-body">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" />
<span>Ready</span>
</span>
</div> </div>
{/* Instant Search Bar with shortcut hint */} {/* Instant Search Bar with shortcut hint */}
@@ -564,7 +577,7 @@ export function ToolGridSection({
<Search className="w-3.5 h-3.5 absolute left-3.5 top-1/2 -translate-y-1/2 text-muted pointer-events-none" /> <Search className="w-3.5 h-3.5 absolute left-3.5 top-1/2 -translate-y-1/2 text-muted pointer-events-none" />
<input <input
type="text" type="text"
placeholder="Search tools & models..." placeholder="Search tools..."
value={searchQuery} value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)} onChange={(e) => setSearchQuery(e.target.value)}
className="w-full pl-9 pr-8 py-2.5 rounded-2xl text-xs border border-rule bg-paper text-ink placeholder:text-muted focus:outline-none focus:border-accent focus:ring-2 focus:ring-accent/20 shadow-2xs font-body transition-colors" className="w-full pl-9 pr-8 py-2.5 rounded-2xl text-xs border border-rule bg-paper text-ink placeholder:text-muted focus:outline-none focus:border-accent focus:ring-2 focus:ring-accent/20 shadow-2xs font-body transition-colors"
@@ -587,8 +600,8 @@ export function ToolGridSection({
{/* Categories Navigation */} {/* Categories Navigation */}
<div className="space-y-2"> <div className="space-y-2">
<div className="flex items-center justify-between px-1 text-[11px] font-semibold text-muted uppercase tracking-wider font-body"> <div className="flex items-center justify-between px-1 font-body">
<span>Workspaces</span> <span className="text-xs font-bold text-ink uppercase tracking-wider">Workspaces</span>
{(selectedCategory !== 'all' || searchQuery) && ( {(selectedCategory !== 'all' || searchQuery) && (
<button <button
onClick={() => { onClick={() => {
@@ -681,20 +694,8 @@ export function ToolGridSection({
</div> </div>
{/* Bottom: GPU RAM Ephemeral Telemetry & Native App Suite Link */} {/* Bottom: Native App Suite Link */}
<div className="pt-4 border-t border-rule space-y-3"> <div className="pt-4 border-t border-rule space-y-3">
<div className="p-3.5 rounded-2xl bg-paper border border-rule space-y-1.5">
<div className="flex items-center gap-2">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
<span className="text-xs font-semibold text-ink font-body">
Volatile GPU RAM
</span>
</div>
<p className="text-[11px] text-muted leading-relaxed font-body">
In-browser GPU execution with immediate memory flush upon completion. Zero server storage.
</p>
</div>
<Link <Link
href="/apps" href="/apps"
className="w-full inline-flex items-center justify-between px-3.5 py-2.5 rounded-2xl text-xs font-body font-semibold text-ink bg-paper-2 hover:bg-ink hover:text-paper-hi transition-colors duration-150 group shadow-2xs" className="w-full inline-flex items-center justify-between px-3.5 py-2.5 rounded-2xl text-xs font-body font-semibold text-ink bg-paper-2 hover:bg-ink hover:text-paper-hi transition-colors duration-150 group shadow-2xs"
@@ -717,11 +718,11 @@ export function ToolGridSection({
{/* ================= MOBILE FILTER HEADER (< lg) ================= */} {/* ================= MOBILE FILTER HEADER (< lg) ================= */}
<div className="lg:hidden space-y-3 pb-4 border-b border-rule"> <div className="lg:hidden space-y-3 pb-4 border-b border-rule">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<span className="text-xs font-semibold text-accent uppercase tracking-wider font-body"> <span className="text-sm font-bold text-ink font-body">
Studio Directory Categories
</span> </span>
<span className="text-xs font-semibold text-muted font-body"> <span className="text-xs font-medium text-muted font-body">
{tools.length} neural models {tools.length} tools
</span> </span>
</div> </div>
@@ -789,62 +790,80 @@ export function ToolGridSection({
{/* ================= INTEGRATED STUDIO HEADER ================= */} {/* ================= INTEGRATED STUDIO HEADER ================= */}
<div className="space-y-4 border-b border-rule pb-8"> <div className="space-y-4 border-b border-rule pb-8">
{/* Breadcrumb row & telemetry */} {/* Breadcrumb row */}
<div className="flex flex-wrap items-center justify-between gap-3 text-xs font-body"> <div className="flex items-center gap-2 text-xs font-body text-muted">
<div className="flex items-center gap-2 text-muted">
<span>Studio Directory</span> <span>Studio Directory</span>
<span>/</span> <span>/</span>
{activeCategoryItem ? (
<>
<button
type="button"
onClick={() => handleSelectCategory('all')}
className="hover:text-ink hover:underline cursor-pointer"
>
All Vision Workspaces
</button>
<span>/</span>
<span className="text-accent font-semibold"> <span className="text-accent font-semibold">
{activeCategoryItem {resolveLocalised(activeCategoryItem.category?.name, locale)}
? resolveLocalised(activeCategoryItem.category?.name, locale)
: 'All Vision Workspaces'}
</span> </span>
</div> </>
<div className="flex items-center gap-3"> ) : (
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-hi border border-rule text-[11px] font-semibold text-ink shadow-2xs"> <span className="text-accent font-semibold">
<Sparkles className="w-3.5 h-3.5 text-accent" /> All Vision Workspaces
<span>{tools.length} Models Online</span>
</span> </span>
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-hi border border-rule text-[11px] font-semibold text-emerald-600 shadow-2xs"> )}
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
<span>Zero Server Storage</span>
</span>
</div>
</div> </div>
{/* Kinetic Headline */} {activeCategoryItem ? (
<h1 className="text-3xl sm:text-4xl lg:text-5xl font-display font-bold text-ink tracking-tight"> /* Focused Category Workspace Header */
<div className="flex flex-col sm:flex-row sm:items-start justify-between gap-4 pt-1">
<div className="flex items-start gap-3.5">
<div className="w-12 h-12 rounded-2xl flex items-center justify-center bg-paper-hi shadow-xs border border-rule text-accent shrink-0 mt-0.5">
{CATEGORY_THEMES[activeCategoryItem.id]?.icon || <Wand2 className="w-5 h-5 text-accent" />}
</div>
<div>
<div className="flex items-center gap-3">
<h1 className="text-2xl sm:text-3xl lg:text-4xl font-display font-bold text-ink tracking-tight">
<KineticText> <KineticText>
{activeCategoryItem {resolveLocalised(activeCategoryItem.category?.name, locale)}
? resolveLocalised(activeCategoryItem.category?.name, locale)
: resolveLocalised(title, locale) || 'AI Photo & Vision Tools Studio'}
</KineticText> </KineticText>
</h1> </h1>
<span className="text-xs font-semibold text-accent bg-accent/10 px-2.5 py-0.5 rounded-full border border-accent/20 font-body">
{/* Subtitle */} {activeCategoryItem.tools.length}{' '}
<p className="text-sm sm:text-base text-ink-2 font-body max-w-3xl leading-relaxed"> {activeCategoryItem.tools.length === 1 ? 'tool' : 'tools'}
{activeCategoryItem
? CATEGORY_THEMES[activeCategoryItem.id]?.description ||
resolveLocalised(activeCategoryItem.category?.description, locale)
: resolveLocalised(subtitle, locale) ||
'Client-side neural vision models running directly in volatile GPU memory with zero retention. Test interactive before/after sliders or export in native 4K.'}
</p>
{/* Studio Capability Badges */}
<div className="pt-2 flex flex-wrap items-center gap-2 text-xs font-body text-ink-2">
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-2 border border-rule/70">
<Zap className="w-3.5 h-3.5 text-amber-500" />
<span>Instant in-browser trial</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-2 border border-rule/70">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
<span>Ephemeral RAM purge</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-2 border border-rule/70">
<Smartphone className="w-3.5 h-3.5 text-accent" />
<span>iOS & Mac app handoff</span>
</span> </span>
</div> </div>
<p className="text-sm sm:text-base text-ink-2 font-body max-w-2xl mt-1.5 leading-relaxed">
{CATEGORY_THEMES[activeCategoryItem.id]?.description ||
resolveLocalised(activeCategoryItem.category?.description, locale)}
</p>
</div>
</div>
<button
type="button"
onClick={() => handleSelectCategory('all')}
className="self-start sm:self-center shrink-0 inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-body font-semibold text-ink bg-paper-hi border border-rule hover:border-accent hover:text-accent transition-colors shadow-2xs cursor-pointer"
>
<span>Show all {tools.length} tools</span>
<ArrowRight className="w-3.5 h-3.5 text-accent" />
</button>
</div>
) : (
/* Universal Studio Overview Header */
<div>
<h1 className="text-3xl sm:text-4xl lg:text-5xl font-display font-bold text-ink tracking-tight">
<KineticText>
{resolveLocalised(title, locale) || 'AI Photo & Vision Tools Studio'}
</KineticText>
</h1>
<p className="text-sm sm:text-base text-ink-2 font-body max-w-3xl mt-3 leading-relaxed">
{resolveLocalised(subtitle, locale) ||
'Client-side neural vision models running directly in volatile GPU memory with zero retention. Test interactive before/after sliders or export in native 4K.'}
</p>
</div>
)}
</div> </div>
{/* ================= SEARCH RESULTS ACTIVE VIEW ================= */} {/* ================= SEARCH RESULTS ACTIVE VIEW ================= */}
@@ -891,41 +910,25 @@ export function ToolGridSection({
</div> </div>
)} )}
</div> </div>
) : activeCategoryItem ? (
/* ================= SINGLE CATEGORY FOCUSED WORKSPACE ================= */
<div className="space-y-6">
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6 sm:gap-7 lg:gap-8">
{activeCategoryItem.tools.map((tool) => (
<ToolCard
key={tool.id}
tool={tool}
locale={locale}
categoryName={resolveLocalised(activeCategoryItem.category?.name, locale)}
/>
))}
</div>
</div>
) : ( ) : (
/* ================= CATEGORIZED TOOLS GALLERY ================= */ /* ================= CATEGORIZED TOOLS GALLERY ================= */
<div className="space-y-12 sm:space-y-16"> <div className="space-y-12 sm:space-y-16">
{/* Active Category Header Banner if filtered */}
{activeCategoryItem && (
<div className="studio-sheet p-6 sm:p-7 rounded-3xl bg-paper-hi border border-rule shadow-[0_4px_24px_-4px_rgba(0,0,0,0.03)] flex flex-col sm:flex-row sm:items-center justify-between gap-5">
<div className="space-y-2">
<div className="flex items-center gap-2">
<span className="w-2 h-2 rounded-full bg-accent animate-pulse" />
<span className="text-xs font-semibold text-accent font-body">
Active Studio Workspace
</span>
</div>
<h2 className="text-2xl sm:text-3xl font-display font-extrabold text-ink tracking-tight">
{resolveLocalised(activeCategoryItem.category?.name, locale)}
</h2>
<p className="text-xs sm:text-sm text-ink-2 font-body max-w-2xl leading-relaxed">
{CATEGORY_THEMES[activeCategoryItem.id]?.description ||
resolveLocalised(activeCategoryItem.category?.description, locale)}
</p>
</div>
<button
onClick={() => handleSelectCategory('all')}
className="self-start sm:self-center shrink-0 inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-body font-semibold text-ink bg-paper border border-rule hover:border-accent hover:text-accent transition-colors shadow-2xs cursor-pointer"
>
<span>Show all {tools.length} tools</span>
<ArrowRight className="w-3.5 h-3.5 text-accent" />
</button>
</div>
)}
{/* Displayed Categories */} {/* Displayed Categories */}
{displayedCategories.map((group) => { {categorizedTools.map((group) => {
const theme = CATEGORY_THEMES[group.id]; const theme = CATEGORY_THEMES[group.id];
const catName = group.category const catName = group.category
? resolveLocalised(group.category.name, locale) ? resolveLocalised(group.category.name, locale)
@@ -953,7 +956,7 @@ export function ToolGridSection({
</h3> </h3>
<span className="text-xs font-semibold text-accent bg-accent/10 px-2.5 py-0.5 rounded-full border border-accent/20 font-body"> <span className="text-xs font-semibold text-accent bg-accent/10 px-2.5 py-0.5 rounded-full border border-accent/20 font-body">
{group.tools.length}{' '} {group.tools.length}{' '}
{group.tools.length === 1 ? 'model' : 'models'} {group.tools.length === 1 ? 'tool' : 'tools'}
</span> </span>
</div> </div>
{catDesc && ( {catDesc && (
+20 -4
View File
@@ -81,17 +81,22 @@ export function CardBeforeAfterSlider({
); );
const handlePointerDown = (e: React.PointerEvent) => { const handlePointerDown = (e: React.PointerEvent) => {
if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
isDraggingRef.current = true; isDraggingRef.current = true;
isInteractedRef.current = true; isInteractedRef.current = true;
if (containerRef.current) { if (containerRef.current) {
cachedRectRef.current = containerRef.current.getBoundingClientRect(); cachedRectRef.current = containerRef.current.getBoundingClientRect();
} }
(e.target as HTMLElement).setPointerCapture(e.pointerId); try {
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
} catch {}
updatePosition(e.clientX); updatePosition(e.clientX);
}; };
const handlePointerMove = (e: React.PointerEvent) => { const handlePointerMove = (e: React.PointerEvent) => {
if (!isDraggingRef.current) return; if (!isDraggingRef.current) return;
e.stopPropagation();
if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current); if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current);
rafIdRef.current = requestAnimationFrame(() => { rafIdRef.current = requestAnimationFrame(() => {
updatePosition(e.clientX); updatePosition(e.clientX);
@@ -99,15 +104,25 @@ export function CardBeforeAfterSlider({
}; };
const handlePointerUp = (e: React.PointerEvent) => { const handlePointerUp = (e: React.PointerEvent) => {
if (!isDraggingRef.current) return;
e.stopPropagation();
isDraggingRef.current = false; isDraggingRef.current = false;
cachedRectRef.current = null; cachedRectRef.current = null;
try { try {
(e.target as HTMLElement).releasePointerCapture(e.pointerId); (e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
} catch { } catch {
// Ignore if pointer capture already released // Ignore if pointer capture already released
} }
}; };
// On desktop with mouse, clicking anywhere on the card moves the slider.
// On phones / touch screens, touching the card does NOT move the slider,
// allowing completely unobstructed vertical page scrolling!
const handleContainerPointerDown = (e: React.PointerEvent) => {
if (e.pointerType !== 'mouse' || e.button !== 0) return;
handlePointerDown(e);
};
const handleMouseEnter = () => { const handleMouseEnter = () => {
isHoveredRef.current = true; isHoveredRef.current = true;
setIsHoveredState(true); setIsHoveredState(true);
@@ -128,9 +143,10 @@ export function CardBeforeAfterSlider({
return ( return (
<div <div
ref={containerRef} ref={containerRef}
onPointerDown={handleContainerPointerDown}
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
className={`relative w-full ${aspectRatio} select-none overflow-hidden rounded-card bg-paper-2 cursor-ew-resize group/slider`} className={`relative w-full ${aspectRatio} select-none overflow-hidden rounded-card bg-paper-2 cursor-ew-resize group/slider touch-pan-y`}
style={{ touchAction: 'pan-y', ['--split' as any]: '50%' }} style={{ touchAction: 'pan-y', ['--split' as any]: '50%' }}
role="region" role="region"
aria-label={`${title} comparison slider`} aria-label={`${title} comparison slider`}
@@ -174,7 +190,7 @@ export function CardBeforeAfterSlider({
aria-valuenow={50} aria-valuenow={50}
tabIndex={0} tabIndex={0}
style={{ touchAction: 'none' }} style={{ touchAction: 'none' }}
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink border border-rule flex items-center justify-center pointer-events-auto cursor-ew-resize touch-none shadow-sm" className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink border border-rule flex items-center justify-center pointer-events-auto cursor-ew-resize touch-none shadow-sm before:absolute before:-inset-3 before:content-['']"
> >
<svg className="w-3.5 h-3.5 text-accent pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"> <svg className="w-3.5 h-3.5 text-accent pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 9l-3 3 3 3m8-6l3 3-3 3" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 9l-3 3 3 3m8-6l3 3-3 3" />
+32
View File
@@ -5,6 +5,7 @@ import { Cinematic3DComparison } from '@/components/ui/Cinematic3DComparison';
import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider'; import { CardBeforeAfterSlider } from '@/components/ui/CardBeforeAfterSlider';
import { ShiftableToolsGridSection } from '@/components/sections/ShiftableToolsGridSection'; import { ShiftableToolsGridSection } from '@/components/sections/ShiftableToolsGridSection';
import { TrendyBentoSection } from '@/components/sections/TrendyBentoSection'; import { TrendyBentoSection } from '@/components/sections/TrendyBentoSection';
import { ToolGridSection } from '@/components/sections/ToolGridSection';
describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () => { describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () => {
it('Cinematic3DComparison arrow handle has touch-none, role="slider", and touchAction: none', () => { it('Cinematic3DComparison arrow handle has touch-none, role="slider", and touchAction: none', () => {
@@ -62,4 +63,35 @@ describe('Before/After Comparison Sliders (Mobile & Touch Responsiveness)', () =
expect(html).toContain('href="/tools/old-photo-restorer"'); expect(html).toContain('href="/tools/old-photo-restorer"');
expect(html).toContain('href="/tools/cartoon-avatar"'); expect(html).toContain('href="/tools/cartoon-avatar"');
}); });
it('ToolGridSection comparison cards allow smooth mobile scrolling (touch-action: pan-y) and drag only on handle button (touch-action: none)', () => {
const html = renderToString(
<ToolGridSection
tools={[
{
id: 'blemish-remover',
slug: 'blemish-remover',
name: { en: 'Blemish Remover' },
summary: { en: 'Smooth blemishes' },
category: 'portrait-retouch',
content: {
examples: [
{
before: '/before.jpg',
after: '/after.jpg',
},
],
},
} as any,
]}
/>
);
expect(html).toContain('role="slider"');
expect(html).toContain('aria-label="Before and after transformation slider"');
expect(html).toContain('touch-none');
expect(html).toContain('touch-action:none');
expect(html).toContain('touch-action:pan-y');
expect(html).toContain('touch-pan-y');
});
}); });