blob: d1bf229e5ee383db3949cc470534746c810f60e8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
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 (
<div>
{/* Autocomplete component for searching */}
{JSON.stringify({ 1: searchTerm, filteredIcons: filteredIcons })}
<Input
onChange={(event, newValue) => {
setSearchTerm(newValue)
}}
/>
{/* Grid to display icons */}
<Grid container spacing={2}>
{filteredIcons.map(iconName => {
const IconComponent = allIcons[iconName]
if (IconComponent) {
// Add this check to prevent errors
return (
<Grid item key={iconName} xs={3} sm={2} md={1}>
<SvgIcon
component={IconComponent}
onClick={() => handleIconClick(iconName)}
style={{ cursor: 'pointer' }}
/>
</Grid>
)
}
return null // Return null for non-icon exports
})}
</Grid>
</div>
)
}
export default MuiIconPicker
|