index.tsx 2.0 KB

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