Sootzani-Inspector/components/Search.tsx

133 lines
4.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";
import { useMediaQuery } from "react-responsive";
export default function Search({
mode,
value,
action,
changeValue,
}: {
mode: string;
value: any;
action: (any: any) => any;
changeValue: (any: any) => any;
}) {
// useEffect(() => {
// const isMobile = useMediaQuery({ query: "(max-width: 768px)" });
// }, []);
return (
<div>
{mode === "controller" || mode === "admin" ? (
<div className="relative flex items-center bg-gray-300 rounded-xl">
<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-14 max-lg:min-w-[95vw]"}
${
mode === "admin" &&
"w-full min-w-full bg-white lg:min-w-full h-11"
}
`}
value={value}
onChange={(e) => changeValue(e.target.value)}
placeholder="جستجو..."
required
/>
{/* <Button
className="absolute left-0 w-auto h-auto bg-transparent text-slate-800"
>
<CiSearch />
</Button> */}
<button onClick={action} className="absolute left-3">
<CiSearch />
</button>
</div>
) : (
<>
<div className="relative flex items-center bg-gray-300 max-md:hidden rounded-xl">
<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-3">
<CiSearch />
</button>
</div>
<div className="md:hidden">
<AlertDialog>
<AlertDialogTrigger asChild>
<button
// variant="outline"
// type="submit"
className="p-1 font-bold text-white rounded-md bg-gradient2"
>
<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="h-auto p-0 border-0">
<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 text-black left-16">
<CiSearch />
</button>
</AlertDialogDescription>
</AlertDialogHeader>
</AlertDialogContent>
</AlertDialog>
</div>
</>
)}
</div>
);
}