import * as allIcons from '@mui/icons-material' // Import all icons using * as import { Grid, Input, SvgIcon } from '@mui/joy' import React, { useEffect, useState } from 'react' function MuiIconPicker({ onIconSelect }) { const [searchTerm, setSearchTerm] = useState('') const [filteredIcons, setFilteredIcons] = useState([]) const outlined = Object.keys(allIcons).filter(name => name.includes('Outlined'), ) useEffect(() => { // Filter icons based on the search term setFilteredIcons( outlined.filter(name => name .toLowerCase() .includes(searchTerm ? searchTerm.toLowerCase() : false), ), ) }, [searchTerm]) const handleIconClick = iconName => { onIconSelect(iconName) // Callback for selected icon } return (
{/* Autocomplete component for searching */} {JSON.stringify({ 1: searchTerm, filteredIcons: filteredIcons })} { setSearchTerm(newValue) }} /> {/* Grid to display icons */} {filteredIcons.map(iconName => { const IconComponent = allIcons[iconName] if (IconComponent) { // Add this check to prevent errors return ( handleIconClick(iconName)} style={{ cursor: 'pointer' }} /> ) } return null // Return null for non-icon exports })}
) } export default MuiIconPicker