react-crud-mobile 1.1.3 → 1.3.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/dist/elements/UI.d.ts +47 -0
- package/dist/elements/UIChildren.d.ts +15 -0
- package/dist/elements/UIComplete.d.ts +3 -0
- package/dist/elements/UIElement.d.ts +3 -0
- package/dist/elements/UITag.d.ts +7 -0
- package/dist/elements/charts/ElChart.d.ts +3 -0
- package/dist/elements/core/SafeView.d.ts +9 -0
- package/dist/elements/core/UIAutoComplete.d.ts +2 -0
- package/dist/elements/core/UIButton.d.ts +3 -0
- package/dist/elements/core/UIIcon.d.ts +3 -0
- package/dist/elements/core/UIInclude.d.ts +3 -0
- package/dist/elements/core/UIInput.d.ts +3 -0
- package/dist/elements/core/UILink.d.ts +2 -0
- package/dist/elements/core/UIList.d.ts +3 -0
- package/dist/elements/core/UIListItem.d.ts +7 -0
- package/dist/elements/core/UIListRow.d.ts +8 -0
- package/dist/elements/core/UIModal.d.ts +3 -0
- package/dist/elements/core/UIOption.d.ts +2 -0
- package/dist/elements/core/UIQuantity.d.ts +3 -0
- package/dist/elements/core/UIRadio.d.ts +2 -0
- package/dist/elements/core/UISelect.d.ts +3 -0
- package/dist/elements/core/UISlider.d.ts +3 -0
- package/dist/elements/core/UISwitch.d.ts +3 -0
- package/dist/elements/core/UIToast.d.ts +2 -0
- package/dist/elements/core/UIToggle.d.ts +3 -0
- package/dist/elements/core/UIView.d.ts +3 -0
- package/dist/elements/index.d.ts +1 -0
- package/dist/elements/tabs/ElTabs.d.ts +3 -0
- package/dist/hooks/useIsVisible.d.ts +2 -0
- package/dist/index.d.ts +1 -2
- package/dist/react-crud-mobile.cjs.development.js +2367 -0
- package/dist/react-crud-mobile.cjs.development.js.map +1 -0
- package/dist/react-crud-mobile.cjs.production.min.js +2 -0
- package/dist/react-crud-mobile.cjs.production.min.js.map +1 -0
- package/dist/react-crud-mobile.esm.js +2359 -0
- package/dist/react-crud-mobile.esm.js.map +1 -0
- package/dist/utils/MobileUtils.d.ts +3 -0
- package/package.json +54 -30
- package/src/elements/UI.tsx +34 -18
- package/src/elements/UIChildren.tsx +38 -16
- package/src/elements/UIComplete.tsx +1 -2
- package/src/elements/UIElement.tsx +542 -225
- package/src/elements/core/SafeView.tsx +69 -0
- package/src/elements/core/{Link.tsx → UIAutoComplete.tsx} +17 -18
- package/src/elements/core/UIButton.tsx +139 -0
- package/src/elements/core/UIIcon.tsx +25 -0
- package/src/elements/{grid/ElInclude.tsx → core/UIInclude.tsx} +3 -3
- package/src/elements/core/UIInput.tsx +96 -0
- package/src/elements/core/{Icon.tsx → UILink.tsx} +17 -18
- package/src/elements/core/UIList.tsx +168 -0
- package/src/elements/core/UIListItem.tsx +32 -0
- package/src/elements/core/UIListRow.tsx +123 -0
- package/src/elements/core/UIModal.tsx +204 -0
- package/src/elements/core/{Input.tsx → UIOption.tsx} +17 -18
- package/src/elements/core/UIQuantity.tsx +98 -0
- package/src/elements/core/{Radio.tsx → UIRadio.tsx} +17 -18
- package/src/elements/core/UISelect.tsx +135 -0
- package/src/elements/core/UISlider.tsx +61 -0
- package/src/elements/core/UISwitch.tsx +27 -0
- package/src/elements/core/UIToast.tsx +44 -0
- package/src/elements/core/UIToggle.tsx +102 -0
- package/src/elements/core/UIView.tsx +94 -0
- package/src/elements/grid/ElInclude +0 -0
- package/src/hooks/useIsVisible.ts +39 -0
- package/src/index.ts +1 -1
- package/src/utils/MobileUtils.ts +12 -0
- package/src/elements/card/ElCard.tsx +0 -26
- package/src/elements/core/AutoComplete.tsx +0 -18
- package/src/elements/core/Button.tsx +0 -18
- package/src/elements/core/Option.tsx +0 -18
- package/src/elements/core/Select.tsx +0 -18
- package/src/elements/core/Switch.tsx +0 -18
- package/src/elements/grid/ElGrid.tsx +0 -50
- package/src/elements/grid/ElGridBotom.tsx +0 -21
- package/src/elements/grid/ElGridCheck.tsx +0 -67
- package/src/elements/grid/ElGridColumn.tsx +0 -32
- package/src/elements/grid/ElGridFilter.tsx +0 -5
- package/src/elements/grid/ElGridPaginator.tsx +0 -82
- package/src/elements/grid/ElGridRow.tsx +0 -123
- package/src/elements/grid/ElGridTop.tsx +0 -45
- package/src/elements/grid/ElLabel.tsx +0 -50
- package/src/elements/grid/ElRepeat.tsx +0 -24
- package/src/elements/grid/ElRepeatRow.tsx +0 -40
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Keyboard,
|
|
3
|
+
KeyboardAvoidingView,
|
|
4
|
+
Platform,
|
|
5
|
+
StatusBar,
|
|
6
|
+
StyleProp,
|
|
7
|
+
TouchableWithoutFeedback,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import {
|
|
11
|
+
SafeAreaProvider,
|
|
12
|
+
SafeAreaView as SafeAreaContextView,
|
|
13
|
+
} from 'react-native-safe-area-context';
|
|
14
|
+
import { ThemeUtils, useTheme, Utils } from 'react-crud-utils';
|
|
15
|
+
import { useEffect } from 'react';
|
|
16
|
+
|
|
17
|
+
interface SafeViewType {
|
|
18
|
+
safeStyle?: StyleProp<ViewStyle> | any;
|
|
19
|
+
viewStyle?: StyleProp<ViewStyle> | any;
|
|
20
|
+
children?: any;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function SafeView(props: SafeViewType) {
|
|
24
|
+
let theme = ThemeUtils.getCurrentTheme();
|
|
25
|
+
|
|
26
|
+
if (Utils.isEmpty(theme)) {
|
|
27
|
+
theme = useTheme();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const dismissKeyboard = () => {
|
|
31
|
+
if (Platform.OS !== 'web') {
|
|
32
|
+
Keyboard.dismiss();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
//ajustes tema v1
|
|
38
|
+
StatusBar.setBarStyle(Utils.nvl(theme.theme, 'light-content'));
|
|
39
|
+
StatusBar.setBackgroundColor?.(theme.colors.theme);
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<SafeAreaProvider>
|
|
44
|
+
<StatusBar barStyle="light-content" />
|
|
45
|
+
<SafeAreaContextView
|
|
46
|
+
style={{
|
|
47
|
+
backgroundColor: theme.colors?.theme,
|
|
48
|
+
...props.viewStyle,
|
|
49
|
+
flex: 1,
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<KeyboardAvoidingView
|
|
53
|
+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
54
|
+
style={{
|
|
55
|
+
flex: 1, // 🔹 Ocupa 100% da tela
|
|
56
|
+
justifyContent: 'center',
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
<TouchableWithoutFeedback
|
|
60
|
+
onPress={dismissKeyboard}
|
|
61
|
+
accessible={false}
|
|
62
|
+
>
|
|
63
|
+
<>{props.children}</>
|
|
64
|
+
</TouchableWithoutFeedback>
|
|
65
|
+
</KeyboardAvoidingView>
|
|
66
|
+
</SafeAreaContextView>
|
|
67
|
+
</SafeAreaProvider>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
1
|
+
import { Text, TouchableOpacity, Linking, StyleSheet } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default function UIAutoComplete(props: any) {
|
|
4
|
+
const handlePress = () => {
|
|
5
|
+
Linking.openURL('https://reactnative.dev/');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<TouchableOpacity onPress={handlePress}>
|
|
10
|
+
<Text style={styles.link}>Clique aqui para acessar o React Native</Text>
|
|
11
|
+
</TouchableOpacity>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const styles = {
|
|
16
|
+
link: {},
|
|
17
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
2
|
+
import { ChildType, Utils } from 'react-crud-utils';
|
|
3
|
+
import { Text, TouchableHighlight, View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
const BUTTONS_SIZE: any = { small: { minWidth: 30, height: 30 } };
|
|
6
|
+
|
|
7
|
+
export default function UIButton(props: ChildType) {
|
|
8
|
+
let scope = props.scope;
|
|
9
|
+
let element = scope.original;
|
|
10
|
+
let size = Utils.nvl(element.size, 'default');
|
|
11
|
+
let align = Utils.nvl(element.align, 'center');
|
|
12
|
+
let variant = Utils.nvl(element.variant, 'default');
|
|
13
|
+
|
|
14
|
+
let color = element.color;
|
|
15
|
+
let label = scope.getLabel();
|
|
16
|
+
let icon = element.icon;
|
|
17
|
+
|
|
18
|
+
//ajuste align v3
|
|
19
|
+
if (!color) color = 'primaryLight';
|
|
20
|
+
|
|
21
|
+
const styles: any = {
|
|
22
|
+
buttonLabel: {
|
|
23
|
+
color: '#ffffff',
|
|
24
|
+
fontWeight: '500',
|
|
25
|
+
fontSize: 16,
|
|
26
|
+
},
|
|
27
|
+
buttonInner: {
|
|
28
|
+
flexDirection: 'row',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
height: 44,
|
|
32
|
+
minWidth: 44,
|
|
33
|
+
},
|
|
34
|
+
buttonIcon: {
|
|
35
|
+
color: '#fff',
|
|
36
|
+
fontSize: 18,
|
|
37
|
+
},
|
|
38
|
+
button: {
|
|
39
|
+
backgroundColor: color,
|
|
40
|
+
borderRadius: 24,
|
|
41
|
+
gap: 10,
|
|
42
|
+
justifyContent: 'center',
|
|
43
|
+
alignItems: 'center',
|
|
44
|
+
flexDirection: 'row',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const onClick = (e: any) => {
|
|
49
|
+
scope.call('click', {});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const style = (part: string, extra?: any) => {
|
|
53
|
+
let css = { ...styles[part], ...extra };
|
|
54
|
+
|
|
55
|
+
if (variant === 'text' || variant === 'outlined') {
|
|
56
|
+
css.backgroundColor = 'transparent';
|
|
57
|
+
css.color = Utils.nvl(color, 'text');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (size === 'small') {
|
|
61
|
+
css.fontSize = 12;
|
|
62
|
+
css.fontWeight = 500;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (size === 'medium') {
|
|
66
|
+
css.fontSize = 14;
|
|
67
|
+
css.fontWeight = 500;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (align === 'left') {
|
|
71
|
+
css.justifyContent = 'flex-start';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return scope.getStyle(part, css);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let extra: any = {};
|
|
78
|
+
|
|
79
|
+
if (icon) {
|
|
80
|
+
extra.button = { height: 40, padding: 0 };
|
|
81
|
+
} else {
|
|
82
|
+
extra.button = { height: 50 };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const buttonStyle = Utils.call(() => {
|
|
86
|
+
let def: any = { ...extra?.button };
|
|
87
|
+
|
|
88
|
+
if (variant === 'outlined') {
|
|
89
|
+
def.borderWidth = 1;
|
|
90
|
+
def.borderColor = Utils.nvl(color, 'text');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (size) {
|
|
94
|
+
def = { ...def, ...BUTTONS_SIZE[size] };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let css = style('button', def);
|
|
98
|
+
|
|
99
|
+
if (!css.width) {
|
|
100
|
+
let h = css.height;
|
|
101
|
+
|
|
102
|
+
if (typeof h === 'number') {
|
|
103
|
+
css.minWidth = h;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return css;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const buttonLabel = style('buttonLabel');
|
|
111
|
+
const iconStyle = Utils.call(() => {
|
|
112
|
+
let css: any = style('buttonIcon', extra.icon);
|
|
113
|
+
|
|
114
|
+
css.fontSize = Utils.nvl(buttonLabel.fontSize, css.fontSize);
|
|
115
|
+
|
|
116
|
+
return css;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<TouchableHighlight
|
|
121
|
+
underlayColor={'transparent'}
|
|
122
|
+
onPress={onClick}
|
|
123
|
+
style={buttonStyle}
|
|
124
|
+
>
|
|
125
|
+
<>
|
|
126
|
+
{icon && (
|
|
127
|
+
<>
|
|
128
|
+
<Ionicons
|
|
129
|
+
size={Utils.nvl(element.iconSize, 30)}
|
|
130
|
+
style={iconStyle}
|
|
131
|
+
name={icon}
|
|
132
|
+
/>
|
|
133
|
+
</>
|
|
134
|
+
)}
|
|
135
|
+
{label && <Text style={buttonLabel}>{label}</Text>}
|
|
136
|
+
</>
|
|
137
|
+
</TouchableHighlight>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Ionicons,
|
|
3
|
+
MaterialCommunityIcons,
|
|
4
|
+
AntDesign,
|
|
5
|
+
Entypo,
|
|
6
|
+
EvilIcons,
|
|
7
|
+
} from '@expo/vector-icons';
|
|
8
|
+
|
|
9
|
+
import { ChildType, Utils } from 'react-crud-utils';
|
|
10
|
+
|
|
11
|
+
export default function UIIcon({ scope }: ChildType) {
|
|
12
|
+
let name = scope.getValue();
|
|
13
|
+
let libs: any = {
|
|
14
|
+
ion: Ionicons,
|
|
15
|
+
ant: AntDesign,
|
|
16
|
+
entypo: Entypo,
|
|
17
|
+
evil: EvilIcons,
|
|
18
|
+
material: MaterialCommunityIcons,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let library = Utils.nvl(scope.original.library, 'ion');
|
|
22
|
+
let Aux = libs[library];
|
|
23
|
+
|
|
24
|
+
return <Aux name={name} style={scope.getStyle('icon')} />;
|
|
25
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import UIChildren from
|
|
2
|
-
import { ComponentUtils, DefineType, Utils } from
|
|
1
|
+
import UIChildren from '../UIChildren';
|
|
2
|
+
import { ComponentUtils, DefineType, Utils } from 'react-crud-utils';
|
|
3
3
|
|
|
4
|
-
export default function
|
|
4
|
+
export default function UIInclude(props: DefineType) {
|
|
5
5
|
if (props.rendered === false) {
|
|
6
6
|
return <></>;
|
|
7
7
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { ChildType, Utils } from 'react-crud-utils';
|
|
3
|
+
import { StyleSheet, TextInput, View } from 'react-native';
|
|
4
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
5
|
+
|
|
6
|
+
export default function UIInput(props: ChildType) {
|
|
7
|
+
let scope = props.scope;
|
|
8
|
+
let initial = Utils.call(() => {
|
|
9
|
+
let val = Utils.nvl(scope.getValue(), '');
|
|
10
|
+
|
|
11
|
+
if (val && val?.push) {
|
|
12
|
+
return val.join(', ').trim();
|
|
13
|
+
}
|
|
14
|
+
return val;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
let label = scope.getLabel();
|
|
18
|
+
let placeholder = scope.getPart('placeholder', null, label);
|
|
19
|
+
let el = scope.original;
|
|
20
|
+
|
|
21
|
+
const [value, setValue] = useState(initial);
|
|
22
|
+
|
|
23
|
+
let onChange = v => {
|
|
24
|
+
v = scope.changeValue(v);
|
|
25
|
+
|
|
26
|
+
setValue(v);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const style = (part: string, extra?: any) => {
|
|
30
|
+
return { ...scope.getStyle(part, styles[part]), ...extra };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const CustomIcon = () => {
|
|
34
|
+
let icon = el.icon;
|
|
35
|
+
|
|
36
|
+
if (icon) {
|
|
37
|
+
if (typeof icon === 'string') {
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
{el.icon && (
|
|
41
|
+
<Ionicons
|
|
42
|
+
name={el.icon}
|
|
43
|
+
size={scope.attr('iconSize', 20)}
|
|
44
|
+
color={scope.attr('iconColor', '#888')}
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return <>{icon}</>;
|
|
51
|
+
}
|
|
52
|
+
return <></>;
|
|
53
|
+
};
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<View style={style('base')}>
|
|
57
|
+
{scope.getPart('left')}
|
|
58
|
+
<TextInput
|
|
59
|
+
style={style('input')}
|
|
60
|
+
onChangeText={onChange}
|
|
61
|
+
value={value}
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
/>
|
|
64
|
+
<CustomIcon />
|
|
65
|
+
</View>
|
|
66
|
+
{scope.getPart('right')}
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const styles = StyleSheet.create({
|
|
72
|
+
base: {
|
|
73
|
+
flex: 1,
|
|
74
|
+
width: '100%',
|
|
75
|
+
paddingBottom: 0,
|
|
76
|
+
paddingTop: 0,
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
borderWidth: 1,
|
|
79
|
+
borderColor: 'borderColor',
|
|
80
|
+
borderRadius: 5,
|
|
81
|
+
paddingHorizontal: 15,
|
|
82
|
+
alignSelf: 'flex-start',
|
|
83
|
+
flexDirection: 'row',
|
|
84
|
+
flexWrap: 'wrap',
|
|
85
|
+
gap: 10,
|
|
86
|
+
},
|
|
87
|
+
icon: {
|
|
88
|
+
marginRight: 10, // Espaço entre ícone e input
|
|
89
|
+
},
|
|
90
|
+
input: {
|
|
91
|
+
marginHorizontal: 0,
|
|
92
|
+
marginVertical: 0,
|
|
93
|
+
height: 40,
|
|
94
|
+
flex: 1, // Para o input ocupar o espaço restante
|
|
95
|
+
},
|
|
96
|
+
});
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
1
|
+
import { Text, TouchableOpacity, Linking, StyleSheet } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default function UILink(props: any) {
|
|
4
|
+
const handlePress = () => {
|
|
5
|
+
Linking.openURL('https://reactnative.dev/');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<TouchableOpacity onPress={handlePress}>
|
|
10
|
+
<Text style={styles.link}>Clique aqui para acessar o React Native</Text>
|
|
11
|
+
</TouchableOpacity>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const styles = {
|
|
16
|
+
link: {},
|
|
17
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { ChildType, ComponentUtils, ScopeUtils, Utils } from 'react-crud-utils';
|
|
3
|
+
import { StyleSheet, Text, TouchableHighlight, View } from 'react-native';
|
|
4
|
+
import UIListRow from './UIListRow';
|
|
5
|
+
import UI from '../UI';
|
|
6
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
7
|
+
|
|
8
|
+
export default function UIList(props: ChildType) {
|
|
9
|
+
const scope = props.scope;
|
|
10
|
+
const crud = scope.crud;
|
|
11
|
+
const original = scope.original;
|
|
12
|
+
const cols = Utils.nvl(scope.getPart('cols', undefined, 1));
|
|
13
|
+
const styles = { repeat: stylesRepeat, list: stylesList }?.[original.type];
|
|
14
|
+
const add = ComponentUtils.getDefine(props, 'add');
|
|
15
|
+
const hideAddWhenEmpty = original.hideAddWhenEmpty;
|
|
16
|
+
|
|
17
|
+
const getStyle = (key: string, extra?: any) => {
|
|
18
|
+
return scope.getStyle(key, { ...extra, ...styles[key] });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getContainerStyle = (extra?: any) => {
|
|
22
|
+
let row = getStyle('container', {});
|
|
23
|
+
|
|
24
|
+
if (cols > 1) {
|
|
25
|
+
row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return row;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const LocalData = () => {
|
|
32
|
+
let [index, setIndex] = useState(scope.updateIndex);
|
|
33
|
+
|
|
34
|
+
scope.update = () => {
|
|
35
|
+
scope.updateIndex = ++index;
|
|
36
|
+
|
|
37
|
+
setIndex(index);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let keyData = scope.key('data');
|
|
41
|
+
|
|
42
|
+
const items = Utils.call(() => {
|
|
43
|
+
let list = Utils.nvl(scope.getItems(), []);
|
|
44
|
+
|
|
45
|
+
if (original.search && !original.list?.url) {
|
|
46
|
+
let query = crud
|
|
47
|
+
.get('query', '')
|
|
48
|
+
.toLowerCase()
|
|
49
|
+
.trim() as string;
|
|
50
|
+
|
|
51
|
+
if (query.length > 1) {
|
|
52
|
+
let filters: any[] = [];
|
|
53
|
+
let filterBy = Utils.nvl(original.filterBy, 'label');
|
|
54
|
+
|
|
55
|
+
Utils.each(list, o => {
|
|
56
|
+
let label = o[filterBy];
|
|
57
|
+
|
|
58
|
+
if (label) {
|
|
59
|
+
if (label.includes(query)) {
|
|
60
|
+
filters.push(o);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return filters;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return list;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const isShowAdd = () => {
|
|
72
|
+
if (!Utils.isEmpty(items)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return hideAddWhenEmpty !== true;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
let Empty = () => {
|
|
79
|
+
if (!Utils.isEmpty(items)) {
|
|
80
|
+
return <></>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let empty = scope.attr('empty', 'Sem registro');
|
|
84
|
+
|
|
85
|
+
if (!empty) {
|
|
86
|
+
return <></>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof empty === 'string') {
|
|
90
|
+
return (
|
|
91
|
+
<Text
|
|
92
|
+
style={scope.getStyle('empty', {
|
|
93
|
+
flex: 1,
|
|
94
|
+
fontWeight: 500,
|
|
95
|
+
fontSize: 20,
|
|
96
|
+
padding: 10,
|
|
97
|
+
textAlign: 'center',
|
|
98
|
+
justifyContent: 'center',
|
|
99
|
+
alignItems: 'center',
|
|
100
|
+
})}
|
|
101
|
+
>
|
|
102
|
+
{empty}
|
|
103
|
+
</Text>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return <>{empty}</>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<View key={keyData} style={getContainerStyle()}>
|
|
112
|
+
<Empty />
|
|
113
|
+
{items.map((item: any, i: number) => (
|
|
114
|
+
<UIListRow index={i} item={item} scope={scope}>
|
|
115
|
+
{props.children}
|
|
116
|
+
</UIListRow>
|
|
117
|
+
))}
|
|
118
|
+
{isShowAdd() && <>{add}</>}
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<>
|
|
125
|
+
{original.search !== false && (
|
|
126
|
+
<UI.Text
|
|
127
|
+
placeholder="Pesquisar..."
|
|
128
|
+
field="query"
|
|
129
|
+
crud={crud}
|
|
130
|
+
style={{ marginBottom: 10 }}
|
|
131
|
+
change={{
|
|
132
|
+
action: () => {
|
|
133
|
+
scope.search();
|
|
134
|
+
},
|
|
135
|
+
}}
|
|
136
|
+
icon={<Ionicons name="search" size={20} color="#888" />}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
<LocalData />
|
|
140
|
+
</>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const stylesList = StyleSheet.create({
|
|
145
|
+
container: {
|
|
146
|
+
display: 'flex',
|
|
147
|
+
flexWrap: 'wrap',
|
|
148
|
+
gap: 10,
|
|
149
|
+
width: '100%',
|
|
150
|
+
},
|
|
151
|
+
text: {
|
|
152
|
+
fontSize: 18,
|
|
153
|
+
fontWeight: 'bold',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const stylesRepeat = StyleSheet.create({
|
|
158
|
+
container: {
|
|
159
|
+
display: 'flex',
|
|
160
|
+
flexWrap: 'wrap',
|
|
161
|
+
gap: 10,
|
|
162
|
+
width: '100%',
|
|
163
|
+
},
|
|
164
|
+
text: {
|
|
165
|
+
fontSize: 18,
|
|
166
|
+
fontWeight: 'bold',
|
|
167
|
+
},
|
|
168
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { ChildType, Utils } from 'react-crud-utils';
|
|
3
|
+
import { FlatList, StyleSheet, Switch, Text, View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
interface UIListItemType extends ChildType {
|
|
6
|
+
data: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function UIListItem(props: UIListItemType) {
|
|
10
|
+
const scope = props.scope;
|
|
11
|
+
const crud = props.crud;
|
|
12
|
+
|
|
13
|
+
return <View style={styles.item}></View>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const styles = StyleSheet.create({
|
|
17
|
+
container: {
|
|
18
|
+
flex: 1,
|
|
19
|
+
padding: 20,
|
|
20
|
+
backgroundColor: '#fff',
|
|
21
|
+
},
|
|
22
|
+
item: {
|
|
23
|
+
padding: 15,
|
|
24
|
+
marginVertical: 8,
|
|
25
|
+
backgroundColor: '#f9c2ff',
|
|
26
|
+
borderRadius: 8,
|
|
27
|
+
},
|
|
28
|
+
text: {
|
|
29
|
+
fontSize: 18,
|
|
30
|
+
fontWeight: 'bold',
|
|
31
|
+
},
|
|
32
|
+
});
|