react-crud-mobile 1.0.476 → 1.0.478

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.
@@ -1,162 +1,162 @@
1
- import React, { useState } from 'react';
2
- import { ChildType, 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(original.cols, 1);
13
- const rowWidth = Math.floor(100 / cols) + '%';
14
- const items = Utils.nvl(scope.getItems(), []);
15
- const styles = { repeat: stylesRepeat, list: stylesList }?.[original.type];
16
-
17
- const onClick = (item: any) => {
18
- scope.call('click', { value: item, item, edit: true });
19
- };
20
-
21
- const getStyle = (key: string, extra?: any) => {
22
- return scope.getStyle(key, { ...extra, ...styles[key] });
23
- };
24
-
25
- const getRowStyle = (extra?: any) => {
26
- let row = getStyle('row', {});
27
-
28
- if (cols > 0) {
29
- row.width = rowWidth;
30
- }
31
-
32
- return row;
33
- };
34
-
35
- const getContainerStyle = (extra?: any) => {
36
- let row = getStyle('container', {});
37
-
38
- if (cols > 1) {
39
- row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
40
- }
41
-
42
- return row;
43
- };
44
-
45
- let Empty = () => {
46
- if (!Utils.isEmpty(items)) {
47
- return <></>;
48
- }
49
-
50
- let empty = scope.attr('empty', 'Sem registro');
51
-
52
- if (!empty) {
53
- return <></>;
54
- }
55
-
56
- if (typeof empty === 'string') {
57
- return (
58
- <Text
59
- style={scope.getStyle('empty', {
60
- flex: 1,
61
- fontWeight: 500,
62
- fontSize: 20,
63
- padding: 10,
64
- textAlign: 'center',
65
- justifyContent: 'center',
66
- alignItems: 'center',
67
- })}
68
- >
69
- {empty}
70
- </Text>
71
- );
72
- }
73
-
74
- return <>{empty}</>;
75
- };
76
-
77
- return (
78
- <>
79
- {original.search !== false && (
80
- <UI.Text
81
- placeholder="Pesquisar..."
82
- field="query"
83
- crud={crud}
84
- right={<Ionicons name="search" size={20} color="#888" />}
85
- />
86
- )}
87
-
88
- <View style={getContainerStyle()}>
89
- <Empty />
90
- {items.map((item: any, i: number) => (
91
- <TouchableHighlight
92
- key={`k-${i}`}
93
- style={getRowStyle()}
94
- underlayColor={'transparent'}
95
- onPress={e => {
96
- onClick(item);
97
- }}
98
- >
99
- <View style={getStyle('rowInner')}>
100
- <UIListRow scope={scope} item={item} index={i}>
101
- {props.children}
102
- </UIListRow>
103
- </View>
104
- </TouchableHighlight>
105
- ))}
106
- </View>
107
- </>
108
- );
109
- }
110
-
111
- const stylesList = StyleSheet.create({
112
- container: {
113
- flex: 1,
114
- width: '100%',
115
- flexDirection: 'row',
116
- flexWrap: 'wrap',
117
- alignItems: 'stretch',
118
- },
119
- row: {
120
- padding: 5,
121
- width: '100%',
122
- },
123
- rowInner: {
124
- flexGrow: 1, // ✅ cresce conforme o conteúdo
125
- justifyContent: 'center',
126
- alignItems: 'center',
127
- backgroundColor: '#f5f5f5',
128
- borderRadius: 8,
129
- padding: 10,
130
- width: '100%',
131
- },
132
- text: {
133
- fontSize: 18,
134
- fontWeight: 'bold',
135
- },
136
- });
137
-
138
- const stylesRepeat = StyleSheet.create({
139
- container: {
140
- flex: 1,
141
- width: '100%',
142
- flexDirection: 'row',
143
- flexWrap: 'wrap',
144
- gap: 10,
145
- alignItems: 'stretch',
146
- },
147
- row: {
148
- padding: 0,
149
- width: '100%',
150
- },
151
- rowInner: {
152
- flexGrow: 1, // ✅ cresce conforme o conteúdo
153
- justifyContent: 'center',
154
- alignItems: 'center',
155
- padding: 0,
156
- width: '100%',
157
- },
158
- text: {
159
- fontSize: 18,
160
- fontWeight: 'bold',
161
- },
162
- });
1
+ import React, { useState } from 'react';
2
+ import { ChildType, 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(original.cols, 1);
13
+ const rowWidth = Math.floor(100 / cols) + '%';
14
+ const items = Utils.nvl(scope.getItems(), []);
15
+ const styles = { repeat: stylesRepeat, list: stylesList }?.[original.type];
16
+
17
+ const onClick = (item: any) => {
18
+ scope.call('click', { value: item, item, edit: true });
19
+ };
20
+
21
+ const getStyle = (key: string, extra?: any) => {
22
+ return scope.getStyle(key, { ...extra, ...styles[key] });
23
+ };
24
+
25
+ const getRowStyle = (extra?: any) => {
26
+ let row = getStyle('row', {});
27
+
28
+ if (cols > 0) {
29
+ row.width = rowWidth;
30
+ }
31
+
32
+ return row;
33
+ };
34
+
35
+ const getContainerStyle = (extra?: any) => {
36
+ let row = getStyle('container', {});
37
+
38
+ if (cols > 1) {
39
+ row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
40
+ }
41
+
42
+ return row;
43
+ };
44
+
45
+ let Empty = () => {
46
+ if (!Utils.isEmpty(items)) {
47
+ return <></>;
48
+ }
49
+
50
+ let empty = scope.attr('empty', 'Sem registro');
51
+
52
+ if (!empty) {
53
+ return <></>;
54
+ }
55
+
56
+ if (typeof empty === 'string') {
57
+ return (
58
+ <Text
59
+ style={scope.getStyle('empty', {
60
+ flex: 1,
61
+ fontWeight: 500,
62
+ fontSize: 20,
63
+ padding: 10,
64
+ textAlign: 'center',
65
+ justifyContent: 'center',
66
+ alignItems: 'center',
67
+ })}
68
+ >
69
+ {empty}
70
+ </Text>
71
+ );
72
+ }
73
+
74
+ return <>{empty}</>;
75
+ };
76
+
77
+ return (
78
+ <>
79
+ {original.search !== false && (
80
+ <UI.Text
81
+ placeholder="Pesquisar..."
82
+ field="query"
83
+ crud={crud}
84
+ right={<Ionicons name="search" size={20} color="#888" />}
85
+ />
86
+ )}
87
+
88
+ <View style={getContainerStyle()}>
89
+ <Empty />
90
+ {items.map((item: any, i: number) => (
91
+ <TouchableHighlight
92
+ key={`k-${i}`}
93
+ style={getRowStyle()}
94
+ underlayColor={'transparent'}
95
+ onPress={e => {
96
+ onClick(item);
97
+ }}
98
+ >
99
+ <View style={getStyle('rowInner')}>
100
+ <UIListRow scope={scope} item={item} index={i}>
101
+ {props.children}
102
+ </UIListRow>
103
+ </View>
104
+ </TouchableHighlight>
105
+ ))}
106
+ </View>
107
+ </>
108
+ );
109
+ }
110
+
111
+ const stylesList = StyleSheet.create({
112
+ container: {
113
+ flex: 1,
114
+ width: '100%',
115
+ flexDirection: 'row',
116
+ flexWrap: 'wrap',
117
+ alignItems: 'stretch',
118
+ },
119
+ row: {
120
+ padding: 5,
121
+ width: '100%',
122
+ },
123
+ rowInner: {
124
+ flexGrow: 1, // ✅ cresce conforme o conteúdo
125
+ justifyContent: 'center',
126
+ alignItems: 'center',
127
+ backgroundColor: '#f5f5f5',
128
+ borderRadius: 8,
129
+ padding: 10,
130
+ width: '100%',
131
+ },
132
+ text: {
133
+ fontSize: 18,
134
+ fontWeight: 'bold',
135
+ },
136
+ });
137
+
138
+ const stylesRepeat = StyleSheet.create({
139
+ container: {
140
+ flex: 1,
141
+ width: '100%',
142
+ flexDirection: 'row',
143
+ flexWrap: 'wrap',
144
+ gap: 10,
145
+ alignItems: 'stretch',
146
+ },
147
+ row: {
148
+ padding: 0,
149
+ width: '100%',
150
+ },
151
+ rowInner: {
152
+ flexGrow: 1, // ✅ cresce conforme o conteúdo
153
+ justifyContent: 'center',
154
+ alignItems: 'center',
155
+ padding: 0,
156
+ width: '100%',
157
+ },
158
+ text: {
159
+ fontSize: 18,
160
+ fontWeight: 'bold',
161
+ },
162
+ });
@@ -1,32 +1,32 @@
1
- import React, { useState } from 'react';
2
- import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
- import UIChildren from '../UIChildren';
4
-
5
- interface UIListRowType extends ChildType {
6
- item: any;
7
- index: number;
8
- }
9
-
10
- export default function UIListRow(props: UIListRowType) {
11
- const parent = props.scope;
12
- const item = props.item;
13
- const index = props.index;
14
- const name = `${parent.key('row', index)}`;
15
- const row = {
16
- parent,
17
- name,
18
- crud: parent.crud,
19
- index,
20
- type: 'row',
21
- data: item,
22
- };
23
- let [scope] = useState(ScopeUtils.create(row));
24
-
25
- return (
26
- <>
27
- <UIChildren scope={scope} crud={scope.crud}>
28
- {props.children}
29
- </UIChildren>
30
- </>
31
- );
32
- }
1
+ import React, { useState } from 'react';
2
+ import { ChildType, ScopeUtils, Utils } from 'react-crud-utils';
3
+ import UIChildren from '../UIChildren';
4
+
5
+ interface UIListRowType extends ChildType {
6
+ item: any;
7
+ index: number;
8
+ }
9
+
10
+ export default function UIListRow(props: UIListRowType) {
11
+ const parent = props.scope;
12
+ const item = props.item;
13
+ const index = props.index;
14
+ const name = `${parent.key('row', index)}`;
15
+ const row = {
16
+ parent,
17
+ name,
18
+ crud: parent.crud,
19
+ index,
20
+ type: 'row',
21
+ data: item,
22
+ };
23
+ let [scope] = useState(ScopeUtils.create(row));
24
+
25
+ return (
26
+ <>
27
+ <UIChildren scope={scope} crud={scope.crud}>
28
+ {props.children}
29
+ </UIChildren>
30
+ </>
31
+ );
32
+ }
@@ -1,134 +1,134 @@
1
- import { useEffect, useState } from 'react';
2
- import {
3
- ChildType,
4
- CrudUtils,
5
- MethodType,
6
- useTheme,
7
- Utils,
8
- } from 'react-crud-utils';
9
- import {
10
- Text,
11
- TouchableOpacity,
12
- StyleSheet,
13
- Modal,
14
- View,
15
- StatusBar,
16
- SafeAreaView,
17
- ScrollView,
18
- } from 'react-native';
19
- import UIChildren from '../UIChildren';
20
-
21
- export default function UIModal(props: ChildType) {
22
- let [modalVisible, setModalVisible] = useState(false);
23
-
24
- const scope = props.scope;
25
- const label = scope.getLabel();
26
- const theme = useTheme();
27
-
28
- const style = (part: string, extra?: any) => {
29
- let st = { ...styles[part], ...extra };
30
-
31
- return { ...scope.getStyle(part, st) };
32
- };
33
-
34
- const toggle = vis => {
35
- modalVisible = vis;
36
- setModalVisible(modalVisible);
37
- };
38
-
39
- scope.show = (args?: MethodType) => {
40
- let { crud } = args;
41
- let name = scope.getName('modal');
42
- let data = Utils.nvl(args.item, {});
43
- let edit = args.edit === true;
44
- let d = CrudUtils.create('dialog', {
45
- parent: crud,
46
- name,
47
- data,
48
- edit,
49
- scope,
50
- });
51
-
52
- scope.currentDialog = d;
53
-
54
- toggle(true);
55
- };
56
-
57
- scope.hide = (args?: MethodType) => {
58
- scope.currentDialog = null;
59
-
60
- toggle(false);
61
- };
62
-
63
- useEffect(() => {
64
- StatusBar.setBarStyle('light-content');
65
- StatusBar.setBackgroundColor?.(theme.colors.primary);
66
- }, [modalVisible]);
67
-
68
- if (!scope.currentDialog) {
69
- return <></>;
70
- }
71
-
72
- return (
73
- <Modal
74
- animationType="slide"
75
- transparent={true}
76
- visible={modalVisible}
77
- onRequestClose={() => setModalVisible(false)}
78
- >
79
- <SafeAreaView style={style('modalSafe')}>
80
- <View style={style('modalHeader')}>
81
- <TouchableOpacity
82
- onPress={() => setModalVisible(false)}
83
- style={style('modalCloseButton')}
84
- >
85
- <Text style={style('modalCloseText')}>X</Text>
86
- </TouchableOpacity>
87
- <Text style={style('modalTitle')}>{label}</Text>
88
- </View>
89
- <ScrollView
90
- contentContainerStyle={{ flexGrow: 1 }}
91
- style={style('modalContent')}
92
- >
93
- <View style={{ flex: 1 }}>
94
- <UIChildren scope={scope} crud={scope.currentDialog}>
95
- {props.children}
96
- </UIChildren>
97
- </View>
98
- </ScrollView>
99
- </SafeAreaView>
100
- </Modal>
101
- );
102
- }
103
-
104
- const styles = StyleSheet.create({
105
- modalSafe: {
106
- flex: 1,
107
- backgroundColor: 'primary',
108
- width: '100%',
109
- },
110
- modalHeader: {
111
- flexDirection: 'row',
112
- alignItems: 'center',
113
- padding: 15,
114
- backgroundColor: 'primary',
115
- },
116
- modalCloseButton: {
117
- padding: 10,
118
- },
119
- modalCloseText: {
120
- fontSize: 18,
121
- color: 'white',
122
- },
123
- modalTitle: {
124
- fontSize: 18,
125
- color: 'white',
126
- fontWeight: 'bold',
127
- marginLeft: 10,
128
- },
129
- modalContent: {
130
- flex: 1,
131
- backgroundColor: '#f5f5f5',
132
- padding: 20,
133
- },
134
- });
1
+ import { useEffect, useState } from 'react';
2
+ import {
3
+ ChildType,
4
+ CrudUtils,
5
+ MethodType,
6
+ useTheme,
7
+ Utils,
8
+ } from 'react-crud-utils';
9
+ import {
10
+ Text,
11
+ TouchableOpacity,
12
+ StyleSheet,
13
+ Modal,
14
+ View,
15
+ StatusBar,
16
+ SafeAreaView,
17
+ ScrollView,
18
+ } from 'react-native';
19
+ import UIChildren from '../UIChildren';
20
+
21
+ export default function UIModal(props: ChildType) {
22
+ let [modalVisible, setModalVisible] = useState(false);
23
+
24
+ const scope = props.scope;
25
+ const label = scope.getLabel();
26
+ const theme = useTheme();
27
+
28
+ const style = (part: string, extra?: any) => {
29
+ let st = { ...styles[part], ...extra };
30
+
31
+ return { ...scope.getStyle(part, st) };
32
+ };
33
+
34
+ const toggle = vis => {
35
+ modalVisible = vis;
36
+ setModalVisible(modalVisible);
37
+ };
38
+
39
+ scope.show = (args?: MethodType) => {
40
+ let { crud } = args;
41
+ let name = scope.getName('modal');
42
+ let data = Utils.nvl(args.item, {});
43
+ let edit = args.edit === true;
44
+ let d = CrudUtils.create('dialog', {
45
+ parent: crud,
46
+ name,
47
+ data,
48
+ edit,
49
+ scope,
50
+ });
51
+
52
+ scope.currentDialog = d;
53
+
54
+ toggle(true);
55
+ };
56
+
57
+ scope.hide = (args?: MethodType) => {
58
+ scope.currentDialog = null;
59
+
60
+ toggle(false);
61
+ };
62
+
63
+ useEffect(() => {
64
+ StatusBar.setBarStyle('light-content');
65
+ StatusBar.setBackgroundColor?.(theme.colors.primary);
66
+ }, [modalVisible]);
67
+
68
+ if (!scope.currentDialog) {
69
+ return <></>;
70
+ }
71
+
72
+ return (
73
+ <Modal
74
+ animationType="slide"
75
+ transparent={true}
76
+ visible={modalVisible}
77
+ onRequestClose={() => setModalVisible(false)}
78
+ >
79
+ <SafeAreaView style={style('modalSafe')}>
80
+ <View style={style('modalHeader')}>
81
+ <TouchableOpacity
82
+ onPress={() => setModalVisible(false)}
83
+ style={style('modalCloseButton')}
84
+ >
85
+ <Text style={style('modalCloseText')}>X</Text>
86
+ </TouchableOpacity>
87
+ <Text style={style('modalTitle')}>{label}</Text>
88
+ </View>
89
+ <ScrollView
90
+ contentContainerStyle={{ flexGrow: 1 }}
91
+ style={style('modalContent')}
92
+ >
93
+ <View style={{ flex: 1 }}>
94
+ <UIChildren scope={scope} crud={scope.currentDialog}>
95
+ {props.children}
96
+ </UIChildren>
97
+ </View>
98
+ </ScrollView>
99
+ </SafeAreaView>
100
+ </Modal>
101
+ );
102
+ }
103
+
104
+ const styles = StyleSheet.create({
105
+ modalSafe: {
106
+ flex: 1,
107
+ backgroundColor: 'primary',
108
+ width: '100%',
109
+ },
110
+ modalHeader: {
111
+ flexDirection: 'row',
112
+ alignItems: 'center',
113
+ padding: 15,
114
+ backgroundColor: 'primary',
115
+ },
116
+ modalCloseButton: {
117
+ padding: 10,
118
+ },
119
+ modalCloseText: {
120
+ fontSize: 18,
121
+ color: 'white',
122
+ },
123
+ modalTitle: {
124
+ fontSize: 18,
125
+ color: 'white',
126
+ fontWeight: 'bold',
127
+ marginLeft: 10,
128
+ },
129
+ modalContent: {
130
+ flex: 1,
131
+ backgroundColor: '#f5f5f5',
132
+ padding: 20,
133
+ },
134
+ });