Skip to content

Commit

Permalink
feat(TelInput): add FormField in TelInput
Browse files Browse the repository at this point in the history
  • Loading branch information
neighborhood999 committed Dec 12, 2019
1 parent e578a2b commit 54502a1
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions packages/tailor-ui/src/TelInput/TelInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import IntlTelInput from 'react-intl-tel-input';
import React, { FC, MouseEventHandler } from 'react';
import React, { ChangeEvent, FC, MouseEventHandler } from 'react';

import { mergeEventProps } from '@tailor-ui/utils';

import { useFormField } from '../FormField';

import StyledTelInput from './style';

Expand All @@ -23,18 +27,33 @@ const TelInput: FC<TelInputProps> = ({
onChange,
onBlur,
...props
}) => (
<StyledTelInput>
<IntlTelInput
fieldId={id}
fieldName={name}
onPhoneNumberChange={onChange}
onPhoneNumberBlur={onBlur}
format
preferredCountries={['tw']}
{...props}
/>
</StyledTelInput>
);
}) => {
const [invalid, labelId, setValue] = useFormField({
id,
value: props.value,
defaultValue: props.defaultValue,
});
return (
<StyledTelInput
id={labelId}
invalid={invalid}
{...mergeEventProps(props, {
onChange: (event: ChangeEvent<HTMLInputElement>) => {
setValue(event.currentTarget.value);
},
})}
>
<IntlTelInput
fieldId={id}
fieldName={name}
onPhoneNumberChange={onChange}
onPhoneNumberBlur={onBlur}
format
preferredCountries={['tw']}
{...props}
/>
</StyledTelInput>
);
};

export { TelInput };

0 comments on commit 54502a1

Please sign in to comment.