inputs.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 maxValue = parseInt(globalThis.document?.body?.getAttribute('data-public-indexing-max-segmentation-tokens-length') || '4000', 10)
  39. const { t } = useTranslation()
  40. return <FormField label={<div className='system-sm-semibold mb-1'>
  41. {t('datasetCreation.stepTwo.maxLength')}
  42. </div>}>
  43. <InputNumber
  44. type="number"
  45. className='h-9'
  46. placeholder={`≤ ${maxValue}`}
  47. max={maxValue}
  48. min={1}
  49. {...props}
  50. />
  51. </FormField>
  52. }
  53. export const OverlapInput: FC<InputNumberProps> = (props) => {
  54. const { t } = useTranslation()
  55. return <FormField label={<div className='flex items-center mb-1'>
  56. <span className='system-sm-semibold'>{t('datasetCreation.stepTwo.overlap')}</span>
  57. <Tooltip
  58. popupContent={
  59. <div className='max-w-[200px]'>
  60. {t('datasetCreation.stepTwo.overlapTip')}
  61. </div>
  62. }
  63. />
  64. </div>}>
  65. <InputNumber
  66. type="number"
  67. className='h-9'
  68. placeholder={t('datasetCreation.stepTwo.overlap') || ''}
  69. min={1}
  70. {...props}
  71. />
  72. </FormField>
  73. }