-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add user dropdown seed-able list (#2308)
* add user dropdown seedable list * minor cleanup * fix build issue * minor type update * remove log * quick update to divider logic (squash) * tiny icon updates
- Loading branch information
Showing
7 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import { IconBaseProps, IconType } from "react-icons"; | ||
import { FaQuestion } from "react-icons/fa"; | ||
|
||
interface DynamicIconProps extends IconBaseProps { | ||
name: string; | ||
} | ||
|
||
// Renders a FontAwesome icon dynamically based on the provided name | ||
const DynamicFaIcon: React.FC<DynamicIconProps> = ({ name, ...props }) => { | ||
const IconComponent = getPreloadedIcon(name); | ||
return IconComponent ? ( | ||
<IconComponent className="h-4 w-4" {...props} /> | ||
) : ( | ||
<FaQuestion className="h-4 w-4" {...props} /> | ||
); | ||
}; | ||
|
||
// Cache for storing preloaded icons | ||
const iconCache: Record<string, IconType> = {}; | ||
|
||
// Preloads icons asynchronously and stores them in the cache | ||
export async function preloadIcons(iconNames: string[]): Promise<void> { | ||
const promises = iconNames.map(async (name) => { | ||
try { | ||
const iconModule = await import("react-icons/fa"); | ||
const iconName = | ||
`Fa${name.charAt(0).toUpperCase() + name.slice(1)}` as keyof typeof iconModule; | ||
iconCache[name] = (iconModule[iconName] as IconType) || FaQuestion; | ||
} catch (error) { | ||
console.error(`Failed to load icon: ${name}`, error); | ||
iconCache[name] = FaQuestion; | ||
} | ||
}); | ||
|
||
await Promise.all(promises); | ||
} | ||
|
||
// Retrieves a preloaded icon from the cache | ||
export function getPreloadedIcon(name: string): IconType | undefined { | ||
return iconCache[name] || FaQuestion; | ||
} | ||
|
||
export default DynamicFaIcon; |