index.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { init } from 'emoji-mart'
  4. import data from '@emoji-mart/data'
  5. import style from './style.module.css'
  6. import classNames from '@/utils/classnames'
  7. import type { AppIconType } from '@/types/app'
  8. init({ data })
  9. export type AppIconProps = {
  10. size?: 'xs' | 'tiny' | 'small' | 'medium' | 'large'
  11. rounded?: boolean
  12. iconType?: AppIconType | null
  13. icon?: string
  14. background?: string | null
  15. imageUrl?: string | null
  16. className?: string
  17. innerIcon?: React.ReactNode
  18. onClick?: () => void
  19. }
  20. const AppIcon: FC<AppIconProps> = ({
  21. size = 'medium',
  22. rounded = false,
  23. iconType,
  24. icon,
  25. background,
  26. imageUrl,
  27. className,
  28. innerIcon,
  29. onClick,
  30. }) => {
  31. const wrapperClassName = classNames(
  32. style.appIcon,
  33. size !== 'medium' && style[size],
  34. rounded && style.rounded,
  35. className ?? '',
  36. 'overflow-hidden',
  37. )
  38. const isValidImageIcon = iconType === 'image' && imageUrl
  39. return <span
  40. className={wrapperClassName}
  41. style={{ background: isValidImageIcon ? undefined : (background || '#FFEAD5') }}
  42. onClick={onClick}
  43. >
  44. {isValidImageIcon
  45. ? <img src={imageUrl} className="w-full h-full" alt="app icon" />
  46. : (innerIcon || ((icon && icon !== '') ? <em-emoji id={icon} /> : <em-emoji id='🤖' />))
  47. }
  48. </span>
  49. }
  50. export default AppIcon