import React, { useMemo } from "react"; import styled from "styled-components"; import { Flex, Loader, Typography } from "@strapi/design-system"; // @ts-expect-error import { IconsManifest } from "react-icons"; import useIconSet from "../hooks/useIconSet"; import IconButton from "./IconButton"; type IconCollectionProps = { id: string; value: string; filter: string; withTitle?: boolean; onChange: (newVal: string) => void; }; type IconManifest = { id: string; name: string; }; export default function IconCollection({ id, value, filter, withTitle, onChange, }: IconCollectionProps) { const name = (IconsManifest as IconManifest[]).find((manifest) => manifest.id === id) ?.name ?? "Unknown"; const { loading, iconSet } = useIconSet(id); const filteredIconSet = useMemo( () => iconSet.filter(([key]) => key.toLowerCase().includes(filter)), [filter, iconSet] ); return ( {withTitle && ( {name} ({filteredIconSet.length}/{iconSet.length}) )} {loading ? ( ) : ( filteredIconSet.map(([icon, Icon]) => ( } size="L" variant={value === icon ? "secondary" : "tertiary"} onClick={() => onChange(icon)} /> )) )} ); }