diff --git a/src/components/search.tsx b/src/components/search.tsx new file mode 100644 index 0000000..4de71b9 --- /dev/null +++ b/src/components/search.tsx @@ -0,0 +1,63 @@ +import { useState } from "react"; +import { Flex, Input, Text, Image } from "@chakra-ui/react"; +import useSWR from "swr"; +import useDebounce from "@/hooks/useDebounce"; +import { SVGCardProps } from "@/interfaces/components"; +import CustomLink from "@/common/link"; +import Error from "@/components/error"; +import { getSvgByQuery } from "@/services"; +import CustomIconBtn from "@/common/iconBtn"; +import { Trash } from "phosphor-react"; + +const Search = () => { + const [search, setSearch] = useState(""); + const debouncedSearch = useDebounce(search, 500); + const { data, error } = useSWR(`${getSvgByQuery}${debouncedSearch}`); + + if (error) { + ; + } + + const handleClear = () => { + setSearch(""); + }; + + return ( + <> + setSearch(e.target.value)} + /> + {data && data.length > 0 && ( + + {data.map((item: SVGCardProps) => ( + + + {item.title} + {item.title} + + + ))} + } + onClick={handleClear} + /> + + )} + + ); +}; + +export default Search; diff --git a/src/layout/header/index.tsx b/src/layout/header/index.tsx index 855bfac..a5f34c2 100644 --- a/src/layout/header/index.tsx +++ b/src/layout/header/index.tsx @@ -7,20 +7,23 @@ import { Button, Container, Heading, - Center, Icon, - Input, + useDisclosure, + Collapse, } from "@chakra-ui/react"; -import { ArrowSquareOut, Sticker } from "phosphor-react"; +import { ArrowSquareOut, MagnifyingGlass, Sticker, X } from "phosphor-react"; import Theme from "./theme"; import Tap from "@/animations/tap"; import Mobile from "./mobile"; import { Links } from "./links"; import CustomLink from "@/common/link"; import Categories from "./categories"; +import Search from "@/components/search"; +import CustomIconBtn from "@/common/iconBtn"; const Header = () => { const bg = useColorModeValue("bg.light", "bg.dark"); + const { isOpen, onToggle } = useDisclosure(); return ( <> { borderBottomWidth="1px" w="full" py={6} + zIndex={1} shadow="sm" > @@ -54,7 +58,7 @@ const Header = () => { href={link.slug} external={link.external} > - ))} + : } + onClick={onToggle} + /> @@ -69,6 +78,11 @@ const Header = () => { + + + + +