Sootzani-Inspector/components/Search.tsx

86 lines
2.3 KiB
TypeScript

"use client";
import React, { useState, useEffect, useRef } from "react";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { Button } from "./ui/button";
import { CiSearch } from "react-icons/ci";
import { X, XCircle } from "lucide-react";
export default function Search({
mode,
value,
action,
Cancel,
changeValue,
}: {
mode?: string;
value?: any;
action?: (any: any) => any;
Cancel: (any: any) => any;
changeValue?: (any: any) => any;
}) {
const inputRef = useRef<HTMLInputElement>(null);
const [cancel, setCancel] = useState<boolean>(false);
const handleSubmit = (e: any) => {
console.log(222);
e.preventDefault();
setCancel(true);
};
const cancelSearch = (e: any) => {
e.preventDefault();
setCancel(false);
if (changeValue !== undefined) {
console.log(444);
changeValue("");
}
Cancel(true);
};
console.log(value);
return (
<form
onSubmit={handleSubmit}
className="relative flex items-center w-full bg-gray-300 lg:w-1/5 rounded-xl"
>
<Input
// type="search"
ref={inputRef}
id="default-search"
className={`mb-0 h-8 bg-[#E9E9E9] border-none focus-visible:none rounded-lg
block w-full min-w-[13rem] text-xs md:text-sm text-black
text-opacity-60 dark:text-white
${mode === "controller" && "h-14 "}
${
mode === "admin" &&
"w-full min-w-full bg-white lg:min-w-full h-11"
}
`}
value={value}
onChange={(e) => {
if (changeValue) {
setCancel(false);
changeValue(e.target.value);
}
}}
placeholder="جستجو..."
/>
{cancel ? (
<button
onClick={cancelSearch}
type="button"
className="absolute left-3"
>
<X className=" text-gray-600 h-5 w-5" />
</button>
) : (
<button onClick={action} className="absolute left-3">
<CiSearch className="h-4 w-4" />
</button>
)}
{/* <button onClick={action} className="absolute left-3">
<CiSearch />
</button> */}
</form>
);
}