item.tsx 1.3 KB

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