@codeleap/mobile 1.8.4 → 1.9.2
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.
- package/package.json +3 -2
- package/src/components/Checkbox/index.tsx +3 -1
- package/src/components/FileInput.tsx +3 -1
- package/src/components/List.tsx +1 -1
- package/src/components/Scroll.tsx +1 -1
- package/src/components/TextInput.tsx +34 -6
- package/src/modules/textInputMask.ts +7 -0
- package/src/modules/types/textInputMask.ts +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/mobile",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"author": "Paulo Henrique De Souza <paulosouza300272@gmail.com>",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"react-native-fast-image": "^8.5.11",
|
|
29
29
|
"react-native-gesture-handler": "^2.2.0",
|
|
30
30
|
"react-native-image-crop-picker": "*",
|
|
31
|
-
"react-native-keyboard-aware-scroll-view": "^0.9.5"
|
|
31
|
+
"react-native-keyboard-aware-scroll-view": "^0.9.5",
|
|
32
|
+
"react-native-text-input-mask": "3.1.4"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@miblanchard/react-native-slider": "^2.1.0",
|
|
@@ -26,6 +26,7 @@ type CheckboxProps = NativeCheckboxProps & {
|
|
|
26
26
|
label?: ReactNode
|
|
27
27
|
styles?: StylesOf<CheckboxComposition>
|
|
28
28
|
validate?: Form.ValidatorFunctionWithoutForm | string
|
|
29
|
+
required?: boolean
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export const Checkbox = forwardRef<NativeCheckbox, CheckboxProps>(
|
|
@@ -38,6 +39,7 @@ export const Checkbox = forwardRef<NativeCheckbox, CheckboxProps>(
|
|
|
38
39
|
value,
|
|
39
40
|
onValueChange,
|
|
40
41
|
validate,
|
|
42
|
+
required,
|
|
41
43
|
...props
|
|
42
44
|
} = checkboxProps
|
|
43
45
|
|
|
@@ -72,7 +74,7 @@ export const Checkbox = forwardRef<NativeCheckbox, CheckboxProps>(
|
|
|
72
74
|
<View style={getStyles('checkmarkWrapper')}>
|
|
73
75
|
<View style={getStyles('checkmark')} />
|
|
74
76
|
</View>
|
|
75
|
-
<InputLabel label={label} style={getStyles('label')} />
|
|
77
|
+
<InputLabel label={label} style={getStyles('label')} required={required}/>
|
|
76
78
|
</Touchable>
|
|
77
79
|
<FormError message={error.message} style={getStyles('error')} />
|
|
78
80
|
</View>
|
|
@@ -36,6 +36,7 @@ export type FileInputProps = {
|
|
|
36
36
|
type?: 'image' | 'anyFile'
|
|
37
37
|
alertProps?: Parameters<typeof OSAlert.ask>[0]
|
|
38
38
|
pickerOptions?: Partial<Options>
|
|
39
|
+
required?: boolean
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const pickerDefaults = {
|
|
@@ -77,6 +78,7 @@ export const FileInput = forwardRef<
|
|
|
77
78
|
alertProps,
|
|
78
79
|
placeholder = 'Select a file',
|
|
79
80
|
pickerOptions,
|
|
81
|
+
required,
|
|
80
82
|
buttonProps,
|
|
81
83
|
} = fileInputProps
|
|
82
84
|
|
|
@@ -162,7 +164,7 @@ export const FileInput = forwardRef<
|
|
|
162
164
|
if (mode === 'button') {
|
|
163
165
|
return (
|
|
164
166
|
<View style={variantStyles.wrapper}>
|
|
165
|
-
<InputLabel label={label} style={variantStyles.label} />
|
|
167
|
+
<InputLabel label={label} style={variantStyles.label} required={required}/>
|
|
166
168
|
<Button
|
|
167
169
|
onPress={() => openFilePicker()}
|
|
168
170
|
text={filenames || placeholder}
|
package/src/components/List.tsx
CHANGED
|
@@ -95,12 +95,12 @@ const ListCP = forwardRef<FlatList, FlatListProps>(
|
|
|
95
95
|
contentContainerStyle={[variantStyles.wrapper]}
|
|
96
96
|
ref={ref as unknown as FlatList}
|
|
97
97
|
ItemSeparatorComponent={separator}
|
|
98
|
-
{...props}
|
|
99
98
|
refreshControl={
|
|
100
99
|
hasRefresh && (
|
|
101
100
|
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
|
|
102
101
|
)
|
|
103
102
|
}
|
|
103
|
+
{...props}
|
|
104
104
|
/>
|
|
105
105
|
)
|
|
106
106
|
},
|
|
@@ -90,12 +90,12 @@ export const Scroll = forwardRef<ScrollView, ScrollProps>(
|
|
|
90
90
|
style={[Theme.presets.full, style]}
|
|
91
91
|
contentContainerStyle={[variantStyles.wrapper]}
|
|
92
92
|
ref={ref as unknown as ScrollView}
|
|
93
|
-
{...props}
|
|
94
93
|
refreshControl={
|
|
95
94
|
hasRefresh && (
|
|
96
95
|
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
|
|
97
96
|
)
|
|
98
97
|
}
|
|
98
|
+
{...props}
|
|
99
99
|
>
|
|
100
100
|
{children}
|
|
101
101
|
</Component>
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
TextInputComposition,
|
|
7
7
|
TextInputStyles,
|
|
8
8
|
useBooleanToggle,
|
|
9
|
+
useComponentStyle,
|
|
9
10
|
useDefaultComponentStyle,
|
|
10
11
|
useValidate,
|
|
11
12
|
} from '@codeleap/common'
|
|
@@ -17,6 +18,8 @@ import { StylesOf } from '../types/utility'
|
|
|
17
18
|
import { Icon } from './Icon'
|
|
18
19
|
import { NativeSyntheticEvent, StyleSheet, TextInput as NativeTextInput, TextInputChangeEventData } from 'react-native'
|
|
19
20
|
import { Touchable, TouchableProps } from './Touchable'
|
|
21
|
+
import { MaskedTextInput } from '../modules/textInputMask'
|
|
22
|
+
import { TextInputMaskProps } from '../modules/types/textInputMask'
|
|
20
23
|
|
|
21
24
|
type IconProp = { name: IconPlaceholder; action?: () => void }
|
|
22
25
|
|
|
@@ -42,7 +45,10 @@ export type TextInputProps =
|
|
|
42
45
|
visibilityToggle?: boolean
|
|
43
46
|
touchableWrapper?: boolean
|
|
44
47
|
onPress?: () => void
|
|
48
|
+
masking?: FormTypes.TextField['masking']
|
|
45
49
|
innerWrapperProps?: TouchableProps | ViewProps
|
|
50
|
+
onChangeMask?: TextInputMaskProps['onChangeText']
|
|
51
|
+
required?:boolean
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops, inputRef) => {
|
|
@@ -65,7 +71,10 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops,
|
|
|
65
71
|
visibilityToggle,
|
|
66
72
|
touchableWrapper,
|
|
67
73
|
innerWrapperProps,
|
|
74
|
+
masking = null,
|
|
75
|
+
onChangeMask,
|
|
68
76
|
debugName,
|
|
77
|
+
required = false,
|
|
69
78
|
...props
|
|
70
79
|
} = rawprops
|
|
71
80
|
|
|
@@ -78,7 +87,7 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops,
|
|
|
78
87
|
variants,
|
|
79
88
|
styles,
|
|
80
89
|
})
|
|
81
|
-
const InputElement = NativeTextInput
|
|
90
|
+
const InputElement = masking ? MaskedTextInput : NativeTextInput
|
|
82
91
|
|
|
83
92
|
const handleBlur: TextInputProps['onBlur'] = (e) => {
|
|
84
93
|
if (!editedState && value) setEdited(true)
|
|
@@ -95,7 +104,10 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops,
|
|
|
95
104
|
onFocus(e)
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
|
-
|
|
107
|
+
const handleMaskChange = (masked, unmasked, obfuscated) => {
|
|
108
|
+
if (onChangeText) onChangeText(masking.saveFormatted ? masked : unmasked)
|
|
109
|
+
if (onChangeMask) onChangeMask(masked, unmasked, obfuscated)
|
|
110
|
+
}
|
|
99
111
|
const handleChange = (event: NativeSyntheticEvent<TextInputChangeEventData>) => {
|
|
100
112
|
const text = event.nativeEvent.text
|
|
101
113
|
|
|
@@ -156,20 +168,29 @@ export const TextInput = forwardRef<NativeTextInput, TextInputProps>((rawprops,
|
|
|
156
168
|
onPress={handlePress}
|
|
157
169
|
{...innerWrapperProps}
|
|
158
170
|
>
|
|
159
|
-
<InputLabel
|
|
171
|
+
<InputLabel
|
|
172
|
+
label={label}
|
|
173
|
+
style={getStyles('label')}
|
|
174
|
+
asteriskStyle={getStyles('requiredAsterisk')}
|
|
175
|
+
wrapperStyle={getStyles('labelWrapper')}
|
|
176
|
+
required={required}
|
|
177
|
+
/>
|
|
160
178
|
<View style={getStyles('innerWrapper')} {...innerWrapperProps}>
|
|
161
179
|
<InputIcon {...leftIcon} style={leftIconStyle} wrapperStyle={buttonIconWrapperStyle} />
|
|
180
|
+
{/* @ts-ignore */}
|
|
162
181
|
<InputElement
|
|
163
182
|
ref={input}
|
|
164
183
|
secureTextEntry={password && !textIsVisible}
|
|
165
|
-
onChange={handleChange}
|
|
184
|
+
onChange={(e) => masking ? onChange?.(e) : handleChange(e)}
|
|
166
185
|
value={value}
|
|
167
186
|
editable={disabled}
|
|
168
187
|
onFocus={handleFocus}
|
|
169
188
|
onBlur={handleBlur}
|
|
170
189
|
placeholderTextColor={StyleSheet.flatten(getStyles('placeholder'))?.color}
|
|
171
190
|
selectionColor={StyleSheet.flatten(getStyles('selection'))?.color}
|
|
191
|
+
mask={masking?.mask}
|
|
172
192
|
{...props}
|
|
193
|
+
{...(masking ? { onChangeText: handleMaskChange } : {})}
|
|
173
194
|
style={getStyles('textField')}
|
|
174
195
|
/>
|
|
175
196
|
{
|
|
@@ -204,12 +225,19 @@ export const InputIcon: React.FC<{ style: any; wrapperStyle: any } & IconProp> =
|
|
|
204
225
|
return <Icon name={name} style={style} />
|
|
205
226
|
}
|
|
206
227
|
|
|
207
|
-
export const InputLabel = ({ label, style }) => {
|
|
228
|
+
export const InputLabel = ({ label, variants = [], styles = {}, style, asteriskStyle = null, required = false, wrapperStyle = null }) => {
|
|
229
|
+
const labelStyles = useDefaultComponentStyle('TextInput', {
|
|
230
|
+
variants, styles, transform: StyleSheet.flatten,
|
|
231
|
+
})
|
|
232
|
+
|
|
208
233
|
if (!label) return null
|
|
209
234
|
|
|
210
235
|
switch (typeof label) {
|
|
211
236
|
case 'string':
|
|
212
|
-
return <
|
|
237
|
+
return <View style={ wrapperStyle || labelStyles.labelWrapper}>
|
|
238
|
+
<Text style={style || labelStyles.label} text={label} />
|
|
239
|
+
{required && <Text style={asteriskStyle || labelStyles.requiredAsterisk} text={' *'} />}
|
|
240
|
+
</View>
|
|
213
241
|
case 'object':
|
|
214
242
|
return label
|
|
215
243
|
default:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FormTypes } from '@codeleap/common'
|
|
2
|
+
import { ComponentPropsWithoutRef } from 'react'
|
|
3
|
+
import { TextInput as NativeTextInput } from 'react-native'
|
|
4
|
+
type NativeProps = ComponentPropsWithoutRef<typeof NativeTextInput>
|
|
5
|
+
|
|
6
|
+
export type TextInputMaskProps = {
|
|
7
|
+
mask: FormTypes.TextField['masking']['mask']
|
|
8
|
+
onChangeText?: (maskedText:string, unmaskedText:string, obfuscatedText:string) => any
|
|
9
|
+
} & NativeProps
|