react-crud-mobile 1.3.52 → 1.3.53

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,169 +1,169 @@
1
- import React, { useState } from 'react';
2
- import { ChildType, ComponentUtils, ScopeUtils, Utils } from 'react-crud-utils';
3
- import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
4
- import UI from '../UI';
5
- import { Ionicons } from '@expo/vector-icons';
6
- import DraggableFlatList from 'react-native-draggable-flatlist';
7
-
8
- export default function UIOrder(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 add = ComponentUtils.getDefine(props, 'add');
14
- const hideAddWhenEmpty = original.hideAddWhenEmpty;
15
-
16
- const getStyle = (key: string, extra?: any) => {
17
- return scope.getStyle(key, { ...extra, ...styles[key] });
18
- };
19
-
20
- const getContainerStyle = (extra?: any) => {
21
- let row = getStyle('container', {});
22
-
23
- if (cols > 1) {
24
- row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
25
- }
26
-
27
- return row;
28
- };
29
-
30
- const LocalData = () => {
31
- let [index, setIndex] = useState(scope.updateIndex);
32
-
33
- scope.update = () => {
34
- scope.updateIndex = ++index;
35
-
36
- setIndex(index);
37
- };
38
-
39
- let keyData = scope.key('data');
40
-
41
- const items = Utils.call(() => {
42
- let list = Utils.nvl(scope.getItems(), []);
43
-
44
- if (original.search && !original.list?.url) {
45
- let query = crud
46
- .get('query', '')
47
- .toLowerCase()
48
- .trim() as string;
49
-
50
- if (query.length > 1) {
51
- let filters: any[] = [];
52
- let filterBy = Utils.nvl(original.filterBy, 'label');
53
-
54
- Utils.each(list, o => {
55
- let label = o[filterBy];
56
-
57
- if (label) {
58
- if (label.includes(query)) {
59
- filters.push(o);
60
- }
61
- }
62
- });
63
-
64
- return filters;
65
- }
66
- }
67
- return list;
68
- });
69
-
70
- const isShowAdd = () => {
71
- if (!Utils.isEmpty(items)) {
72
- return true;
73
- }
74
- return hideAddWhenEmpty !== true;
75
- };
76
-
77
- let Empty = () => {
78
- if (!Utils.isEmpty(items)) {
79
- return <></>;
80
- }
81
-
82
- let empty = scope.attr('empty', 'Sem registro');
83
-
84
- if (!empty) {
85
- return <></>;
86
- }
87
-
88
- if (typeof empty === 'string') {
89
- return (
90
- <Text
91
- style={scope.getStyle('empty', {
92
- flex: 1,
93
- fontWeight: 500,
94
- fontSize: 20,
95
- padding: 10,
96
- textAlign: 'center',
97
- justifyContent: 'center',
98
- alignItems: 'center',
99
- })}
100
- >
101
- {empty}
102
- </Text>
103
- );
104
- }
105
-
106
- return <>{empty}</>;
107
- };
108
-
109
- const renderItem = ({ item, drag, isActive }) => {
110
- return (
111
- <TouchableOpacity
112
- style={[
113
- styles.row,
114
- { backgroundColor: isActive ? 'lightblue' : 'white' },
115
- ]}
116
- onLongPress={drag} // Initiate drag on long press
117
- >
118
- <Text style={styles.text}>{scope.getItemLabel(item)}</Text>
119
- </TouchableOpacity>
120
- );
121
- };
122
-
123
- return (
124
- <View key={keyData} style={getContainerStyle()}>
125
- <Empty />
126
- <DraggableFlatList
127
- data={items}
128
- renderItem={renderItem}
129
- keyExtractor={item => scope.getItemValue(item)}
130
- onDragEnd={({ data }) => {
131
- scope.changeValue(data);
132
- }}
133
- />
134
- {isShowAdd() && <>{add}</>}
135
- </View>
136
- );
137
- };
138
-
139
- return (
140
- <>
141
- {original.search !== false && (
142
- <UI.Text
143
- placeholder="Pesquisar..."
144
- field="query"
145
- crud={crud}
146
- style={{ marginBottom: 10 }}
147
- change={{
148
- action: () => {
149
- scope.search();
150
- },
151
- }}
152
- icon={<Ionicons name="search" size={20} color="#888" />}
153
- />
154
- )}
155
- <LocalData />
156
- </>
157
- );
158
- }
159
-
160
- const styles = StyleSheet.create({
161
- row: {
162
- padding: 20,
163
- borderBottomWidth: 1,
164
- borderBottomColor: '#ccc',
165
- },
166
- text: {
167
- fontSize: 18,
168
- },
169
- });
1
+ import React, { useState } from 'react';
2
+ import { ChildType, ComponentUtils, ScopeUtils, Utils } from 'react-crud-utils';
3
+ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
4
+ import UI from '../UI';
5
+ import { Ionicons } from '@expo/vector-icons';
6
+ import DraggableFlatList from 'react-native-draggable-flatlist';
7
+
8
+ export default function UIOrder(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 add = ComponentUtils.getDefine(props, 'add');
14
+ const hideAddWhenEmpty = original.hideAddWhenEmpty;
15
+
16
+ const getStyle = (key: string, extra?: any) => {
17
+ return scope.getStyle(key, { ...extra, ...styles[key] });
18
+ };
19
+
20
+ const getContainerStyle = (extra?: any) => {
21
+ let row = getStyle('container', {});
22
+
23
+ if (cols > 1) {
24
+ row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
25
+ }
26
+
27
+ return row;
28
+ };
29
+
30
+ const LocalData = () => {
31
+ let [index, setIndex] = useState(scope.updateIndex);
32
+
33
+ scope.update = () => {
34
+ scope.updateIndex = ++index;
35
+
36
+ setIndex(index);
37
+ };
38
+
39
+ let keyData = scope.key('data');
40
+
41
+ const items = Utils.call(() => {
42
+ let list = Utils.nvl(scope.getItems(), []);
43
+
44
+ if (original.search && !original.list?.url) {
45
+ let query = crud
46
+ .get('query', '')
47
+ .toLowerCase()
48
+ .trim() as string;
49
+
50
+ if (query.length > 1) {
51
+ let filters: any[] = [];
52
+ let filterBy = Utils.nvl(original.filterBy, 'label');
53
+
54
+ Utils.each(list, o => {
55
+ let label = o[filterBy];
56
+
57
+ if (label) {
58
+ if (label.includes(query)) {
59
+ filters.push(o);
60
+ }
61
+ }
62
+ });
63
+
64
+ return filters;
65
+ }
66
+ }
67
+ return list;
68
+ });
69
+
70
+ const isShowAdd = () => {
71
+ if (!Utils.isEmpty(items)) {
72
+ return true;
73
+ }
74
+ return hideAddWhenEmpty !== true;
75
+ };
76
+
77
+ let Empty = () => {
78
+ if (!Utils.isEmpty(items)) {
79
+ return <></>;
80
+ }
81
+
82
+ let empty = scope.attr('empty', 'Sem registro');
83
+
84
+ if (!empty) {
85
+ return <></>;
86
+ }
87
+
88
+ if (typeof empty === 'string') {
89
+ return (
90
+ <Text
91
+ style={scope.getStyle('empty', {
92
+ flex: 1,
93
+ fontWeight: 500,
94
+ fontSize: 20,
95
+ padding: 10,
96
+ textAlign: 'center',
97
+ justifyContent: 'center',
98
+ alignItems: 'center',
99
+ })}
100
+ >
101
+ {empty}
102
+ </Text>
103
+ );
104
+ }
105
+
106
+ return <>{empty}</>;
107
+ };
108
+
109
+ const renderItem = ({ item, drag, isActive }) => {
110
+ return (
111
+ <TouchableOpacity
112
+ style={[
113
+ styles.row,
114
+ { backgroundColor: isActive ? 'lightblue' : 'white' },
115
+ ]}
116
+ onLongPress={drag} // Initiate drag on long press
117
+ >
118
+ <Text style={styles.text}>{scope.getItemLabel(item)}</Text>
119
+ </TouchableOpacity>
120
+ );
121
+ };
122
+
123
+ return (
124
+ <View key={keyData} style={getContainerStyle()}>
125
+ <Empty />
126
+ <DraggableFlatList
127
+ data={items}
128
+ renderItem={renderItem}
129
+ keyExtractor={item => scope.getItemValue(item)}
130
+ onDragEnd={({ data }) => {
131
+ scope.changeValue(data);
132
+ }}
133
+ />
134
+ {isShowAdd() && <>{add}</>}
135
+ </View>
136
+ );
137
+ };
138
+
139
+ return (
140
+ <>
141
+ {original.search !== false && (
142
+ <UI.Text
143
+ placeholder="Pesquisar..."
144
+ field="query"
145
+ crud={crud}
146
+ style={{ marginBottom: 10 }}
147
+ change={{
148
+ action: () => {
149
+ scope.search();
150
+ },
151
+ }}
152
+ icon={<Ionicons name="search" size={20} color="#888" />}
153
+ />
154
+ )}
155
+ <LocalData />
156
+ </>
157
+ );
158
+ }
159
+
160
+ const styles = StyleSheet.create({
161
+ row: {
162
+ padding: 20,
163
+ borderBottomWidth: 1,
164
+ borderBottomColor: '#ccc',
165
+ },
166
+ text: {
167
+ fontSize: 18,
168
+ },
169
+ });
@@ -1,98 +1,98 @@
1
- import { Ionicons } from '@expo/vector-icons';
2
- import { useState } from 'react';
3
- import { ChildType, Utils } from 'react-crud-utils';
4
- import { Text, TouchableHighlight, View } from 'react-native';
5
-
6
- export default function UIQuantity(props: ChildType) {
7
- const scope = props.scope;
8
- const element = scope.original;
9
-
10
- let [index, setIndex] = useState(0);
11
-
12
- const value = scope.getValue(0);
13
-
14
- let color = element.color;
15
-
16
- if (!color) color = 'primary';
17
-
18
- const btn = {
19
- padding: 0,
20
- alignItems: 'center',
21
- height: 30,
22
- width: 30,
23
- textAlign: 'center',
24
- verticalAling: 'middle',
25
- borderRadius: 24,
26
- backgroundColor: color,
27
- color: '#ffffff',
28
- justifyContent: 'center',
29
- };
30
-
31
- const styles: any = {
32
- buttonLabel: {
33
- color: '#ffffff',
34
- fontWeight: '500',
35
- fontSize: 16,
36
- },
37
- value: {
38
- flex: 1,
39
- flexDirection: 'row',
40
- textAlign: 'center',
41
- fontWeight: '500',
42
- },
43
- buttonInner: {
44
- flexDirection: 'row',
45
- alignItems: 'center',
46
- justifyContent: 'center',
47
- },
48
- buttonIcon: {
49
- color: '#fff',
50
- fontSize: 18,
51
- },
52
- button: btn,
53
- addButton: {
54
- ...btn,
55
- },
56
- delButton: {
57
- ...btn,
58
- },
59
- };
60
-
61
- const change = (val: number) => {
62
- scope.changeValue(value + val);
63
- setIndex(++index);
64
- };
65
-
66
- const onClickAdd = () => {
67
- change(1);
68
- };
69
-
70
- const onClickDel = () => {
71
- change(-1);
72
- };
73
-
74
- const style = (part: string, extra?: any) => {
75
- let s = { ...styles[part], ...extra };
76
- return scope.getStyle(part, s);
77
- };
78
-
79
- return (
80
- <>
81
- <TouchableHighlight
82
- underlayColor={'transparent'}
83
- onPress={onClickDel}
84
- style={style('delButton')}
85
- >
86
- <Ionicons size={30} style={style('buttonIcon')} name="remove" />
87
- </TouchableHighlight>
88
- <Text style={style('value')}>{Utils.nvl(value, 0)}</Text>
89
- <TouchableHighlight
90
- underlayColor={'transparent'}
91
- onPress={onClickAdd}
92
- style={style('addButton')}
93
- >
94
- <Ionicons size={30} style={style('buttonIcon')} name="add" />
95
- </TouchableHighlight>
96
- </>
97
- );
98
- }
1
+ import { Ionicons } from '@expo/vector-icons';
2
+ import { useState } from 'react';
3
+ import { ChildType, Utils } from 'react-crud-utils';
4
+ import { Text, TouchableHighlight, View } from 'react-native';
5
+
6
+ export default function UIQuantity(props: ChildType) {
7
+ const scope = props.scope;
8
+ const element = scope.original;
9
+
10
+ let [index, setIndex] = useState(0);
11
+
12
+ const value = scope.getValue(0);
13
+
14
+ let color = element.color;
15
+
16
+ if (!color) color = 'primary';
17
+
18
+ const btn = {
19
+ padding: 0,
20
+ alignItems: 'center',
21
+ height: 30,
22
+ width: 30,
23
+ textAlign: 'center',
24
+ verticalAling: 'middle',
25
+ borderRadius: 24,
26
+ backgroundColor: color,
27
+ color: '#ffffff',
28
+ justifyContent: 'center',
29
+ };
30
+
31
+ const styles: any = {
32
+ buttonLabel: {
33
+ color: '#ffffff',
34
+ fontWeight: '500',
35
+ fontSize: 16,
36
+ },
37
+ value: {
38
+ flex: 1,
39
+ flexDirection: 'row',
40
+ textAlign: 'center',
41
+ fontWeight: '500',
42
+ },
43
+ buttonInner: {
44
+ flexDirection: 'row',
45
+ alignItems: 'center',
46
+ justifyContent: 'center',
47
+ },
48
+ buttonIcon: {
49
+ color: '#fff',
50
+ fontSize: 18,
51
+ },
52
+ button: btn,
53
+ addButton: {
54
+ ...btn,
55
+ },
56
+ delButton: {
57
+ ...btn,
58
+ },
59
+ };
60
+
61
+ const change = (val: number) => {
62
+ scope.changeValue(value + val);
63
+ setIndex(++index);
64
+ };
65
+
66
+ const onClickAdd = () => {
67
+ change(1);
68
+ };
69
+
70
+ const onClickDel = () => {
71
+ change(-1);
72
+ };
73
+
74
+ const style = (part: string, extra?: any) => {
75
+ let s = { ...styles[part], ...extra };
76
+ return scope.getStyle(part, s);
77
+ };
78
+
79
+ return (
80
+ <>
81
+ <TouchableHighlight
82
+ underlayColor={'transparent'}
83
+ onPress={onClickDel}
84
+ style={style('delButton')}
85
+ >
86
+ <Ionicons size={30} style={style('buttonIcon')} name="remove" />
87
+ </TouchableHighlight>
88
+ <Text style={style('value')}>{Utils.nvl(value, 0)}</Text>
89
+ <TouchableHighlight
90
+ underlayColor={'transparent'}
91
+ onPress={onClickAdd}
92
+ style={style('addButton')}
93
+ >
94
+ <Ionicons size={30} style={style('buttonIcon')} name="add" />
95
+ </TouchableHighlight>
96
+ </>
97
+ );
98
+ }