Skip to content

Commit 6981092

Browse files
committed
feat: consolidate and improve inputs
1 parent 8303ae1 commit 6981092

14 files changed

Lines changed: 12305 additions & 14131 deletions

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@babel/preset-env": "7.3.1",
5656
"@babel/preset-react": "7.0.0",
5757
"@babel/preset-typescript": "7.1.0",
58+
"@emotion/core": "^10.0.7",
5859
"@mdx-js/mdx": "0.16.8",
5960
"@semantic-release/changelog": "3.0.2",
6061
"@semantic-release/commit-analyzer": "6.1.0",
@@ -73,6 +74,7 @@
7374
"docz": "0.13.7",
7475
"docz-plugin-snapshots": "0.2.0",
7576
"docz-theme-default": "0.13.7",
77+
"emotion-theming": "^10.0.7",
7678
"husky": "1.3.1",
7779
"jest": "23.6.0",
7880
"jest-canvas-mock": "1.1.0",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from 'react';
2+
import { TextInput as RNTextInput, TouchableOpacity } from 'react-native';
3+
4+
import { Icon } from '../../icons';
5+
import { ThemeContext } from '../../theme';
6+
import TextInputWithIcon, { TextInputWithIconProps } from './TextInputWithIcon';
7+
8+
export interface ClearableTextInputProps extends TextInputWithIconProps {
9+
onClear?: () => void;
10+
}
11+
12+
const ClearableTextInputBase = (props: ClearableTextInputProps) => {
13+
const { onClear, innerRef, onChangeText, ...textInputWithIconProps } = props;
14+
const theme = React.useContext(ThemeContext);
15+
16+
return (
17+
<TextInputWithIcon
18+
ref={innerRef}
19+
rightIcon={
20+
<TouchableOpacity
21+
onPress={() => {
22+
if (onChangeText) onChangeText('');
23+
if (onClear) onClear();
24+
}}
25+
>
26+
<Icon name="x" size={24} color={theme.colors.text.default} />
27+
</TouchableOpacity>
28+
}
29+
onChangeText={onChangeText}
30+
{...textInputWithIconProps}
31+
/>
32+
);
33+
};
34+
35+
export const ClearableTextInput = React.forwardRef<
36+
RNTextInput,
37+
ClearableTextInputProps
38+
>((props, ref) => <ClearableTextInputBase {...props} innerRef={ref} />);
39+
40+
export default ClearableTextInput;

src/components/Inputs/Inputs.mdx

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
name: Inputs
3+
menu: Components
4+
---
5+
6+
import { Playground, PropsTable } from 'docz';
7+
import { State } from 'react-powerplug';
8+
9+
import { Heading, Label } from '../Typography';
10+
import { Box, Spacing } from '../Layout';
11+
import TextInput from './TextInput';
12+
import ClearableTextInput from './ClearableTextInput';
13+
import TextArea from './TextArea';
14+
import PhoneNumberInput from './PhoneNumberInput';
15+
16+
## TextInput
17+
18+
<Playground>
19+
<Box marginBottom={24} width={360}>
20+
<Label size="medium">Medium (default)</Label>
21+
<TextInput placeholder="With placeholder" />
22+
</Box>
23+
<Box marginBottom={24} width={360}>
24+
<Label size="medium">Disabled</Label>
25+
<TextInput value="This is disabled" isDisabled />
26+
</Box>
27+
<Box marginBottom={24} width={360}>
28+
<Label size="medium">Is Invalid</Label>
29+
<TextInput isInvalid />
30+
</Box>
31+
<Box marginBottom={24}>
32+
<Label size="small">Small</Label>
33+
<TextInput size="small" />
34+
</Box>
35+
<Box marginBottom={24}>
36+
<Label size="medium">Medium</Label>
37+
<TextInput size="medium" />
38+
</Box>
39+
<Box marginBottom={24}>
40+
<Label size="large">Large</Label>
41+
<TextInput size="large" />
42+
</Box>
43+
</Playground>
44+
45+
## TextArea
46+
47+
<Playground>
48+
<Box marginBottom={24} width={360}>
49+
<Label size="medium">Medium (default)</Label>
50+
<TextArea placeholder="With placeholder" />
51+
</Box>
52+
<Box marginBottom={24} width={360}>
53+
<Label size="medium">Disabled</Label>
54+
<TextArea value="This is disabled" isDisabled />
55+
</Box>
56+
<Box marginBottom={24} width={360}>
57+
<Label size="medium">Is Invalid</Label>
58+
<TextArea isInvalid />
59+
</Box>
60+
<Box marginBottom={24}>
61+
<Label size="small">Small</Label>
62+
<TextArea size="small" />
63+
</Box>
64+
<Box marginBottom={24}>
65+
<Label size="medium">Medium</Label>
66+
<TextArea size="medium" />
67+
</Box>
68+
<Box marginBottom={24}>
69+
<Label size="large">Large</Label>
70+
<TextArea size="large" />
71+
</Box>
72+
</Playground>
73+
74+
## ClearableTextInput
75+
76+
<Playground>
77+
<Box marginBottom={24}>
78+
<State initial={{ value: '' }}>
79+
{({ state, setState }) => (
80+
<ClearableTextInput
81+
onChangeText={text => setState({ value: text })}
82+
value={state.value}
83+
onClear={() => {
84+
console.log('Cleared!');
85+
}}
86+
placeholder="Clearable text input"
87+
/>
88+
)}
89+
</State>
90+
</Box>
91+
</Playground>
92+
93+
## PhoneNumberInput
94+
95+
### Usage
96+
97+
<Playground>
98+
<State initial={{ countryCode: 'US', phoneNumber: '' }}>
99+
{({ state, setState }) => (
100+
<PhoneNumberInput
101+
header={
102+
<Spacing marginVertical={3} paddingHorizontal={2}>
103+
<Heading size="xxxlarge">Select your country</Heading>
104+
</Spacing>
105+
}
106+
onChangeCountryCode={countryCode => setState({ countryCode })}
107+
onChangePhoneNumber={phoneNumber => setState({ phoneNumber })}
108+
phoneNumber={state.phoneNumber}
109+
countryCode={state.countryCode}
110+
placeholder="Enter your phone number"
111+
/>
112+
)}
113+
</State>
114+
</Playground>
115+
116+
### Props
117+
118+
<PropsTable of={PhoneNumberInput} />

src/components/Inputs/PhoneNumberInput.mdx

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)