index.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import s from './index.module.css'
  4. import classNames from '@/utils/classnames'
  5. import type { DataSet } from '@/models/datasets'
  6. const itemClass = `
  7. w-full sm:w-[234px] p-3 rounded-xl bg-gray-25 border border-gray-100 cursor-pointer
  8. `
  9. const radioClass = `
  10. w-4 h-4 border-[2px] border-gray-200 rounded-full
  11. `
  12. type IIndexMethodRadioProps = {
  13. value?: DataSet['indexing_technique']
  14. onChange: (v?: DataSet['indexing_technique']) => void
  15. disable?: boolean
  16. itemClassName?: string
  17. }
  18. const IndexMethodRadio = ({
  19. value,
  20. onChange,
  21. disable,
  22. itemClassName,
  23. }: IIndexMethodRadioProps) => {
  24. const { t } = useTranslation()
  25. const options = [
  26. {
  27. key: 'high_quality',
  28. text: t('datasetSettings.form.indexMethodHighQuality'),
  29. desc: t('datasetSettings.form.indexMethodHighQualityTip'),
  30. icon: 'high-quality',
  31. },
  32. {
  33. key: 'economy',
  34. text: t('datasetSettings.form.indexMethodEconomy'),
  35. desc: t('datasetSettings.form.indexMethodEconomyTip'),
  36. icon: 'economy',
  37. },
  38. ]
  39. return (
  40. <div className={classNames(s.wrapper, 'flex justify-between w-full flex-wrap gap-y-2')}>
  41. {
  42. options.map(option => (
  43. <div
  44. key={option.key}
  45. className={classNames(
  46. itemClass,
  47. itemClassName,
  48. s.item,
  49. option.key === value && s['item-active'],
  50. disable && s.disable,
  51. )}
  52. onClick={() => {
  53. if (!disable)
  54. onChange(option.key as DataSet['indexing_technique'])
  55. }}
  56. >
  57. <div className='flex items-center mb-1'>
  58. <div className={classNames(s.icon, s[`${option.icon}-icon`])} />
  59. <div className='grow text-sm text-gray-900'>{option.text}</div>
  60. <div className={classNames(radioClass, s.radio)} />
  61. </div>
  62. <div className='pl-9 text-xs text-gray-500 leading-[18px]'>{option.desc}</div>
  63. </div>
  64. ))
  65. }
  66. </div>
  67. )
  68. }
  69. export default IndexMethodRadio