diff --git a/src/components/SearchWithSuggestion/index.js b/src/components/SearchWithSuggestion/index.js new file mode 100644 index 0000000..3515a66 --- /dev/null +++ b/src/components/SearchWithSuggestion/index.js @@ -0,0 +1,88 @@ +import React, { useState } from "react"; +import _ from "lodash"; + +const langDetector = (lang, option1, option2) => { + return lang === "fa" ? option1 : option2; +}; + +export default function PopularSearch(props) { + const [value, setValue] = useState(""); + const [popularsToggle, setPopularsToggle] = useState(false); + const { lang, theme, populars } = props; + + const onChange = (val) => { + setValue(val); + }; + + return ( +
+ onChange(e.target.value)} + value={value} + placeholder={langDetector( + lang, + "نام کالا را جستجو کنید", + "search product name" + )} + onFocus={() => setPopularsToggle(true)} + onBlur={() => + setTimeout(() => { + setPopularsToggle(false); + }, 250) + } + /> + {langDetector(lang, +
+ + {langDetector(lang, "جستجوهای پرطرفدار", "Popular search")} + + +
+
+ ); +} + +PopularSearch.defaultProps = { + lang: "fa", + theme: "light", + populars: ["علی", "علیرضا", "محمد", "محمدرضا"], + searchIcon: "images/SearchWithSuggestionsearch.png", +};