Sootzani/components/Search.tsx

114 lines
3.6 KiB
TypeScript

"use client";
import React, { useState, useEffect } from "react";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { Button } from "./ui/button";
import { CiSearch } from "react-icons/ci";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { IoMdClose } from "react-icons/io";
export default function Search({mode}:{mode:string}) {
// resize
function getSize() {
return {
width: window.innerWidth,
};
}
const [windowSize, setWindowSize] = useState(getSize);
useEffect(() => {
function handleResize() {
setWindowSize(getSize());
}
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, [windowSize]);
return (
<div>
{window.innerWidth >= 768 || mode === 'controller' || mode === 'admin'? (
<div className=" relative flex bg-gray-300 rounded-xl items-center">
<Input
// type="search"
id="default-search"
className={`mb-0 h-8 bg-[#D6D8DE66] border-none focus-visible:none rounded-lg
block w-full min-w-[13rem] lg:min-w-[16rem] text-xs text-black
text-opacity-60 dark:text-white
${mode === 'controller' && 'h-12 max-lg:min-w-[95vw]'}
${mode === 'admin' && 'w-full min-w-full bg-white lg:min-w-full h-11'}
`}
placeholder="جستجو..."
required
/>
{/* <Button
className="absolute left-0 bg-transparent h-auto w-auto text-slate-800"
>
<CiSearch />
</Button> */}
<button className="absolute left-3">
<CiSearch />
</button>
</div>
) : (
<div className="">
<AlertDialog>
<AlertDialogTrigger asChild>
<button
// variant="outline"
// type="submit"
className=" bg-gradient2 text-white font-bold rounded-md p-1"
>
<CiSearch />
</button>
</AlertDialogTrigger>
<AlertDialogContent className=" h-1/5 min-w-[80%] max-w-fit">
<AlertDialogHeader className="w-full" >
<AlertDialogTitle className=" py-1">
<p className="text-[#464646] text-base font-bold">
فرم جستجو
</p>
<AlertDialogCancel className="p-0 border-0 h-auto">
<IoMdClose />
</AlertDialogCancel>
</AlertDialogTitle>
<AlertDialogDescription className="justify-center sm:px-14 sm:py-6">
<Input
// type="search"
id="default-search"
className="mb-0 h-12 bg-gray border-none focus-visible:none rounded-lg
block w-full min-w-[13rem] lg:min-w-[16rem] text-xs text-black text-opacity-60 dark:text-white "
placeholder="جستجو..."
required
/>
<button className="absolute left-16 text-black">
<CiSearch />
</button>
</AlertDialogDescription>
</AlertDialogHeader>
</AlertDialogContent>
</AlertDialog>
</div>
)}
</div>
);
}