index.tsx 1.9 KB

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