fix(tools): top category slider self-sliding sync, topbar blur removal, web grid filling & mobile section horizontal scroller
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useState, useMemo, useRef } from 'react';
|
import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import {
|
import {
|
||||||
Search,
|
Search,
|
||||||
@@ -298,6 +298,8 @@ export function ToolGridSection({
|
|||||||
const [selectedCategory, setSelectedCategory] = useState<string>('all');
|
const [selectedCategory, setSelectedCategory] = useState<string>('all');
|
||||||
const [searchQuery, setSearchQuery] = useState<string>('');
|
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||||
const railRef = useRef<HTMLDivElement>(null);
|
const railRef = useRef<HTMLDivElement>(null);
|
||||||
|
const buttonRefs = useRef<Record<string, HTMLButtonElement | null>>({});
|
||||||
|
const isClickScrollingRef = useRef(false);
|
||||||
|
|
||||||
// Group all tools by category
|
// Group all tools by category
|
||||||
const categorizedTools = useMemo(() => {
|
const categorizedTools = useMemo(() => {
|
||||||
@@ -335,15 +337,22 @@ export function ToolGridSection({
|
|||||||
});
|
});
|
||||||
}, [tools, searchQuery, locale]);
|
}, [tools, searchQuery, locale]);
|
||||||
|
|
||||||
// Categories to display based on selectedCategory
|
// Center a pill smoothly in the horizontal top rail
|
||||||
const displayedCategories = useMemo(() => {
|
const centerPillInRail = useCallback((catId: string) => {
|
||||||
if (selectedCategory === 'all') {
|
const pill = buttonRefs.current[catId];
|
||||||
return categorizedTools;
|
const rail = railRef.current;
|
||||||
|
if (pill && rail) {
|
||||||
|
const pillLeft = pill.offsetLeft;
|
||||||
|
const pillWidth = pill.offsetWidth;
|
||||||
|
const railWidth = rail.offsetWidth;
|
||||||
|
rail.scrollTo({
|
||||||
|
left: Math.max(0, pillLeft - railWidth / 2 + pillWidth / 2),
|
||||||
|
behavior: 'smooth',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return categorizedTools.filter((group) => group.id === selectedCategory);
|
}, []);
|
||||||
}, [categorizedTools, selectedCategory]);
|
|
||||||
|
|
||||||
// Smooth scroll rail for categories
|
// Smooth scroll rail for manual chevron arrows
|
||||||
const scrollRail = (direction: 'left' | 'right') => {
|
const scrollRail = (direction: 'left' | 'right') => {
|
||||||
if (railRef.current) {
|
if (railRef.current) {
|
||||||
railRef.current.scrollBy({
|
railRef.current.scrollBy({
|
||||||
@@ -353,24 +362,79 @@ export function ToolGridSection({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fluid category tab selection with smooth pill centering
|
// Fluid click handler: scrolls to category section on page and centers pill in rail
|
||||||
const handleCategoryClick = (
|
const handleCategoryClick = (catId: string) => {
|
||||||
catId: string,
|
|
||||||
e?: React.MouseEvent<HTMLButtonElement>
|
|
||||||
) => {
|
|
||||||
setSelectedCategory(catId);
|
setSelectedCategory(catId);
|
||||||
if (searchQuery) setSearchQuery('');
|
if (searchQuery) setSearchQuery('');
|
||||||
|
centerPillInRail(catId);
|
||||||
|
|
||||||
// Smoothly center the clicked pill in the scrolling rail
|
isClickScrollingRef.current = true;
|
||||||
if (e?.currentTarget) {
|
|
||||||
e.currentTarget.scrollIntoView({
|
if (catId === 'all') {
|
||||||
behavior: 'smooth',
|
const el = document.getElementById('tools-catalog');
|
||||||
inline: 'center',
|
if (el) {
|
||||||
block: 'nearest',
|
const y = el.getBoundingClientRect().top + window.pageYOffset - 90;
|
||||||
});
|
window.scrollTo({ top: Math.max(0, y), behavior: 'smooth' });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const el = document.getElementById(`category-${catId}`);
|
||||||
|
if (el) {
|
||||||
|
const headerOffset = 145; // Space for navbar + sticky category rail
|
||||||
|
const y = el.getBoundingClientRect().top + window.pageYOffset - headerOffset;
|
||||||
|
window.scrollTo({ top: Math.max(0, y), behavior: 'smooth' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
isClickScrollingRef.current = false;
|
||||||
|
}, 850);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Synchronized Scroll-Spy: Top slider slides itself as categories slide into view
|
||||||
|
useEffect(() => {
|
||||||
|
if (searchQuery) return;
|
||||||
|
|
||||||
|
const handleScroll = () => {
|
||||||
|
if (isClickScrollingRef.current) return;
|
||||||
|
|
||||||
|
const headerOffset = 180;
|
||||||
|
const categoryIds = categorizedTools.map((g) => g.id);
|
||||||
|
|
||||||
|
// Check if at the top before the categories start
|
||||||
|
const catalogEl = document.getElementById('tools-catalog');
|
||||||
|
if (catalogEl) {
|
||||||
|
const catalogTop = catalogEl.getBoundingClientRect().top;
|
||||||
|
if (catalogTop > 100) {
|
||||||
|
if (selectedCategory !== 'all') {
|
||||||
|
setSelectedCategory('all');
|
||||||
|
centerPillInRail('all');
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check each category section in chronological order
|
||||||
|
let matchedCategory = 'all';
|
||||||
|
for (const catId of categoryIds) {
|
||||||
|
const el = document.getElementById(`category-${catId}`);
|
||||||
|
if (el) {
|
||||||
|
const rect = el.getBoundingClientRect();
|
||||||
|
if (rect.top <= headerOffset + 50 && rect.bottom >= 100) {
|
||||||
|
matchedCategory = catId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchedCategory !== selectedCategory) {
|
||||||
|
setSelectedCategory(matchedCategory);
|
||||||
|
centerPillInRail(matchedCategory);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||||
|
return () => window.removeEventListener('scroll', handleScroll);
|
||||||
|
}, [categorizedTools, searchQuery, selectedCategory, centerPillInRail]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section id="tools-catalog" className="py-10 sm:py-16 bg-[#FAF8F5]">
|
<section id="tools-catalog" className="py-10 sm:py-16 bg-[#FAF8F5]">
|
||||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
@@ -390,11 +454,11 @@ export function ToolGridSection({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Sticky Fluid Horizontal Scrolling Category Bar & Search */}
|
{/* Sticky Solid Category Bar & Search (Immune to topbar blur, solid bg-[#FAF8F5], z-40) */}
|
||||||
{(showCategoryFilter || showSearch) && (
|
{(showCategoryFilter || showSearch) && (
|
||||||
<div className="sticky top-[64px] sm:top-[72px] z-30 mb-10 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-3 bg-[#FAF8F5]/95 backdrop-blur-md border-y border-slate-200/80 shadow-[0_4px_20px_-10px_rgba(0,0,0,0.06)]">
|
<div className="sticky top-[64px] sm:top-[72px] z-40 mb-10 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-3 bg-[#FAF8F5] border-y border-slate-200/90 shadow-sm">
|
||||||
<div className="max-w-7xl mx-auto flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3 sm:gap-4">
|
<div className="max-w-7xl mx-auto flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3 sm:gap-4">
|
||||||
{/* Category Rail with Fluid Scrolling */}
|
{/* Category Rail that slides itself smoothly */}
|
||||||
{showCategoryFilter && (
|
{showCategoryFilter && (
|
||||||
<div className="relative flex-1 flex items-center min-w-0">
|
<div className="relative flex-1 flex items-center min-w-0">
|
||||||
{/* Left Scroll Arrow */}
|
{/* Left Scroll Arrow */}
|
||||||
@@ -414,7 +478,10 @@ export function ToolGridSection({
|
|||||||
>
|
>
|
||||||
{/* All Categories Pill */}
|
{/* All Categories Pill */}
|
||||||
<button
|
<button
|
||||||
onClick={(e) => handleCategoryClick('all', e)}
|
ref={(el) => {
|
||||||
|
buttonRefs.current['all'] = el;
|
||||||
|
}}
|
||||||
|
onClick={() => handleCategoryClick('all')}
|
||||||
className={`shrink-0 flex items-center gap-2 px-4 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm cursor-pointer ${
|
className={`shrink-0 flex items-center gap-2 px-4 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm cursor-pointer ${
|
||||||
selectedCategory === 'all' && !searchQuery
|
selectedCategory === 'all' && !searchQuery
|
||||||
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30 scale-[1.02]'
|
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30 scale-[1.02]'
|
||||||
@@ -446,7 +513,10 @@ export function ToolGridSection({
|
|||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={group.id}
|
key={group.id}
|
||||||
onClick={(e) => handleCategoryClick(group.id, e)}
|
ref={(el) => {
|
||||||
|
buttonRefs.current[group.id] = el;
|
||||||
|
}}
|
||||||
|
onClick={() => handleCategoryClick(group.id)}
|
||||||
className={`shrink-0 flex items-center gap-2 px-3.5 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm cursor-pointer ${
|
className={`shrink-0 flex items-center gap-2 px-3.5 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm cursor-pointer ${
|
||||||
isSelected
|
isSelected
|
||||||
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30 scale-[1.02]'
|
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30 scale-[1.02]'
|
||||||
@@ -507,7 +577,7 @@ export function ToolGridSection({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Content: Categorized Sections or Search Results */}
|
{/* Content: Search Results or Categorized Sections */}
|
||||||
{searchResults ? (
|
{searchResults ? (
|
||||||
/* Search Results View */
|
/* Search Results View */
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
@@ -526,11 +596,26 @@ export function ToolGridSection({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{searchResults.length > 0 ? (
|
{searchResults.length > 0 ? (
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6 sm:gap-7">
|
<>
|
||||||
{searchResults.map((tool) => (
|
{/* Mobile Scroller */}
|
||||||
<ToolCard key={tool.id} tool={tool} locale={locale} />
|
<div className="sm:hidden -mx-4 px-4 overflow-x-auto no-scrollbar scroll-smooth snap-x snap-mandatory flex gap-4 pb-4 pt-1 touch-pan-x">
|
||||||
))}
|
{searchResults.map((tool) => (
|
||||||
</div>
|
<div
|
||||||
|
key={tool.id}
|
||||||
|
className="w-[84vw] max-w-[320px] shrink-0 snap-start"
|
||||||
|
>
|
||||||
|
<ToolCard tool={tool} locale={locale} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Web Grid View: Keeps filling naturally */}
|
||||||
|
<div className="hidden sm:grid sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6 sm:gap-7">
|
||||||
|
{searchResults.map((tool) => (
|
||||||
|
<ToolCard key={tool.id} tool={tool} locale={locale} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-center py-16 text-slate-500 space-y-3 font-mono">
|
<div className="text-center py-16 text-slate-500 space-y-3 font-mono">
|
||||||
<p className="font-bold text-slate-800 text-base">
|
<p className="font-bold text-slate-800 text-base">
|
||||||
@@ -550,24 +635,11 @@ export function ToolGridSection({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
/* Categorized Tools Sections (Fluid, All 12 Tools Included) */
|
/* Categorized Sections:
|
||||||
|
- On phones (< sm): Each section has a smooth horizontal scroller
|
||||||
|
- On web (>= sm): Grid that keeps filling naturally as tools are added */
|
||||||
<div className="space-y-12 sm:space-y-16">
|
<div className="space-y-12 sm:space-y-16">
|
||||||
{/* Quick reset button if filtered to single category */}
|
{categorizedTools.map((group) => {
|
||||||
{selectedCategory !== 'all' && (
|
|
||||||
<div className="flex items-center justify-between pb-2">
|
|
||||||
<button
|
|
||||||
onClick={() => setSelectedCategory('all')}
|
|
||||||
className="inline-flex items-center gap-1.5 text-xs font-mono font-bold text-blue-600 hover:text-blue-700 bg-blue-50 border border-blue-200 px-3 py-1.5 rounded-full transition-colors cursor-pointer shadow-sm"
|
|
||||||
>
|
|
||||||
<span>← Show All {tools.length} Tools</span>
|
|
||||||
</button>
|
|
||||||
<span className="text-xs text-slate-400 font-mono">
|
|
||||||
Filtered Category
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{displayedCategories.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)
|
||||||
@@ -580,19 +652,19 @@ export function ToolGridSection({
|
|||||||
<div
|
<div
|
||||||
key={group.id}
|
key={group.id}
|
||||||
id={`category-${group.id}`}
|
id={`category-${group.id}`}
|
||||||
className="space-y-6"
|
className="scroll-mt-36 space-y-5 sm:space-y-6"
|
||||||
>
|
>
|
||||||
{/* Category Header */}
|
{/* Category Header */}
|
||||||
<div className="flex flex-col sm:flex-row sm:items-end justify-between gap-3 pb-4 border-b border-slate-200/90">
|
<div className="flex flex-col sm:flex-row sm:items-end justify-between gap-3 pb-3 sm:pb-4 border-b border-slate-200/90">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<div
|
<div
|
||||||
className={`w-11 h-11 rounded-2xl flex items-center justify-center bg-white shadow-sm border border-slate-200/80 shrink-0`}
|
className={`w-10 h-10 sm:w-11 sm:h-11 rounded-2xl flex items-center justify-center bg-white shadow-sm border border-slate-200/80 shrink-0`}
|
||||||
>
|
>
|
||||||
{theme?.icon || <Wand2 className="w-5 h-5 text-blue-600" />}
|
{theme?.icon || <Wand2 className="w-5 h-5 text-blue-600" />}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center gap-2.5">
|
<div className="flex items-center gap-2.5">
|
||||||
<h3 className="text-xl sm:text-2xl font-display font-black text-slate-900 tracking-tight">
|
<h3 className="text-lg sm:text-2xl font-display font-black text-slate-900 tracking-tight">
|
||||||
{catName}
|
{catName}
|
||||||
</h3>
|
</h3>
|
||||||
<span
|
<span
|
||||||
@@ -614,8 +686,29 @@ export function ToolGridSection({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Category Tools Grid with Image-Dominant Cards */}
|
{/* 1. Phone View (< sm): Horizontal Scroller for this particular section */}
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6 sm:gap-7">
|
<div className="sm:hidden relative">
|
||||||
|
<div className="-mx-4 px-4 overflow-x-auto no-scrollbar scroll-smooth snap-x snap-mandatory flex gap-4 pb-4 pt-1 touch-pan-x">
|
||||||
|
{group.tools.map((tool) => (
|
||||||
|
<div
|
||||||
|
key={tool.id}
|
||||||
|
className="w-[84vw] max-w-[320px] shrink-0 snap-start"
|
||||||
|
>
|
||||||
|
<ToolCard tool={tool} locale={locale} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{/* Swipe hint */}
|
||||||
|
{group.tools.length > 1 && (
|
||||||
|
<div className="flex items-center justify-between text-[11px] font-mono text-slate-600 px-1 mt-1">
|
||||||
|
<span>Swipe to see all {group.tools.length} tools</span>
|
||||||
|
<span className="font-bold">→</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 2. Web View (>= sm): Grid that keeps filling naturally as tools are added */}
|
||||||
|
<div className="hidden sm:grid sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6 sm:gap-7">
|
||||||
{group.tools.map((tool) => (
|
{group.tools.map((tool) => (
|
||||||
<ToolCard key={tool.id} tool={tool} locale={locale} />
|
<ToolCard key={tool.id} tool={tool} locale={locale} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -79,16 +79,16 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
|||||||
>
|
>
|
||||||
{/* 1. Ultra-Smooth High-Performance Gradient Blur Canopy (Active only when menu is closed) */}
|
{/* 1. Ultra-Smooth High-Performance Gradient Blur Canopy (Active only when menu is closed) */}
|
||||||
{!mobileMenuOpen && (
|
{!mobileMenuOpen && (
|
||||||
<div className="absolute top-0 inset-x-0 h-28 sm:h-32 pointer-events-none overflow-hidden select-none">
|
<div className="absolute top-0 inset-x-0 h-16 sm:h-18 pointer-events-none overflow-hidden select-none">
|
||||||
<div
|
<div
|
||||||
className="absolute inset-0 backdrop-blur-md"
|
className="absolute inset-0 backdrop-blur-md"
|
||||||
style={{
|
style={{
|
||||||
maskImage: 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 45%, rgba(0,0,0,0) 100%)',
|
maskImage: 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 70%, rgba(0,0,0,0) 100%)',
|
||||||
WebkitMaskImage: 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 45%, rgba(0,0,0,0) 100%)',
|
WebkitMaskImage: 'linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 70%, rgba(0,0,0,0) 100%)',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className="absolute inset-0 bg-gradient-to-b from-[#FAF8F5] via-[#FAF8F5]/85 to-transparent pointer-events-none"
|
className="absolute inset-0 bg-gradient-to-b from-[#FAF8F5] via-[#FAF8F5]/90 to-transparent pointer-events-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user