通用评论

Emoji.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. class Emoji extends React.Component {
  9. next() {
  10. if (this.carousel) {
  11. this.carousel.next();
  12. }
  13. }
  14. prev() {
  15. if (this.carousel) {
  16. this.carousel.prev();
  17. }
  18. }
  19. render() {
  20. const { onClick, emojiList } = this.props;
  21. const content = [];
  22. // let curPage = [];
  23. // for (let i = 0; i < 115; i++) {
  24. // if (curPage.length < 30) {
  25. // curPage.push(emoji[i]);
  26. // } else {
  27. // content.push(curPage);
  28. // curPage = [];
  29. // }
  30. // }
  31. // if (curPage.length > 0) {
  32. // content.push(curPage);
  33. // }
  34. for (let i = 0; i < emojiList.length; i += 30) {
  35. content.push(emojiList.slice(i, i + 30));
  36. }
  37. return (
  38. <Carousel
  39. ref={node => {
  40. this.carousel = node;
  41. }}
  42. >
  43. {content.map((page, index) => (
  44. <div key={index} className="emoji">
  45. {page.map((item, index) => (
  46. <div className="item" key={item.id}>
  47. {/* <span className="helper" /> */}
  48. <img
  49. src={item.url}
  50. alt={item.name}
  51. style={{ display: "inline-block", width: "28px" }}
  52. onClick={() => onClick(item.name)}
  53. />
  54. </div>
  55. ))}
  56. </div>
  57. ))}
  58. </Carousel>
  59. );
  60. }
  61. }
  62. export default Emoji;