react-crud-mobile 1.3.1 → 1.3.3

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.
Files changed (38) hide show
  1. package/dist/react-crud-mobile.cjs.development.js +5 -1
  2. package/dist/react-crud-mobile.cjs.development.js.map +1 -1
  3. package/dist/react-crud-mobile.cjs.production.min.js +1 -1
  4. package/dist/react-crud-mobile.cjs.production.min.js.map +1 -1
  5. package/dist/react-crud-mobile.esm.js +5 -1
  6. package/dist/react-crud-mobile.esm.js.map +1 -1
  7. package/package.json +75 -75
  8. package/src/elements/UI.tsx +73 -73
  9. package/src/elements/UIChildren.tsx +139 -139
  10. package/src/elements/UIComplete.tsx +14 -14
  11. package/src/elements/UIElement.tsx +696 -692
  12. package/src/elements/UITag.tsx +13 -13
  13. package/src/elements/charts/ElChart.tsx +10 -10
  14. package/src/elements/core/SafeView.tsx +69 -69
  15. package/src/elements/core/UIAutoComplete.tsx +17 -17
  16. package/src/elements/core/UIButton.tsx +139 -139
  17. package/src/elements/core/UIIcon.tsx +25 -25
  18. package/src/elements/core/UIInclude.tsx +40 -40
  19. package/src/elements/core/UIInput.tsx +96 -96
  20. package/src/elements/core/UILink.tsx +17 -17
  21. package/src/elements/core/UIList.tsx +168 -168
  22. package/src/elements/core/UIListItem.tsx +32 -32
  23. package/src/elements/core/UIListRow.tsx +123 -123
  24. package/src/elements/core/UIModal.tsx +204 -204
  25. package/src/elements/core/UIOption.tsx +17 -17
  26. package/src/elements/core/UIQuantity.tsx +98 -98
  27. package/src/elements/core/UIRadio.tsx +17 -17
  28. package/src/elements/core/UISelect.tsx +135 -135
  29. package/src/elements/core/UISlider.tsx +61 -61
  30. package/src/elements/core/UISwitch.tsx +27 -27
  31. package/src/elements/core/UIToast.tsx +44 -44
  32. package/src/elements/core/UIToggle.tsx +102 -102
  33. package/src/elements/core/UIView.tsx +94 -94
  34. package/src/elements/index.ts +1 -1
  35. package/src/elements/tabs/ElTabs.tsx +178 -178
  36. package/src/hooks/useIsVisible.ts +39 -39
  37. package/src/index.ts +1 -1
  38. package/src/utils/MobileUtils.ts +12 -12
