import { useEffect, useRef } from 'react'; import { IoEye, IoEyeOffOutline } from 'react-icons/io5'; import { Input } from '@chakra-ui/react'; import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn'; import { tooltipDelayMid } from '../../../ontimeConfig'; import style from './InputRow.module.scss'; interface InputRowProps { label: string; placeholder: string; text: string; visible: boolean; actionHandler: () => void; changeHandler: (newValue: string) => void; } export default function InputRow(props: InputRowProps) { const { label, placeholder, text, visible, actionHandler, changeHandler } = props; const inputRef = useRef(null); const cursorPositionRef = useRef(0); // sync cursor position with text useEffect(() => { if (inputRef.current) { inputRef.current.selectionStart = cursorPositionRef.current; inputRef.current.selectionEnd = cursorPositionRef.current; } }, [text]); const handleInputChange = (event: React.ChangeEvent) => { cursorPositionRef.current = event.target.selectionStart ?? 0; changeHandler(event.target.value); }; return (
: } variant={visible ? 'ontime-filled' : 'ontime-subtle'} size='sm' />
); }