item.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useContext } from 'use-context-selector'
  5. import cn from 'classnames'
  6. import AppIcon from '../../base/app-icon'
  7. import type { Collection } from '@/app/components/tools/types'
  8. import I18n from '@/context/i18n'
  9. type Props = {
  10. isCurrent: boolean
  11. payload: Collection
  12. onClick: () => void
  13. }
  14. const Item: FC<Props> = ({
  15. isCurrent,
  16. payload,
  17. onClick,
  18. }) => {
  19. const { locale } = useContext(I18n)
  20. return (
  21. <div
  22. className={cn(isCurrent && 'bg-white shadow-xs rounded-lg', 'mt-1 flex h-9 items-center px-2 space-x-2 cursor-pointer')}
  23. onClick={() => !isCurrent && onClick()}
  24. >
  25. {typeof payload.icon === 'string'
  26. ? (
  27. <div
  28. className='w-6 h-6 bg-cover bg-center rounded-md'
  29. style={{
  30. backgroundImage: `url(${payload.icon})`,
  31. }}
  32. ></div>
  33. )
  34. : (
  35. <AppIcon
  36. size='tiny'
  37. icon={payload.icon.content}
  38. background={payload.icon.background}
  39. />
  40. )}
  41. <div className={cn(isCurrent && 'text-primary-600 font-semibold', 'leading-5 text-sm font-normal truncate')}>{payload.label[locale === 'en' ? 'en_US' : 'zh_Hans']}</div>
  42. </div>
  43. )
  44. }
  45. export default React.memo(Item)