index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import ProgressBar from '../progress-bar'
  6. import { NUM_INFINITE } from '../config'
  7. import Tooltip from '@/app/components/base/tooltip'
  8. type Props = {
  9. className?: string
  10. Icon: any
  11. name: string
  12. tooltip?: string
  13. usage: number
  14. total: number
  15. unit?: string
  16. }
  17. const LOW = 50
  18. const MIDDLE = 80
  19. const UsageInfo: FC<Props> = ({
  20. className,
  21. Icon,
  22. name,
  23. tooltip,
  24. usage,
  25. total,
  26. unit = '',
  27. }) => {
  28. const { t } = useTranslation()
  29. const percent = usage / total * 100
  30. const color = (() => {
  31. if (percent < LOW)
  32. return '#155EEF'
  33. if (percent < MIDDLE)
  34. return '#F79009'
  35. return '#F04438'
  36. })()
  37. return (
  38. <div className={className}>
  39. <div className='flex justify-between h-5 items-center'>
  40. <div className='flex items-center'>
  41. <Icon className='w-4 h-4 text-gray-700' />
  42. <div className='mx-1 leading-5 text-sm font-medium text-gray-700'>{name}</div>
  43. {tooltip && (
  44. <Tooltip
  45. popupContent={
  46. <div className='w-[180px]'>
  47. {tooltip}
  48. </div>
  49. }
  50. />
  51. )}
  52. </div>
  53. <div className='flex items-center leading-[18px] text-[13px] font-normal'>
  54. <div style={{
  55. color: percent < LOW ? '#344054' : color,
  56. }}>{usage}{unit}</div>
  57. <div className='mx-1 text-gray-300'>/</div>
  58. <div className='text-gray-500'>{total === NUM_INFINITE ? t('billing.plansCommon.unlimited') : `${total}${unit}`}</div>
  59. </div>
  60. </div>
  61. <div className='mt-2'>
  62. <ProgressBar
  63. percent={percent}
  64. color={color}
  65. />
  66. </div>
  67. </div>
  68. )
  69. }
  70. export default React.memo(UsageInfo)