Skip to content

Commit

Permalink
Add filter scrollbar styles and filters component
Browse files Browse the repository at this point in the history
  • Loading branch information
maxontech committed Mar 17, 2024
1 parent 4ae5c1c commit a359be7
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 25 deletions.
28 changes: 28 additions & 0 deletions next-site/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@ body {
}
}

.filter-scrollbar {
cursor: ew-resize;
}

.filter-scrollbar::-webkit-scrollbar {
width: 0; /* For vertical scrollbars */
height: 0; /* For horizontal scrollbars */
}

.filter-scrollbar::-webkit-scrollbar-track,
.filter-scrollbar::-webkit-scrollbar-thumb,
.filter-scrollbar::-webkit-scrollbar-thumb:hover {
background: transparent;
}

.card-scrollbar::-webkit-scrollbar {
width: 6px;
}

.card-scrollbar::-webkit-scrollbar-thumb {
background: rgba(var(--foreground-rgb), 0.3);
border-radius: 20px;
border: 0px solid rgba(var(--foreground-rgb), 0);
background-clip: padding-box;
width: 5px;
}



33 changes: 9 additions & 24 deletions next-site/src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import Card from '@/components/card';
import Banner from '@/components/banner';
import Navbar from '@/components/navbar';
import Hero from '@/components/hero';
import Filters from '@/components/filters';

export default function Home() {
const [data, setData] = useState([]);
const [selectedTags, setSelectedTags] = useState([]);

const handleTagClick = (tag) => {
console.log(selectedTags);
setSelectedTags(prevTags => {
if (prevTags.includes(tag)) {
// Remove tag from selected tags
Expand Down Expand Up @@ -43,40 +45,23 @@ export default function Home() {
return (
<>
<Banner />

<Navbar />


<main className="flex min-h-screen flex-col">

<Hero />

<Filters selectedTags={selectedTags} handleTagClick={handleTagClick} resetFilters={resetFilters} />

<div className="bg-white dark:bg-gray-900 w-full z-20 top-0 start-0 border-b border-gray-200 dark:border-gray-600">
<div className="w-full max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
<div className="bg-white py-2 px-3 ">
<nav className="flex flex-wrap gap-4">
{['startup', 'bootstrap', 'vc'].map((tag) => (
<button
key={tag}
onClick={() => handleTagClick(tag)}
className={`inline-flex whitespace-nowrap border-b-2 border-transparent py-2 px-3 text-xs sm:text-sm font-medium transition-all duration-200 ease-in-out ${selectedTags.includes(tag) ? 'border-b-purple-600 text-purple-600' : 'text-gray-600 hover:border-b-purple-600 hover:text-purple-600'}`}
>
{tag}
</button>
))}
<button onClick={resetFilters} className="inline-flex whitespace-nowrap border-b-2 border-transparent py-2 px-3 text-xs sm:text-sm font-medium text-gray-600 transition-all duration-200 ease-in-out hover:border-b-purple-600 hover:text-purple-600">
Reset Filters
</button>
</nav>
</div>
</div>
</div>

<div className="items-start z-10 w-full flex-wrap gap-4 justify-center text-sm lg:flex">
{data.filter(item => selectedTags.length === 0 || selectedTags.every(tag => item.tags.includes(tag))).map((item, index) => (
{data.filter(item => selectedTags.length === 0 || selectedTags.every(tag => item.tags.includes(tag.toLowerCase()))).map((item, index) => (
<Card key={index} item={item} />
))}
</div>

</main>
</>
);
}
}

2 changes: 1 addition & 1 deletion next-site/src/components/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Card({ item }) {
return (
<div className="flex flex-col justify-center mr-1 ml-1 mt-1 mb-3">
<div className="flex flex-col items-start">
<div className='overflow-hidden rounded-xl w-[350px] h-[400px] transition-transform duration-500 ease-in-out transform lg:hover:scale-105 shadow-md'>
<div className='overflow-y-auto card-scrollbar rounded-sm w-[350px] h-[400px] transition-transform duration-500 ease-in-out transform lg:hover:scale-105 shadow-md'>
<Image
src={`https://raw.githubusercontent.com/maxontech/landing-page-design-examples/master/docs/${item.screenshotPath}`}
alt={item.title}
Expand Down
67 changes: 67 additions & 0 deletions next-site/src/components/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useEffect } from 'react';

export default function Filters({ selectedTags, handleTagClick, resetFilters }) {
useEffect(() => {
let isDown = false;
let startX;
let scrollLeft;

const slider = document.querySelector('.custom-scrollbar');

if (slider) {
slider.addEventListener('mousedown', (e) => {
isDown = true;
startX = e.pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
});

slider.addEventListener('mouseleave', () => {
isDown = false;
});

slider.addEventListener('mouseup', () => {
isDown = false;
});

slider.addEventListener('mousemove', (e) => {

if (!isDown) return;
e.preventDefault();
const x = e.pageX - slider.offsetLeft;
const walk = (x - startX) * 3; //scroll-fast
slider.scrollLeft = scrollLeft - walk;
});

slider.addEventListener('wheel', (e) => {
e.preventDefault();
slider.scrollLeft += e.deltaY;
});
}
}, []);

return (
<div className="w-full z-20 max-w-screen-xl mx-auto m-6 rounded-md">
<div className="flex m-1">
<button onClick={resetFilters} className="whitespace-nowrap mr-4 m-2
px-3 text-xs sm:text-sm font-medium text-back transition-all duration-200 ease-in-out hover:text-red-500 bg-white rounded-md ">
❌ Reset Filters
</button>
<div className="overflow-x-scroll filter-scrollbar px-1 bg-slate-300 rounded-md p-2">
<nav className="flex gap-4 ">
{['🚀 Startup', '👢 Bootstrap', '💼 VC', '☁️ SAAS', '🌐 Web', '📈 Marketing', '🎁 Product', '🎨 Design', '💻 Tech', '💰 Finance', '🎓 Education', '🏥 Healthcare', '🌳 Nonprofit', '🛍️ Ecommerce', '🎥 Video', '📸 Photography', '🎵 Music', '🍽️ Food', '🏋️ Fitness', '🌍 Travel', '🏠 Real Estate', '👔 Corporate', '👨‍💻 Freelance'].map((tag) => (
<button
key={tag}
onClick={() => handleTagClick(tag.slice(3))}
className={`bg-white rounded-md whitespace-nowrap py-2 px-3 text-xs sm:text-sm font-medium
${selectedTags.includes(tag.slice(3)) ? 'bg-green-600 text-white' : 'text-black hover:scale-105 transition-all duration-200 ease-in-out hover:bg-slate-400 hover:text-white'}`}
>
{tag}
</button>
))}
</nav>
</div>

</div>
</div>
);
}

0 comments on commit a359be7

Please sign in to comment.