Skip to content

Commit 98e2d64

Browse files
authored
Merge pull request #1 from Dhruv-Rathi/master
Add Text-Input
2 parents 53eaf76 + c02af3b commit 98e2d64

9 files changed

Lines changed: 127 additions & 212 deletions

File tree

rollup.config.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import babel from '@rollup/plugin-babel';
33
import commonjs from 'rollup-plugin-commonjs';
44

55
export default {
6-
input: [
7-
'src/index.js',
8-
'src/Base/index.js',
9-
'src/Blue/index.js',
10-
'src/Outline/index.js',
11-
],
6+
input: ['src/index.js', 'src/Base/index.js'],
127
output: [
138
{
149
dir: 'build',

src/Base/Base.stories.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {action} from '@storybook/addon-actions';
2+
import {text} from '@storybook/addon-knobs';
3+
import {storiesOf} from '@storybook/react-native';
4+
import React, {useState} from 'react';
5+
import Input from '.';
6+
import {
7+
StyleSheet,
8+
View,
9+
SafeAreaView,
10+
Text,
11+
Alert,
12+
onChangeText,
13+
} from 'react-native';
14+
15+
storiesOf('Default', module)
16+
.addDecorator(getStory => (
17+
<SafeAreaView
18+
style={{
19+
flex: 1,
20+
justifyContent: 'center',
21+
marginHorizontal: 16,
22+
}}>
23+
{getStory()}
24+
</SafeAreaView>
25+
))
26+
.add('Default Input Text', () => (
27+
<Input
28+
label="Username"
29+
onChangeText={text => onChangeText(text)}
30+
// value={value}
31+
// icon={<Text>+91</Text>}
32+
// iconPosition="left"
33+
// focusColor="#22D3EE"
34+
/>
35+
))
36+
.add('Default Required Field', () => (
37+
<Input
38+
label="Username"
39+
onChangeText={text => onChangeText(text)}
40+
// value={value}
41+
icon={<Text>😊</Text>}
42+
iconPosition="left"
43+
error={'This field is required'}
44+
// borderColor="#FDBA74"
45+
// errorTextStyles={{color: '#FDBA74'}}
46+
/>
47+
));

src/Base/Button.stories.js

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

src/Base/index.js

Lines changed: 78 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,94 @@
11
import React from 'react';
2-
import {ActivityIndicator, Text, View, Pressable} from 'react-native';
2+
import {Text, View, TextInput} from 'react-native';
33

4-
const Button = ({
5-
disabled = false,
6-
onPress,
7-
busy = false,
8-
loaderIcon = <ActivityIndicator color="#fff" />,
9-
busyText = 'Processing..',
4+
const Input = ({
5+
onChangeText,
6+
iconPosition,
7+
icon,
8+
value,
9+
placeholder = 'Enter Text',
10+
label = null,
11+
error,
1012
...props
1113
}) => {
12-
const textStyles = {
13-
...(props.textStyles || {
14-
fontWeight: 'bold',
14+
const [focused, setFocused] = React.useState(false);
15+
const textInputStyles = {
16+
...(props.textInputStyles || {
17+
flex: 1,
18+
width: '100%',
1519
color: props.textColor || '#fff',
1620
letterSpacing: 0,
1721
}),
1822
};
23+
const getFlexDirection = () => {
24+
if (icon && iconPosition) {
25+
if (iconPosition === 'left') {
26+
return 'row';
27+
} else if (iconPosition === 'right') {
28+
return 'row-reverse';
29+
}
30+
}
31+
};
1932

20-
return (
21-
<Pressable
22-
disabledd={disabled}
23-
onPress={() => {
24-
if (!disabled) {
25-
onPress();
26-
}
27-
}}
28-
style={({pressed}) => [
29-
{
30-
backgroundColor: pressed
31-
? props.onPressColor || '#27272A'
32-
: props.backgroundColor || '#18181B',
33-
width: '100%',
34-
borderColor: props.borderColor || '#27272A',
35-
borderWidth: 1,
36-
borderRadius: 4,
37-
paddingVertical: 8,
38-
paddingHorizontal: 4,
39-
alignItems: 'center',
40-
justifyContent: 'center',
41-
},
42-
]}>
43-
{busy === false && (
44-
<View>
45-
{typeof props.children === 'string' ? (
46-
<Text style={textStyles}>{props.children}</Text>
47-
) : (
48-
props.children
49-
)}
50-
</View>
51-
)}
33+
const getBorderColor = () => {
34+
if (error) {
35+
return props.borderColor || '#DC2626';
36+
}
37+
38+
if (focused) {
39+
return props.focusColor || '#52525B';
40+
}
41+
};
5242

53-
{busy === true && (
54-
<View
55-
style={{
56-
...(props.loaderIconWrapperStyles || {
57-
alignItems: 'center',
58-
flexDirection: 'row',
59-
justifyContent: 'center',
60-
}),
61-
}}>
62-
<View
43+
return (
44+
<>
45+
<View style={{...props.labelStyles}}>
46+
{label && <Text>{label}</Text>}
47+
</View>
48+
<View
49+
style={{
50+
...(props.wrapperStyles || {
51+
height: 42,
52+
borderWidth: 1,
53+
borderRadius: 4,
54+
paddingHorizontal: 5,
55+
marginTop: 5,
56+
alignItems: icon ? 'center' : 'baseline',
57+
borderColor: getBorderColor(),
58+
flexDirection: getFlexDirection(),
59+
}),
60+
}}>
61+
<View>{icon && icon}</View>
62+
<TextInput
63+
placeholder={placeholder}
64+
style={textInputStyles}
65+
onChangeText={onChangeText}
66+
value={value}
67+
onFocus={() => {
68+
setFocused(true);
69+
}}
70+
onBlur={() => {
71+
setFocused(false);
72+
}}
73+
{...props}
74+
/>
75+
</View>
76+
<View>
77+
{error && (
78+
<Text
6379
style={{
64-
...(props.loaderStyles || {
65-
marginRight: 20,
80+
...(props.errorTextStyles || {
81+
color: '#DC2626',
82+
paddingTop: 4,
83+
fontSize: 12,
6684
}),
6785
}}>
68-
{loaderIcon}
69-
</View>
70-
71-
<Text style={textStyles}>{busyText}</Text>
72-
</View>
73-
)}
74-
</Pressable>
86+
{error}
87+
</Text>
88+
)}
89+
</View>
90+
</>
7591
);
7692
};
7793

78-
export default Button;
94+
export default Input;

src/Blue/Button.stories.js

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

src/Blue/index.js

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

src/Outline/Button.stories.js

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

src/Outline/index.js

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

storybook/stories/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import '../../src/Base/Button.stories.js';
2-
import '../../src/Blue/Button.stories.js';
3-
import '../../src/Outline/Button.stories.js';
1+
import '../../src/Base/Base.stories.js';

0 commit comments

Comments
 (0)