You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { init } from 'emoji-mart'
  4. import data from '@emoji-mart/data'
  5. import { cva } from 'class-variance-authority'
  6. import type { AppIconType } from '@/types/app'
  7. import classNames from '@/utils/classnames'
  8. init({ data })
  9. export type AppIconProps = {
  10. size?: 'xs' | 'tiny' | 'small' | 'medium' | 'large' | 'xl' | 'xxl'
  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. coverElement?: React.ReactNode
  19. onClick?: () => void
  20. }
  21. const appIconVariants = cva(
  22. 'flex items-center justify-center relative text-lg rounded-lg grow-0 shrink-0 overflow-hidden leading-none',
  23. {
  24. variants: {
  25. size: {
  26. xs: 'w-4 h-4 text-xs',
  27. tiny: 'w-6 h-6 text-base',
  28. small: 'w-8 h-8 text-xl',
  29. medium: 'w-9 h-9 text-[22px]',
  30. large: 'w-10 h-10 text-[24px]',
  31. xl: 'w-12 h-12 text-[28px]',
  32. xxl: 'w-14 h-14 text-[32px]',
  33. },
  34. rounded: {
  35. true: 'rounded-full',
  36. },
  37. },
  38. defaultVariants: {
  39. size: 'medium',
  40. rounded: false,
  41. },
  42. })
  43. const AppIcon: FC<AppIconProps> = ({
  44. size = 'medium',
  45. rounded = false,
  46. iconType,
  47. icon,
  48. background,
  49. imageUrl,
  50. className,
  51. innerIcon,
  52. coverElement,
  53. onClick,
  54. }) => {
  55. const isValidImageIcon = iconType === 'image' && imageUrl
  56. return <span
  57. className={classNames(appIconVariants({ size, rounded }), className)}
  58. style={{ background: isValidImageIcon ? undefined : (background || '#FFEAD5') }}
  59. onClick={onClick}
  60. >
  61. {isValidImageIcon
  62. ? <img src={imageUrl} className="h-full w-full" alt="app icon" />
  63. : (innerIcon || ((icon && icon !== '') ? <em-emoji id={icon} /> : <em-emoji id='🤖' />))
  64. }
  65. {coverElement}
  66. </span>
  67. }
  68. export default AppIcon