index.tsx 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { MehOutlined } from '@ant-design/icons'
  2. import { Popover } from 'antd'
  3. import style from './index.less'
  4. import React, { useCallback, useState } from 'react'
  5. const arr1 = [
  6. "😄", "😊", "😃", "😉", "😍", "😘", "😚", "😳", "😁", "😌", "😜", "😝", "😒", "😏",
  7. "😓", "😔", "😞", "😖", "😥", "😰", "😨", "😣", "😢", "😭", "😂", "😲", "😱", "😠",
  8. "😡", "😪", "😷", "👿", "👽", "❤️", "💔", "💘", "✨", "🌟", "❕", "❔", "💤", "💦",
  9. "🎵", "🔥", "💩", "👍", "👎", "👊", "✌️", "👆", "👇", "👉", "👈", "☝️"
  10. ]
  11. const arr2 = [
  12. "💪", "💏", "💑", "👦", "👧", "👩", "👨", "👼", "💀", "👄", "☀", "☔", "☁", "⛄",
  13. "🌙", "⚡", "🌊", "🐱", "🐶", "🐭", "🐹", "🐰", "🐺", "🐸", "🐯", "🐨", "🐻", "🐷",
  14. "🐮", "🐗", "🐵", "🐴", "🐍", "🐦", "🐔", "🐧", "🐛", "🐙", "🐠", "🐳", "🐬", "🌹",
  15. "🌺", "🌴", "🌵", "💝", "🎃", "👻", "🎅", "🎄", "🎁", "🔔", "🎉", "🎈"
  16. ]
  17. const arr3 = [
  18. "💿", "📷", "🎥", "💻", "📺", "☎", "🔓", "🔒", "🔑", "🔨", "💡", "📫", "🛀", "💰",
  19. "💣", "🔫", "💊", "🏈", "🏀", "⚽", "⚾", "⛳", "🏆", "👾", "🎤", "🎸", "👙", "👑",
  20. "🌂", "👜", "💄", "💍", "💎", "☕", "🍺", "🍻", "🍸", "🍔", "🍟", "🍝", "🍣", "🍜",
  21. "🍳", "🍦", "🎂", "🍎", "✈", "🚀", "🚲", "🚄", "⚠", "🏁", "🚹", "🚺"
  22. ]
  23. const arr4 = ["⭕", "❌", "©", "®", "™"]
  24. type Props = {
  25. getStr: (str: string, range: Range) => void//回调传回选中表情和最后光标位置
  26. range: Range//文本光标节点
  27. }
  28. function Expression(props: Props) {
  29. const [eq, setEq] = useState<number>(0)//当前页
  30. const [left, setLeft] = useState<number>(0)//偏移
  31. const [isShow, setIsShow] = useState<boolean>(false)//弹窗
  32. //显示关闭弹窗
  33. const exit = useCallback(() => {
  34. setIsShow(!isShow)
  35. }, [isShow])
  36. //点击表情
  37. const handelClick = useCallback((str: string) => {
  38. props.getStr(str, props.range)
  39. setIsShow(false)
  40. }, [props.range])
  41. //点击翻页
  42. const handelAction = useCallback((eq: number) => {
  43. setEq(eq)
  44. setLeft(eq * 400)
  45. }, [])
  46. return <div>
  47. <Popover
  48. content={
  49. <div className={style.expression} >
  50. {
  51. [arr1, arr2, arr3, arr4].map((item: string[], index: number) => {
  52. return <div key={index} className={style.box} style={{ transform: `translateX(-${left}px)` }} >
  53. {
  54. item.map((em: string, index: number) => {
  55. return <span key={index} onClick={() => handelClick(em)}>{em}</span>
  56. })
  57. }
  58. </div>
  59. })
  60. }
  61. <div className={style.bottom}>
  62. {
  63. [0, 1, 2, 3].map((item) => {
  64. return <span className={`${style.yd} ${eq === item ? style.action : undefined}`} key={item} onClick={() => handelAction(item)} />
  65. })
  66. }
  67. </div>
  68. </div>
  69. }
  70. trigger="click"
  71. open={isShow}
  72. onOpenChange={exit}
  73. >
  74. <MehOutlined onClick={exit} />
  75. </Popover>
  76. </div>
  77. }
  78. export default Expression