2022-09-21 15:56:51 +02:00
|
|
|
import React, { useRef } from 'react'
|
|
|
|
import { useClickAway } from 'react-use'
|
2022-04-15 18:11:51 +02:00
|
|
|
import NumberInput from '../shared/NumberInput'
|
|
|
|
import SettingBlock from './SettingBlock'
|
|
|
|
|
|
|
|
interface NumberInputSettingProps {
|
|
|
|
title: string
|
2022-09-15 16:21:27 +02:00
|
|
|
allowFloat?: boolean
|
2022-07-18 15:20:52 +02:00
|
|
|
desc?: string
|
2022-04-15 18:11:51 +02:00
|
|
|
value: string
|
|
|
|
suffix?: string
|
2022-09-15 16:21:27 +02:00
|
|
|
width?: number
|
|
|
|
widthUnit?: string
|
|
|
|
disable?: boolean
|
2022-04-15 18:11:51 +02:00
|
|
|
onValue: (val: string) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
function NumberInputSetting(props: NumberInputSettingProps) {
|
2022-09-15 16:21:27 +02:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
allowFloat,
|
|
|
|
desc,
|
|
|
|
value,
|
|
|
|
suffix,
|
|
|
|
onValue,
|
|
|
|
width,
|
|
|
|
widthUnit,
|
|
|
|
disable,
|
|
|
|
} = props
|
2022-04-15 18:11:51 +02:00
|
|
|
|
2022-09-21 15:56:51 +02:00
|
|
|
const ref = useRef(null)
|
|
|
|
|
|
|
|
useClickAway<MouseEvent>(ref, () => {
|
|
|
|
if (ref?.current) {
|
|
|
|
const input = ref.current as HTMLInputElement
|
|
|
|
input.blur()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-04-15 18:11:51 +02:00
|
|
|
return (
|
|
|
|
<SettingBlock
|
|
|
|
className="sub-setting-block"
|
|
|
|
title={title}
|
2022-07-18 15:20:52 +02:00
|
|
|
desc={desc}
|
2022-04-15 18:11:51 +02:00
|
|
|
input={
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
gap: '8px',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<NumberInput
|
2022-09-15 16:21:27 +02:00
|
|
|
allowFloat={allowFloat}
|
|
|
|
style={{ width: `${width}${widthUnit}` }}
|
2022-09-20 16:43:20 +02:00
|
|
|
value={value}
|
2022-09-15 16:21:27 +02:00
|
|
|
disabled={disable}
|
2022-04-15 18:11:51 +02:00
|
|
|
onValue={onValue}
|
2022-09-21 15:56:51 +02:00
|
|
|
ref={ref}
|
2022-04-15 18:11:51 +02:00
|
|
|
/>
|
|
|
|
{suffix && <span>{suffix}</span>}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-09-15 16:21:27 +02:00
|
|
|
NumberInputSetting.defaultProps = {
|
|
|
|
allowFloat: false,
|
|
|
|
width: 80,
|
|
|
|
widthUnit: 'px',
|
|
|
|
disable: false,
|
|
|
|
}
|
|
|
|
|
2022-04-15 18:11:51 +02:00
|
|
|
export default NumberInputSetting
|