"use client"; import React, { useState } from "react"; import { useField } from "@payloadcms/ui"; import * as LucideIcons from "lucide-react"; const COMMON_ICONS = [ "Check", "X", "AlertTriangle", "Info", "ArrowRight", "ArrowUpRight", "ChevronRight", "Settings", "Tool", "Terminal", "Code", "Database", "Server", "Cpu", "Zap", "Shield", "Lock", "Key", "Eye", "Search", "Filter", "BarChart", "LineChart", "PieChart", "TrendingUp", "TrendingDown", "Users", "User", "Briefcase", "Building", "Globe", "Mail", "FileText", "File", "Folder", "Image", "Video", "MessageSquare", "Clock", "Calendar", "CheckCircle", "XCircle", "Play", "Pause", "Activity", "Box", "Layers", "Layout", "Monitor", "Smartphone", "Tablet", "Wifi", "Cloud", "Crosshair", "Target", "Trophy", "Star", "Heart", ]; export default function IconSelectorField({ path }: { path: string }) { const { value, setValue } = useField({ path }); const [searchTerm, setSearchTerm] = useState(""); const filteredIcons = COMMON_ICONS.filter((name) => name.toLowerCase().includes(searchTerm.toLowerCase()), ); const handleIconClick = (iconName: string) => { // Toggle off if clicking the current value if (value === iconName) { setValue(null); } else { setValue(iconName); } }; return (
setSearchTerm(e.target.value)} style={{ padding: "8px 12px", border: "1px solid var(--theme-elevation-200)", borderRadius: "4px", background: "var(--theme-elevation-50)", color: "var(--theme-text)", fontSize: "0.875rem", width: "100%", marginBottom: "12px", boxSizing: "border-box", }} />
{filteredIcons.map((iconName) => { const Icon = (LucideIcons as any)[iconName]; if (!Icon) return null; const isSelected = value === iconName; return ( ); })}
{filteredIcons.length === 0 && (
No matching icons found.
)}
); }