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.
- package/dist/react-crud-mobile.cjs.development.js.map +1 -1
- package/dist/react-crud-mobile.cjs.production.min.js.map +1 -1
- package/dist/react-crud-mobile.esm.js.map +1 -1
- package/package.json +76 -76
- package/src/elements/UI.tsx +74 -74
- package/src/elements/UIChildren.tsx +139 -139
- package/src/elements/UIComplete.tsx +14 -14
- package/src/elements/UIElement.tsx +707 -707
- package/src/elements/UITag.tsx +13 -13
- package/src/elements/charts/ElChart.tsx +10 -10
- package/src/elements/core/SafeView.tsx +69 -69
- package/src/elements/core/UIButton.tsx +139 -139
- package/src/elements/core/UIIcon.tsx +25 -25
- package/src/elements/core/UIInclude.tsx +40 -40
- package/src/elements/core/UIInput.tsx +96 -96
- package/src/elements/core/UIList.tsx +168 -168
- package/src/elements/core/UIListRow.tsx +123 -123
- package/src/elements/core/UIModal.tsx +206 -206
- package/src/elements/core/UIOrder.tsx +169 -169
- package/src/elements/core/UIQuantity.tsx +98 -98
- package/src/elements/core/UISelect.tsx +177 -177
- package/src/elements/core/UIToast.tsx +44 -44
- package/src/elements/core/UIToggle.tsx +102 -102
- package/src/elements/core/UIView.tsx +94 -94
- package/src/elements/index.ts +1 -1
- package/src/elements/tabs/ElTabs.tsx +178 -178
- package/src/index.ts +1 -1
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { ChildType, MethodType, Utils, ViewUtils } from 'react-crud-utils';
|
|
3
|
-
import {
|
|
4
|
-
Text,
|
|
5
|
-
TouchableOpacity,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
Modal,
|
|
8
|
-
View,
|
|
9
|
-
StatusBar,
|
|
10
|
-
SafeAreaView,
|
|
11
|
-
ScrollView,
|
|
12
|
-
} from 'react-native';
|
|
13
|
-
import { Ionicons } from '@expo/vector-icons';
|
|
14
|
-
import UI from '../UI';
|
|
15
|
-
import MobileUtils from '../../utils/MobileUtils';
|
|
16
|
-
|
|
17
|
-
export default function UISelect(props: ChildType) {
|
|
18
|
-
const [modalVisible, setModalVisible] = useState(false);
|
|
19
|
-
const scope = props.scope;
|
|
20
|
-
const element = scope.original;
|
|
21
|
-
const items = Utils.nvl(scope.getOptions(), []);
|
|
22
|
-
const placeholder = scope.attr('placeholder', 'Selecione...');
|
|
23
|
-
const value = scope.getDisplayValue();
|
|
24
|
-
const theme = scope.getTheme();
|
|
25
|
-
const headerStyle = Utils.nvl(theme.styles?.defaults?.header, {});
|
|
26
|
-
const handlePress = () => {
|
|
27
|
-
setModalVisible(!modalVisible);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const scrollRef = useRef(null);
|
|
31
|
-
const iconColor = Utils.nvl(theme.colors?.text, '#100e0e');
|
|
32
|
-
const modalColor = Utils.nvl(headerStyle.color, 'white');
|
|
33
|
-
const defaults = { color: modalColor };
|
|
34
|
-
const onClick = ({ crud, value }: MethodType) => {
|
|
35
|
-
let val = value as any;
|
|
36
|
-
|
|
37
|
-
if (element.isObject && val?.object) {
|
|
38
|
-
scope.changeValue(val?.object);
|
|
39
|
-
} else if (val?.value) {
|
|
40
|
-
scope.changeValue(val?.value);
|
|
41
|
-
} else {
|
|
42
|
-
scope.changeValue(value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
setModalVisible(false);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const style = (part: string, extra?: any) => {
|
|
49
|
-
let all = { ...styles[part], ...extra };
|
|
50
|
-
|
|
51
|
-
return scope.getStyle(part, all);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const isModalVisible = () => {
|
|
55
|
-
return modalVisible;
|
|
56
|
-
};
|
|
57
|
-
//v4
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
MobileUtils.syncTheme();
|
|
61
|
-
}, [modalVisible]);
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<View
|
|
65
|
-
key={scope.getName(`${scope.getPart('modal')}_${modalVisible}`)}
|
|
66
|
-
style={style('selectRoot')}
|
|
67
|
-
>
|
|
68
|
-
<TouchableOpacity onPress={handlePress} style={style('selectInput')}>
|
|
69
|
-
<Text style={style('selectLabel')}>
|
|
70
|
-
{Utils.nvl(value, placeholder)}
|
|
71
|
-
</Text>
|
|
72
|
-
<Ionicons
|
|
73
|
-
name="chevron-down-outline"
|
|
74
|
-
size={scope.getPart('iconSize', null, 24)}
|
|
75
|
-
color={scope.getPart('iconColor', null, iconColor)}
|
|
76
|
-
style={style('iconStyle', {})}
|
|
77
|
-
/>
|
|
78
|
-
</TouchableOpacity>
|
|
79
|
-
<Modal
|
|
80
|
-
animationType="slide"
|
|
81
|
-
transparent={true}
|
|
82
|
-
visible={isModalVisible()}
|
|
83
|
-
onRequestClose={() => setModalVisible(false)}
|
|
84
|
-
>
|
|
85
|
-
<SafeAreaView style={style('modalTop')} />
|
|
86
|
-
<SafeAreaView style={style('modalSafe')}>
|
|
87
|
-
<View style={scope.getStyle('header', headerStyle)}>
|
|
88
|
-
<TouchableOpacity
|
|
89
|
-
onPress={handlePress}
|
|
90
|
-
style={style('modalCloseButton')}
|
|
91
|
-
>
|
|
92
|
-
<Ionicons
|
|
93
|
-
name="close"
|
|
94
|
-
size={24}
|
|
95
|
-
color={modalColor}
|
|
96
|
-
style={style('modalCloseText', defaults)}
|
|
97
|
-
/>
|
|
98
|
-
</TouchableOpacity>
|
|
99
|
-
<Text style={style('modalTitle', defaults)}>{placeholder}</Text>
|
|
100
|
-
</View>
|
|
101
|
-
<ScrollView
|
|
102
|
-
contentContainerStyle={{ flexGrow: 1, paddingBottom: 50 }}
|
|
103
|
-
style={style('modalContent')}
|
|
104
|
-
nestedScrollEnabled={true}
|
|
105
|
-
ref={scrollRef}
|
|
106
|
-
>
|
|
107
|
-
<View
|
|
108
|
-
style={{
|
|
109
|
-
flex: 1,
|
|
110
|
-
paddingLeft: 15,
|
|
111
|
-
paddingRight: 15,
|
|
112
|
-
paddingTop: 10,
|
|
113
|
-
paddingBottom: 10,
|
|
114
|
-
}}
|
|
115
|
-
>
|
|
116
|
-
<UI.List
|
|
117
|
-
data={items}
|
|
118
|
-
name={scope.getName('list')}
|
|
119
|
-
layout="card"
|
|
120
|
-
click={onClick}
|
|
121
|
-
rowStyle={{
|
|
122
|
-
paddingLeft: 15,
|
|
123
|
-
paddinRight: 15,
|
|
124
|
-
...scope.original?.rowStyle,
|
|
125
|
-
}}
|
|
126
|
-
{...scope.original?.listProps}
|
|
127
|
-
>
|
|
128
|
-
<UI.Value value="#{@this.label}" />
|
|
129
|
-
</UI.List>
|
|
130
|
-
</View>
|
|
131
|
-
</ScrollView>
|
|
132
|
-
</SafeAreaView>
|
|
133
|
-
</Modal>
|
|
134
|
-
</View>
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const styles = StyleSheet.create({
|
|
139
|
-
selectRoot: {
|
|
140
|
-
justifyContent: 'flex-start',
|
|
141
|
-
alignItems: 'flex-start',
|
|
142
|
-
flex: 1,
|
|
143
|
-
},
|
|
144
|
-
selectInput: {
|
|
145
|
-
width: '100%',
|
|
146
|
-
flexDirection: 'row',
|
|
147
|
-
borderRadius: 5,
|
|
148
|
-
paddingHorizontal: 15,
|
|
149
|
-
paddingVertical: 10,
|
|
150
|
-
},
|
|
151
|
-
selectLabel: { flex: 1 },
|
|
152
|
-
modalTop: {
|
|
153
|
-
backgroundColor: 'primary',
|
|
154
|
-
width: '100%',
|
|
155
|
-
},
|
|
156
|
-
modalSafe: {
|
|
157
|
-
flex: 1,
|
|
158
|
-
width: '100%',
|
|
159
|
-
backgroundColor: 'background',
|
|
160
|
-
},
|
|
161
|
-
modalCloseButton: {
|
|
162
|
-
padding: 10,
|
|
163
|
-
},
|
|
164
|
-
modalCloseText: {
|
|
165
|
-
fontSize: 18,
|
|
166
|
-
color: 'white',
|
|
167
|
-
},
|
|
168
|
-
modalTitle: {
|
|
169
|
-
fontSize: 18,
|
|
170
|
-
fontWeight: 'bold',
|
|
171
|
-
marginLeft: 10,
|
|
172
|
-
},
|
|
173
|
-
modalContent: {
|
|
174
|
-
flex: 1,
|
|
175
|
-
backgroundColor: 'background',
|
|
176
|
-
},
|
|
177
|
-
});
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { ChildType, MethodType, Utils, ViewUtils } from 'react-crud-utils';
|
|
3
|
+
import {
|
|
4
|
+
Text,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Modal,
|
|
8
|
+
View,
|
|
9
|
+
StatusBar,
|
|
10
|
+
SafeAreaView,
|
|
11
|
+
ScrollView,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
14
|
+
import UI from '../UI';
|
|
15
|
+
import MobileUtils from '../../utils/MobileUtils';
|
|
16
|
+
|
|
17
|
+
export default function UISelect(props: ChildType) {
|
|
18
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
19
|
+
const scope = props.scope;
|
|
20
|
+
const element = scope.original;
|
|
21
|
+
const items = Utils.nvl(scope.getOptions(), []);
|
|
22
|
+
const placeholder = scope.attr('placeholder', 'Selecione...');
|
|
23
|
+
const value = scope.getDisplayValue();
|
|
24
|
+
const theme = scope.getTheme();
|
|
25
|
+
const headerStyle = Utils.nvl(theme.styles?.defaults?.header, {});
|
|
26
|
+
const handlePress = () => {
|
|
27
|
+
setModalVisible(!modalVisible);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const scrollRef = useRef(null);
|
|
31
|
+
const iconColor = Utils.nvl(theme.colors?.text, '#100e0e');
|
|
32
|
+
const modalColor = Utils.nvl(headerStyle.color, 'white');
|
|
33
|
+
const defaults = { color: modalColor };
|
|
34
|
+
const onClick = ({ crud, value }: MethodType) => {
|
|
35
|
+
let val = value as any;
|
|
36
|
+
|
|
37
|
+
if (element.isObject && val?.object) {
|
|
38
|
+
scope.changeValue(val?.object);
|
|
39
|
+
} else if (val?.value) {
|
|
40
|
+
scope.changeValue(val?.value);
|
|
41
|
+
} else {
|
|
42
|
+
scope.changeValue(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setModalVisible(false);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const style = (part: string, extra?: any) => {
|
|
49
|
+
let all = { ...styles[part], ...extra };
|
|
50
|
+
|
|
51
|
+
return scope.getStyle(part, all);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const isModalVisible = () => {
|
|
55
|
+
return modalVisible;
|
|
56
|
+
};
|
|
57
|
+
//v4
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
MobileUtils.syncTheme();
|
|
61
|
+
}, [modalVisible]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<View
|
|
65
|
+
key={scope.getName(`${scope.getPart('modal')}_${modalVisible}`)}
|
|
66
|
+
style={style('selectRoot')}
|
|
67
|
+
>
|
|
68
|
+
<TouchableOpacity onPress={handlePress} style={style('selectInput')}>
|
|
69
|
+
<Text style={style('selectLabel')}>
|
|
70
|
+
{Utils.nvl(value, placeholder)}
|
|
71
|
+
</Text>
|
|
72
|
+
<Ionicons
|
|
73
|
+
name="chevron-down-outline"
|
|
74
|
+
size={scope.getPart('iconSize', null, 24)}
|
|
75
|
+
color={scope.getPart('iconColor', null, iconColor)}
|
|
76
|
+
style={style('iconStyle', {})}
|
|
77
|
+
/>
|
|
78
|
+
</TouchableOpacity>
|
|
79
|
+
<Modal
|
|
80
|
+
animationType="slide"
|
|
81
|
+
transparent={true}
|
|
82
|
+
visible={isModalVisible()}
|
|
83
|
+
onRequestClose={() => setModalVisible(false)}
|
|
84
|
+
>
|
|
85
|
+
<SafeAreaView style={style('modalTop')} />
|
|
86
|
+
<SafeAreaView style={style('modalSafe')}>
|
|
87
|
+
<View style={scope.getStyle('header', headerStyle)}>
|
|
88
|
+
<TouchableOpacity
|
|
89
|
+
onPress={handlePress}
|
|
90
|
+
style={style('modalCloseButton')}
|
|
91
|
+
>
|
|
92
|
+
<Ionicons
|
|
93
|
+
name="close"
|
|
94
|
+
size={24}
|
|
95
|
+
color={modalColor}
|
|
96
|
+
style={style('modalCloseText', defaults)}
|
|
97
|
+
/>
|
|
98
|
+
</TouchableOpacity>
|
|
99
|
+
<Text style={style('modalTitle', defaults)}>{placeholder}</Text>
|
|
100
|
+
</View>
|
|
101
|
+
<ScrollView
|
|
102
|
+
contentContainerStyle={{ flexGrow: 1, paddingBottom: 50 }}
|
|
103
|
+
style={style('modalContent')}
|
|
104
|
+
nestedScrollEnabled={true}
|
|
105
|
+
ref={scrollRef}
|
|
106
|
+
>
|
|
107
|
+
<View
|
|
108
|
+
style={{
|
|
109
|
+
flex: 1,
|
|
110
|
+
paddingLeft: 15,
|
|
111
|
+
paddingRight: 15,
|
|
112
|
+
paddingTop: 10,
|
|
113
|
+
paddingBottom: 10,
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
<UI.List
|
|
117
|
+
data={items}
|
|
118
|
+
name={scope.getName('list')}
|
|
119
|
+
layout="card"
|
|
120
|
+
click={onClick}
|
|
121
|
+
rowStyle={{
|
|
122
|
+
paddingLeft: 15,
|
|
123
|
+
paddinRight: 15,
|
|
124
|
+
...scope.original?.rowStyle,
|
|
125
|
+
}}
|
|
126
|
+
{...scope.original?.listProps}
|
|
127
|
+
>
|
|
128
|
+
<UI.Value value="#{@this.label}" />
|
|
129
|
+
</UI.List>
|
|
130
|
+
</View>
|
|
131
|
+
</ScrollView>
|
|
132
|
+
</SafeAreaView>
|
|
133
|
+
</Modal>
|
|
134
|
+
</View>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const styles = StyleSheet.create({
|
|
139
|
+
selectRoot: {
|
|
140
|
+
justifyContent: 'flex-start',
|
|
141
|
+
alignItems: 'flex-start',
|
|
142
|
+
flex: 1,
|
|
143
|
+
},
|
|
144
|
+
selectInput: {
|
|
145
|
+
width: '100%',
|
|
146
|
+
flexDirection: 'row',
|
|
147
|
+
borderRadius: 5,
|
|
148
|
+
paddingHorizontal: 15,
|
|
149
|
+
paddingVertical: 10,
|
|
150
|
+
},
|
|
151
|
+
selectLabel: { flex: 1 },
|
|
152
|
+
modalTop: {
|
|
153
|
+
backgroundColor: 'primary',
|
|
154
|
+
width: '100%',
|
|
155
|
+
},
|
|
156
|
+
modalSafe: {
|
|
157
|
+
flex: 1,
|
|
158
|
+
width: '100%',
|
|
159
|
+
backgroundColor: 'background',
|
|
160
|
+
},
|
|
161
|
+
modalCloseButton: {
|
|
162
|
+
padding: 10,
|
|
163
|
+
},
|
|
164
|
+
modalCloseText: {
|
|
165
|
+
fontSize: 18,
|
|
166
|
+
color: 'white',
|
|
167
|
+
},
|
|
168
|
+
modalTitle: {
|
|
169
|
+
fontSize: 18,
|
|
170
|
+
fontWeight: 'bold',
|
|
171
|
+
marginLeft: 10,
|
|
172
|
+
},
|
|
173
|
+
modalContent: {
|
|
174
|
+
flex: 1,
|
|
175
|
+
backgroundColor: 'background',
|
|
176
|
+
},
|
|
177
|
+
});
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
2
|
-
import Toast, { BaseToast, ErrorToast } from 'react-native-toast-message';
|
|
3
|
-
|
|
4
|
-
export default function UIToast() {
|
|
5
|
-
const toastConfig = {
|
|
6
|
-
success: props => (
|
|
7
|
-
<BaseToast
|
|
8
|
-
{...props}
|
|
9
|
-
style={styles.darkToast}
|
|
10
|
-
contentContainerStyle={{ paddingHorizontal: 15 }}
|
|
11
|
-
text1Style={styles.text}
|
|
12
|
-
text2Style={styles.text}
|
|
13
|
-
/>
|
|
14
|
-
),
|
|
15
|
-
error: props => (
|
|
16
|
-
<ErrorToast
|
|
17
|
-
{...props}
|
|
18
|
-
style={styles.darkToast}
|
|
19
|
-
text1Style={styles.text}
|
|
20
|
-
text2Style={styles.text}
|
|
21
|
-
/>
|
|
22
|
-
),
|
|
23
|
-
info: props => (
|
|
24
|
-
<BaseToast
|
|
25
|
-
{...props}
|
|
26
|
-
style={styles.darkToast}
|
|
27
|
-
text1Style={styles.text}
|
|
28
|
-
text2Style={styles.text}
|
|
29
|
-
/>
|
|
30
|
-
),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const styles = StyleSheet.create({
|
|
34
|
-
darkToast: {
|
|
35
|
-
backgroundColor: 'rgba(34, 34, 34, 0.85)',
|
|
36
|
-
borderLeftColor: '#222', // borda mais escura
|
|
37
|
-
},
|
|
38
|
-
text: {
|
|
39
|
-
color: '#fff', // letras brancas
|
|
40
|
-
textAlign: 'center',
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
return <Toast config={toastConfig} />;
|
|
44
|
-
}
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import Toast, { BaseToast, ErrorToast } from 'react-native-toast-message';
|
|
3
|
+
|
|
4
|
+
export default function UIToast() {
|
|
5
|
+
const toastConfig = {
|
|
6
|
+
success: props => (
|
|
7
|
+
<BaseToast
|
|
8
|
+
{...props}
|
|
9
|
+
style={styles.darkToast}
|
|
10
|
+
contentContainerStyle={{ paddingHorizontal: 15 }}
|
|
11
|
+
text1Style={styles.text}
|
|
12
|
+
text2Style={styles.text}
|
|
13
|
+
/>
|
|
14
|
+
),
|
|
15
|
+
error: props => (
|
|
16
|
+
<ErrorToast
|
|
17
|
+
{...props}
|
|
18
|
+
style={styles.darkToast}
|
|
19
|
+
text1Style={styles.text}
|
|
20
|
+
text2Style={styles.text}
|
|
21
|
+
/>
|
|
22
|
+
),
|
|
23
|
+
info: props => (
|
|
24
|
+
<BaseToast
|
|
25
|
+
{...props}
|
|
26
|
+
style={styles.darkToast}
|
|
27
|
+
text1Style={styles.text}
|
|
28
|
+
text2Style={styles.text}
|
|
29
|
+
/>
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const styles = StyleSheet.create({
|
|
34
|
+
darkToast: {
|
|
35
|
+
backgroundColor: 'rgba(34, 34, 34, 0.85)',
|
|
36
|
+
borderLeftColor: '#222', // borda mais escura
|
|
37
|
+
},
|
|
38
|
+
text: {
|
|
39
|
+
color: '#fff', // letras brancas
|
|
40
|
+
textAlign: 'center',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return <Toast config={toastConfig} />;
|
|
44
|
+
}
|
|
@@ -1,102 +1,102 @@
|
|
|
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
|
-
|
|
6
|
-
export default function UIToggle(props: ChildType) {
|
|
7
|
-
const scope = props.scope;
|
|
8
|
-
const options = Utils.nvl(scope.getOptions(), []);
|
|
9
|
-
const value = scope.getInputValue();
|
|
10
|
-
|
|
11
|
-
let [index, setIndex] = useState(0);
|
|
12
|
-
|
|
13
|
-
const isSelected = (item: any) => {
|
|
14
|
-
return item?.value === value;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const onClick = (item: any) => {
|
|
18
|
-
scope.changeValue(item.object);
|
|
19
|
-
setIndex(++index);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const Item = ({ item, index }) => {
|
|
23
|
-
let selected = isSelected(item);
|
|
24
|
-
let style: any = { ...styles.text };
|
|
25
|
-
|
|
26
|
-
if (selected) style.color = '#ffffff';
|
|
27
|
-
|
|
28
|
-
if (Utils.isEmpty(props.children)) {
|
|
29
|
-
return <Text style={style}>{item.label}</Text>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<UIListRow scope={scope} item={item.object} index={index}>
|
|
34
|
-
{props.children}
|
|
35
|
-
</UIListRow>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getItemStyle = (item: any) => {
|
|
40
|
-
let style = { ...styles.item, ...scope.getStyle('item') };
|
|
41
|
-
|
|
42
|
-
let wPart = 100 / options.length;
|
|
43
|
-
let width = Math.floor(wPart) + '%';
|
|
44
|
-
|
|
45
|
-
if (isSelected(item)) {
|
|
46
|
-
let selectedColor = scope.getPart('selectedColor', undefined, 'primary');
|
|
47
|
-
let st = scope.getStyle('selected', {
|
|
48
|
-
backgroundColor: selectedColor,
|
|
49
|
-
color: '#ffffff',
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
style = { ...style, ...st };
|
|
53
|
-
|
|
54
|
-
if (!style.color) {
|
|
55
|
-
style.color = '#ffffff';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
style.width = width;
|
|
60
|
-
|
|
61
|
-
return style;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<>
|
|
66
|
-
{options.map((item: any, i: number) => (
|
|
67
|
-
<TouchableHighlight
|
|
68
|
-
key={`k-${i}`}
|
|
69
|
-
style={getItemStyle(item)}
|
|
70
|
-
onPress={e => {
|
|
71
|
-
onClick(item);
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
<Item item={item} index={i} />
|
|
75
|
-
</TouchableHighlight>
|
|
76
|
-
))}
|
|
77
|
-
</>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const styles = StyleSheet.create({
|
|
82
|
-
container: {
|
|
83
|
-
flex: 1,
|
|
84
|
-
width: '100%',
|
|
85
|
-
gap: 10,
|
|
86
|
-
justifyContent: 'center',
|
|
87
|
-
flexDirection: 'row',
|
|
88
|
-
},
|
|
89
|
-
item: {
|
|
90
|
-
padding: 10,
|
|
91
|
-
marginVertical: 8,
|
|
92
|
-
backgroundColor: 'background',
|
|
93
|
-
borderRadius: 8,
|
|
94
|
-
justifyContent: 'center',
|
|
95
|
-
width: 'auto',
|
|
96
|
-
flexDirection: 'row',
|
|
97
|
-
},
|
|
98
|
-
text: {
|
|
99
|
-
fontSize: 15,
|
|
100
|
-
fontWeight: '500',
|
|
101
|
-
},
|
|
102
|
-
});
|
|
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
|
+
|
|
6
|
+
export default function UIToggle(props: ChildType) {
|
|
7
|
+
const scope = props.scope;
|
|
8
|
+
const options = Utils.nvl(scope.getOptions(), []);
|
|
9
|
+
const value = scope.getInputValue();
|
|
10
|
+
|
|
11
|
+
let [index, setIndex] = useState(0);
|
|
12
|
+
|
|
13
|
+
const isSelected = (item: any) => {
|
|
14
|
+
return item?.value === value;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const onClick = (item: any) => {
|
|
18
|
+
scope.changeValue(item.object);
|
|
19
|
+
setIndex(++index);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const Item = ({ item, index }) => {
|
|
23
|
+
let selected = isSelected(item);
|
|
24
|
+
let style: any = { ...styles.text };
|
|
25
|
+
|
|
26
|
+
if (selected) style.color = '#ffffff';
|
|
27
|
+
|
|
28
|
+
if (Utils.isEmpty(props.children)) {
|
|
29
|
+
return <Text style={style}>{item.label}</Text>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<UIListRow scope={scope} item={item.object} index={index}>
|
|
34
|
+
{props.children}
|
|
35
|
+
</UIListRow>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getItemStyle = (item: any) => {
|
|
40
|
+
let style = { ...styles.item, ...scope.getStyle('item') };
|
|
41
|
+
|
|
42
|
+
let wPart = 100 / options.length;
|
|
43
|
+
let width = Math.floor(wPart) + '%';
|
|
44
|
+
|
|
45
|
+
if (isSelected(item)) {
|
|
46
|
+
let selectedColor = scope.getPart('selectedColor', undefined, 'primary');
|
|
47
|
+
let st = scope.getStyle('selected', {
|
|
48
|
+
backgroundColor: selectedColor,
|
|
49
|
+
color: '#ffffff',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
style = { ...style, ...st };
|
|
53
|
+
|
|
54
|
+
if (!style.color) {
|
|
55
|
+
style.color = '#ffffff';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
style.width = width;
|
|
60
|
+
|
|
61
|
+
return style;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<>
|
|
66
|
+
{options.map((item: any, i: number) => (
|
|
67
|
+
<TouchableHighlight
|
|
68
|
+
key={`k-${i}`}
|
|
69
|
+
style={getItemStyle(item)}
|
|
70
|
+
onPress={e => {
|
|
71
|
+
onClick(item);
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<Item item={item} index={i} />
|
|
75
|
+
</TouchableHighlight>
|
|
76
|
+
))}
|
|
77
|
+
</>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const styles = StyleSheet.create({
|
|
82
|
+
container: {
|
|
83
|
+
flex: 1,
|
|
84
|
+
width: '100%',
|
|
85
|
+
gap: 10,
|
|
86
|
+
justifyContent: 'center',
|
|
87
|
+
flexDirection: 'row',
|
|
88
|
+
},
|
|
89
|
+
item: {
|
|
90
|
+
padding: 10,
|
|
91
|
+
marginVertical: 8,
|
|
92
|
+
backgroundColor: 'background',
|
|
93
|
+
borderRadius: 8,
|
|
94
|
+
justifyContent: 'center',
|
|
95
|
+
width: 'auto',
|
|
96
|
+
flexDirection: 'row',
|
|
97
|
+
},
|
|
98
|
+
text: {
|
|
99
|
+
fontSize: 15,
|
|
100
|
+
fontWeight: '500',
|
|
101
|
+
},
|
|
102
|
+
});
|