justfrenzy

CrackFlix - frontend /src/components/App/SearchForm.tsx

May 12th, 2024
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. import { Button, Spacer } from "@nextui-org/react";
  2. import { SlidersHorizontal, Search } from "lucide-react";
  3. import { useNavigate } from "react-router-dom";
  4. import { SearchI } from "./Search";
  5.  
  6. import { Input } from "@nextui-org/input";
  7.  
  8. interface SearchFormI extends SearchI {
  9. //searchRef: React.RefObject<HTMLInputElement>;
  10. isLoading: boolean;
  11. isMobile: boolean;
  12. placeholderTxt: string;
  13. filterTxt: string;
  14. setSelected: React.Dispatch<React.SetStateAction<boolean>>;
  15. }
  16.  
  17. const SearchForm: React.FC<SearchFormI> = ({
  18. //searchRef,
  19. isLoading,
  20. isMobile,
  21. placeholderTxt,
  22. filterTxt,
  23. search,
  24. setSearch,
  25. setSelected,
  26. }) => {
  27. const navigate = useNavigate();
  28.  
  29. return (
  30. <div className="flex flex-row justify-center z-0 items-center text-white w-[95vw] sm:w-[50vw] ">
  31. <div className="w-full">
  32. <Input
  33. color="primary"
  34. required
  35. isRequired={true}
  36. isReadOnly={isLoading}
  37. isDisabled={isLoading}
  38. variant="flat"
  39. //size="lg"
  40. className="text-center text-white "
  41. classNames={{
  42. inputWrapper: "bg-background/40 h-[56px] dark:bg-default/40",
  43. }}
  44. startContent={
  45. <div onClick={() => navigate("/filter?sort=popularity&type=multi")}>
  46. {isMobile ? (
  47. <Button
  48. isIconOnly
  49. isLoading={isLoading}
  50. isDisabled={isLoading}
  51. onClick={() => navigate("/filter?sort=popularity&type=multi")}
  52. radius="full"
  53. variant="flat"
  54. color="primary"
  55. className="ml-[-10px] mr-3 text-white font-bold"
  56. >
  57. <SlidersHorizontal size={16} />
  58. </Button>
  59. ) : (
  60. <Button
  61. isLoading={isLoading}
  62. isDisabled={isLoading}
  63. onClick={() => navigate("/filter?sort=popularity&type=multi")}
  64. radius="full"
  65. color="primary"
  66. variant={`flat`}
  67. startContent={<SlidersHorizontal size={16} />}
  68. className=" text-white font-bold"
  69. >
  70. {filterTxt}
  71. </Button>
  72. )}
  73. </div>
  74. }
  75. placeholder={placeholderTxt}
  76. radius="full"
  77. value={search}
  78. onChange={(e) => {
  79. if (e.target.value.length > 3) {
  80. setSelected(true);
  81. setSearch(e.target.value);
  82. } else {
  83. setSearch(e.target.value);
  84. }
  85. }}
  86. onClear={() => setSearch("")}
  87. />
  88. </div>
  89. <Spacer x={2} />
  90. <Button
  91. className="text-white"
  92. type="submit"
  93. color="primary"
  94. size="lg"
  95. isIconOnly
  96. isLoading={isLoading}
  97. isDisabled={isLoading}
  98. variant={`flat`}
  99. radius="full"
  100. aria-label="search movies or tv series"
  101. spinner={
  102. isLoading ? (
  103. <svg
  104. className="animate-spin h-5 w-5 text-current"
  105. fill="none"
  106. viewBox="0 0 24 24"
  107. xmlns="http://www.w3.org/2000/svg"
  108. >
  109. <circle
  110. className="opacity-25"
  111. cx="12"
  112. cy="12"
  113. r="10"
  114. stroke="currentColor"
  115. strokeWidth="4"
  116. />
  117. <path
  118. className="opacity-75"
  119. d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
  120. fill="currentColor"
  121. />
  122. </svg>
  123. ) : (
  124. <></>
  125. )
  126. }
  127. >
  128. {isLoading ? "Loading..." : <Search />}
  129. </Button>
  130. </div>
  131. );
  132. };
  133.  
  134. export default SearchForm;
  135.  
Advertisement
Add Comment
Please, Sign In to add comment