import React, { useRef, useState } from 'react'; import { PhoneField } from '@lendi/ui/PhoneField'; import { Button } from '@lendi/ui/Button'; import { Spacer } from '@lendi/ui/Layout'; export const Interactive = (args) => ; Interactive.args = { label: 'Phone number', }; Interactive.argTypes = { inlineAction: { control: { type: 'radio', options: ['clear'] }, }, variant: { control: { type: 'radio', options: ['default', 'mobile'] }, }, }; export const Variants = () => ( ); export const ClearAction = () => { const [value, setValue] = useState(''); const inputRef = useRef(); const onChange = (e) => { setValue(e.target.value); }; return ( ); }; export const ClearActionWithValue = () => { const defaultValue = '9001'; const [value, setValue] = useState(defaultValue); const inputRef = useRef(); const onChange = (e) => { setValue(e.target.value); }; return ( ); }; export const Controlled = (args) => { const [value, setValue] = useState(''); const handleChange = (e) => { console.log(e.target.value); setValue(e.target.value); }; return ; }; Controlled.args = { label: 'Label', placeholder: 'Placeholder text', helpText: 'Help text', }; export const Uncontrolled = () => { const inputRef = useRef(null); const showVal = () => { console.log(inputRef.current.value); }; return ( ); }; export const Errors = () => ( ); export const Labels = () => ( ); export const Widths = () => ( ); export const Validation = () => { const [value, setValue] = useState(''); const [validationState, setValidationState] = useState<'valid' | 'invalid'>('valid'); const [mobileValue, setMobileValue] = useState(''); const [validationMobileState, setValidationMobileState] = useState<'valid' | 'invalid'>('valid'); const handlePhoneChange = (e) => { setValue(e.target.value); console.log(e.target.validity); if (e.target.validity.patternMismatch) { setValidationState('invalid'); } else { setValidationState('valid'); } }; const handleMobileChange = (e) => { setMobileValue(e.target.value); console.log(e.target.validity); if (e.target.validity.patternMismatch) { setValidationMobileState('invalid'); } else { setValidationMobileState('valid'); } }; return ( ); };