@bigbinary/neetoui-rn 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ import React, { useContext, useState } from "react";
2
+ import { flexbox, space, border, buttonStyle, typography } from "styled-system";
3
+ import styled, { ThemeContext } from "styled-components/native";
4
+ import propTypes from "@styled-system/prop-types";
5
+ import PropTypes from "prop-types";
6
+ import { Typography, Container } from "@components";
7
+
8
+ export const TextInput = styled.TextInput`
9
+ ${flexbox}
10
+ ${space}
11
+ ${border}
12
+ ${buttonStyle}
13
+ ${typography}
14
+ `;
15
+
16
+ const InputText = ({ theme, text }) => (
17
+ <Container
18
+ bg={theme.colors.background.menubackground}
19
+ justifyContent="center"
20
+ px={2}
21
+ >
22
+ <Typography>{text}</Typography>
23
+ </Container>
24
+ );
25
+
26
+ const LabelText = ({ inline, label }) => (
27
+ <Typography
28
+ numberOfLines={1}
29
+ textStyle="subtext"
30
+ mb={inline ? "12px" : "7px"}
31
+ >
32
+ {label}
33
+ </Typography>
34
+ );
35
+
36
+ const ErrorMessage = ({ error, message, theme }) => {
37
+ if (error) {
38
+ return (
39
+ <Typography textStyle="subtext" color={theme.colors.font.danger}>
40
+ {message}
41
+ </Typography>
42
+ );
43
+ }
44
+ return null;
45
+ };
46
+
47
+ export const Input = ({
48
+ label = "",
49
+ message = "",
50
+ error = false,
51
+ onFocus,
52
+ onBlur,
53
+ inline = false,
54
+ brandRight,
55
+ brandLeft,
56
+ disabled = false,
57
+ ...rest
58
+ }) => {
59
+ const theme = useContext(ThemeContext);
60
+ const [isFocus, setIsFocus] = useState(false);
61
+ const borderColor = error
62
+ ? theme.colors.border.danger
63
+ : theme.colors.border.primary;
64
+
65
+ const handleFocus = e => {
66
+ onFocus && onFocus(e);
67
+ setIsFocus(true);
68
+ };
69
+
70
+ const handleBlur = e => {
71
+ onBlur && onBlur(e);
72
+ setIsFocus(false);
73
+ };
74
+
75
+ const focusStyles = isFocus && {
76
+ borderRadius: 4,
77
+ borderColor: error
78
+ ? "rgba(255, 105, 105, 0.3)"
79
+ : theme.colors.border.grey400,
80
+ borderWidth: inline ? "0px" : "3px",
81
+ borderStyle: "solid",
82
+ };
83
+
84
+ const disabledStyles = disabled && {
85
+ opacity: 0.5,
86
+ bg: theme.colors.background.secondary,
87
+ };
88
+
89
+ const inlineInputStyles = isFocus && {
90
+ backgroundColor: error
91
+ ? theme.colors.border.danger
92
+ : theme.colors.border.base,
93
+ };
94
+
95
+ return (
96
+ <Container mb={20}>
97
+ {!inline && <LabelText inline={inline} label={label} />}
98
+ <Container
99
+ {...focusStyles}
100
+ {...disabledStyles}
101
+ flexDirection={inline && "row"}
102
+ onBlur={handleBlur}
103
+ onFocus={handleFocus}
104
+ >
105
+ {inline && (
106
+ <Container alignSelf="flex-end" maxWidth={100} px={2}>
107
+ <LabelText inline={inline} label={label} />
108
+ </Container>
109
+ )}
110
+ <Container flexDirection="row" width="100%">
111
+ {brandLeft && <InputText theme={theme} text={brandLeft} />}
112
+ <TextInput
113
+ height={40}
114
+ flex={1}
115
+ textStyle="subtext"
116
+ {...rest}
117
+ border={!inline && borderColor}
118
+ editable={!disabled}
119
+ color={error ? theme.colors.font.danger : theme.colors.font.primary}
120
+ />
121
+ {brandRight && <InputText theme={theme} text={brandRight} />}
122
+ </Container>
123
+ </Container>
124
+ {inline && (
125
+ <Container
126
+ backgroundColor={theme.colors.border.primary}
127
+ height={1}
128
+ {...inlineInputStyles}
129
+ />
130
+ )}
131
+ <ErrorMessage theme={theme} error={error} message={message} />
132
+ </Container>
133
+ );
134
+ };
135
+
136
+ Input.propTypes = {
137
+ ...propTypes.flexbox,
138
+ ...propTypes.space,
139
+ ...propTypes.border,
140
+ ...propTypes.buttonStyle,
141
+ label: PropTypes.string.isRequired,
142
+ message: PropTypes.string,
143
+ error: PropTypes.bool,
144
+ inline: PropTypes.bool,
145
+ brandRight: PropTypes.string,
146
+ brandLeft: PropTypes.string,
147
+ disabled: PropTypes.bool,
148
+ children: PropTypes.node,
149
+ };
150
+
151
+ InputText.propTypes = {
152
+ text: PropTypes.string,
153
+ };
154
+
155
+ LabelText.propTypes = {
156
+ inline: PropTypes.bool,
157
+ label: PropTypes.string,
158
+ };
159
+
160
+ ErrorMessage.propTypes = {
161
+ error: PropTypes.bool,
162
+ message: PropTypes.message,
163
+ };
164
+
165
+ TextInput.defaultProps = {
166
+ height: 40,
167
+ border: 1,
168
+ px: 2,
169
+ fontFamily: "inter400",
170
+ fontSize: "14px",
171
+ borderRadius: 2,
172
+ };
@@ -1,3 +1,4 @@
1
1
  export { Button } from "./Button";
2
2
  export { Container } from "./Container";
3
3
  export { Typography } from "./Typography";
4
+ export { Input } from "./Input";
@@ -3,6 +3,7 @@ const defaultColors = {
3
3
  black: "#000000",
4
4
  base: "#2f3941",
5
5
  danger: "#ff6969",
6
+ menubackground: "#f4f5f7",
6
7
  };
7
8
 
8
9
  const greyVarients = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neetoui-rn",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "main": "lib/index.js",
5
5
  "author": "BigBinary",
6
6
  "license": "MIT",