inputs.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type { FC, PropsWithChildren, ReactNode } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import type { InputProps } from '@/app/components/base/input'
  4. import Input from '@/app/components/base/input'
  5. import Tooltip from '@/app/components/base/tooltip'
  6. import type { InputNumberProps } from '@/app/components/base/input-number'
  7. import { InputNumber } from '@/app/components/base/input-number'
  8. const TextLabel: FC<PropsWithChildren> = (props) => {
  9. return <label className='text-text-secondary text-xs font-semibold leading-none'>{props.children}</label>
  10. }
  11. const FormField: FC<PropsWithChildren<{ label: ReactNode }>> = (props) => {
  12. return <div className='space-y-2 flex-1'>
  13. <TextLabel>{props.label}</TextLabel>
  14. {props.children}
  15. </div>
  16. }
  17. export const DelimiterInput: FC<InputProps & { tooltip?: string }> = (props) => {
  18. const { t } = useTranslation()
  19. return <FormField label={<div className='flex items-center mb-1'>
  20. <span className='system-sm-semibold mr-0.5'>{t('datasetCreation.stepTwo.separator')}</span>
  21. <Tooltip
  22. popupContent={
  23. <div className='max-w-[200px]'>
  24. {props.tooltip || t('datasetCreation.stepTwo.separatorTip')}
  25. </div>
  26. }
  27. />
  28. </div>}>
  29. <Input
  30. type="text"
  31. className='h-9'
  32. placeholder={t('datasetCreation.stepTwo.separatorPlaceholder')!}
  33. {...props}
  34. />
  35. </FormField>
  36. }
  37. export const MaxLengthInput: FC<InputNumberProps> = (props) => {
  38. const { t } = useTranslation()
  39. return <FormField label={<div className='system-sm-semibold mb-1'>
  40. {t('datasetCreation.stepTwo.maxLength')}
  41. </div>}>
  42. <InputNumber
  43. type="number"
  44. className='h-9'
  45. placeholder={'≤ 4000'}
  46. max={4000}
  47. min={1}
  48. {...props}
  49. />
  50. </FormField>
  51. }
  52. export const OverlapInput: FC<InputNumberProps> = (props) => {
  53. const { t } = useTranslation()
  54. return <FormField label={<div className='flex items-center mb-1'>
  55. <span className='system-sm-semibold'>{t('datasetCreation.stepTwo.overlap')}</span>
  56. <Tooltip
  57. popupContent={
  58. <div className='max-w-[200px]'>
  59. {t('datasetCreation.stepTwo.overlapTip')}
  60. </div>
  61. }
  62. />
  63. </div>}>
  64. <InputNumber
  65. type="number"
  66. className='h-9'
  67. placeholder={t('datasetCreation.stepTwo.overlap') || ''}
  68. min={1}
  69. {...props}
  70. />
  71. </FormField>
  72. }