From 28f04d9b1ebb3d217e96e40327aeeedcd47ed4dd Mon Sep 17 00:00:00 2001 From: Aziz Khambati Date: Wed, 10 Oct 2018 17:23:48 +0530 Subject: [PATCH] Fix Phone Number Input (#107) * Fix Phone Number Input * synthetic fixes --- src/components/PhoneNumberInput.tsx | 48 ++++++++++++---------- src/components/typings/PhoneNumberInput.ts | 20 ++++----- src/components/typings/Select.ts | 1 - stories/phonenumberinput.story.tsx | 16 ++++++-- 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/components/PhoneNumberInput.tsx b/src/components/PhoneNumberInput.tsx index a42e8420..d64a49dd 100644 --- a/src/components/PhoneNumberInput.tsx +++ b/src/components/PhoneNumberInput.tsx @@ -1,50 +1,56 @@ import * as React from "react"; import Select from "./Select"; import Input from "./Input"; -import Option from "./Option"; -import { - PhoneNumberInputProps, - PhoneNumberInputState -} from "./typings/PhoneNumberInput"; +import { cx } from "emotion"; +import { PhoneNumberInputProps } from "./typings/PhoneNumberInput"; import { wrapper, selectStyle } from "./styles/PhoneNumberInput.styles"; export default class PhoneNumberInput extends React.Component< - PhoneNumberInputProps, - PhoneNumberInputState + PhoneNumberInputProps > { - onCountrySelect = country_code => { + onCountrySelect = countryCode => { this.props.onChange({ - country_code: country_code, + countryCode, phone: this.props.phone }); }; + onNumberChange = (value: string) => { if (!value.match(/^\d*$/)) { return; } this.props.onChange({ - country_code: this.props.country_code, + countryCode: this.props.countryCode, phone: value }); }; + render() { - const { countries, phone, country_code } = this.props; + const { + phone, + countryCode, + className, + selectProps, + inputProps, + placeholder + } = this.props; return ( -
+
- +
); } diff --git a/src/components/typings/PhoneNumberInput.ts b/src/components/typings/PhoneNumberInput.ts index d4f70cf3..7bb05d99 100644 --- a/src/components/typings/PhoneNumberInput.ts +++ b/src/components/typings/PhoneNumberInput.ts @@ -1,18 +1,16 @@ -export interface Country { - id: number; - name: string; - country_code: string; -} +import { SelectProps } from "./Select"; +import { InputProps } from "./Input"; export interface PhoneNumberInputProps { - country_code: string; + countryCode: string; phone: string; onChange: ( - { country_code, phone }: { country_code: string; phone: string } + { countryCode, phone }: { countryCode: string; phone: string } ) => void; - countries: Country[]; -} -export interface PhoneNumberInputState { - country?: Country; + // Optional + className?: string; + selectProps?: Partial; + inputProps?: Partial; + placeholder?: string; } diff --git a/src/components/typings/Select.ts b/src/components/typings/Select.ts index d354b11b..c8d33cc5 100644 --- a/src/components/typings/Select.ts +++ b/src/components/typings/Select.ts @@ -7,7 +7,6 @@ export interface SelectProps { placeholder: string; required?: boolean; errorMessage?: string; - children: React.ReactNodeArray; value?: string; selected?: Selected; multiSelect?: boolean; diff --git a/stories/phonenumberinput.story.tsx b/stories/phonenumberinput.story.tsx index 1ca984fe..14f869d8 100644 --- a/stories/phonenumberinput.story.tsx +++ b/stories/phonenumberinput.story.tsx @@ -4,6 +4,7 @@ import PhoneNumberInput from "../src/components/PhoneNumberInput"; // import { boolean, select, text } from "@storybook/addon-knobs"; // import { css } from "emotion"; import { withState } from "@dump247/storybook-state"; +import Option from "../src/components/Option"; // const className = css({ // width: 400 @@ -920,10 +921,17 @@ storiesOf("PhoneNumberInput", module).add( "Material", withState({})(({ store }) => ( store.set({ country_code, phone })} - /> + onChange={({ countryCode, phone }) => store.set({ countryCode, phone })} + > + {countries.map(country => ( + )) );