@servesall/atoms 1.1.7 → 1.1.10

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.
@@ -24,6 +24,8 @@ const Input = ({
24
24
  keyboardVerticalOffset = 0,
25
25
  hasError = false,
26
26
  error,
27
+ isRightBound = false,
28
+ isLeftBound = false,
27
29
  }) => {
28
30
  const [isFocused, setIsFocused] = useState(false);
29
31
  const [textValue, setTextValue] = useState(value || defaultValue);
@@ -50,6 +52,8 @@ const Input = ({
50
52
  }}
51
53
  >
52
54
  <BorderWrapper
55
+ isRightBound={isRightBound}
56
+ isLeftBound={isLeftBound}
53
57
  active={isFocused}
54
58
  color={
55
59
  !hasError
@@ -0,0 +1,23 @@
1
+ import styled from "styled-components/native";
2
+
3
+ export const InputWrapper = styled.Pressable`
4
+ min-height: 70px;
5
+ `;
6
+
7
+ export const InputElement = styled.TextInput`
8
+ min-height: 40px;
9
+ font-family: ${(props) => props.theme.fontFamily2};
10
+ font-size: ${(props) => props.theme.small};
11
+ color: ${(props) => props.theme.color2};
12
+ background-color: ${(props) =>
13
+ props.active ? props.theme.color1 : props.theme.color10};
14
+ `;
15
+ export const BorderWrapper = styled.View`
16
+ min-height: 70px;
17
+ padding-top: 26px;
18
+ border-width: 2px;
19
+ border-color: ${(props) => props.color};
20
+ border-radius: ${(props) => props.theme.borderRadiusSmall};
21
+ background-color: ${(props) =>
22
+ props.active ? props.theme.color1 : props.theme.color10};
23
+ `;
@@ -0,0 +1,46 @@
1
+ import React, { useEffect } from "react";
2
+ import Animated, {
3
+ Easing,
4
+ useAnimatedStyle,
5
+ useSharedValue,
6
+ withTiming,
7
+ } from "react-native-reanimated";
8
+
9
+ const PlaceholderElement = React.memo(({ children, active }) => {
10
+ const top = useSharedValue(active ? 10 : 30);
11
+
12
+ const animatedStyle = useAnimatedStyle(() => {
13
+ return {
14
+ top: withTiming(top.value, {
15
+ duration: 250,
16
+ easing: Easing.bezier(0.19, 1.0, 0.22, 1.0),
17
+ }),
18
+ };
19
+ });
20
+
21
+ useEffect(() => {
22
+ if (active) {
23
+ top.value = 10;
24
+ }
25
+ if (!active) {
26
+ top.value = 30;
27
+ }
28
+ }, [active]);
29
+
30
+ return (
31
+ <Animated.View
32
+ style={[
33
+ {
34
+ position: "absolute",
35
+ zIndex: 1,
36
+ justifyContent: "center",
37
+ },
38
+ animatedStyle,
39
+ ]}
40
+ >
41
+ {children}
42
+ </Animated.View>
43
+ );
44
+ });
45
+
46
+ export default PlaceholderElement;
@@ -0,0 +1,151 @@
1
+ import React, { useEffect, useState, useRef } from "react";
2
+ import { H4 } from "../../Text";
3
+ import { MarginHorizontal, Row, Box } from "../../Layout";
4
+ import { KeyboardAvoidingView, Platform } from "react-native";
5
+ import { InputWrapper, InputElement, BorderWrapper } from "./Animated.style";
6
+ import Placeholder from "./Placeholder";
7
+
8
+ const InputPhone = ({
9
+ children,
10
+ style,
11
+ borderColorIdle,
12
+ borderColorActive,
13
+ borderColorError,
14
+ textChangePrefix = () => {},
15
+ textChangeNumber = () => {},
16
+ onPress = () => {},
17
+ valuePrefix,
18
+ valueNumber,
19
+ defaultValuePrefix,
20
+ defaultValueNumber,
21
+ multiline = false,
22
+ numberOfLines = 1,
23
+ maxLength = 1000,
24
+ autoFocus = false,
25
+ keyboardType,
26
+ editable = true,
27
+ keyboardVerticalOffset = 0,
28
+ hasError = false,
29
+ error,
30
+ }) => {
31
+ const [isFocused, setIsFocused] = useState(false);
32
+ const [textValue, setTextValue] = useState(valuePrefix || defaultValuePrefix);
33
+ const [isFocusedPrefix, setIsFocusedPrefix] = useState(false);
34
+ const [textPrefixValue, setTextPrefixValue] = useState(
35
+ valueNumber || defaultValueNumber
36
+ );
37
+ const inputRef = useRef();
38
+
39
+ useEffect(() => {
40
+ textChangeNumber(textValue);
41
+ }, [textValue]);
42
+
43
+ useEffect(() => {
44
+ textChangePrefix(textPrefixValue);
45
+ }, [textPrefixValue]);
46
+
47
+ useEffect(() => {
48
+ autoFocus && inputRef.current?.focus();
49
+ }, [autoFocus]);
50
+
51
+ return (
52
+ <KeyboardAvoidingView
53
+ behavior={Platform.OS === "ios" ? "padding" : "height"}
54
+ keyboardVerticalOffset={keyboardVerticalOffset}
55
+ >
56
+ <InputWrapper
57
+ onPress={() => {
58
+ onPress();
59
+ editable && setIsFocused(true);
60
+ editable && inputRef.current?.focus();
61
+ }}
62
+ >
63
+ <BorderWrapper
64
+ active={isFocused}
65
+ color={
66
+ !hasError
67
+ ? isFocused
68
+ ? borderColorActive
69
+ : borderColorIdle
70
+ : borderColorError
71
+ }
72
+ >
73
+ <Row style={{ backgroundColor: "red", width: "100%" }}>
74
+ <Box>
75
+ <Placeholder
76
+ active={
77
+ isFocusedPrefix ||
78
+ (textPrefixValue && textPrefixValue.length > 0) ||
79
+ (valuePrefix && valuePrefix.length > 0)
80
+ }
81
+ >
82
+ <MarginHorizontal>
83
+ {!hasError ? (
84
+ children[0]
85
+ ) : (
86
+ <H4 color={borderColorError}>{error || hasError}</H4>
87
+ )}
88
+ </MarginHorizontal>
89
+ </Placeholder>
90
+ </Box>
91
+ <Box>
92
+ <Placeholder
93
+ active={
94
+ isFocused ||
95
+ (textValue && textValue.length > 0) ||
96
+ (valueNumber && valueNumber.length > 0)
97
+ }
98
+ >
99
+ <MarginHorizontal>
100
+ {!hasError ? (
101
+ children[1]
102
+ ) : (
103
+ <H4 color={borderColorError}>{error || hasError}</H4>
104
+ )}
105
+ </MarginHorizontal>
106
+ </Placeholder>
107
+ </Box>
108
+ </Row>
109
+
110
+ <MarginHorizontal>
111
+ <Row>
112
+ <InputElement
113
+ onFocus={() => setIsFocusedPrefix(true)}
114
+ onBlur={() => setIsFocusedPrefix(false)}
115
+ onChangeText={(text) => setTextPrefixValue(text)}
116
+ defaultValue={defaultValuePrefix}
117
+ value={valuePrefix}
118
+ multiline={multiline}
119
+ numberOfLines={numberOfLines}
120
+ maxLength={maxLength}
121
+ autoFocus={autoFocus}
122
+ keyboardType={keyboardType}
123
+ editable={editable}
124
+ active={isFocusedPrefix}
125
+ style={style}
126
+ />
127
+ <InputElement
128
+ ref={inputRef}
129
+ onFocus={() => setIsFocused(true)}
130
+ onBlur={() => setIsFocused(false)}
131
+ onChangeText={(text) => setTextValue(text)}
132
+ defaultValue={defaultValueNumber}
133
+ value={valueNumber}
134
+ multiline={multiline}
135
+ numberOfLines={numberOfLines}
136
+ maxLength={maxLength}
137
+ autoFocus={autoFocus}
138
+ keyboardType={keyboardType}
139
+ editable={editable}
140
+ active={isFocused}
141
+ style={style}
142
+ />
143
+ </Row>
144
+ </MarginHorizontal>
145
+ </BorderWrapper>
146
+ </InputWrapper>
147
+ </KeyboardAvoidingView>
148
+ );
149
+ };
150
+
151
+ export default InputPhone;
@@ -2,5 +2,6 @@ import Input from "./Animated";
2
2
  import AnimatedPlaceholder from "./AnimatedPlaceholder";
3
3
  import InputOtp from "./Otp";
4
4
  import InputNormal from "./InputNormal";
5
+ import InputPhone from "./PhoneNumber";
5
6
 
6
- export { Input, AnimatedPlaceholder, InputOtp, InputNormal };
7
+ export { Input, AnimatedPlaceholder, InputOtp, InputNormal, InputPhone };
@@ -105,6 +105,18 @@ export const PaddingBottomElement = styled.View`
105
105
  ${(props) => props.style};
106
106
  `;
107
107
 
108
+ export const PaddingLeftElement = styled.View`
109
+ padding-left: ${(props) => props.theme.padding};
110
+ flex-direction: ${(props) => props.flexDirection || DEFAULT_FLEX_DIRECTION};
111
+ ${(props) => props.style};
112
+ `;
113
+
114
+ export const PaddingRightElement = styled.View`
115
+ padding-right: ${(props) => props.theme.padding};
116
+ flex-direction: ${(props) => props.flexDirection || DEFAULT_FLEX_DIRECTION};
117
+ ${(props) => props.style};
118
+ `;
119
+
108
120
  export const RowElement = styled.View`
109
121
  flex-direction: row;
110
122
  ${(props) => props.style};
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { PaddingLeftElement } from "./Layout.style";
3
+
4
+ const PaddingLeft = ({ children, style, direction = false }) => {
5
+ return (
6
+ <PaddingLeftElement style={style} flexDirection={direction}>
7
+ {children}
8
+ </PaddingLeftElement>
9
+ );
10
+ };
11
+
12
+ export default PaddingLeft;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { PaddingRightElement } from "./Layout.style";
3
+
4
+ const PaddingRight = ({ children, style, direction = false }) => {
5
+ return (
6
+ <PaddingRightElement style={style} flexDirection={direction}>
7
+ {children}
8
+ </PaddingRightElement>
9
+ );
10
+ };
11
+
12
+ export default PaddingRight;
@@ -12,6 +12,8 @@ import PaddingHorizontal from "./PaddingHorizontal";
12
12
  import PaddingVertical from "./PaddingVertical";
13
13
  import PaddingTop from "./PaddingTop";
14
14
  import PaddingBottom from "./PaddingBottom";
15
+ import PaddingLeft from "./PaddingLeft";
16
+ import PaddingRight from "./PaddingRight";
15
17
  import Row from "./Row";
16
18
  import Stretch from "./Stretch";
17
19
  import FullScreen from "./FullScreen";
@@ -34,6 +36,8 @@ export {
34
36
  PaddingVertical,
35
37
  PaddingTop,
36
38
  PaddingBottom,
39
+ PaddingLeft,
40
+ PaddingRight,
37
41
  Row,
38
42
  Stretch,
39
43
  FullScreen,
@@ -36,6 +36,7 @@ const colors = {
36
36
  greenLight: "#F3FFFC",
37
37
  greenDark: "#236A56",
38
38
  greyText: "#b2bec3",
39
+ greyButton: "#94A3A9",
39
40
  red: "#ff7675",
40
41
  redlight: "#FFFAF9",
41
42
  redDark: "#9C4140",
package/src/index.js CHANGED
@@ -15,6 +15,8 @@ import {
15
15
  PaddingVertical,
16
16
  PaddingTop,
17
17
  PaddingBottom,
18
+ PaddingLeft,
19
+ PaddingRight,
18
20
  Row,
19
21
  Stretch,
20
22
  FullScreen,
@@ -22,7 +24,13 @@ import {
22
24
  Box,
23
25
  RoundedTopBox,
24
26
  } from "./Layout";
25
- import { Input, AnimatedPlaceholder, InputOtp, InputNormal } from "./Inputs";
27
+ import {
28
+ Input,
29
+ AnimatedPlaceholder,
30
+ InputOtp,
31
+ InputNormal,
32
+ InputPhone,
33
+ } from "./Inputs";
26
34
  import {
27
35
  TextBtn,
28
36
  RoundedBtn,
@@ -68,6 +76,8 @@ export {
68
76
  PaddingVertical,
69
77
  PaddingTop,
70
78
  PaddingBottom,
79
+ PaddingLeft,
80
+ PaddingRight,
71
81
  Row,
72
82
  Stretch,
73
83
  FullScreen,
@@ -78,6 +88,7 @@ export {
78
88
  InputNormal,
79
89
  AnimatedPlaceholder,
80
90
  InputOtp,
91
+ InputPhone,
81
92
  TextBtn,
82
93
  RoundedBtn,
83
94
  RoundBtn,
@@ -1,200 +0,0 @@
1
- import React, { useMemo, useCallback, useState, useEffect } from "react";
2
- import { View, StatusBar } from "react-native";
3
- import {
4
- FullScreen,
5
- Center,
6
- Loader,
7
- Success,
8
- Error,
9
- Switch,
10
- Row,
11
- Box,
12
- Margin,
13
- MarginHorizontal,
14
- MarginVertical,
15
- Padding,
16
- H4,
17
- H2,
18
- H3,
19
- RoundedBtn,
20
- ErrorText,
21
- MarginRight,
22
- MarginBottom,
23
- PaddingVertical,
24
- PaddingTop,
25
- useThemeContext,
26
- Input,
27
- } from "@servesall/atoms";
28
- import BottomSheet, {
29
- BottomSheetScrollView,
30
- BottomSheetFooter,
31
- } from "@gorhom/bottom-sheet";
32
- import { useNavigation } from "@react-navigation/native";
33
- import { useSubmitHook } from "@servesall/organisms";
34
- import {
35
- UserRolesQueryProvider,
36
- useUserRoles,
37
- UPDATE_MERCHANT_USER,
38
- } from "@servesall/merchantglobalstate";
39
- import LottieView from "lottie-react-native";
40
-
41
- export default function NewUser({ data }) {
42
- const { merchant } = data;
43
- const [selectedRole, setSelectedRole] = useState(false);
44
- const [userPhoneNumber, setUserPhoneNumber] = useState("");
45
- const [userPrefix, setUserPrefix] = useState("+356");
46
- const theme = useThemeContext();
47
- const navigation = useNavigation();
48
-
49
- const { submitForm, loading, success, error, errorText } = useSubmitHook({
50
- gql: UPDATE_MERCHANT_USER,
51
- formState: { isValid: true, isDirty: true },
52
- });
53
-
54
- useEffect(() => {
55
- success && setTimeout(() => navigation.goBack(), 1000);
56
- }, [success]);
57
-
58
- const submit = () => {};
59
-
60
- // variables
61
- const snapPoints = useMemo(() => ["90%"], []);
62
-
63
- // callbacks
64
- const handleSheetChanges = useCallback((index) => {
65
- if (index === -1) {
66
- navigation.goBack();
67
- }
68
- }, []);
69
-
70
- const renderFooter = useCallback(
71
- (props) => (
72
- <BottomSheetFooter {...props} bottomInset={0}>
73
- <View
74
- style={{
75
- backgroundColor: theme.color1,
76
- borderTopWidth: 2,
77
- borderColor: theme.color7,
78
- }}
79
- >
80
- <Margin>
81
- <RoundedBtn
82
- active={
83
- userPrefix !== "" && userPhoneNumber !== "" && selectedRole
84
- }
85
- size="small"
86
- color={theme.color2}
87
- onClick={submit}
88
- >
89
- <Center>
90
- <H3 color={theme.color1}>Save</H3>
91
- </Center>
92
- </RoundedBtn>
93
- </Margin>
94
- </View>
95
- </BottomSheetFooter>
96
- ),
97
- [selectedRole, userPhoneNumber, userPrefix]
98
- );
99
-
100
- return (
101
- <View
102
- style={{
103
- flex: 1,
104
- backgroundColor: "rgba(0, 0, 0, 0.4)",
105
- }}
106
- >
107
- <StatusBar barStyle="dark-content" backgroundColor="rgba(0, 0, 0, 0.4)" />
108
-
109
- <BottomSheet
110
- index={0}
111
- snapPoints={snapPoints}
112
- onChange={handleSheetChanges}
113
- enablePanDownToClose={true}
114
- footerComponent={renderFooter}
115
- >
116
- <BottomSheetScrollView contentContainerStyle={{ paddingBottom: 100 }}>
117
- {loading && (
118
- <FullScreen style={{ backgroundColor: "rgba(255, 255, 255, 0.8)" }}>
119
- <Center>
120
- <Loader color={theme.color2} />
121
- </Center>
122
- </FullScreen>
123
- )}
124
-
125
- {success && (
126
- <FullScreen style={{ backgroundColor: "rgba(255, 255, 255, 0.8)" }}>
127
- <Center>
128
- <Success />
129
- </Center>
130
- </FullScreen>
131
- )}
132
-
133
- {error && (
134
- <FullScreen style={{ backgroundColor: "rgba(255, 255, 255, 0.8)" }}>
135
- <Center>
136
- <Error />
137
- </Center>
138
- </FullScreen>
139
- )}
140
- <Box>
141
- <View style={{ borderBottomWidth: 2, borderColor: theme.color7 }}>
142
- <Margin style={{ alignItems: "center" }}>
143
- <LottieView
144
- style={{
145
- width: 80,
146
- }}
147
- autoPlay={true}
148
- loop={true}
149
- source={adduser}
150
- />
151
- <PaddingTop>
152
- <H3>Add a new user to {merchant.profile.name}</H3>
153
- </PaddingTop>
154
- </Margin>
155
- </View>
156
-
157
- <Margin>
158
- {errorText && (
159
- <PaddingVertical>
160
- <ErrorText>
161
- <Center>
162
- <Padding>
163
- <H4 color={theme.red}>{errorText}</H4>
164
- </Padding>
165
- </Center>
166
- </ErrorText>
167
- </PaddingVertical>
168
- )}
169
- </Margin>
170
-
171
- <MarginBottom>
172
- <Margin>
173
- <H3>User phone number</H3>
174
- </Margin>
175
- <UserPhone
176
- theme={theme}
177
- setUserPhoneNumber={setUserPhoneNumber}
178
- setUserPrefix={setUserPrefix}
179
- userPrefix={userPrefix}
180
- />
181
- </MarginBottom>
182
-
183
- <Margin>
184
- <PaddingVertical>
185
- <H3>Choose Role</H3>
186
- </PaddingVertical>
187
- <UserRolesQueryProvider>
188
- <Roles
189
- selectedRole={selectedRole}
190
- setSelectedRole={setSelectedRole}
191
- theme={theme}
192
- />
193
- </UserRolesQueryProvider>
194
- </Margin>
195
- </Box>
196
- </BottomSheetScrollView>
197
- </BottomSheet>
198
- </View>
199
- );
200
- }