react-crud-mobile 1.0.419 → 1.0.421

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,509 +1,509 @@
1
- import React, {
2
- createContext,
3
- useContext,
4
- useEffect,
5
- useLayoutEffect,
6
- useRef,
7
- useState,
8
- } from 'react';
9
- import UIChildren from './UIChildren';
10
- import ElTabs from './tabs/ElTabs';
11
- import ElChart from './charts/ElChart';
12
- import UIComplete from './UIComplete';
13
- import {
14
- Crud,
15
- HtmlUtils,
16
- ScopeUtils,
17
- Utils,
18
- ElementType,
19
- ChildType,
20
- } from 'react-crud-utils';
21
- import UILink from './core/UILink';
22
- import UIIcon from './core/UIIcon';
23
- import UIButton from './core/UIButton';
24
- import UISelect from './core/UISelect';
25
- import UISwitch from './core/UISwitch';
26
- import UIOption from './core/UIOption';
27
- import UIRadio from './core/UIRadio';
28
- import UIInput from './core/UIInput';
29
- import { Image, Linking, StyleSheet, Text, View } from 'react-native';
30
- import UIList from './core/UIList';
31
- import UIToggle from './core/UIToggle';
32
- import UIQuantity from './core/UIQuantity';
33
- import UIModal from './core/UIModal';
34
- import { Ionicons } from '@expo/vector-icons';
35
-
36
- const CrudContext = createContext<any>({});
37
-
38
- export default function UIElement(props: ElementType) {
39
- const ctx = useContext(CrudContext);
40
- const theme = Utils.nvl(props.theme, ctx?.theme);
41
-
42
- let crud: Crud = Utils.nvl(props.crud, ctx?.crud);
43
- let [scope] = useState(ScopeUtils.create({ crud, ...props, theme }));
44
-
45
- crud = scope.crud;
46
-
47
- let [index, setIndex] = useState(0);
48
- let [error, setError]: string | any = useState(null);
49
-
50
- let options: any = scope.getOptions();
51
-
52
- let original = scope.original;
53
- let ref = useRef(null);
54
-
55
- scope.update = () => {
56
- setIndex(++index);
57
- };
58
-
59
- scope.updateElement = () => {
60
- setIndex(++index);
61
- };
62
-
63
- const Custom = () => {
64
- let c: any = original.custom;
65
-
66
- if (c) {
67
- if (typeof c === 'string') {
68
- return (
69
- <UIElement
70
- element={{ value: c, type: 'dummy' }}
71
- crud={crud}
72
- ></UIElement>
73
- );
74
- }
75
-
76
- return (
77
- <UIElement
78
- type={c.type}
79
- tag={c.type}
80
- {...c.props}
81
- crud={crud}
82
- ></UIElement>
83
- );
84
- }
85
-
86
- return <></>;
87
- };
88
-
89
- if (scope.is('type', 'dummy')) {
90
- return <>{scope.getDisplayValue()}</>;
91
- }
92
-
93
- let onCheck = () => {
94
- let v = scope.getValue();
95
- let check = !(v === true);
96
-
97
- onChange({ target: { value: check } });
98
- };
99
-
100
- let onChange = (e: any) => {
101
- let val = e.target.value;
102
-
103
- if (scope.isType('integer', 'int', 'number')) {
104
- val = parseInt(val);
105
- } else if (scope.isType('decimal')) {
106
- val = parseFloat(val);
107
- }
108
-
109
- if (scope.isType('select', 'complete')) {
110
- val = scope.getSelectedItem(val);
111
- }
112
-
113
- scope.changeValue(val);
114
- scope.update();
115
- };
116
-
117
- let onClick = (e: any) => {
118
- scope.call('click');
119
- };
120
-
121
- let defaultsInput: any = {
122
- scope,
123
- crud,
124
- onChange: onChange,
125
- };
126
-
127
- if (scope.isType('password')) {
128
- defaultsInput.type = 'password';
129
- }
130
-
131
- let isChecked = () => {
132
- let v = scope.getValue();
133
-
134
- return v === true;
135
- };
136
-
137
- let hasChildren = () => {
138
- if (scope.isInput()) {
139
- return false;
140
- }
141
-
142
- return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
143
- };
144
-
145
- let isInput = scope.is(
146
- 'type',
147
- 'text',
148
- 'number',
149
- 'phone',
150
- 'postalCode',
151
- 'money',
152
- 'password',
153
- 'email'
154
- );
155
-
156
- const getStyle = (part?: string) => {
157
- let type = Utils.nvl(original.type, 'none');
158
- let key = Utils.nvl(part, 'root');
159
- let def = { ...styles[key], ...elementStyle?.[type]?.[key] };
160
- let hasChild = hasChildren();
161
-
162
- if (!part && !hasChild) {
163
- def = { ...def };
164
- }
165
-
166
- if (hasChild && part) {
167
- def = { ...def, ...withChildStyles[part] };
168
- }
169
-
170
- if (isInput) {
171
- def = { ...def, ...elementStyle.input[key] };
172
- }
173
-
174
- return { ...def, ...scope.getStyle(part, def) };
175
- };
176
-
177
- let elStyle = getStyle('element');
178
-
179
- let defaultsUI: any = {
180
- required: scope.isRequired(),
181
- size: 'small',
182
- scope,
183
- crud,
184
- style: elStyle,
185
- placeholder: scope.attr('placeholder', 'Digite aqui'),
186
- };
187
-
188
- scope.error = (msg: string) => {
189
- error = msg;
190
- setError(msg);
191
- };
192
-
193
- if (!original.list?.url && !original.load?.url) {
194
- scope.start();
195
- }
196
-
197
- useEffect(() => {
198
- scope.start();
199
- });
200
-
201
- const CustomIcon = () => {
202
- if (typeof original.icon === 'string') {
203
- return <Ionicons name={original.icon} style={scope.getStyle('icon')} />;
204
- }
205
- return <>{original.icon}</>;
206
- };
207
-
208
- scope.open = (args: any) => {
209
- Linking.openURL(args.url);
210
- };
211
-
212
- useLayoutEffect(() => {
213
- if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
214
- let el: any = ref?.current;
215
-
216
- if (el?.classList) {
217
- let bg = HtmlUtils.getBGColor(el);
218
-
219
- if (bg === 'rgb(255, 255, 255)') {
220
- el.classList.add('ui-dark');
221
- } else {
222
- el.classList.add('ui-light');
223
- }
224
- }
225
- }
226
- });
227
-
228
- const isShowLabel = () => {
229
- if (
230
- typeof original.label !== 'undefined' &&
231
- original.label !== false &&
232
- !scope.isType('button', 'dialog', 'modal')
233
- ) {
234
- return true;
235
- }
236
-
237
- return false;
238
- };
239
-
240
- const isShowInner = () => {
241
- if (hasChildren()) {
242
- return false;
243
- }
244
- return true;
245
- };
246
-
247
- if (!scope.isRendered() || scope.is('type', 'define')) {
248
- return <></>;
249
- }
250
-
251
- const isShowChild = () => {
252
- if (
253
- scope.is(
254
- 'type',
255
- 'tabs',
256
- 'grid',
257
- 'list',
258
- 'define',
259
- 'repeat',
260
- 'modal',
261
- 'dialog',
262
- 'chart'
263
- )
264
- ) {
265
- return false;
266
- }
267
-
268
- return true;
269
- };
270
-
271
- return (
272
- <CrudContext.Provider value={{ crud, theme }}>
273
- <View ref={ref} style={getStyle()}>
274
- <>
275
- {isShowLabel() && (
276
- <Text style={getStyle('label')}>{scope.getLabel()}</Text>
277
- )}
278
- {isShowInner() && (
279
- <>
280
- <View style={getStyle('inner')}>
281
- {scope.is('type', 'button') && (
282
- <UIButton
283
- {...defaultsUI}
284
- onClick={onClick}
285
- variant={scope.attr('variant', 'outlined')}
286
- >
287
- {original.icon && <CustomIcon />}
288
- {original.label && (
289
- <Text style={scope.getPart('label', 'button')}>
290
- {scope.getLabel()}
291
- </Text>
292
- )}
293
- </UIButton>
294
- )}
295
- {scope.is('type', 'icon') && (
296
- <UIIcon
297
- {...defaultsUI}
298
- onClick={onClick}
299
- variant={scope.attr('variant', 'outlined')}
300
- >
301
- {scope.getDisplayValue()}
302
- </UIIcon>
303
- )}
304
- {scope.is('type', 'link') && (
305
- <UILink
306
- {...defaultsUI}
307
- onClick={onClick}
308
- variant={scope.attr('variant', 'outlined')}
309
- >
310
- {original.icon && <CustomIcon />}
311
- {original.label && (
312
- <Text style={scope.getPart('label', 'link')}>
313
- {scope.getLabel()}
314
- </Text>
315
- )}
316
- </UILink>
317
- )}
318
- {isInput && (
319
- <UIInput
320
- {...defaultsInput}
321
- {...defaultsUI}
322
- InputProps={{ ...original.inputProps }}
323
- />
324
- )}
325
- {scope.is('type', 'complete', 'autocomplete') && (
326
- <UIComplete
327
- scope={scope}
328
- defaultsInput={defaultsInput}
329
- defaultsUI={defaultsUI}
330
- />
331
- )}
332
- {scope.is('type', 'quantity') && (
333
- <UIQuantity
334
- scope={scope}
335
- defaultsInput={defaultsInput}
336
- defaultsUI={defaultsUI}
337
- />
338
- )}
339
- {scope.is('type', 'checkbox', 'boolean', 'switch') && (
340
- <UISwitch
341
- checked={isChecked()}
342
- {...defaultsInput}
343
- onChange={onCheck}
344
- />
345
- )}
346
- {scope.is('type', 'select') && (
347
- <UISelect
348
- {...defaultsInput}
349
- {...defaultsUI}
350
- value={scope.getSelectedValue()}
351
- />
352
- )}
353
- {scope.is('type', 'toggle') && (
354
- <UIToggle
355
- {...defaultsInput}
356
- {...defaultsUI}
357
- value={scope.getSelectedValue()}
358
- />
359
- )}
360
- {scope.is('type', 'radio') && (
361
- <UIRadio {...defaultsInput} {...defaultsUI} row>
362
- {options.map((row: any, i: number) => (
363
- <UIOption
364
- key={'i' + i}
365
- control={<UIRadio {...defaultsUI} />}
366
- label={row.label}
367
- value={row.value}
368
- />
369
- ))}
370
- </UIRadio>
371
- )}
372
- {scope.is('type', 'custom') && <Custom />}
373
- {scope.is('type', 'column') && (
374
- <>
375
- {scope.is('format', 'img') && (
376
- <Image source={scope.getDisplayValue()} />
377
- )}
378
- {scope.is('format', 'icon') && (
379
- <UIIcon scope={scope} crud={crud} />
380
- )}
381
- {!scope.is('format', 'icon', 'img') && (
382
- <Text>{scope.getDisplayValue()}</Text>
383
- )}
384
- </>
385
- )}
386
- {scope.is('type', 'output', 'value') && (
387
- <Text>{scope.getDisplayValue()}</Text>
388
- )}
389
- </View>
390
- {error && <View style={getStyle('error')}>{error}</View>}
391
- </>
392
- )}
393
- {scope.isType('type', 'list', 'repeat') && (
394
- <UIList {...props} scope={scope} crud={crud} />
395
- )}
396
- {scope.isType('type', 'dialog') && (
397
- <UIModal {...props} scope={scope} crud={crud} />
398
- )}
399
- {scope.isType('type', 'chart') && (
400
- <ElChart {...props} scope={scope} crud={crud} />
401
- )}
402
- {scope.isType('type', 'tabs') && (
403
- <ElTabs {...props} scope={scope} crud={crud} />
404
- )}
405
-
406
- {isShowChild() && <UIChildren {...props} scope={scope} crud={crud} />}
407
- </>
408
- </View>
409
- </CrudContext.Provider>
410
- );
411
- }
412
-
413
- const box: any = {
414
- backgroundColor: 'white',
415
- padding: 16,
416
- borderRadius: 10,
417
- width: '100%',
418
- shadowColor: '#888', // iOS
419
- shadowOffset: { width: 0, height: 1 }, // iOS
420
- shadowOpacity: 0.25, // iOS
421
- shadowRadius: 3.84, // iOS
422
- elevation: 3, // Android
423
- };
424
-
425
- const elementStyle: any = {};
426
-
427
- elementStyle.card = StyleSheet.create({
428
- root: {
429
- ...box,
430
- },
431
- inner: {
432
- flex: 1,
433
- width: '100%',
434
- paddingBottom: 10,
435
- paddingTop: 5,
436
- alignSelf: 'flex-start',
437
- flexDirection: 'row',
438
- flexWrap: 'wrap',
439
- gap: 10,
440
- },
441
- });
442
-
443
- elementStyle.input = StyleSheet.create({
444
- inner: {
445
- flex: 1,
446
- width: '100%',
447
- paddingBottom: 0,
448
- paddingTop: 0,
449
- alignItems: 'center',
450
- borderWidth: 1,
451
- borderColor: 'borderColor',
452
- borderRadius: 20,
453
- paddingHorizontal: 15,
454
- alignSelf: 'flex-start',
455
- flexDirection: 'row',
456
- flexWrap: 'wrap',
457
- },
458
- });
459
-
460
- elementStyle.quantity = {
461
- inner: {
462
- ...box,
463
- padding: 5,
464
- borderRadius: 25,
465
- flexWrap: 'nowrap',
466
- flex: 1,
467
- flexDirection: 'row',
468
- justifyContent: 'center',
469
- alignItems: 'center',
470
- },
471
- };
472
-
473
- elementStyle.toggle = StyleSheet.create({
474
- inner: {
475
- ...box,
476
- flex: 1,
477
- width: '100%',
478
- gap: 10,
479
- justifyContent: 'center',
480
- flexDirection: 'row',
481
- paddingHorizontal: 10,
482
- paddingVertical: 0,
483
- alignSelf: 'flex-start',
484
- flexWrap: 'nowrap',
485
- },
486
- });
487
-
488
- const styles = StyleSheet.create({
489
- root: {
490
- gap: 5,
491
- flexDirection: 'column',
492
- flexWrap: 'wrap',
493
- width: '100%',
494
- alignItems: 'flex-start',
495
- },
496
- label: { width: '100%', fontWeight: 500, fontSize: 12 },
497
- inner: { width: '100%', marginBottom: 10 },
498
- });
499
-
500
- const withChildStyles = StyleSheet.create({
501
- root: {
502
- gap: 10,
503
- },
504
- label: {
505
- width: '100%',
506
- fontWeight: 500,
507
- fontSize: 24,
508
- },
509
- });
1
+ import React, {
2
+ createContext,
3
+ useContext,
4
+ useEffect,
5
+ useLayoutEffect,
6
+ useRef,
7
+ useState,
8
+ } from 'react';
9
+ import UIChildren from './UIChildren';
10
+ import ElTabs from './tabs/ElTabs';
11
+ import ElChart from './charts/ElChart';
12
+ import UIComplete from './UIComplete';
13
+ import {
14
+ Crud,
15
+ HtmlUtils,
16
+ ScopeUtils,
17
+ Utils,
18
+ ElementType,
19
+ ChildType,
20
+ } from 'react-crud-utils';
21
+ import UILink from './core/UILink';
22
+ import UIIcon from './core/UIIcon';
23
+ import UIButton from './core/UIButton';
24
+ import UISelect from './core/UISelect';
25
+ import UISwitch from './core/UISwitch';
26
+ import UIOption from './core/UIOption';
27
+ import UIRadio from './core/UIRadio';
28
+ import UIInput from './core/UIInput';
29
+ import { Image, Linking, StyleSheet, Text, View } from 'react-native';
30
+ import UIList from './core/UIList';
31
+ import UIToggle from './core/UIToggle';
32
+ import UIQuantity from './core/UIQuantity';
33
+ import UIModal from './core/UIModal';
34
+ import { Ionicons } from '@expo/vector-icons';
35
+
36
+ const CrudContext = createContext<any>({});
37
+
38
+ export default function UIElement(props: ElementType) {
39
+ const ctx = useContext(CrudContext);
40
+ const theme = Utils.nvl(props.theme, ctx?.theme);
41
+
42
+ let crud: Crud = Utils.nvl(props.crud, ctx?.crud);
43
+ let [scope] = useState(ScopeUtils.create({ crud, ...props, theme }));
44
+
45
+ crud = scope.crud;
46
+
47
+ let [index, setIndex] = useState(0);
48
+ let [error, setError]: string | any = useState(null);
49
+
50
+ let options: any = scope.getOptions();
51
+
52
+ let original = scope.original;
53
+ let ref = useRef(null);
54
+
55
+ scope.update = () => {
56
+ setIndex(++index);
57
+ };
58
+
59
+ scope.updateElement = () => {
60
+ setIndex(++index);
61
+ };
62
+
63
+ const Custom = () => {
64
+ let c: any = original.custom;
65
+
66
+ if (c) {
67
+ if (typeof c === 'string') {
68
+ return (
69
+ <UIElement
70
+ element={{ value: c, type: 'dummy' }}
71
+ crud={crud}
72
+ ></UIElement>
73
+ );
74
+ }
75
+
76
+ return (
77
+ <UIElement
78
+ type={c.type}
79
+ tag={c.type}
80
+ {...c.props}
81
+ crud={crud}
82
+ ></UIElement>
83
+ );
84
+ }
85
+
86
+ return <></>;
87
+ };
88
+
89
+ if (scope.is('type', 'dummy')) {
90
+ return <>{scope.getDisplayValue()}</>;
91
+ }
92
+
93
+ let onCheck = () => {
94
+ let v = scope.getValue();
95
+ let check = !(v === true);
96
+
97
+ onChange({ target: { value: check } });
98
+ };
99
+
100
+ let onChange = (e: any) => {
101
+ let val = e.target.value;
102
+
103
+ if (scope.isType('integer', 'int', 'number')) {
104
+ val = parseInt(val);
105
+ } else if (scope.isType('decimal')) {
106
+ val = parseFloat(val);
107
+ }
108
+
109
+ if (scope.isType('select', 'complete')) {
110
+ val = scope.getSelectedItem(val);
111
+ }
112
+
113
+ scope.changeValue(val);
114
+ scope.update();
115
+ };
116
+
117
+ let onClick = (e: any) => {
118
+ scope.call('click');
119
+ };
120
+
121
+ let defaultsInput: any = {
122
+ scope,
123
+ crud,
124
+ onChange: onChange,
125
+ };
126
+
127
+ if (scope.isType('password')) {
128
+ defaultsInput.type = 'password';
129
+ }
130
+
131
+ let isChecked = () => {
132
+ let v = scope.getValue();
133
+
134
+ return v === true;
135
+ };
136
+
137
+ let hasChildren = () => {
138
+ if (scope.isInput()) {
139
+ return false;
140
+ }
141
+
142
+ return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
143
+ };
144
+
145
+ let isInput = scope.is(
146
+ 'type',
147
+ 'text',
148
+ 'number',
149
+ 'phone',
150
+ 'postalCode',
151
+ 'money',
152
+ 'password',
153
+ 'email'
154
+ );
155
+
156
+ const getStyle = (part?: string) => {
157
+ let type = Utils.nvl(original.type, 'none');
158
+ let key = Utils.nvl(part, 'root');
159
+ let def = { ...styles[key], ...elementStyle?.[type]?.[key] };
160
+ let hasChild = hasChildren();
161
+
162
+ if (!part && !hasChild) {
163
+ def = { ...def };
164
+ }
165
+
166
+ if (hasChild && part) {
167
+ def = { ...def, ...withChildStyles[part] };
168
+ }
169
+
170
+ if (isInput) {
171
+ def = { ...def, ...elementStyle.input[key] };
172
+ }
173
+
174
+ return { ...def, ...scope.getStyle(part, def) };
175
+ };
176
+
177
+ let elStyle = getStyle('element');
178
+
179
+ let defaultsUI: any = {
180
+ required: scope.isRequired(),
181
+ size: 'small',
182
+ scope,
183
+ crud,
184
+ style: elStyle,
185
+ placeholder: scope.attr('placeholder', 'Digite aqui'),
186
+ };
187
+
188
+ scope.error = (msg: string) => {
189
+ error = msg;
190
+ setError(msg);
191
+ };
192
+
193
+ if (!original.list?.url && !original.load?.url) {
194
+ scope.start();
195
+ }
196
+
197
+ useEffect(() => {
198
+ scope.start();
199
+ });
200
+
201
+ const CustomIcon = () => {
202
+ if (typeof original.icon === 'string') {
203
+ return <Ionicons name={original.icon} style={scope.getStyle('icon')} />;
204
+ }
205
+ return <>{original.icon}</>;
206
+ };
207
+
208
+ scope.open = (args: any) => {
209
+ Linking.openURL(args.url);
210
+ };
211
+
212
+ useLayoutEffect(() => {
213
+ if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
214
+ let el: any = ref?.current;
215
+
216
+ if (el?.classList) {
217
+ let bg = HtmlUtils.getBGColor(el);
218
+
219
+ if (bg === 'rgb(255, 255, 255)') {
220
+ el.classList.add('ui-dark');
221
+ } else {
222
+ el.classList.add('ui-light');
223
+ }
224
+ }
225
+ }
226
+ });
227
+
228
+ const isShowLabel = () => {
229
+ if (
230
+ typeof original.label !== 'undefined' &&
231
+ original.label !== false &&
232
+ !scope.isType('button', 'dialog', 'modal')
233
+ ) {
234
+ return true;
235
+ }
236
+
237
+ return false;
238
+ };
239
+
240
+ const isShowInner = () => {
241
+ if (hasChildren()) {
242
+ return false;
243
+ }
244
+ return true;
245
+ };
246
+
247
+ if (!scope.isRendered() || scope.is('type', 'define')) {
248
+ return <></>;
249
+ }
250
+
251
+ const isShowChild = () => {
252
+ if (
253
+ scope.is(
254
+ 'type',
255
+ 'tabs',
256
+ 'grid',
257
+ 'list',
258
+ 'define',
259
+ 'repeat',
260
+ 'modal',
261
+ 'dialog',
262
+ 'chart'
263
+ )
264
+ ) {
265
+ return false;
266
+ }
267
+
268
+ return true;
269
+ };
270
+
271
+ return (
272
+ <CrudContext.Provider value={{ crud, theme }}>
273
+ <View ref={ref} style={getStyle()}>
274
+ <>
275
+ {isShowLabel() && (
276
+ <Text style={getStyle('label')}>{scope.getLabel()}</Text>
277
+ )}
278
+ {isShowInner() && (
279
+ <>
280
+ <View style={getStyle('inner')}>
281
+ {scope.is('type', 'button') && (
282
+ <UIButton
283
+ {...defaultsUI}
284
+ onClick={onClick}
285
+ variant={scope.attr('variant', 'outlined')}
286
+ >
287
+ {original.icon && <CustomIcon />}
288
+ {original.label && (
289
+ <Text style={scope.getPart('label', 'button')}>
290
+ {scope.getLabel()}
291
+ </Text>
292
+ )}
293
+ </UIButton>
294
+ )}
295
+ {scope.is('type', 'icon') && (
296
+ <UIIcon
297
+ {...defaultsUI}
298
+ onClick={onClick}
299
+ variant={scope.attr('variant', 'outlined')}
300
+ >
301
+ {scope.getDisplayValue()}
302
+ </UIIcon>
303
+ )}
304
+ {scope.is('type', 'link') && (
305
+ <UILink
306
+ {...defaultsUI}
307
+ onClick={onClick}
308
+ variant={scope.attr('variant', 'outlined')}
309
+ >
310
+ {original.icon && <CustomIcon />}
311
+ {original.label && (
312
+ <Text style={scope.getPart('label', 'link')}>
313
+ {scope.getLabel()}
314
+ </Text>
315
+ )}
316
+ </UILink>
317
+ )}
318
+ {isInput && (
319
+ <UIInput
320
+ {...defaultsInput}
321
+ {...defaultsUI}
322
+ InputProps={{ ...original.inputProps }}
323
+ />
324
+ )}
325
+ {scope.is('type', 'complete', 'autocomplete') && (
326
+ <UIComplete
327
+ scope={scope}
328
+ defaultsInput={defaultsInput}
329
+ defaultsUI={defaultsUI}
330
+ />
331
+ )}
332
+ {scope.is('type', 'quantity') && (
333
+ <UIQuantity
334
+ scope={scope}
335
+ defaultsInput={defaultsInput}
336
+ defaultsUI={defaultsUI}
337
+ />
338
+ )}
339
+ {scope.is('type', 'checkbox', 'boolean', 'switch') && (
340
+ <UISwitch
341
+ checked={isChecked()}
342
+ {...defaultsInput}
343
+ onChange={onCheck}
344
+ />
345
+ )}
346
+ {scope.is('type', 'select') && (
347
+ <UISelect
348
+ {...defaultsInput}
349
+ {...defaultsUI}
350
+ value={scope.getSelectedValue()}
351
+ />
352
+ )}
353
+ {scope.is('type', 'toggle') && (
354
+ <UIToggle
355
+ {...defaultsInput}
356
+ {...defaultsUI}
357
+ value={scope.getSelectedValue()}
358
+ />
359
+ )}
360
+ {scope.is('type', 'radio') && (
361
+ <UIRadio {...defaultsInput} {...defaultsUI} row>
362
+ {options.map((row: any, i: number) => (
363
+ <UIOption
364
+ key={'i' + i}
365
+ control={<UIRadio {...defaultsUI} />}
366
+ label={row.label}
367
+ value={row.value}
368
+ />
369
+ ))}
370
+ </UIRadio>
371
+ )}
372
+ {scope.is('type', 'custom') && <Custom />}
373
+ {scope.is('type', 'column') && (
374
+ <>
375
+ {scope.is('format', 'img') && (
376
+ <Image source={scope.getDisplayValue()} />
377
+ )}
378
+ {scope.is('format', 'icon') && (
379
+ <UIIcon scope={scope} crud={crud} />
380
+ )}
381
+ {!scope.is('format', 'icon', 'img') && (
382
+ <Text>{scope.getDisplayValue()}</Text>
383
+ )}
384
+ </>
385
+ )}
386
+ {scope.is('type', 'output', 'value') && (
387
+ <Text>{scope.getDisplayValue()}</Text>
388
+ )}
389
+ </View>
390
+ {error && <View style={getStyle('error')}>{error}</View>}
391
+ </>
392
+ )}
393
+ {scope.isType('type', 'list', 'repeat') && (
394
+ <UIList {...props} scope={scope} crud={crud} />
395
+ )}
396
+ {scope.isType('type', 'dialog') && (
397
+ <UIModal {...props} scope={scope} crud={crud} />
398
+ )}
399
+ {scope.isType('type', 'chart') && (
400
+ <ElChart {...props} scope={scope} crud={crud} />
401
+ )}
402
+ {scope.isType('type', 'tabs') && (
403
+ <ElTabs {...props} scope={scope} crud={crud} />
404
+ )}
405
+
406
+ {isShowChild() && <UIChildren {...props} scope={scope} crud={crud} />}
407
+ </>
408
+ </View>
409
+ </CrudContext.Provider>
410
+ );
411
+ }
412
+
413
+ const box: any = {
414
+ backgroundColor: 'white',
415
+ padding: 16,
416
+ borderRadius: 10,
417
+ width: '100%',
418
+ shadowColor: '#888', // iOS
419
+ shadowOffset: { width: 0, height: 1 }, // iOS
420
+ shadowOpacity: 0.25, // iOS
421
+ shadowRadius: 3.84, // iOS
422
+ elevation: 3, // Android
423
+ };
424
+
425
+ const elementStyle: any = {};
426
+
427
+ elementStyle.card = StyleSheet.create({
428
+ root: {
429
+ ...box,
430
+ },
431
+ inner: {
432
+ flex: 1,
433
+ width: '100%',
434
+ paddingBottom: 10,
435
+ paddingTop: 5,
436
+ alignSelf: 'flex-start',
437
+ flexDirection: 'row',
438
+ flexWrap: 'wrap',
439
+ gap: 10,
440
+ },
441
+ });
442
+
443
+ elementStyle.input = StyleSheet.create({
444
+ inner: {
445
+ flex: 1,
446
+ width: '100%',
447
+ paddingBottom: 0,
448
+ paddingTop: 0,
449
+ alignItems: 'center',
450
+ borderWidth: 1,
451
+ borderColor: 'borderColor',
452
+ borderRadius: 20,
453
+ paddingHorizontal: 15,
454
+ alignSelf: 'flex-start',
455
+ flexDirection: 'row',
456
+ flexWrap: 'wrap',
457
+ },
458
+ });
459
+
460
+ elementStyle.quantity = {
461
+ inner: {
462
+ ...box,
463
+ padding: 5,
464
+ borderRadius: 25,
465
+ flexWrap: 'nowrap',
466
+ flex: 1,
467
+ flexDirection: 'row',
468
+ justifyContent: 'center',
469
+ alignItems: 'center',
470
+ },
471
+ };
472
+
473
+ elementStyle.toggle = StyleSheet.create({
474
+ inner: {
475
+ ...box,
476
+ flex: 1,
477
+ width: '100%',
478
+ gap: 10,
479
+ justifyContent: 'center',
480
+ flexDirection: 'row',
481
+ paddingHorizontal: 10,
482
+ paddingVertical: 0,
483
+ alignSelf: 'flex-start',
484
+ flexWrap: 'nowrap',
485
+ },
486
+ });
487
+
488
+ const styles = StyleSheet.create({
489
+ root: {
490
+ gap: 5,
491
+ flexDirection: 'column',
492
+ flexWrap: 'wrap',
493
+ width: '100%',
494
+ alignItems: 'flex-start',
495
+ },
496
+ label: { width: '100%', fontWeight: 500, fontSize: 12 },
497
+ inner: { width: '100%', marginBottom: 10 },
498
+ });
499
+
500
+ const withChildStyles = StyleSheet.create({
501
+ root: {
502
+ gap: 10,
503
+ },
504
+ label: {
505
+ width: '100%',
506
+ fontWeight: 500,
507
+ fontSize: 24,
508
+ },
509
+ });