From 1df49160d03a5ef0807ba741f675ecc49436ff70 Mon Sep 17 00:00:00 2001 From: pheralb Date: Sun, 26 Jun 2022 16:34:34 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=92=EF=B8=8F=20Add=20search=20component.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/search.tsx | 63 +++++++++++++++++++++++++++++++++++++ src/layout/header/index.tsx | 22 ++++++++++--- 2 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/components/search.tsx 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 = () => { + + + + +