Skip to content

Commit 0f9d751

Browse files
committed
fix: export phone number input
1 parent 1e5bb14 commit 0f9d751

5 files changed

Lines changed: 45 additions & 24 deletions

File tree

src/components/Inputs/PhoneNumberInput.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ menu: Components
66
import { Playground, PropsTable } from 'docz';
77
import PhoneNumberInput from './PhoneNumberInput';
88
import { State } from 'react-powerplug';
9+
import { Spacing } from '../Layout';
10+
import { Heading } from '../Typography';
911

1012
## Usage
1113

@@ -15,7 +17,11 @@ import { State } from 'react-powerplug';
1517
<State initial={{ countryCode: 'US', phoneNumber: '' }}>
1618
{({ state, setState }) => (
1719
<PhoneNumberInput
18-
label="Select your country"
20+
header={
21+
<Spacing marginVertical={3} paddingHorizontal={2}>
22+
<Heading size="xxxlarge">Select your country</Heading>
23+
</Spacing>
24+
}
1925
onChangeCountryCode={countryCode => setState({ countryCode })}
2026
onChangePhoneNumber={phoneNumber => setState({ phoneNumber })}
2127
phoneNumber={state.phoneNumber}

src/components/Inputs/PhoneNumberInput.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import { Icon } from '../../icons';
88
import { Theme, withTheme } from '../../theme';
99
import { mergeStyles, ReplaceReturnType } from '../../utils/mergeStyles';
1010
import { Button } from '../Button';
11-
import { Spacing } from '../Layout';
1211
import { ListItem } from '../ListItem';
1312
import { Modal } from '../Modal';
1413
import ModalContent from '../Modal/ModalContent';
15-
import { Heading } from '../Typography';
1614
import {
1715
GetPhoneNumberInputStyles,
1816
getPhoneNumberInputStyles,
@@ -22,12 +20,13 @@ import TextInput from './TextInput';
2220

2321
export interface PhoneNumberInputProps {
2422
countryCode?: string;
23+
isInvalid?: boolean;
2524
onChangeCountryCode?: (countryCode: string) => void;
2625
phoneNumber?: string;
2726
onChangePhoneNumber?: (phoneNumber: string) => void;
2827
theme: Theme;
2928
/** Label displayed when showing country selection */
30-
label?: string;
29+
header?: React.ReactElement<any>;
3130
placeholder?: string;
3231
getStyles?: ReplaceReturnType<
3332
GetPhoneNumberInputStyles,
@@ -50,9 +49,10 @@ const PhoneNumberInputBase = (props: PhoneNumberInputProps) => {
5049
onChangeCountryCode,
5150
onChangePhoneNumber,
5251
placeholder,
53-
label,
52+
header,
5453
theme,
5554
getStyles,
55+
isInvalid,
5656
} = props;
5757

5858
const { containerStyle } = mergeStyles(getPhoneNumberInputStyles, getStyles)(
@@ -89,13 +89,7 @@ const PhoneNumberInputBase = (props: PhoneNumberInputProps) => {
8989
<Modal visible={on}>
9090
<ModalContent onClose={() => set(false)}>
9191
<FlatList
92-
ListHeaderComponent={
93-
label ? (
94-
<Spacing marginVertical={3} paddingHorizontal={2}>
95-
<Heading size="xxxlarge">{label}</Heading>
96-
</Spacing>
97-
) : null
98-
}
92+
ListHeaderComponent={header}
9993
keyExtractor={item => item.key}
10094
getItemLayout={(data, index) => ({
10195
index,
@@ -135,6 +129,7 @@ const PhoneNumberInputBase = (props: PhoneNumberInputProps) => {
135129
borderTopLeftRadius: 0,
136130
},
137131
})}
132+
isInvalid={isInvalid}
138133
keyboardType="number-pad"
139134
value={phoneNumber}
140135
onChangeText={onChangePhoneNumber}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
3+
import { withTheme } from '../../theme';
4+
import { FormField, FormFieldProps } from '../Form';
5+
import PhoneNumberInput, { PhoneNumberInputProps } from './PhoneNumberInput';
6+
7+
export interface PhoneNumberInputFieldProps
8+
extends FormFieldProps,
9+
PhoneNumberInputProps {}
10+
11+
const PhoneNumberInputFieldBase = (props: PhoneNumberInputFieldProps) => {
12+
const { label, error, description, ...passThroughProps } = props;
13+
14+
return (
15+
<FormField label={label} error={error} description={description}>
16+
<PhoneNumberInput isInvalid={!!error} {...passThroughProps} />
17+
</FormField>
18+
);
19+
};
20+
21+
export const PhoneNumberInputField = withTheme(PhoneNumberInputFieldBase);
22+
export default PhoneNumberInputField;

src/components/Inputs/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ export {
33
default as TextInputField,
44
TextInputFieldProps,
55
} from './TextInputField';
6-
export { default as TextArea, TextAreaProps } from '../Inputs/TextArea';
7-
export { default as TextAreaField } from '../Inputs/TextAreaField';
6+
export { default as TextArea, TextAreaProps } from './TextArea';
7+
export { default as TextAreaField, TextAreaFieldProps } from './TextAreaField';
8+
export {
9+
default as PhoneNumberInput,
10+
PhoneNumberInputProps,
11+
} from './PhoneNumberInput';
12+
export {
13+
default as PhoneNumberInputField,
14+
PhoneNumberInputFieldProps,
15+
} from './PhoneNumberInputField';

src/theme/default-theme/foundational-styles/colors.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ import palette from './palette';
33

44
// tslint:disable object-literal-sort-keys
55

6-
/**
7-
* This object are functional colors being used the default theme.
8-
* A required property is required by the default theme NOT by Evergreen itself.
9-
*/
106
const colors: Colors = {
11-
/**
12-
* Available on Pane as `<Pane background="tint1" />`
13-
*/
147
background: {
158
overlay: 'rgba(0,0,0,0.3)',
169
plain: 'white',
@@ -53,9 +46,6 @@ const colors: Colors = {
5346
},
5447
},
5548

56-
/**
57-
* Available on Pane as `<Pane borderBottom borderRight="muted" />`
58-
*/
5949
border: {
6050
default: palette.neutral.light,
6151
muted: '#EDF0F2',

0 commit comments

Comments
 (0)