mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-09 04:58:57 +01:00
styling
This commit is contained in:
@@ -58,7 +58,7 @@
|
||||
|
||||
--animate-marquee: marquee var(--duration) infinite linear;
|
||||
--animate-marquee-vertical: marquee-vertical var(--duration) linear infinite;
|
||||
}
|
||||
--animate-aurora: aurora 8s ease-in-out infinite alternate;
|
||||
|
||||
@keyframes accordion-down {
|
||||
from {
|
||||
@@ -68,7 +68,7 @@
|
||||
height: var(--radix-accordion-content-height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@keyframes accordion-up {
|
||||
from {
|
||||
height: var(--radix-accordion-content-height);
|
||||
@@ -77,23 +77,55 @@
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@keyframes marquee {
|
||||
from {
|
||||
transform: translateX(0);}
|
||||
to {
|
||||
transform: translateX(calc(-100% - var(--gap)));}}
|
||||
transform: translateX(calc(-100% - var(--gap)));}
|
||||
}
|
||||
|
||||
@keyframes marquee-vertical {
|
||||
from {
|
||||
transform: translateY(0);}
|
||||
to {
|
||||
transform: translateY(calc(-100% - var(--gap)));}}
|
||||
transform: translateY(calc(-100% - var(--gap)));}
|
||||
}
|
||||
|
||||
@keyframes aurora {
|
||||
0% {
|
||||
background-position: 0% 50%;
|
||||
transform: rotate(-5deg) scale(0.9);
|
||||
}
|
||||
25% {
|
||||
background-position: 50% 100%;
|
||||
transform: rotate(5deg) scale(1.1);
|
||||
}
|
||||
50% {
|
||||
background-position: 100% 50%;
|
||||
transform: rotate(-3deg) scale(0.95);
|
||||
}
|
||||
75% {
|
||||
background-position: 50% 0%;
|
||||
transform: rotate(3deg) scale(1.05);
|
||||
}
|
||||
100% {
|
||||
background-position: 0% 50%;
|
||||
transform: rotate(-5deg) scale(0.9);
|
||||
}
|
||||
}
|
||||
|
||||
--animate-shiny-text: shiny-text 8s infinite
|
||||
|
||||
;
|
||||
@keyframes shiny-text {
|
||||
0%, 90%, 100% {
|
||||
background-position: calc(-100% - var(--shiny-width)) 0;}
|
||||
30%, 60% {
|
||||
background-position: calc(100% + var(--shiny-width)) 0;}}}
|
||||
|
||||
:root {
|
||||
--radius: 0.75rem;
|
||||
--radius: 0.4rem;
|
||||
|
||||
--background: oklch(0.99 0 0);
|
||||
--foreground: oklch(0.32 0 0);
|
||||
@@ -107,14 +139,14 @@
|
||||
--secondary-foreground: oklch(0.45 0.03 256.80);
|
||||
--muted: oklch(0.98 0.00 247.84);
|
||||
--muted-foreground: oklch(0.55 0.02 264.36);
|
||||
--accent: oklch(0.74 0.09 251.62);
|
||||
--accent-foreground: oklch(0.38 0.14 265.52);
|
||||
--accent: oklch(0.967 0.001 286.375);
|
||||
--accent-foreground: oklch(0.21 0.006 285.885);
|
||||
--destructive: oklch(0.64 0.21 25.33);
|
||||
--destructive-foreground: oklch(1.00 0 0);
|
||||
--border: oklch(0.90 0.01 247.88);
|
||||
|
||||
--input: oklch(0.92 0.004 286.32);
|
||||
--ring: oklch(0.637 0.237 25.331);
|
||||
|
||||
--chart-1: oklch(0.646 0.222 41.116);
|
||||
--chart-2: oklch(0.6 0.118 184.704);
|
||||
--chart-3: oklch(0.398 0.07 227.392);
|
||||
@@ -140,13 +172,13 @@
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.26 0.03 262.67);
|
||||
--background: oklch(.141 .005 285.823);
|
||||
--foreground: oklch(0.92 0 0);
|
||||
--card: oklch(0.31 0.03 268.64);
|
||||
--card-foreground: oklch(0.92 0 0);
|
||||
--popover: oklch(0.29 0.02 268.40);
|
||||
--popover-foreground: oklch(0.92 0 0);
|
||||
--primary: oklch(0.64 0.17 36.44);
|
||||
--primary: oklch(0.67 0.20 23.80);
|
||||
--primary-foreground: oklch(1.00 0 0);
|
||||
--secondary: oklch(0.31 0.03 266.71);
|
||||
--secondary-foreground: oklch(0.92 0 0);
|
||||
|
||||
@@ -106,41 +106,6 @@ export default async function IconPage({ params }: { params: Promise<{ icon: str
|
||||
|
||||
return (
|
||||
<div className="relative isolate overflow-hidden pt-14">
|
||||
{/* Background glow effect */}
|
||||
<div className="absolute inset-x-0 -top-40 -z-10 transform-gpu overflow-hidden blur-3xl sm:-top-80" aria-hidden="true">
|
||||
<div
|
||||
className="relative left-[calc(50%-11rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 rotate-[30deg] bg-gradient-to-tr from-rose-400/50 to-red-300/50 dark:from-red-600/70 dark:to-red-900/70 opacity-50 dark:opacity-60 sm:left-[calc(50%-30rem)] sm:w-[72.1875rem]"
|
||||
style={{
|
||||
clipPath:
|
||||
"polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Secondary glow for additional effect */}
|
||||
<div
|
||||
className="absolute inset-x-0 top-[calc(100%-13rem)] -z-10 transform-gpu overflow-hidden blur-3xl sm:top-[calc(100%-30rem)]"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<div
|
||||
className="relative left-[calc(50%+3rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 bg-gradient-to-tr from-red-300/50 to-rose-500/50 dark:from-red-700/50 dark:to-red-500/50 opacity-50 dark:opacity-50 sm:left-[calc(50%+36rem)] sm:w-[72.1875rem]"
|
||||
style={{
|
||||
clipPath:
|
||||
"polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Additional central glow */}
|
||||
<div className="absolute inset-x-0 top-1/2 -z-10 transform-gpu overflow-hidden blur-3xl" aria-hidden="true">
|
||||
<div
|
||||
className="relative left-[calc(50%)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 bg-gradient-to-tr from-rose-300/50 to-red-400/50 dark:from-red-800/40 dark:to-red-600/40 opacity-50 dark:opacity-40 sm:w-[50.1875rem]"
|
||||
style={{
|
||||
clipPath:
|
||||
"polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/* Existing Icon Details */}
|
||||
<IconDetails icon={icon} iconData={originalIconData} authorData={authorData} />
|
||||
</div>
|
||||
|
||||
@@ -1,302 +1,259 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import { IconSubmissionContent } from "@/components/icon-submission-form"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { IconSubmissionContent } from "@/components/icon-submission-form";
|
||||
import { MagicCard } from "@/components/magicui/magic-card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { BASE_URL } from "@/constants"
|
||||
import { fuzzySearch } from "@/lib/utils"
|
||||
import { cn } from "@/lib/utils"
|
||||
import type { Icon, IconSearchProps, IconWithName } from "@/types/icons"
|
||||
import { motion } from "framer-motion"
|
||||
import { useInView } from "framer-motion"
|
||||
import { ArrowDownAZ, ArrowUpZA, Calendar, Filter, Search, SortAsc, X } from "lucide-react"
|
||||
import { useTheme } from "next-themes"
|
||||
import Image from "next/image"
|
||||
import Link from "next/link"
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { BASE_URL } from "@/constants";
|
||||
import type { Icon, IconSearchProps } from "@/types/icons";
|
||||
import { useInView } from "framer-motion";
|
||||
import {
|
||||
ArrowDownAZ,
|
||||
ArrowUpZA,
|
||||
Calendar,
|
||||
Filter,
|
||||
Search,
|
||||
SortAsc,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { useTheme } from "next-themes";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
type SortOption = "relevance" | "alphabetical-asc" | "alphabetical-desc" | "newest"
|
||||
type SortOption =
|
||||
| "relevance"
|
||||
| "alphabetical-asc"
|
||||
| "alphabetical-desc"
|
||||
| "newest";
|
||||
|
||||
export function IconSearch({ icons }: IconSearchProps) {
|
||||
const searchParams = useSearchParams()
|
||||
const initialQuery = searchParams.get("q")
|
||||
const initialCategories = searchParams.getAll("category")
|
||||
const initialSort = (searchParams.get("sort") as SortOption) || "relevance"
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
const [searchQuery, setSearchQuery] = useState(initialQuery ?? "")
|
||||
const [selectedCategories, setSelectedCategories] = useState<string[]>(initialCategories ?? [])
|
||||
const [sortOption, setSortOption] = useState<SortOption>(initialSort)
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||
const { resolvedTheme } = useTheme()
|
||||
const searchParams = useSearchParams();
|
||||
const initialQuery = searchParams.get("q");
|
||||
const initialCategories = searchParams.getAll("category");
|
||||
const initialSort = (searchParams.get("sort") as SortOption) || "relevance";
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const [searchQuery, setSearchQuery] = useState(initialQuery ?? "");
|
||||
const [selectedCategories, setSelectedCategories] = useState<string[]>(
|
||||
initialCategories ?? [],
|
||||
);
|
||||
const [sortOption, setSortOption] = useState<SortOption>(initialSort);
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const { resolvedTheme } = useTheme();
|
||||
|
||||
// Extract all unique categories
|
||||
const allCategories = useMemo(() => {
|
||||
const categories = new Set<string>()
|
||||
const categories = new Set<string>();
|
||||
for (const icon of icons) {
|
||||
for (const category of icon.data.categories) {
|
||||
categories.add(category)
|
||||
categories.add(category);
|
||||
}
|
||||
}
|
||||
return Array.from(categories).sort()
|
||||
}, [icons])
|
||||
return Array.from(categories).sort();
|
||||
}, [icons]);
|
||||
|
||||
// Define filterIconsByQueryAndCategory BEFORE it's used in useState
|
||||
const filterIconsByQueryAndCategories = useCallback((iconList: typeof icons, query: string, categories: string[], sort: SortOption) => {
|
||||
let filtered = iconList
|
||||
|
||||
// Apply category filters (if any are selected)
|
||||
if (categories.length > 0) {
|
||||
filtered = filtered.filter(({ data }) =>
|
||||
// Check if the icon has at least one of the selected categories
|
||||
data.categories.some((cat) => categories.some((selectedCat) => cat.toLowerCase() === selectedCat.toLowerCase())),
|
||||
)
|
||||
}
|
||||
|
||||
// Create a scored version of icons for relevance and other sorting
|
||||
let scoredIcons: { icon: (typeof filtered)[0]; score: number; matchedAlias?: string }[] = []
|
||||
|
||||
// Apply search query filter and calculate scores
|
||||
if (query.trim()) {
|
||||
scoredIcons = filtered.map((icon) => {
|
||||
// Calculate scores for different fields
|
||||
const nameScore = fuzzySearch(icon.name, query) * 1.5 // Give more weight to name matches
|
||||
|
||||
// Find matching alias if any
|
||||
let matchedAlias: string | undefined = undefined
|
||||
let maxAliasScore = 0
|
||||
|
||||
// Check each alias for a match
|
||||
if (icon.data.aliases.length > 0) {
|
||||
for (const alias of icon.data.aliases) {
|
||||
const aliasScore = fuzzySearch(alias, query) * 1.4
|
||||
if (aliasScore > maxAliasScore) {
|
||||
maxAliasScore = aliasScore
|
||||
matchedAlias = alias
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get max score from categories
|
||||
const categoryScore =
|
||||
icon.data.categories.length > 0 ? Math.max(...icon.data.categories.map((category) => fuzzySearch(category, query))) : 0
|
||||
|
||||
// Use the highest score
|
||||
const score = Math.max(nameScore, maxAliasScore, categoryScore)
|
||||
|
||||
return {
|
||||
icon,
|
||||
score,
|
||||
matchedAlias: score === maxAliasScore && maxAliasScore > 0 ? matchedAlias : undefined,
|
||||
}
|
||||
})
|
||||
|
||||
// Filter icons with a minimum score
|
||||
scoredIcons = scoredIcons.filter((item) => item.score > 0.2) // Minimum threshold
|
||||
|
||||
// If we're using relevance sorting, apply it now
|
||||
if (sort === "relevance") {
|
||||
// Sort by score
|
||||
scoredIcons.sort((a, b) => b.score - a.score)
|
||||
return scoredIcons.map((item) => item.icon)
|
||||
// Simple filter function using substring matching
|
||||
const filterIcons = useCallback(
|
||||
(query: string, categories: string[], sort: SortOption) => {
|
||||
// First filter by categories if any are selected
|
||||
let filtered = icons;
|
||||
if (categories.length > 0) {
|
||||
filtered = filtered.filter(({ data }) =>
|
||||
data.categories.some((cat) =>
|
||||
categories.some(
|
||||
(selectedCat) => cat.toLowerCase() === selectedCat.toLowerCase(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Otherwise, we'll use the filtered results for other sorting methods
|
||||
filtered = scoredIcons.map((item) => item.icon)
|
||||
}
|
||||
// Then filter by search query
|
||||
if (query.trim()) {
|
||||
const q = query.toLowerCase();
|
||||
filtered = filtered.filter(({ name, data }) => {
|
||||
if (name.toLowerCase().includes(q)) return true;
|
||||
if (data.aliases.some((alias) => alias.toLowerCase().includes(q))) return true;
|
||||
if (data.categories.some((category) => category.toLowerCase().includes(q))) return true;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if not by relevance (which was already handled above)
|
||||
if (sort === "alphabetical-asc") {
|
||||
return filtered.sort((a, b) => a.name.localeCompare(b.name))
|
||||
}
|
||||
if (sort === "alphabetical-desc") {
|
||||
return filtered.sort((a, b) => b.name.localeCompare(a.name))
|
||||
}
|
||||
if (sort === "newest") {
|
||||
return filtered.sort((a, b) => {
|
||||
return new Date(b.data.update.timestamp).getTime() - new Date(a.data.update.timestamp).getTime()
|
||||
})
|
||||
}
|
||||
// Apply sorting
|
||||
if (sort === "alphabetical-asc") {
|
||||
return filtered.sort((a, b) => a.name.localeCompare(b.name));
|
||||
}
|
||||
if (sort === "alphabetical-desc") {
|
||||
return filtered.sort((a, b) => b.name.localeCompare(a.name));
|
||||
}
|
||||
if (sort === "newest") {
|
||||
return filtered.sort((a, b) => {
|
||||
return (
|
||||
new Date(b.data.update.timestamp).getTime() -
|
||||
new Date(a.data.update.timestamp).getTime()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Default alphabetical sort if no query or sort option not recognized
|
||||
return filtered.sort((a, b) => a.name.localeCompare(b.name))
|
||||
}, [])
|
||||
// Default sort (relevance or fallback to alphabetical)
|
||||
return filtered.sort((a, b) => a.name.localeCompare(b.name));
|
||||
},
|
||||
[icons],
|
||||
);
|
||||
|
||||
// Now use the function after it's been defined
|
||||
const [filteredIcons, setFilteredIcons] = useState(() => {
|
||||
return filterIconsByQueryAndCategories(icons, initialQuery ?? "", initialCategories ?? [], initialSort)
|
||||
})
|
||||
// Find matched aliases for display purposes
|
||||
const matchedAliases = useMemo(() => {
|
||||
if (!searchQuery.trim()) return {};
|
||||
|
||||
// Store matched aliases separately
|
||||
const [matchedAliases, setMatchedAliases] = useState<Record<string, string>>({})
|
||||
const q = searchQuery.toLowerCase();
|
||||
const matches: Record<string, string> = {};
|
||||
|
||||
icons.forEach(({ name, data }) => {
|
||||
// If name doesn't match but an alias does, store the first matching alias
|
||||
if (!name.toLowerCase().includes(q)) {
|
||||
const matchingAlias = data.aliases.find((alias) =>
|
||||
alias.toLowerCase().includes(q)
|
||||
);
|
||||
if (matchingAlias) {
|
||||
matches[name] = matchingAlias;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return matches;
|
||||
}, [icons, searchQuery]);
|
||||
|
||||
// Use useMemo for filtered icons
|
||||
const filteredIcons = useMemo(() => {
|
||||
return filterIcons(searchQuery, selectedCategories, sortOption);
|
||||
}, [filterIcons, searchQuery, selectedCategories, sortOption]);
|
||||
|
||||
const updateResults = useCallback(
|
||||
(query: string, categories: string[], sort: SortOption) => {
|
||||
// Clear existing matched aliases
|
||||
setMatchedAliases({})
|
||||
|
||||
// If we have a query, capture any matched aliases before filtering
|
||||
if (query.trim()) {
|
||||
const newMatches: Record<string, string> = {}
|
||||
const scoredResults = icons.map((icon) => {
|
||||
// Check for alias matches
|
||||
let bestAliasScore = 0
|
||||
let bestAlias = ""
|
||||
for (const alias of icon.data.aliases) {
|
||||
const score = fuzzySearch(alias, query) * 1.4
|
||||
if (score > bestAliasScore && score > 0.3) {
|
||||
// Only consider strong matches
|
||||
bestAliasScore = score
|
||||
bestAlias = alias
|
||||
}
|
||||
}
|
||||
|
||||
// If the name match is weaker than alias match, store the alias
|
||||
const nameScore = fuzzySearch(icon.name, query) * 1.5
|
||||
if (bestAliasScore > nameScore && bestAliasScore > 0.3) {
|
||||
newMatches[icon.name] = bestAlias
|
||||
}
|
||||
|
||||
return { icon }
|
||||
})
|
||||
|
||||
// Update the matched aliases
|
||||
setMatchedAliases(newMatches)
|
||||
}
|
||||
|
||||
// Continue with normal filtering
|
||||
setFilteredIcons(filterIconsByQueryAndCategories(icons, query, categories, sort))
|
||||
const params = new URLSearchParams()
|
||||
if (query) params.set("q", query)
|
||||
const params = new URLSearchParams();
|
||||
if (query) params.set("q", query);
|
||||
|
||||
// Clear existing category params and add new ones
|
||||
for (const category of categories) {
|
||||
params.append("category", category)
|
||||
params.append("category", category);
|
||||
}
|
||||
|
||||
// Add sort parameter if not default
|
||||
if (sort !== "relevance" || initialSort !== "relevance") {
|
||||
params.set("sort", sort)
|
||||
params.set("sort", sort);
|
||||
}
|
||||
|
||||
const newUrl = params.toString() ? `${pathname}?${params.toString()}` : pathname
|
||||
router.push(newUrl, { scroll: false })
|
||||
const newUrl = params.toString()
|
||||
? `${pathname}?${params.toString()}`
|
||||
: pathname;
|
||||
router.push(newUrl, { scroll: false });
|
||||
},
|
||||
[filterIconsByQueryAndCategories, icons, pathname, router, initialSort],
|
||||
)
|
||||
[pathname, router, initialSort],
|
||||
);
|
||||
|
||||
const handleSearch = useCallback(
|
||||
(query: string) => {
|
||||
setSearchQuery(query)
|
||||
setSearchQuery(query);
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current)
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
updateResults(query, selectedCategories, sortOption)
|
||||
}, 100)
|
||||
updateResults(query, selectedCategories, sortOption);
|
||||
}, 200); // Changed from 100ms to 200ms
|
||||
},
|
||||
[updateResults, selectedCategories, sortOption],
|
||||
)
|
||||
);
|
||||
|
||||
const handleCategoryChange = useCallback(
|
||||
(category: string) => {
|
||||
let newCategories: string[]
|
||||
let newCategories: string[];
|
||||
|
||||
if (selectedCategories.includes(category)) {
|
||||
// Remove the category if it's already selected
|
||||
newCategories = selectedCategories.filter((c) => c !== category)
|
||||
newCategories = selectedCategories.filter((c) => c !== category);
|
||||
} else {
|
||||
// Add the category if it's not selected
|
||||
newCategories = [...selectedCategories, category]
|
||||
newCategories = [...selectedCategories, category];
|
||||
}
|
||||
|
||||
setSelectedCategories(newCategories)
|
||||
updateResults(searchQuery, newCategories, sortOption)
|
||||
setSelectedCategories(newCategories);
|
||||
updateResults(searchQuery, newCategories, sortOption);
|
||||
},
|
||||
[updateResults, searchQuery, selectedCategories, sortOption],
|
||||
)
|
||||
);
|
||||
|
||||
const handleSortChange = useCallback(
|
||||
(sort: SortOption) => {
|
||||
setSortOption(sort)
|
||||
updateResults(searchQuery, selectedCategories, sort)
|
||||
setSortOption(sort);
|
||||
updateResults(searchQuery, selectedCategories, sort);
|
||||
},
|
||||
[updateResults, searchQuery, selectedCategories],
|
||||
)
|
||||
);
|
||||
|
||||
const clearFilters = useCallback(() => {
|
||||
setSearchQuery("")
|
||||
setSelectedCategories([])
|
||||
setSortOption("relevance")
|
||||
updateResults("", [], "relevance")
|
||||
}, [updateResults])
|
||||
setSearchQuery("");
|
||||
setSelectedCategories([]);
|
||||
setSortOption("relevance");
|
||||
updateResults("", [], "relevance");
|
||||
}, [updateResults]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current)
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!searchParams) return null
|
||||
if (!searchParams) return null;
|
||||
|
||||
const getSortLabel = (sort: SortOption) => {
|
||||
switch (sort) {
|
||||
case "relevance":
|
||||
return "Best match"
|
||||
return "Best match";
|
||||
case "alphabetical-asc":
|
||||
return "A to Z"
|
||||
return "A to Z";
|
||||
case "alphabetical-desc":
|
||||
return "Z to A"
|
||||
return "Z to A";
|
||||
case "newest":
|
||||
return "Newest first"
|
||||
return "Newest first";
|
||||
default:
|
||||
return "Sort"
|
||||
return "Sort";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getSortIcon = (sort: SortOption) => {
|
||||
switch (sort) {
|
||||
case "relevance":
|
||||
return <Search className="h-4 w-4" />
|
||||
return <Search className="h-4 w-4" />;
|
||||
case "alphabetical-asc":
|
||||
return <ArrowDownAZ className="h-4 w-4" />
|
||||
return <ArrowDownAZ className="h-4 w-4" />;
|
||||
case "alphabetical-desc":
|
||||
return <ArrowUpZA className="h-4 w-4" />
|
||||
return <ArrowUpZA className="h-4 w-4" />;
|
||||
case "newest":
|
||||
return <Calendar className="h-4 w-4" />
|
||||
return <Calendar className="h-4 w-4" />;
|
||||
default:
|
||||
return <SortAsc className="h-4 w-4" />
|
||||
return <SortAsc className="h-4 w-4" />;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<motion.div
|
||||
className="space-y-4 w-full"
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5 }}
|
||||
>
|
||||
<div className="space-y-4 w-full">
|
||||
{/* Search input */}
|
||||
<div className="relative w-full">
|
||||
<div className="absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground transition-all duration-300">
|
||||
@@ -305,7 +262,7 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
<Input
|
||||
type="search"
|
||||
placeholder="Search icons by name, alias, or category..."
|
||||
className="w-full h-10 pl-9 cursor-text transition-all duration-300 text-sm md:text-base bg-background/80 dark:bg-background/90 border-border shadow-sm hover:border-rose-500/50 focus-visible:ring-rose-500/20"
|
||||
className="w-full h-10 pl-9 cursor-text transition-all duration-300 text-sm md:text-base border-border shadow-sm"
|
||||
value={searchQuery}
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
/>
|
||||
@@ -319,7 +276,7 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex-1 sm:flex-none cursor-pointer bg-background/80 dark:bg-background/90 border-border shadow-sm hover:bg-rose-500/10 dark:hover:bg-rose-900/20 hover:border-rose-500"
|
||||
className="flex-1 sm:flex-none cursor-pointer border-border shadow-sm0/10 "
|
||||
>
|
||||
<Filter className="h-4 w-4 mr-2" />
|
||||
<span>Filter</span>
|
||||
@@ -331,7 +288,9 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-64 sm:w-56">
|
||||
<DropdownMenuLabel className="font-semibold">Categories</DropdownMenuLabel>
|
||||
<DropdownMenuLabel className="font-semibold">
|
||||
Categories
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<div className="max-h-[40vh] overflow-y-auto p-1">
|
||||
@@ -342,7 +301,9 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
onCheckedChange={() => handleCategoryChange(category)}
|
||||
className="cursor-pointer capitalize"
|
||||
>
|
||||
{category.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())}
|
||||
{category
|
||||
.replace(/-/g, " ")
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase())}
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</div>
|
||||
@@ -352,10 +313,10 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
setSelectedCategories([])
|
||||
updateResults(searchQuery, [], sortOption)
|
||||
setSelectedCategories([]);
|
||||
updateResults(searchQuery, [], sortOption);
|
||||
}}
|
||||
className="cursor-pointer text-rose-500 focus:text-rose-500 focus:bg-rose-50 dark:focus:bg-rose-950/20"
|
||||
className="cursor-pointer focus: focus:bg-rose-50 dark:focus:bg-rose-950/20"
|
||||
>
|
||||
Clear all filters
|
||||
</DropdownMenuItem>
|
||||
@@ -370,27 +331,44 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex-1 sm:flex-none cursor-pointer bg-background/80 dark:bg-background/90 border-border shadow-sm hover:bg-rose-500/10 dark:hover:bg-rose-900/20 hover:border-rose-500"
|
||||
className="flex-1 sm:flex-none cursor-pointer border-border shadow-sm0/10 hover:border-rose-500"
|
||||
>
|
||||
{getSortIcon(sortOption)}
|
||||
<span className="ml-2">{getSortLabel(sortOption)}</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-56">
|
||||
<DropdownMenuLabel className="font-semibold">Sort By</DropdownMenuLabel>
|
||||
<DropdownMenuLabel className="font-semibold">
|
||||
Sort By
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuRadioGroup value={sortOption} onValueChange={(value) => handleSortChange(value as SortOption)}>
|
||||
<DropdownMenuRadioItem value="relevance" className="cursor-pointer">
|
||||
<DropdownMenuRadioGroup
|
||||
value={sortOption}
|
||||
onValueChange={(value) => handleSortChange(value as SortOption)}
|
||||
>
|
||||
<DropdownMenuRadioItem
|
||||
value="relevance"
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<Search className="h-4 w-4 mr-2" />
|
||||
Best match
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="alphabetical-asc" className="cursor-pointer">
|
||||
<DropdownMenuRadioItem
|
||||
value="alphabetical-asc"
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<ArrowDownAZ className="h-4 w-4 mr-2" />A to Z
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="alphabetical-desc" className="cursor-pointer">
|
||||
<DropdownMenuRadioItem
|
||||
value="alphabetical-desc"
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<ArrowUpZA className="h-4 w-4 mr-2" />Z to A
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="newest" className="cursor-pointer">
|
||||
<DropdownMenuRadioItem
|
||||
value="newest"
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<Calendar className="h-4 w-4 mr-2" />
|
||||
Newest first
|
||||
</DropdownMenuRadioItem>
|
||||
@@ -399,12 +377,14 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Clear all button */}
|
||||
{(searchQuery || selectedCategories.length > 0 || sortOption !== "relevance") && (
|
||||
{(searchQuery ||
|
||||
selectedCategories.length > 0 ||
|
||||
sortOption !== "relevance") && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={clearFilters}
|
||||
className="flex-1 sm:flex-none cursor-pointer bg-background/80 dark:bg-background/90 hover:bg-rose-500/10 dark:hover:bg-rose-900/20 border-rose-500/20"
|
||||
className="flex-1 sm:flex-none cursor-pointer border-rose-500/20"
|
||||
>
|
||||
<X className="h-4 w-4 mr-2" />
|
||||
<span>Clear all</span>
|
||||
@@ -421,9 +401,11 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
<Badge
|
||||
key={category}
|
||||
variant="secondary"
|
||||
className="flex items-center gap-1 pl-2 pr-1 bg-rose-500/10 dark:bg-rose-900/20 text-rose-700 dark:text-rose-300 border border-rose-500/20"
|
||||
className="flex items-center gap-1 pl-2 pr-1"
|
||||
>
|
||||
{category.replace(/-/g, " ").replace(/\b\w/g, (c) => c.toUpperCase())}
|
||||
{category
|
||||
.replace(/-/g, " ")
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase())}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
@@ -440,10 +422,10 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
setSelectedCategories([])
|
||||
updateResults(searchQuery, [], sortOption)
|
||||
setSelectedCategories([]);
|
||||
updateResults(searchQuery, [], sortOption);
|
||||
}}
|
||||
className="text-xs h-7 px-2 text-rose-500 hover:text-rose-600 hover:bg-rose-500/10 cursor-pointer"
|
||||
className="text-xs h-7 px-2 0/10 cursor-pointer"
|
||||
>
|
||||
Clear all
|
||||
</Button>
|
||||
@@ -451,17 +433,14 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
)}
|
||||
|
||||
<Separator className="my-2" />
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
{filteredIcons.length === 0 ? (
|
||||
<motion.div
|
||||
className="flex flex-col gap-8 py-12 max-w-2xl mx-auto"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
transition={{ duration: 0.5, delay: 0.2 }}
|
||||
>
|
||||
<div className="flex flex-col gap-8 py-12 max-w-2xl mx-auto">
|
||||
<div className="text-center">
|
||||
<h2 className="text-3xl sm:text-5xl font-semibold">We don't have this one...yet!</h2>
|
||||
<h2 className="text-3xl sm:text-5xl font-semibold">
|
||||
We don't have this one...yet!
|
||||
</h2>
|
||||
<p className="mt-4 text-muted-foreground">
|
||||
{searchQuery && selectedCategories.length > 0
|
||||
? `No icons found matching "${searchQuery}" with the selected filters.`
|
||||
@@ -471,17 +450,15 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
? "No icons found with the selected filters."
|
||||
: "No icons found matching your criteria."}
|
||||
</p>
|
||||
<Button variant="outline" className="mt-4 cursor-pointer" onClick={clearFilters}>
|
||||
Clear all filters
|
||||
</Button>
|
||||
</div>
|
||||
<IconSubmissionContent />
|
||||
</motion.div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex justify-between items-center pb-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Found {filteredIcons.length} icon{filteredIcons.length !== 1 ? "s" : ""}.
|
||||
Found {filteredIcons.length} icon
|
||||
{filteredIcons.length !== 1 ? "s" : ""}.
|
||||
</p>
|
||||
<div className="flex items-center gap-1 text-xs text-muted-foreground">
|
||||
{getSortIcon(sortOption)}
|
||||
@@ -490,30 +467,35 @@ export function IconSearch({ icons }: IconSearchProps) {
|
||||
</div>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 gap-4 mt-2">
|
||||
{filteredIcons.map(({ name, data }) => (
|
||||
<IconCard key={name} name={name} data={data} matchedAlias={matchedAliases[name] || null} />
|
||||
<IconCard
|
||||
key={name}
|
||||
name={name}
|
||||
data={data}
|
||||
matchedAlias={matchedAliases[name] || null}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function IconCard({
|
||||
name,
|
||||
data,
|
||||
data: iconData,
|
||||
matchedAlias,
|
||||
}: {
|
||||
name: string
|
||||
data: Icon
|
||||
matchedAlias?: string | null
|
||||
name: string;
|
||||
data: Icon;
|
||||
matchedAlias?: string | null;
|
||||
}) {
|
||||
const ref = useRef(null)
|
||||
const ref = useRef(null);
|
||||
const isInView = useInView(ref, {
|
||||
once: false,
|
||||
amount: 0.2,
|
||||
margin: "100px 0px",
|
||||
})
|
||||
});
|
||||
|
||||
const variants = {
|
||||
hidden: { opacity: 0, y: 20, scale: 0.95 },
|
||||
@@ -529,40 +511,33 @@ function IconCard({
|
||||
scale: 0.98,
|
||||
transition: { duration: 0.3, ease: [0.25, 0.1, 0.25, 1.0] },
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
ref={ref}
|
||||
initial="hidden"
|
||||
animate={isInView ? "visible" : "hidden"}
|
||||
exit="exit"
|
||||
variants={variants}
|
||||
className="will-change-transform"
|
||||
>
|
||||
<MagicCard className="rounded-md shadow-md">
|
||||
<Link
|
||||
prefetch={false}
|
||||
href={`/icons/${name}`}
|
||||
className="group flex flex-col items-center p-3 sm:p-4 rounded-lg border border-border bg-background hover:border-rose-500 hover:bg-rose-500/10 dark:hover:bg-rose-900/30 dark:hover:border-rose-500 transition-all duration-300 hover:shadow-lg hover:shadow-rose-500/5 relative overflow-hidden cursor-pointer"
|
||||
className="group flex flex-col items-center p-3 sm:p-4 cursor-pointer"
|
||||
>
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-rose-500/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300" />
|
||||
|
||||
<div className="relative h-12 w-12 sm:h-16 sm:w-16 mb-2">
|
||||
<Image
|
||||
src={`${BASE_URL}/${data.base}/${name}.${data.base}`}
|
||||
src={`${BASE_URL}/${iconData.base}/${name}.${iconData.base}`}
|
||||
alt={`${name} icon`}
|
||||
fill
|
||||
className="object-contain p-1 group-hover:scale-110 transition-transform duration-300"
|
||||
/>
|
||||
</div>
|
||||
<span className="text-xs sm:text-sm text-center truncate w-full capitalize group-hover:text-rose-600 dark:group-hover:text-rose-400 transition-colors duration-200 font-medium">
|
||||
<span className="text-xs sm:text-sm text-center truncate w-full capitalize group- dark:group-hover:text-rose-400 transition-colors duration-200 font-medium">
|
||||
{name.replace(/-/g, " ")}
|
||||
</span>
|
||||
|
||||
{matchedAlias && (
|
||||
<span className="text-[10px] text-center truncate w-full text-rose-500 dark:text-rose-400 mt-1">Alias: {matchedAlias}</span>
|
||||
<span className="text-[10px] text-center truncate w-full mt-1">
|
||||
Alias: {matchedAlias}
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
</motion.div>
|
||||
)
|
||||
</MagicCard>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user