Files
no-copy-frontend/src/app/ui/inputs/phone-input.tsx
T

38 lines
940 B
TypeScript
Raw Normal View History

'use client'
2026-02-05 19:31:06 +07:00
import { useState, ChangeEvent, useEffect } from 'react';
2025-12-29 18:47:50 +07:00
import { InputMask } from '@react-input/mask';
2025-12-27 12:10:13 +07:00
import styles from '@/app/styles/module/login.module.scss';
interface PhoneInputProps {
phoneState: string | undefined;
2025-12-22 13:02:39 +07:00
validateHandler: (e: ChangeEvent<HTMLInputElement>) => void;
2026-02-05 19:31:06 +07:00
clearCondition?: string | undefined | null
}
2026-02-05 19:31:06 +07:00
export default function PhoneInput({ phoneState, validateHandler, clearCondition }: PhoneInputProps) {
const [phone, setPhone] = useState<string | undefined>(phoneState ? phoneState : '');
useEffect(() => {
if (clearCondition) {
setPhone('');
}
}, [clearCondition])
2025-12-22 17:19:59 +07:00
return (
2025-12-29 18:47:50 +07:00
<InputMask
type="phone"
id="phone"
name="phone"
className={`${styles['form-input']}`}
2025-12-29 18:47:50 +07:00
mask="+7 (___) ___-__-__"
replacement={{ _: /\d/ }}
value={phone}
2025-12-22 13:02:39 +07:00
onChange={(e) => {
2025-12-29 18:47:50 +07:00
setPhone(e.target.value);
2025-12-22 13:02:39 +07:00
validateHandler(e);
}}
2025-12-29 18:47:50 +07:00
placeholder="+7 (999) 123-45-67"
/>
)
}