index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import s from './style.module.css'
  6. import EmojiPickerInner from './Inner'
  7. import cn from '@/utils/classnames'
  8. import Divider from '@/app/components/base/divider'
  9. import Button from '@/app/components/base/button'
  10. import Modal from '@/app/components/base/modal'
  11. type IEmojiPickerProps = {
  12. isModal?: boolean
  13. onSelect?: (emoji: string, background: string) => void
  14. onClose?: () => void
  15. className?: string
  16. }
  17. const EmojiPicker: FC<IEmojiPickerProps> = ({
  18. isModal = true,
  19. onSelect,
  20. onClose,
  21. className,
  22. }) => {
  23. const { t } = useTranslation()
  24. const [selectedEmoji, setSelectedEmoji] = useState('')
  25. const [selectedBackground, setSelectedBackground] = useState<string>()
  26. const handleSelectEmoji = useCallback((emoji: string, background: string) => {
  27. setSelectedEmoji(emoji)
  28. setSelectedBackground(background)
  29. }, [setSelectedEmoji, setSelectedBackground])
  30. return isModal
  31. ? <Modal
  32. onClose={() => { }}
  33. isShow
  34. closable={false}
  35. wrapperClassName={className}
  36. className={cn(s.container, '!w-[362px] !p-0')}
  37. >
  38. <EmojiPickerInner
  39. className="pt-3"
  40. onSelect={handleSelectEmoji} />
  41. <Divider className='m-0' />
  42. <div className='w-full flex items-center justify-center p-3 gap-2'>
  43. <Button className='w-full' onClick={() => {
  44. onClose && onClose()
  45. }}>
  46. {t('app.iconPicker.cancel')}
  47. </Button>
  48. <Button
  49. disabled={selectedEmoji === '' || !selectedBackground}
  50. variant="primary"
  51. className='w-full'
  52. onClick={() => {
  53. onSelect && onSelect(selectedEmoji, selectedBackground!)
  54. }}>
  55. {t('app.iconPicker.ok')}
  56. </Button>
  57. </div>
  58. </Modal>
  59. : <></>
  60. }
  61. export default EmojiPicker