@@ -1,692 +1,696 @@
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
- MethodType,
20
- ActionType,
21
- ComponentUtils,
22
- } from 'react-crud-utils';
23
- import UILink from './core/UILink';
24
- import UIIcon from './core/UIIcon';
25
- import UIButton from './core/UIButton';
26
- import UISelect from './core/UISelect';
27
- import UISwitch from './core/UISwitch';
28
- import UISlider from './core/UISlider';
29
- import UIOption from './core/UIOption';
30
- import UIRadio from './core/UIRadio';
31
- import UIInput from './core/UIInput';
32
- import {
33
- Alert,
34
- Image,
35
- Linking,
36
- StyleSheet,
37
- Text,
38
- TouchableHighlight,
39
- View,
40
- } from 'react-native';
41
- import UIList from './core/UIList';
42
- import UIToggle from './core/UIToggle';
43
- import UIQuantity from './core/UIQuantity';
44
- import UIModal from './core/UIModal';
45
- import { Ionicons } from '@expo/vector-icons';
46
- import UIView from './core/UIView';
47
- import Toast from 'react-native-toast-message';
48
-
49
- const CrudContext = createContext<any>({});
50
-
51
- export default function UIElement(props: ElementType) {
52
- const ctx = useContext(CrudContext);
53
- const theme = Utils.nvl(props.theme, ctx?.theme);
54
-
55
- let crud: Crud = Utils.nvl(props.crud, ctx?.crud);
56
- let [scope] = useState(ScopeUtils.create({ crud, ...props, theme }));
57
- let [index, setIndex] = useState(0);
58
- let [error, setError]: string | any = useState(null);
59
-
60
- crud = scope.crud;
61
-
62
- let options: any = scope.getOptions();
63
-
64
- let original = scope.original;
65
- let ref = useRef(null);
66
-
67
- scope.update = () => {
68
- setIndex(++index);
69
- };
70
-
71
- scope.updateElement = () => {
72
- setIndex(++index);
73
- };
74
-
75
- scope.toast = (message: string, type = 'info', args?: any) => {
76
- Toast.show({
77
- type, // 'success' | 'error' | 'info'
78
- text1: message,
79
- position: 'bottom', // 'top' é outra opção
80
- visibilityTime: 3000, // tempo que fica visível em ms
81
- ...args,
82
- });
83
- };
84
-
85
- scope.prompt = (args: MethodType) => {
86
- let event = args.event as ActionType;
87
-
88
- if (event) {
89
- let message = 'Você tem certeza que deseja continuar?';
90
- let title = 'Atenção';
91
- let prompt = event.prompt;
92
-
93
- if (typeof prompt === 'string') {
94
- message = prompt;
95
- }
96
-
97
- if (typeof prompt === 'object') {
98
- message = Utils.nvl(prompt.message, message);
99
- title = Utils.nvl(prompt.title, title);
100
- }
101
-
102
- Alert.alert(
103
- title,
104
- message,
105
- [
106
- {
107
- text: 'Cancelar',
108
- style: 'cancel',
109
- },
110
- {
111
- text: 'Confirmar',
112
- onPress: () => scope.execute(args),
113
- },
114
- ],
115
- { cancelable: false }
116
- );
117
- }
118
- };
119
- const Custom = () => {
120
- let c: any = original.custom;
121
-
122
- if (c) {
123
- if (typeof c === 'string') {
124
- return (
125
- <UIElement
126
- element={{ value: c, type: 'dummy' }}
127
- crud={crud}
128
- ></UIElement>
129
- );
130
- }
131
-
132
- return (
133
- <UIElement
134
- type={c.type}
135
- tag={c.type}
136
- {...c.props}
137
- crud={crud}
138
- ></UIElement>
139
- );
140
- }
141
-
142
- return <></>;
143
- };
144
-
145
- if (scope.is('type', 'dummy')) {
146
- return <>{scope.getDisplayValue()}</>;
147
- }
148
-
149
- let onCheck = () => {
150
- let v = scope.getValue();
151
- let check = !(v === true);
152
-
153
- onChange({ target: { value: check } });
154
- };
155
-
156
- let onChange = (e: any) => {
157
- let val = e.target.value;
158
-
159
- if (scope.isType('integer', 'int', 'number')) {
160
- val = parseInt(val);
161
- } else if (scope.isType('decimal')) {
162
- val = parseFloat(val);
163
- }
164
-
165
- if (scope.isType('select', 'complete')) {
166
- val = scope.getSelectedItem(val);
167
- }
168
-
169
- scope.changeValue(val);
170
- scope.update();
171
- };
172
-
173
- let onClick = (e: any) => {
174
- scope.call('click');
175
- };
176
-
177
- let defaultsInput: any = {
178
- scope,
179
- crud,
180
- onChange: onChange,
181
- };
182
-
183
- if (scope.isType('password')) {
184
- defaultsInput.type = 'password';
185
- }
186
-
187
- let isChecked = () => {
188
- let v = scope.getValue();
189
-
190
- return v === true;
191
- };
192
-
193
- let hasChildren = () => {
194
- if (scope.isInput()) {
195
- return false;
196
- }
197
-
198
- return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
199
- };
200
-
201
- let isInput = scope.is(
202
- 'type',
203
- 'text',
204
- 'number',
205
- 'integer',
206
- 'int',
207
- 'phone',
208
- 'postalCode',
209
- 'money',
210
- 'password',
211
- 'email'
212
- );
213
-
214
- const getStyle = (part?: string, extra?: any) => {
215
- let type = Utils.nvl(original.type, 'none');
216
- let key = Utils.nvl(part, 'root');
217
- let def = { ...styles[key] };
218
- let hasChild = hasChildren();
219
-
220
- type = Utils.nvl(original.layout, type);
221
-
222
- if (!part && !hasChild) {
223
- def = { ...def };
224
- }
225
-
226
- if (scope.isInput()) {
227
- def = { ...def, ...elementStyle.input[key] };
228
- }
229
-
230
- def = { ...def, ...elementStyle?.[type]?.[key] };
231
-
232
- if (hasChild && part) {
233
- def = { ...def, ...withChildStyles[part] };
234
- }
235
-
236
- return { ...def, ...scope.getStyle(part, { ...def, ...extra }) };
237
- };
238
-
239
- let elStyle = getStyle('element');
240
-
241
- let defaultsUI: any = {
242
- required: scope.isRequired(),
243
- size: 'small',
244
- scope,
245
- crud,
246
- style: elStyle,
247
- placeholder: scope.attr('placeholder', 'Digite aqui'),
248
- };
249
-
250
- scope.error = (msg: string) => {
251
- error = msg;
252
- setError(msg);
253
- };
254
-
255
- if (!original.list?.url && !original.load?.url) {
256
- scope.start();
257
- }
258
-
259
- useEffect(() => {
260
- scope.start();
261
- });
262
-
263
- const CustomIcon = () => {
264
- if (typeof original.icon === 'string') {
265
- return <Ionicons name={original.icon} style={scope.getStyle('icon')} />;
266
- }
267
- return <>{original.icon}</>;
268
- };
269
-
270
- scope.open = (args: any) => {
271
- Linking.openURL(args.url);
272
- };
273
-
274
- useLayoutEffect(() => {
275
- if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
276
- let el: any = ref?.current;
277
-
278
- if (el?.classList) {
279
- let bg = HtmlUtils.getBGColor(el);
280
-
281
- if (bg === 'rgb(255, 255, 255)') {
282
- el.classList.add('ui-dark');
283
- } else {
284
- el.classList.add('ui-light');
285
- }
286
- }
287
- }
288
- });
289
-
290
- const isShowLabel = () => {
291
- if (
292
- typeof original.label !== 'undefined' &&
293
- original.label !== false &&
294
- !scope.isType('button', 'dialog', 'modal')
295
- ) {
296
- return true;
297
- }
298
-
299
- return false;
300
- };
301
-
302
- const isShowInner = () => {
303
- if (hasChildren()) {
304
- return false;
305
- }
306
- return true;
307
- };
308
-
309
- if (!scope.isRendered() || scope.is('type', 'define')) {
310
- return <></>;
311
- }
312
-
313
- const isShowChild = () => {
314
- if (
315
- scope.isType(
316
- 'tabs',
317
- 'view',
318
- 'grid',
319
- 'list',
320
- 'define',
321
- 'repeat',
322
- 'modal',
323
- 'dialog',
324
- 'chart'
325
- )
326
- ) {
327
- return false;
328
- }
329
-
330
- return true;
331
- };
332
-
333
- let Tag: any = View;
334
- let custom: any = {};
335
-
336
- if (!scope.isType('input', 'grid', 'list', 'repeat') && original.click) {
337
- Tag = TouchableHighlight;
338
-
339
- custom.underlayColor = 'transparent';
340
- custom.onPress = onClick;
341
- }
342
-
343
- let Inner = () => {
344
- return (
345
- <>
346
- {scope.getPart('render', null, <></>)}
347
- {scope.is('type', 'button') && (
348
- <UIButton
349
- {...defaultsUI}
350
- onClick={onClick}
351
- variant={scope.attr('variant', 'outlined')}
352
- >
353
- {original.icon && <CustomIcon />}
354
- {original.label && (
355
- <Text style={scope.getPart('label', 'button')}>
356
- {scope.getLabel()}
357
- </Text>
358
- )}
359
- </UIButton>
360
- )}
361
- {scope.is('type', 'icon') && (
362
- <UIIcon
363
- {...defaultsUI}
364
- onClick={onClick}
365
- variant={scope.attr('variant', 'outlined')}
366
- >
367
- {scope.getDisplayValue()}
368
- </UIIcon>
369
- )}
370
- {scope.is('type', 'link') && (
371
- <UILink
372
- {...defaultsUI}
373
- onClick={onClick}
374
- variant={scope.attr('variant', 'outlined')}
375
- >
376
- {original.icon && <CustomIcon />}
377
- {original.label && (
378
- <Text style={scope.getPart('label', 'link')}>
379
- {scope.getLabel()}
380
- </Text>
381
- )}
382
- </UILink>
383
- )}
384
- {isInput && (
385
- <UIInput
386
- {...defaultsInput}
387
- {...defaultsUI}
388
- InputProps={{ ...original.inputProps }}
389
- />
390
- )}
391
- {scope.is('type', 'complete', 'autocomplete') && (
392
- <UIComplete
393
- scope={scope}
394
- defaultsInput={defaultsInput}
395
- defaultsUI={defaultsUI}
396
- />
397
- )}
398
- {scope.is('type', 'quantity') && (
399
- <UIQuantity
400
- scope={scope}
401
- defaultsInput={defaultsInput}
402
- defaultsUI={defaultsUI}
403
- />
404
- )}
405
- {scope.is('type', 'checkbox', 'boolean', 'switch') && (
406
- <UISwitch
407
- checked={isChecked()}
408
- {...defaultsInput}
409
- onChange={onCheck}
410
- />
411
- )}
412
- {scope.isType('slider') && (
413
- <UISlider {...defaultsInput} onChange={onCheck} />
414
- )}
415
- {scope.is('type', 'select') && (
416
- <UISelect
417
- {...defaultsInput}
418
- {...defaultsUI}
419
- value={scope.getSelectedValue()}
420
- />
421
- )}
422
- {scope.is('type', 'toggle') && (
423
- <UIToggle
424
- {...defaultsInput}
425
- {...defaultsUI}
426
- value={scope.getSelectedValue()}
427
- />
428
- )}
429
- {scope.is('type', 'radio') && (
430
- <UIRadio {...defaultsInput} {...defaultsUI} row>
431
- {options.map((row: any, i: number) => (
432
- <UIOption
433
- key={'i' + i}
434
- control={<UIRadio {...defaultsUI} />}
435
- label={row.label}
436
- value={row.value}
437
- />
438
- ))}
439
- </UIRadio>
440
- )}
441
- {scope.is('type', 'custom') && <Custom />}
442
- {scope.is('type', 'column') && (
443
- <>
444
- {scope.is('format', 'img') && (
445
- <Image source={scope.getDisplayValue()} />
446
- )}
447
- {scope.is('format', 'icon') && <UIIcon scope={scope} crud={crud} />}
448
- {!scope.is('format', 'icon', 'img') && (
449
- <Text>{scope.getDisplayValue()}</Text>
450
- )}
451
- </>
452
- )}
453
- {scope.is('type', 'output', 'value') && (
454
- <Text style={getStyle('value')}>{scope.getDisplayValue()}</Text>
455
- )}
456
- </>
457
- );
458
- };
459
-
460
- let Include = ({ name, style }: any) => {
461
- if (props[name]) {
462
- let define = ComponentUtils.getDefine(props, name);
463
-
464
- if (!Utils.isEmpty(define)) {
465
- return (
466
- <UIChildren
467
- {...props}
468
- scope={scope}
469
- crud={crud}
470
- style={getStyle(name, style)}
471
- >
472
- {define}
473
- </UIChildren>
474
- );
475
- }
476
- }
477
- return <></>;
478
- };
479
-
480
- let Container = () => {
481
- return (
482
- <>
483
- {isShowLabel() && (
484
- <View
485
- style={getStyle('outerLabel', {
486
- alignSelf: 'flex-start',
487
- flexDirection: 'row',
488
- display: 'flex',
489
- justifyContent: 'space-between',
490
- alignItems: 'center',
491
- width: '100%',
492
- })}
493
- >
494
- <Text style={getStyle('label')}>{scope.getLabel()}</Text>
495
- <Include name="actions" style={{ width: 'auto' }} />
496
- </View>
497
- )}
498
- {isShowInner() && (
499
- <>
500
- <View style={getStyle('inner')}>
501
- <Inner />
502
- </View>
503
- {error && <View style={getStyle('error')}>{error}</View>}
504
- </>
505
- )}
506
- {scope.isType('list', 'repeat') && (
507
- <UIList {...props} scope={scope} crud={crud} />
508
- )}
509
- {scope.isType('dialog') && (
510
- <UIModal {...props} scope={scope} crud={crud} />
511
- )}
512
- {scope.isType('chart') && (
513
- <ElChart {...props} scope={scope} crud={crud} />
514
- )}
515
- {scope.isType('tabs') && (
516
- <ElTabs {...props} scope={scope} crud={crud} />
517
- )}
518
-
519
- {scope.isType('view') && (
520
- <UIView {...props} scope={scope} crud={crud} />
521
- )}
522
-
523
- {isShowChild() && (
524
- <UIChildren
525
- {...props}
526
- scope={scope}
527
- crud={crud}
528
- style={getStyle('inner')}
529
- />
530
- )}
531
- </>
532
- );
533
- };
534
-
535
- let Card = (props: any) => {
536
- let isCard = scope.is('type|layout', 'card');
537
-
538
- if (isCard) {
539
- let box = {
540
- ...getStyle('box', { ...boxStyle.box, alignSelf: 'stretch' }),
541
- };
542
-
543
- return (
544
- <View style={getStyle('card', { ...box })}>
545
- <View
546
- style={getStyle('boxInner', {
547
- paddingHorizontal: 15,
548
- paddingVertical: 10,
549
- })}
550
- >
551
- {props.children}
552
- </View>
553
- </View>
554
- );
555
- }
556
-
557
- return <>{props.children}</>;
558
- };
559
-
560
- return (
561
- <CrudContext.Provider value={{ crud, theme }}>
562
- <Tag ref={ref} style={getStyle()} {...custom}>
563
- <Card>
564
- <Container />
565
- </Card>
566
- </Tag>
567
- </CrudContext.Provider>
568
- );
569
- }
570
-
571
- let boxStyle = StyleSheet.create({
572
- box: {
573
- borderWidth: 0,
574
- borderColor: '#dedede',
575
- borderStyle: 'solid',
576
- backgroundColor: 'white',
577
- borderRadius: 12,
578
- width: '100%',
579
- shadowColor: '#000',
580
- shadowOpacity: 0.1,
581
- shadowRadius: 4,
582
- },
583
- });
584
-
585
- const box: any = {
586
- ...boxStyle.box,
587
- };
588
- //v2
589
- const elementStyle: any = {};
590
-
591
- elementStyle.view = {
592
- inner: {
593
- width: '100%',
594
- alignItems: 'normal',
595
- flex: 1,
596
- },
597
- container: {
598
- width: '100%',
599
- backgroundColor: 'background',
600
- flex: 1,
601
- gap: 10,
602
- },
603
- root: {
604
- width: '100%',
605
- flex: 1,
606
- alignItems: 'normal',
607
- padding: 0,
608
- },
609
- };
610
-
611
- elementStyle.input = StyleSheet.create({
612
- label: {
613
- paddingLeft: 0,
614
- },
615
- inner: {
616
- flex: 1,
617
- width: '100%',
618
- padding: 0,
619
- gap: 10,
620
- alignSelf: 'flex-start',
621
- flexDirection: 'row',
622
- flexWrap: 'wrap',
623
- },
624
- });
625
-
626
- elementStyle.switch = {
627
- inner: {
628
- padding: 5,
629
- },
630
- };
631
-
632
- elementStyle.quantity = {
633
- inner: {
634
- ...box,
635
- backgroundColor: 'primarySoft',
636
- fontWeight: 600,
637
- fontSize: 16,
638
- borderRadius: 25,
639
- borderWidth: 0,
640
- padding: 5,
641
- paddingHorizontal: 5,
642
- paddingVertical: 5,
643
- flexWrap: 'nowrap',
644
- flex: 1,
645
- flexDirection: 'row',
646
- justifyContent: 'center',
647
- alignItems: 'center',
648
- },
649
- };
650
-
651
- elementStyle.toggle = StyleSheet.create({
652
- inner: {
653
- ...box,
654
- flex: 1,
655
- width: '100%',
656
- gap: 10,
657
- justifyContent: 'center',
658
- flexDirection: 'row',
659
- paddingHorizontal: 10,
660
- paddingVertical: 0,
661
- alignSelf: 'flex-start',
662
- flexWrap: 'nowrap',
663
- },
664
- });
665
-
666
- const styles = StyleSheet.create({
667
- root: {
668
- gap: 5,
669
- flexDirection: 'column',
670
- flexWrap: 'wrap',
671
- width: '100%',
672
- alignItems: 'flex-start',
673
- },
674
- label: {
675
- fontWeight: 400,
676
- marginTop: 5,
677
- fontSize: 12,
678
- color: 'labelColor',
679
- },
680
- inner: { width: '100%' },
681
- });
682
-
683
- const withChildStyles = StyleSheet.create({
684
- root: {
685
- gap: 10,
686
- },
687
- label: {
688
- width: '100%',
689
- fontWeight: 500,
690
- fontSize: 24,
691
- },
692
- });
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
+ MethodType,
20
+ ActionType,
21
+ ComponentUtils,
22
+ } from 'react-crud-utils';
23
+ import UILink from './core/UILink';
24
+ import UIIcon from './core/UIIcon';
25
+ import UIButton from './core/UIButton';
26
+ import UISelect from './core/UISelect';
27
+ import UISwitch from './core/UISwitch';
28
+ import UISlider from './core/UISlider';
29
+ import UIOption from './core/UIOption';
30
+ import UIRadio from './core/UIRadio';
31
+ import UIInput from './core/UIInput';
32
+ import {
33
+ Alert,
34
+ Image,
35
+ Linking,
36
+ StyleSheet,
37
+ Text,
38
+ TouchableHighlight,
39
+ View,
40
+ } from 'react-native';
41
+ import UIList from './core/UIList';
42
+ import UIToggle from './core/UIToggle';
43
+ import UIQuantity from './core/UIQuantity';
44
+ import UIModal from './core/UIModal';
45
+ import { Ionicons } from '@expo/vector-icons';
46
+ import UIView from './core/UIView';
47
+ import Toast from 'react-native-toast-message';
48
+
49
+ const CrudContext = createContext<any>({});
50
+
51
+ export default function UIElement(props: ElementType) {
52
+ const ctx = useContext(CrudContext);
53
+ const theme = Utils.nvl(props.theme, ctx?.theme);
54
+
55
+ let crud: Crud = Utils.nvl(props.crud, ctx?.crud);
56
+ let [scope] = useState(ScopeUtils.create({ crud, ...props, theme }));
57
+ let [index, setIndex] = useState(0);
58
+ let [error, setError]: string | any = useState(null);
59
+
60
+ crud = scope.crud;
61
+
62
+ let options: any = scope.getOptions();
63
+
64
+ let original = scope.original;
65
+ let ref = useRef(null);
66
+
67
+ scope.update = () => {
68
+ setIndex(++index);
69
+ };
70
+
71
+ scope.updateElement = () => {
72
+ setIndex(++index);
73
+ };
74
+
75
+ scope.toast = (message: string, type = 'info', args?: any) => {
76
+ Toast.show({
77
+ type, // 'success' | 'error' | 'info'
78
+ text1: message,
79
+ position: 'bottom', // 'top' é outra opção
80
+ visibilityTime: 3000, // tempo que fica visível em ms
81
+ ...args,
82
+ });
83
+ };
84
+
85
+ scope.prompt = (args: MethodType) => {
86
+ let event = args.event as ActionType;
87
+
88
+ if (event) {
89
+ let message = 'Você tem certeza que deseja continuar?';
90
+ let title = 'Atenção';
91
+ let prompt = event.prompt;
92
+
93
+ if (typeof prompt === 'string') {
94
+ message = prompt;
95
+ }
96
+
97
+ if (typeof prompt === 'object') {
98
+ message = Utils.nvl(prompt.message, message);
99
+ title = Utils.nvl(prompt.title, title);
100
+ }
101
+
102
+ Alert.alert(
103
+ title,
104
+ message,
105
+ [
106
+ {
107
+ text: 'Cancelar',
108
+ style: 'cancel',
109
+ },
110
+ {
111
+ text: 'Confirmar',
112
+ onPress: () => scope.execute(args),
113
+ },
114
+ ],
115
+ { cancelable: false }
116
+ );
117
+ }
118
+ };
119
+ const Custom = () => {
120
+ let c: any = original.custom;
121
+
122
+ if (c) {
123
+ if (typeof c === 'string') {
124
+ return (
125
+ <UIElement
126
+ element={{ value: c, type: 'dummy' }}
127
+ crud={crud}
128
+ ></UIElement>
129
+ );
130
+ }
131
+
132
+ return (
133
+ <UIElement
134
+ type={c.type}
135
+ tag={c.type}
136
+ {...c.props}
137
+ crud={crud}
138
+ ></UIElement>
139
+ );
140
+ }
141
+
142
+ return <></>;
143
+ };
144
+
145
+ if (scope.is('type', 'dummy')) {
146
+ return <>{scope.getDisplayValue()}</>;
147
+ }
148
+
149
+ let onCheck = () => {
150
+ let v = scope.getValue();
151
+ let check = !(v === true);
152
+
153
+ onChange({ target: { value: check } });
154
+ };
155
+
156
+ let onChange = (e: any) => {
157
+ let val = e.target.value;
158
+
159
+ if (scope.isType('integer', 'int', 'number')) {
160
+ val = parseInt(val);
161
+ } else if (scope.isType('decimal')) {
162
+ val = parseFloat(val);
163
+ }
164
+
165
+ if (scope.isType('select', 'complete')) {
166
+ val = scope.getSelectedItem(val);
167
+ }
168
+
169
+ scope.changeValue(val);
170
+ scope.update();
171
+ };
172
+
173
+ let onClick = (e: any) => {
174
+ scope.call('click');
175
+ };
176
+
177
+ let defaultsInput: any = {
178
+ scope,
179
+ crud,
180
+ onChange: onChange,
181
+ };
182
+
183
+ if (scope.isType('password')) {
184
+ defaultsInput.type = 'password';
185
+ }
186
+
187
+ let isChecked = () => {
188
+ let v = scope.getValue();
189
+
190
+ return v === true;
191
+ };
192
+
193
+ let hasChildren = () => {
194
+ if (scope.isInput()) {
195
+ return false;
196
+ }
197
+
198
+ return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
199
+ };
200
+
201
+ let isInput = scope.is(
202
+ 'type',
203
+ 'text',
204
+ 'number',
205
+ 'integer',
206
+ 'int',
207
+ 'phone',
208
+ 'postalCode',
209
+ 'money',
210
+ 'password',
211
+ 'email'
212
+ );
213
+
214
+ const getStyle = (part?: string, extra?: any) => {
215
+ let type = Utils.nvl(original.type, 'none');
216
+ let key = Utils.nvl(part, 'root');
217
+ let def = { ...styles[key] };
218
+ let hasChild = hasChildren();
219
+
220
+ type = Utils.nvl(original.layout, type);
221
+
222
+ if (!part && !hasChild) {
223
+ def = { ...def };
224
+ }
225
+
226
+ if (scope.isInput()) {
227
+ def = { ...def, ...elementStyle.input[key] };
228
+ }
229
+
230
+ def = { ...def, ...elementStyle?.[type]?.[key] };
231
+
232
+ if (hasChild && part) {
233
+ def = { ...def, ...withChildStyles[part] };
234
+ }
235
+
236
+ return { ...def, ...scope.getStyle(part, { ...def, ...extra }) };
237
+ };
238
+
239
+ let elStyle = getStyle('element');
240
+
241
+ let defaultsUI: any = {
242
+ required: scope.isRequired(),
243
+ size: 'small',
244
+ scope,
245
+ crud,
246
+ style: elStyle,
247
+ placeholder: scope.attr('placeholder', 'Digite aqui'),
248
+ };
249
+
250
+ scope.error = (msg: string) => {
251
+ error = msg;
252
+ setError(msg);
253
+ };
254
+
255
+ if (!original.list?.url && !original.load?.url) {
256
+ scope.start();
257
+ }
258
+
259
+ useEffect(() => {
260
+ scope.start();
261
+ });
262
+
263
+ const CustomIcon = () => {
264
+ if (typeof original.icon === 'string') {
265
+ return <Ionicons name={original.icon} style={scope.getStyle('icon')} />;
266
+ }
267
+ return <>{original.icon}</>;
268
+ };
269
+
270
+ scope.open = (args: any) => {
271
+ Linking.openURL(args.url);
272
+ };
273
+
274
+ useLayoutEffect(() => {
275
+ if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
276
+ let el: any = ref?.current;
277
+
278
+ if (el?.classList) {
279
+ let bg = HtmlUtils.getBGColor(el);
280
+
281
+ if (bg === 'rgb(255, 255, 255)') {
282
+ el.classList.add('ui-dark');
283
+ } else {
284
+ el.classList.add('ui-light');
285
+ }
286
+ }
287
+ }
288
+ });
289
+
290
+ const isShowLabel = () => {
291
+ if (
292
+ typeof original.label !== 'undefined' &&
293
+ original.label !== false &&
294
+ !scope.isType('button', 'dialog', 'modal')
295
+ ) {
296
+ return true;
297
+ }
298
+
299
+ return false;
300
+ };
301
+
302
+ const isShowInner = () => {
303
+ if (hasChildren()) {
304
+ return false;
305
+ }
306
+ return true;
307
+ };
308
+
309
+ if (!scope.isRendered() || scope.is('type', 'define')) {
310
+ return <></>;
311
+ }
312
+
313
+ const isShowChild = () => {
314
+ if (
315
+ scope.isType(
316
+ 'tabs',
317
+ 'view',
318
+ 'grid',
319
+ 'list',
320
+ 'define',
321
+ 'repeat',
322
+ 'modal',
323
+ 'dialog',
324
+ 'chart'
325
+ )
326
+ ) {
327
+ return false;
328
+ }
329
+
330
+ return true;
331
+ };
332
+
333
+ let Tag: any = View;
334
+ let custom: any = {};
335
+
336
+ if (!scope.isType('input', 'grid', 'list', 'repeat') && original.click) {
337
+ Tag = TouchableHighlight;
338
+
339
+ custom.underlayColor = 'transparent';
340
+ custom.onPress = onClick;
341
+ }
342
+
343
+ let Inner = () => {
344
+ return (
345
+ <>
346
+ {scope.getPart('render', null, <></>)}
347
+ {scope.is('type', 'button') && (
348
+ <UIButton
349
+ {...defaultsUI}
350
+ onClick={onClick}
351
+ variant={scope.attr('variant', 'outlined')}
352
+ >
353
+ {original.icon && <CustomIcon />}
354
+ {original.label && (
355
+ <Text style={scope.getPart('label', 'button')}>
356
+ {scope.getLabel()}
357
+ </Text>
358
+ )}
359
+ </UIButton>
360
+ )}
361
+ {scope.is('type', 'icon') && (
362
+ <UIIcon
363
+ {...defaultsUI}
364
+ onClick={onClick}
365
+ variant={scope.attr('variant', 'outlined')}
366
+ >
367
+ {scope.getDisplayValue()}
368
+ </UIIcon>
369
+ )}
370
+ {scope.is('type', 'link') && (
371
+ <UILink
372
+ {...defaultsUI}
373
+ onClick={onClick}
374
+ variant={scope.attr('variant', 'outlined')}
375
+ >
376
+ {original.icon && <CustomIcon />}
377
+ {original.label && (
378
+ <Text style={scope.getPart('label', 'link')}>
379
+ {scope.getLabel()}
380
+ </Text>
381
+ )}
382
+ </UILink>
383
+ )}
384
+ {isInput && (
385
+ <UIInput
386
+ {...defaultsInput}
387
+ {...defaultsUI}
388
+ InputProps={{ ...original.inputProps }}
389
+ />
390
+ )}
391
+ {scope.is('type', 'complete', 'autocomplete') && (
392
+ <UIComplete
393
+ scope={scope}
394
+ defaultsInput={defaultsInput}
395
+ defaultsUI={defaultsUI}
396
+ />
397
+ )}
398
+ {scope.is('type', 'quantity') && (
399
+ <UIQuantity
400
+ scope={scope}
401
+ defaultsInput={defaultsInput}
402
+ defaultsUI={defaultsUI}
403
+ />
404
+ )}
405
+ {scope.is('type', 'checkbox', 'boolean', 'switch') && (
406
+ <UISwitch
407
+ checked={isChecked()}
408
+ {...defaultsInput}
409
+ onChange={onCheck}
410
+ />
411
+ )}
412
+ {scope.isType('slider') && (
413
+ <UISlider {...defaultsInput} onChange={onCheck} />
414
+ )}
415
+ {scope.is('type', 'select') && (
416
+ <UISelect
417
+ {...defaultsInput}
418
+ {...defaultsUI}
419
+ value={scope.getSelectedValue()}
420
+ />
421
+ )}
422
+ {scope.is('type', 'toggle') && (
423
+ <UIToggle
424
+ {...defaultsInput}
425
+ {...defaultsUI}
426
+ value={scope.getSelectedValue()}
427
+ />
428
+ )}
429
+ {scope.is('type', 'radio') && (
430
+ <UIRadio {...defaultsInput} {...defaultsUI} row>
431
+ {options.map((row: any, i: number) => (
432
+ <UIOption
433
+ key={'i' + i}
434
+ control={<UIRadio {...defaultsUI} />}
435
+ label={row.label}
436
+ value={row.value}
437
+ />
438
+ ))}
439
+ </UIRadio>
440
+ )}
441
+ {scope.is('type', 'custom') && <Custom />}
442
+ {scope.is('type', 'column') && (
443
+ <>
444
+ {scope.is('format', 'img') && (
445
+ <Image source={scope.getDisplayValue()} />
446
+ )}
447
+ {scope.is('format', 'icon') && <UIIcon scope={scope} crud={crud} />}
448
+ {!scope.is('format', 'icon', 'img') && (
449
+ <Text>{scope.getDisplayValue()}</Text>
450
+ )}
451
+ </>
452
+ )}
453
+ {scope.is('type', 'output', 'value') && (
454
+ <Text style={getStyle('value')}>{scope.getDisplayValue()}</Text>
455
+ )}
456
+ </>
457
+ );
458
+ };
459
+
460
+ let Include = ({ name, style }: any) => {
461
+ if (props[name]) {
462
+ let define = ComponentUtils.getDefine(props, name);
463
+
464
+ if (!Utils.isEmpty(define)) {
465
+ return (
466
+ <UIChildren
467
+ {...props}
468
+ scope={scope}
469
+ crud={crud}
470
+ style={getStyle(name, style)}
471
+ >
472
+ {define}
473
+ </UIChildren>
474
+ );
475
+ }
476
+ }
477
+ return <></>;
478
+ };
479
+
480
+ let Container = () => {
481
+ return (
482
+ <>
483
+ {isShowLabel() && (
484
+ <View
485
+ style={getStyle('outerLabel', {
486
+ alignSelf: 'flex-start',
487
+ flexDirection: 'row',
488
+ display: 'flex',
489
+ justifyContent: 'space-between',
490
+ alignItems: 'center',
491
+ width: '100%',
492
+ })}
493
+ >
494
+ <Text style={getStyle('label')}>{scope.getLabel()}</Text>
495
+ <Include name="actions" style={{ width: 'auto' }} />
496
+ </View>
497
+ )}
498
+ {isShowInner() && (
499
+ <>
500
+ <View style={getStyle('inner')}>
501
+ <Inner />
502
+ </View>
503
+ {error && <View style={getStyle('error')}>{error}</View>}
504
+ </>
505
+ )}
506
+ {scope.isType('list', 'repeat') && (
507
+ <UIList {...props} scope={scope} crud={crud} />
508
+ )}
509
+ {scope.isType('dialog') && (
510
+ <UIModal {...props} scope={scope} crud={crud} />
511
+ )}
512
+ {scope.isType('chart') && (
513
+ <ElChart {...props} scope={scope} crud={crud} />
514
+ )}
515
+ {scope.isType('tabs') && (
516
+ <ElTabs {...props} scope={scope} crud={crud} />
517
+ )}
518
+
519
+ {scope.isType('view') && (
520
+ <UIView {...props} scope={scope} crud={crud} />
521
+ )}
522
+
523
+ {isShowChild() && (
524
+ <UIChildren
525
+ {...props}
526
+ scope={scope}
527
+ crud={crud}
528
+ style={getStyle('inner')}
529
+ />
530
+ )}
531
+ </>
532
+ );
533
+ };
534
+
535
+ let Card = (props: any) => {
536
+ let isCard = scope.is('type|layout', 'card');
537
+
538
+ if (isCard) {
539
+ let box = {
540
+ ...getStyle('box', { ...boxStyle.box, alignSelf: 'stretch' }),
541
+ };
542
+
543
+ return (
544
+ <View style={getStyle('card', { ...box })}>
545
+ <View
546
+ style={getStyle('boxInner', {
547
+ paddingHorizontal: 15,
548
+ paddingVertical: 10,
549
+ })}
550
+ >
551
+ {props.children}
552
+ </View>
553
+ </View>
554
+ );
555
+ }
556
+
557
+ return (
558
+ <View style={getStyle('container', { padding: 2, width: '100%' })}>
559
+ {props.children}
560
+ </View>
561
+ );
562
+ };
563
+
564
+ return (
565
+ <CrudContext.Provider value={{ crud, theme }}>
566
+ <Tag ref={ref} style={getStyle()} {...custom}>
567
+ <Card>
568
+ <Container />
569
+ </Card>
570
+ </Tag>
571
+ </CrudContext.Provider>
572
+ );
573
+ }
574
+
575
+ let boxStyle = StyleSheet.create({
576
+ box: {
577
+ borderWidth: 0,
578
+ borderColor: '#dedede',
579
+ borderStyle: 'solid',
580
+ backgroundColor: 'white',
581
+ borderRadius: 12,
582
+ width: '100%',
583
+ shadowColor: '#000',
584
+ shadowOpacity: 0.1,
585
+ shadowRadius: 4,
586
+ },
587
+ });
588
+
589
+ const box: any = {
590
+ ...boxStyle.box,
591
+ };
592
+ //v2
593
+ const elementStyle: any = {};
594
+
595
+ elementStyle.view = {
596
+ inner: {
597
+ width: '100%',
598
+ alignItems: 'normal',
599
+ flex: 1,
600
+ },
601
+ container: {
602
+ width: '100%',
603
+ backgroundColor: 'background',
604
+ flex: 1,
605
+ gap: 10,
606
+ },
607
+ root: {
608
+ width: '100%',
609
+ flex: 1,
610
+ alignItems: 'normal',
611
+ padding: 0,
612
+ },
613
+ };
614
+
615
+ elementStyle.input = StyleSheet.create({
616
+ label: {
617
+ paddingLeft: 0,
618
+ },
619
+ inner: {
620
+ flex: 1,
621
+ width: '100%',
622
+ padding: 0,
623
+ gap: 10,
624
+ alignSelf: 'flex-start',
625
+ flexDirection: 'row',
626
+ flexWrap: 'wrap',
627
+ },
628
+ });
629
+
630
+ elementStyle.switch = {
631
+ inner: {
632
+ padding: 5,
633
+ },
634
+ };
635
+
636
+ elementStyle.quantity = {
637
+ inner: {
638
+ ...box,
639
+ backgroundColor: 'primarySoft',
640
+ fontWeight: 600,
641
+ fontSize: 16,
642
+ borderRadius: 25,
643
+ borderWidth: 0,
644
+ padding: 5,
645
+ paddingHorizontal: 5,
646
+ paddingVertical: 5,
647
+ flexWrap: 'nowrap',
648
+ flex: 1,
649
+ flexDirection: 'row',
650
+ justifyContent: 'center',
651
+ alignItems: 'center',
652
+ },
653
+ };
654
+
655
+ elementStyle.toggle = StyleSheet.create({
656
+ inner: {
657
+ ...box,
658
+ flex: 1,
659
+ width: '100%',
660
+ gap: 10,
661
+ justifyContent: 'center',
662
+ flexDirection: 'row',
663
+ paddingHorizontal: 10,
664
+ paddingVertical: 0,
665
+ alignSelf: 'flex-start',
666
+ flexWrap: 'nowrap',
667
+ },
668
+ });
669
+
670
+ const styles = StyleSheet.create({
671
+ root: {
672
+ gap: 5,
673
+ flexDirection: 'column',
674
+ flexWrap: 'wrap',
675
+ width: '100%',
676
+ alignItems: 'flex-start',
677
+ },
678
+ label: {
679
+ fontWeight: 400,
680
+ marginTop: 5,
681
+ fontSize: 12,
682
+ color: 'labelColor',
683
+ },
684
+ inner: { width: '100%' },
685
+ });
686
+
687
+ const withChildStyles = StyleSheet.create({
688
+ root: {
689
+ gap: 10,
690
+ },
691
+ label: {
692
+ width: '100%',
693
+ fontWeight: 500,
694
+ fontSize: 24,
695
+ },
696
+ });