import * as React from "react"; import { GoCircleSlash } from "react-icons/go"; import { Button, wrapFieldsWithMeta } from "tinacms"; import { Popover, Transition } from "@headlessui/react"; import { Icon, IconOptions } from "../../components/util/icon"; import { BiChevronRight } from "react-icons/bi"; const parseIconName = (name: string) => { const splitName = name.split(/(?=[A-Z])/); if (splitName.length > 1) { return splitName.slice(1).join(" "); } return name; }; export const IconPickerInput = wrapFieldsWithMeta(({ input }) => { const [filter, setFilter] = React.useState(""); const filteredBlocks = React.useMemo(() => { return Object.keys(IconOptions).filter((name) => { return name.toLowerCase().includes(filter.toLowerCase()); }); }, [filter]); const inputLabel = Object.keys(IconOptions).includes(input.value) ? parseIconName(input.value) : "Select Icon"; const InputIcon = IconOptions[input.value] ? IconOptions[input.value] : null; return (
{ ({ open }) => ( <>
{ ({ close }) => (
{ event.stopPropagation(); event.preventDefault(); } } value={ filter } onChange={ (event: any) => { setFilter(event.target.value); } } placeholder="Filter..." />
{ filteredBlocks.length === 0 && ( No matches found ) } { filteredBlocks.length > 0 && (
{ filteredBlocks.map((name) => { return ( ); }) }
) }
) }
) }
); });