import React, { useEffect, useState } from "react"; import { useIntl, MessageDescriptor } from "react-intl"; import { Field, FieldLabel, FieldHint, FieldError, Loader, ModalLayout, ModalHeader, ModalBody, Searchbar, SearchForm, Stack, } from "@strapi/design-system"; import IconCollection from "./IconCollection"; import IconButton from "./IconButton"; import { useApi } from "../hooks/useApi"; import { useIcon } from "../hooks/useIcon"; import pluginId from '../../pluginId.json' type InputProps = { name: string; value: string; error: string; description?: MessageDescriptor; intlLabel: MessageDescriptor; placeholder?: string; required: boolean; onChange: (payload: { target: { name: string; type: "string"; value: string }; }) => void; }; export default function Input({ name, value, error, description, intlLabel, required, onChange, }: InputProps) { const { formatMessage } = useIntl(); const [modal, setModal] = useState(false); const [filter, setFilter] = useState(""); const config = useApi(`/${pluginId}`); const SelectedIcon = useIcon(value); const iconSets: string[] = config.data?.pack ?? ["lu"]; function handleChange(value) { onChange({ target: { type: "string", name, value } }); setModal(false); } return ( <> {formatMessage(intlLabel)} } onClick={() => setModal(true)} /> {modal && ( setModal(false)}> setFilter("")} value={filter} onChange={(e: React.ChangeEvent) => setFilter(e.target.value) } /> {config.loading ? ( ) : ( iconSets.map((id) => ( 1} onChange={handleChange} /> )) )} )} ); }