index.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import {
  4. RiAddLine,
  5. } from '@remixicon/react'
  6. import type {
  7. ModelProvider,
  8. } from '../declarations'
  9. import { ConfigurationMethodEnum } from '../declarations'
  10. import {
  11. DEFAULT_BACKGROUND_COLOR,
  12. modelTypeFormat,
  13. } from '../utils'
  14. import {
  15. useLanguage,
  16. } from '../hooks'
  17. import ModelBadge from '../model-badge'
  18. import ProviderIcon from '../provider-icon'
  19. import s from './index.module.css'
  20. import { Settings01 } from '@/app/components/base/icons/src/vender/line/general'
  21. import Button from '@/app/components/base/button'
  22. type ProviderCardProps = {
  23. provider: ModelProvider
  24. onOpenModal: (configurateMethod: ConfigurationMethodEnum) => void
  25. }
  26. const ProviderCard: FC<ProviderCardProps> = ({
  27. provider,
  28. onOpenModal,
  29. }) => {
  30. const { t } = useTranslation()
  31. const language = useLanguage()
  32. const configurateMethods = provider.configurate_methods.filter(method => method !== ConfigurationMethodEnum.fetchFromRemote)
  33. return (
  34. <div
  35. className='group relative flex flex-col justify-between px-4 py-3 h-[148px] border-[0.5px] border-black/5 rounded-xl shadow-xs hover:shadow-lg'
  36. style={{ background: provider.background || DEFAULT_BACKGROUND_COLOR }}
  37. >
  38. <div>
  39. <div className='py-0.5'>
  40. <ProviderIcon provider={provider} />
  41. </div>
  42. {
  43. provider.description && (
  44. <div className='mt-1 leading-4 text-xs text-black/[48]'>{provider.description[language] || provider.description.en_US}</div>
  45. )
  46. }
  47. </div>
  48. <div>
  49. <div className={'flex flex-wrap group-hover:hidden gap-0.5'}>
  50. {
  51. provider.supported_model_types.map(modelType => (
  52. <ModelBadge key={modelType}>
  53. {modelTypeFormat(modelType)}
  54. </ModelBadge>
  55. ))
  56. }
  57. </div>
  58. <div className={`hidden group-hover:grid grid-cols-${configurateMethods.length} gap-1`}>
  59. {
  60. configurateMethods.map((method) => {
  61. if (method === ConfigurationMethodEnum.predefinedModel) {
  62. return (
  63. <Button
  64. key={method}
  65. className={'h-7 text-xs shrink-0'}
  66. onClick={() => onOpenModal(method)}
  67. >
  68. <Settings01 className={`mr-[5px] w-3.5 h-3.5 ${s.icon}`} />
  69. <span className='text-xs inline-flex items-center justify-center overflow-ellipsis shrink-0'>{t('common.operation.setup')}</span>
  70. </Button>
  71. )
  72. }
  73. return (
  74. <Button
  75. key={method}
  76. className='px-0 h-7 text-xs'
  77. onClick={() => onOpenModal(method)}
  78. >
  79. <RiAddLine className='mr-[5px] w-3.5 h-3.5' />
  80. {t('common.modelProvider.addModel')}
  81. </Button>
  82. )
  83. })
  84. }
  85. </div>
  86. </div>
  87. </div>
  88. )
  89. }
  90. export default ProviderCard