index.tsx 1.7 KB

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