mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
Merge branch 'feat/rag-2' into fix/kb-node-rerank-model
This commit is contained in:
commit
409ad3e2b3
@ -1,4 +1,4 @@
|
|||||||
import type { CSSProperties } from 'react'
|
import type { CSSProperties, ChangeEventHandler, FocusEventHandler } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { RiCloseCircleFill, RiErrorWarningLine, RiSearchLine } from '@remixicon/react'
|
import { RiCloseCircleFill, RiErrorWarningLine, RiSearchLine } from '@remixicon/react'
|
||||||
@ -33,6 +33,8 @@ export type InputProps = {
|
|||||||
ref?: React.Ref<HTMLInputElement>
|
ref?: React.Ref<HTMLInputElement>
|
||||||
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> & VariantProps<typeof inputVariants>
|
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size'> & VariantProps<typeof inputVariants>
|
||||||
|
|
||||||
|
const removeLeadingZeros = (value: string) => value.replace(/^(-?)0+(?=\d)/, '$1')
|
||||||
|
|
||||||
const Input = ({
|
const Input = ({
|
||||||
size,
|
size,
|
||||||
disabled,
|
disabled,
|
||||||
@ -46,11 +48,37 @@ const Input = ({
|
|||||||
value,
|
value,
|
||||||
placeholder,
|
placeholder,
|
||||||
onChange = noop,
|
onChange = noop,
|
||||||
|
onBlur = noop,
|
||||||
unit,
|
unit,
|
||||||
ref,
|
ref,
|
||||||
...props
|
...props
|
||||||
}: InputProps) => {
|
}: InputProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const handleNumberChange: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
if (value === 0) {
|
||||||
|
// remove leading zeros
|
||||||
|
const formattedValue = removeLeadingZeros(e.target.value)
|
||||||
|
if (e.target.value !== formattedValue)
|
||||||
|
e.target.value = formattedValue
|
||||||
|
}
|
||||||
|
onChange(e)
|
||||||
|
}
|
||||||
|
const handleNumberBlur: FocusEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
// remove leading zeros
|
||||||
|
const formattedValue = removeLeadingZeros(e.target.value)
|
||||||
|
if (e.target.value !== formattedValue) {
|
||||||
|
e.target.value = formattedValue
|
||||||
|
onChange({
|
||||||
|
...e,
|
||||||
|
type: 'change',
|
||||||
|
target: {
|
||||||
|
...e.target,
|
||||||
|
value: formattedValue,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onBlur(e)
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className={cn('relative w-full', wrapperClassName)}>
|
<div className={cn('relative w-full', wrapperClassName)}>
|
||||||
{showLeftIcon && <RiSearchLine className={cn('absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-components-input-text-placeholder')} />}
|
{showLeftIcon && <RiSearchLine className={cn('absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-components-input-text-placeholder')} />}
|
||||||
@ -74,7 +102,8 @@ const Input = ({
|
|||||||
? (t('common.operation.search') || '')
|
? (t('common.operation.search') || '')
|
||||||
: (t('common.placeholder.input') || ''))}
|
: (t('common.placeholder.input') || ''))}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={props.type === 'number' ? handleNumberChange : onChange}
|
||||||
|
onBlur={props.type === 'number' ? handleNumberBlur : onBlur}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user