index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use client";
  2. import { Tabs } from "antd-mobile";
  3. import { FC, PropsWithChildren, ReactNode } from "react";
  4. import styles from "./style.module.scss";
  5. interface Item {
  6. id: number | string;
  7. name?: string | ReactNode;
  8. content?: number;
  9. render?: ReactNode;
  10. headerRender?: () => ReactNode;
  11. }
  12. interface Props {
  13. items: Item[];
  14. activeKey?: string;
  15. onChanage?: (key?: string) => void;
  16. }
  17. // <Badge
  18. // className={"flex items-center justify-center text-[20px]"}
  19. // content={tab.content > 0 ? tab.content : null}
  20. // style={{
  21. // "--right": "-10px",
  22. // "--top": "8px",
  23. // width: "20px",
  24. // height: "20px",
  25. // }}
  26. // color={"#ff311b"}
  27. // >
  28. // {tab.name}
  29. // </Badge>
  30. const Transactions: FC<PropsWithChildren<Props>> = (props) => {
  31. const { items, activeKey, onChanage } = props;
  32. const tabChange = (key: string) => {
  33. if (typeof onChanage === "function") {
  34. onChanage(key);
  35. }
  36. };
  37. console.log(activeKey);
  38. return (
  39. <Tabs
  40. style={{
  41. "--active-line-color": "#fb8910",
  42. "--active-title-color": "#fb8910",
  43. "--active-line-height": "3px",
  44. // @ts-ignore
  45. "--adm-color-border": "none",
  46. }}
  47. activeKey={activeKey}
  48. onChange={tabChange}
  49. activeLineMode="full"
  50. >
  51. {items.map((tab) => {
  52. return (
  53. <Tabs.Tab
  54. key={tab.id}
  55. className={styles.badge}
  56. title={
  57. // <Badge
  58. // content={tab.content > 0 ? tab.content : null}
  59. // style={{
  60. // "--right": "-0.1rem",
  61. // "--top": "8px",
  62. // }}
  63. // color={"#ff311b"}
  64. // >
  65. // {tab.name}
  66. // </Badge>
  67. <>
  68. {!tab?.headerRender && (
  69. <div style={{ position: "relative" }}>
  70. {tab.name}
  71. {!!tab.content && (
  72. <div
  73. className={`mr-[0.1rem] flex h-[0.15rem] w-[0.15rem] items-center justify-center text-[#fff]`}
  74. style={{
  75. position: "absolute",
  76. borderRadius: "0.075rem",
  77. backgroundColor: "#ff311b",
  78. fontSize: "0.1rem",
  79. top: "-0.02rem",
  80. right: "-0.24rem",
  81. }}
  82. >
  83. {tab.content}
  84. </div>
  85. )}
  86. </div>
  87. )}
  88. {tab?.headerRender && tab.headerRender()}
  89. </>
  90. }
  91. >
  92. {tab.render}
  93. </Tabs.Tab>
  94. );
  95. })}
  96. </Tabs>
  97. );
  98. };
  99. export default Transactions;