import React, { useState } from 'react'; import { useCombobox } from 'downshift'; import { List, ListItem, ListItemPrefix, Card, Typography, } from '@material-tailwind/react'; import SearchBar from '../SearchBar'; import { ProjectDetails } from '../../types/project'; import projectsData from '../../assets/projects.json'; interface ProjectsSearchProps { onChange?: (data: ProjectDetails) => void; } const ProjectSearch = ({ onChange }: ProjectsSearchProps) => { const [items, setItems] = useState([]); const [selectedItem, setSelectedItem] = useState(null); const { isOpen, getMenuProps, getInputProps, getItemProps, highlightedIndex, } = useCombobox({ onInputValueChange({ inputValue }) { setItems( inputValue ? projectsData.filter((project) => project.title.toLowerCase().includes(inputValue.toLowerCase()), ) : [], ); }, items, itemToString(item) { return item ? item.title : ''; }, selectedItem, onSelectedItemChange: ({ selectedItem: newSelectedItem }) => { if (newSelectedItem) { setSelectedItem(newSelectedItem); if (onChange) { onChange(newSelectedItem); } } }, }); return (
Suggestions
{items.map((item, index) => ( ^
{item.title} {item.organization}
))}
); }; export default ProjectSearch;