index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import classNames from 'classnames'
  4. import s from './index.module.css'
  5. import { DataSet } from '@/models/datasets'
  6. const itemClass = `
  7. 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. }
  16. const IndexMethodRadio = ({
  17. value,
  18. onChange
  19. }: IIndexMethodRadioProps) => {
  20. const { t } = useTranslation()
  21. const options = [
  22. {
  23. key: 'high_quality',
  24. text: t('datasetSettings.form.indexMethodHighQuality'),
  25. desc: t('datasetSettings.form.indexMethodHighQualityTip'),
  26. icon: 'high-quality'
  27. },
  28. {
  29. key: 'economy',
  30. text: t('datasetSettings.form.indexMethodEconomy'),
  31. desc: t('datasetSettings.form.indexMethodEconomyTip'),
  32. icon: 'economy'
  33. }
  34. ]
  35. return (
  36. <div className={classNames(s.wrapper, 'flex justify-between w-full')}>
  37. {
  38. options.map(option => (
  39. <div
  40. key={option.key}
  41. className={classNames(
  42. option.key === value && s['item-active'],
  43. s.item,
  44. itemClass
  45. )}
  46. onClick={() => onChange(option.key as DataSet['indexing_technique'])}
  47. >
  48. <div className='flex items-center mb-1'>
  49. <div className={classNames(s.icon, s[`${option.icon}-icon`])} />
  50. <div className='grow text-sm text-gray-900'>{option.text}</div>
  51. <div className={classNames(radioClass, s.radio)} />
  52. </div>
  53. <div className='pl-9 text-xs text-gray-500 leading-[18px]'>{option.desc}</div>
  54. </div>
  55. ))
  56. }
  57. </div>
  58. )
  59. }
  60. export default IndexMethodRadio