chore: input slider

This commit is contained in:
Joel 2024-08-06 15:33:38 +08:00
parent fca5af5073
commit 53a3c199ec
2 changed files with 19 additions and 35 deletions

View File

@ -21,9 +21,17 @@ const InputNumberWithSlider: FC<Props> = ({
onChange, onChange,
}) => { }) => {
const handleBlur = useCallback(() => { const handleBlur = useCallback(() => {
if (value === undefined || value === null) if (value === undefined || value === null) {
onChange(defaultValue) onChange(defaultValue)
}, [defaultValue, onChange, value]) return
}
if (max !== undefined && value > max) {
onChange(max)
return
}
if (min !== undefined && value < min)
onChange(min)
}, [defaultValue, max, min, onChange, value])
const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { const handleChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
onChange(parseFloat(e.target.value)) onChange(parseFloat(e.target.value))
@ -33,7 +41,7 @@ const InputNumberWithSlider: FC<Props> = ({
<div className='flex justify-between items-center h-8 space-x-2'> <div className='flex justify-between items-center h-8 space-x-2'>
<input <input
value={value} value={value}
className='shrink-0 block pl-3 w-12 h-8 appearance-none outline-none rounded-lg bg-gray-100 text-[13px] text-gra-900' className='shrink-0 block pl-3 w-12 h-8 appearance-none outline-none rounded-lg bg-components-input-bg-normal text-[13px] text-components-input-text-filled'
type='number' type='number'
min={min} min={min}
max={max} max={max}

View File

@ -3,10 +3,10 @@ import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import type { Limit } from '../types' import type { Limit } from '../types'
import InputNumberWithSlider from '../../_base/components/input-number-with-slider'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import Field from '@/app/components/workflow/nodes/_base/components/field' import Field from '@/app/components/workflow/nodes/_base/components/field'
import Switch from '@/app/components/base/switch' import Switch from '@/app/components/base/switch'
import Slider from '@/app/components/base/slider'
const i18nPrefix = 'workflow.nodes.listFilter' const i18nPrefix = 'workflow.nodes.listFilter'
const LIMIT_SIZE_MIN = 1 const LIMIT_SIZE_MIN = 1
@ -49,15 +49,6 @@ const LimitConfig: FC<Props> = ({
}) })
}, [onChange, config]) }, [onChange, config])
const handleBlur = useCallback(() => {
const payload = config
if (!payload)
return
if (payload.size === undefined || payload.size === null)
handleLimitSizeChange(LIMIT_SIZE_DEFAULT)
}, [handleLimitSizeChange, config])
return ( return (
<div className={cn(className)}> <div className={cn(className)}>
<Field <Field
@ -73,28 +64,13 @@ const LimitConfig: FC<Props> = ({
> >
{payload?.enabled {payload?.enabled
? ( ? (
<div className='flex justify-between items-center h-8 space-x-2'> <InputNumberWithSlider
<input value={payload?.size || LIMIT_SIZE_DEFAULT}
value={(payload?.size || LIMIT_SIZE_DEFAULT) as number} min={LIMIT_SIZE_MIN}
className='shrink-0 block pl-3 w-12 h-8 appearance-none outline-none rounded-lg bg-gray-100 text-[13px] text-gra-900' max={LIMIT_SIZE_MAX}
type='number' onChange={handleLimitSizeChange}
min={LIMIT_SIZE_MIN} readonly={readonly || !payload?.enabled}
max={LIMIT_SIZE_MAX} />
step={1}
onChange={e => handleLimitSizeChange(e.target.value)}
onBlur={handleBlur}
disabled={readonly || !payload?.enabled}
/>
<Slider
className='grow'
value={(payload?.size || LIMIT_SIZE_DEFAULT) as number}
min={LIMIT_SIZE_MIN}
max={LIMIT_SIZE_MAX}
step={1}
onChange={handleLimitSizeChange}
disabled={readonly || !payload?.enabled}
/>
</div>
) )
: null} : null}
</Field> </Field>