diff --git a/src/components/DiffIntro/DiffIntro.tsx b/src/components/DiffIntro/DiffIntro.tsx index 7acd4eda..3ed5053e 100644 --- a/src/components/DiffIntro/DiffIntro.tsx +++ b/src/components/DiffIntro/DiffIntro.tsx @@ -80,6 +80,7 @@ const DiffIntro = forwardRef( @@ -92,6 +93,7 @@ const DiffIntro = forwardRef( } right={ diff --git a/src/components/DiffIntro/SpecBox.tsx b/src/components/DiffIntro/SpecBox.tsx index 09d8b0ce..e7e3407e 100644 --- a/src/components/DiffIntro/SpecBox.tsx +++ b/src/components/DiffIntro/SpecBox.tsx @@ -1,25 +1,116 @@ -import { Box, BoxProps, Code, forwardRef, Text } from "@chakra-ui/react"; +import { + Box, + BoxProps, + Code, + forwardRef, + Spinner, + Text, +} from "@chakra-ui/react"; +import { useState } from "react"; +import { + useNpmCombobox, + UseNpmComboboxProps, +} from "^/lib/npm-combobox/useNpmCombobox"; +import { + ComboboxBox, + ComboboxInput, + ComboboxSuggestion, + ComboboxSuggestionList, + ComboboxWrapper, +} from "../Landing/MainForm/SpecInput/Combobox"; +import Suggestion from "../Landing/MainForm/SpecInput/Suggestion"; import ServiceLinks from "./ServiceLinks"; -interface SpecBoxProps extends BoxProps { - packageName: string; - packageVersion: string; -} +const SuggestionListText = ({ + children, + error = false, +}: { + children: string; + error?: boolean; +}) => ( + + {children} + +); + +type SpecBoxProps = BoxProps & + Pick & { + packageName: string; + packageVersion: string; + }; const SpecBox = forwardRef( - ({ packageName, packageVersion, ...props }, ref) => ( - - - {packageName}@{packageVersion} - - - + ({ packageName, packageVersion, id, ...props }, ref) => { + const [inputValue, onInputValueChange] = useState( + `${packageName}@${packageVersion}`, + ); + + const { + getInputProps, + getItemProps, + getMenuProps, + highlightedIndex, + isOpen, + items, + loading, + error, + } = useNpmCombobox({ + id, + fallback: [], + inputValue, + onInputValueChange, + }); + + return ( + + + + + + + {isOpen ? ( + <> + {error ? ( + + Something went wrong. + + ) : items.length === 0 ? ( + + No suggestions + + ) : ( + items.map((item, index) => ( + + + + )) + )} + {loading ? ( + + ) : null} + + ) : null} + + + + + - - ), + ); + }, ); export default SpecBox;