index.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. flex items-center w-[234px] h-12 px-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 IPermissionsRadioProps = {
  13. value?: DataSet['permission']
  14. onChange: (v?: DataSet['permission']) => void
  15. disable?: boolean
  16. }
  17. const PermissionsRadio = ({
  18. value,
  19. onChange,
  20. disable,
  21. }: IPermissionsRadioProps) => {
  22. const { t } = useTranslation()
  23. const options = [
  24. {
  25. key: 'only_me',
  26. text: t('datasetSettings.form.permissionsOnlyMe'),
  27. },
  28. {
  29. key: 'all_team_members',
  30. text: t('datasetSettings.form.permissionsAllMember'),
  31. },
  32. ]
  33. return (
  34. <div className={classNames(s.wrapper, 'flex justify-between w-full')}>
  35. {
  36. options.map(option => (
  37. <div
  38. key={option.key}
  39. className={classNames(
  40. itemClass,
  41. s.item,
  42. option.key === value && s['item-active'],
  43. disable && s.disable,
  44. )}
  45. onClick={() => {
  46. if (!disable)
  47. onChange(option.key as DataSet['permission'])
  48. }}
  49. >
  50. <div className={classNames(s['user-icon'], 'mr-3')} />
  51. <div className='grow text-sm text-gray-900'>{option.text}</div>
  52. <div className={classNames(radioClass, s.radio)} />
  53. </div>
  54. ))
  55. }
  56. </div>
  57. )
  58. }
  59. export default PermissionsRadio