通用评论

Emoji.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from "react";
  2. import { Carousel } from "antd";
  3. import emoji, { prefixUrl } from "../../emoji";
  4. import "./Emoji.css";
  5. // 每页 20 5*4
  6. // 共 20 * 3 = 60 (实际是 54)
  7. // class Emoji
  8. const Emoji = ({ onClick }) => {
  9. const content = [];
  10. let curPage = [];
  11. for (let i = 0; i < 115; i++) {
  12. if (curPage.length < 20) {
  13. curPage.push(emoji[i]);
  14. } else {
  15. content.push(curPage);
  16. curPage = [];
  17. }
  18. }
  19. if (curPage.length > 0) {
  20. content.push(curPage);
  21. }
  22. return (
  23. <Carousel>
  24. {content.map((page, index) => (
  25. <div key={index} className="emoji">
  26. {page.map((item, index) => (
  27. <div className="item" key={item.value}>
  28. <span className="helper" />
  29. <img
  30. src={`${prefixUrl}${item.value}.${item.ext}`}
  31. alt={item.title}
  32. style={{ display: "inline-block" }}
  33. onClick={() => onClick(item.title)}
  34. />
  35. </div>
  36. ))}
  37. </div>
  38. ))}
  39. </Carousel>
  40. );
  41. };
  42. export default Emoji;