index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use client";
  2. import { CircleNotch } from "@phosphor-icons/react/dist/ssr/CircleNotch";
  3. import { MagnifyingGlass } from "@phosphor-icons/react/dist/ssr/MagnifyingGlass";
  4. import { XCircle } from "@phosphor-icons/react/dist/ssr/XCircle";
  5. import clsx from "clsx";
  6. import type { CSSProperties, ComponentProps } from "react";
  7. import styles from "./index.module.scss";
  8. import { Button } from "../unstyled/Button/index.jsx";
  9. import { SearchField } from "../unstyled/SearchField/index.jsx";
  10. import { Input } from "../unstyled/TextField/index.jsx";
  11. export const SIZES = ["xs", "sm", "md", "lg"] as const;
  12. type Props = ComponentProps<typeof SearchField> & {
  13. label?: string | undefined;
  14. size?: (typeof SIZES)[number] | undefined;
  15. width?: number | undefined;
  16. isPending?: boolean | undefined;
  17. placeholder?: string;
  18. };
  19. export const SearchInput = ({
  20. label,
  21. size = "md",
  22. width,
  23. className,
  24. isPending,
  25. placeholder = "Search",
  26. ...props
  27. }: Props) => (
  28. <SearchField
  29. aria-label={label ?? "Search"}
  30. className={clsx(styles.searchInput, className)}
  31. data-size={size}
  32. data-static-width={width === undefined ? undefined : ""}
  33. {...(width && { style: { "--width": width } as CSSProperties })}
  34. {...(isPending && { "data-pending": "" })}
  35. {...props}
  36. >
  37. <Input className={styles.input ?? ""} placeholder={placeholder} />
  38. <MagnifyingGlass className={styles.searchIcon} />
  39. <CircleNotch className={styles.loadingIcon} />
  40. <Button className={styles.clearButton ?? ""}>
  41. <XCircle weight="fill" className={styles.clearIcon} />
  42. </Button>
  43. </SearchField>
  44. );