Card.tsx 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "use client";
  2. import { EntityGameListRep } from "@/api/home";
  3. import { Button, Modal, ModalBody, ModalContent, useDisclosure } from "@nextui-org/react";
  4. import { useTranslations } from "next-intl";
  5. import { FC, PropsWithChildren, ReactNode } from "react";
  6. import styles from "./style.module.scss";
  7. export interface CardProps {
  8. item?: EntityGameListRep;
  9. render?: (value: EntityGameListRep) => ReactNode;
  10. }
  11. const Card: FC<PropsWithChildren<CardProps>> = (props) => {
  12. const { render, item } = props;
  13. const { isOpen, onOpen, onOpenChange } = useDisclosure();
  14. const app: HTMLElement = document.querySelector("#app")!;
  15. const t = useTranslations("Game");
  16. const handler = (game: EntityGameListRep) => {
  17. onOpen();
  18. };
  19. return (
  20. <>
  21. <div className={styles.cardWrap} onClick={() => handler(item!)}>
  22. {render ? (
  23. render(item!)
  24. ) : (
  25. <img src={item?.game_icon} alt={item?.game_name_cn} className={"h-1/1"} />
  26. )}
  27. </div>
  28. <Modal
  29. isOpen={isOpen}
  30. portalContainer={app}
  31. placement={"bottom"}
  32. onOpenChange={onOpenChange}
  33. classNames={{
  34. header: "px-0 pb-0 ",
  35. wrapper: "w-[100vw] m-auto",
  36. closeButton: "text-[20px] top-[0rem] right-0 text-[#fff] ",
  37. backdrop: "absolute top-0 left-0 sm:my-0 ",
  38. base: "my-0 my-0 sm:mx-[0] mx-0 sm:my-0 max-w-[4.02rem] ",
  39. body: "py-[12px]",
  40. }}
  41. >
  42. <ModalContent>
  43. {(onClose) => (
  44. <>
  45. <ModalBody className={"w-[4rem] text-[0.1111rem]"}>
  46. <div className={"w-1/1 flex flex-1"}>
  47. <div className={styles.cardWrap}>
  48. <img src={item?.game_icon} alt={item?.game_name_cn} />
  49. </div>
  50. <div className={styles.cardWrapGmeInfo}>
  51. <p className={"h-[0.6rem]"}>{item?.game_name_cn}</p>
  52. <div className={"flex w-[2.2rem] justify-around"}>
  53. <Button
  54. className={
  55. "h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +
  56. " bg-[#3a3a3a]" +
  57. " font-bold"
  58. }
  59. >
  60. {t("demo")}
  61. </Button>
  62. <Button
  63. className={
  64. "h-[0.39rem] w-[0.89rem] text-[0.15rem]" +
  65. " rounded-[0.05rem]" +
  66. " bg-[#009d80]" +
  67. " font-bold"
  68. }
  69. >
  70. {t("join")}
  71. </Button>
  72. </div>
  73. </div>
  74. </div>
  75. </ModalBody>
  76. </>
  77. )}
  78. </ModalContent>
  79. </Modal>
  80. </>
  81. );
  82. };
  83. export default Card;