react-crud-mobile 1.0.80 → 1.0.82

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,411 +1,411 @@
1
- import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
- import ElGrid from './grid/ElGrid';
3
- import UIChildren from './UIChildren';
4
- import ElTabs from './tabs/ElTabs';
5
- import ElLabel from './grid/ElLabel';
6
- import ElChart from './charts/ElChart';
7
- import UIComplete from './UIComplete';
8
- import ElRepeat from './grid/ElRepeat';
9
- import {
10
- Crud,
11
- HtmlUtils,
12
- ScopeUtils,
13
- Utils,
14
- ElementType,
15
- } from 'react-crud-utils';
16
- import Link from './core/Link';
17
- import Icon from './core/Icon';
18
- import Button from './core/Button';
19
- import Select from './core/Select';
20
- import Switch from './core/Switch';
21
- import Option from './core/Option';
22
- import Radio from './core/Radio';
23
- import Input from './core/Input';
24
- import { Image, Linking, StyleSheet, Text, View } from 'react-native';
25
-
26
- export default function UIElement(props: ElementType) {
27
- let [scope] = useState(ScopeUtils.create(props));
28
- let [index, setIndex] = useState(0);
29
- let [error, setError]: string | any = useState(null);
30
- let options: any = scope.getOptions();
31
- let crud: Crud = Utils.nvl(props.crud, scope.crud);
32
- let original = scope.original;
33
- let type = original.type;
34
- let ref = useRef(null);
35
-
36
- scope.update = () => {
37
- setIndex(++index);
38
- };
39
-
40
- let router: any = {
41
- list: ElGrid,
42
- grid: ElGrid,
43
- label: ElLabel,
44
- repeat: ElRepeat,
45
- tabs: ElTabs,
46
- chart: ElChart,
47
- };
48
-
49
- let CurrentRouter = () => {
50
- if (router[type]) {
51
- let Aux = router[type];
52
-
53
- return <Aux crud={crud} {...props} scope={scope} />;
54
- }
55
- return <></>;
56
- };
57
-
58
- const Custom = () => {
59
- let c: any = original.custom;
60
-
61
- if (c) {
62
- if (typeof c === 'string') {
63
- return (
64
- <UIElement
65
- element={{ value: c, type: 'dummy' }}
66
- crud={crud}
67
- ></UIElement>
68
- );
69
- }
70
-
71
- return (
72
- <UIElement
73
- type={c.type}
74
- tag={c.type}
75
- {...c.props}
76
- crud={crud}
77
- ></UIElement>
78
- );
79
- }
80
-
81
- return <></>;
82
- };
83
-
84
- if (scope.is('type', 'dummy')) {
85
- return <>{scope.getDisplayValue()}</>;
86
- }
87
-
88
- let onCheck = () => {
89
- let v = scope.getValue();
90
- let check = !(v === true);
91
-
92
- onChange({ target: { value: check } });
93
- };
94
-
95
- let onChange = (e: any) => {
96
- let val = e.target.value;
97
-
98
- if (scope.isType('integer', 'int', 'number')) {
99
- val = parseInt(val);
100
- } else if (scope.isType('decimal')) {
101
- val = parseFloat(val);
102
- }
103
-
104
- if (scope.isType('select', 'complete')) {
105
- val = scope.getSelectedItem(val);
106
- }
107
-
108
- scope.changeValue(val);
109
- scope.update();
110
- };
111
-
112
- let onClick = (e: any) => {
113
- scope.call('click');
114
- };
115
-
116
- let defaultsInput: any = {
117
- label: scope.getLabel(),
118
- value: scope.getValue(),
119
- onChange: onChange,
120
- };
121
-
122
- if (scope.isType('password')) {
123
- defaultsInput.type = 'password';
124
- }
125
-
126
- const getStyle = (part?: string) => {
127
- let key = Utils.nvl(part, 'root');
128
- let def = styles[key];
129
- let hasChild = hasChildren();
130
-
131
- if (!part && !hasChild) {
132
- def = { ...def, flex: 1 };
133
- }
134
-
135
- if (hasChild && part) {
136
- def = { ...def, ...withChildStyles[part] };
137
- }
138
-
139
- return { ...def, ...scope.getStyle(part) };
140
- };
141
-
142
- let elStyle = getStyle('element');
143
-
144
- let defaultsUI: any = {
145
- required: scope.isRequired(),
146
- size: 'small',
147
- scope,
148
- crud,
149
- style: elStyle,
150
- placeholder: scope.attr('placeholder', 'Digite aqui'),
151
- };
152
-
153
- let isChecked = () => {
154
- let v = scope.getValue();
155
-
156
- return v === true;
157
- };
158
-
159
- let hasChildren = () => {
160
- if (scope.isInput()) {
161
- return false;
162
- }
163
-
164
- return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
165
- };
166
-
167
- if (!scope.isRendered() || scope.is('type', 'define')) {
168
- return <></>;
169
- }
170
-
171
- scope.error = (msg: string) => {
172
- error = msg;
173
- setError(msg);
174
- };
175
-
176
- useEffect(() => {
177
- if (!scope.ready) {
178
- scope.ready = true;
179
-
180
- scope.call('load');
181
-
182
- if (scope.isType('list', 'repeat')) {
183
- scope.search();
184
- } else if (original.list) {
185
- scope.call('list');
186
- }
187
- scope.start();
188
- }
189
- });
190
-
191
- const CustomIcon = () => {
192
- if (typeof original.icon === 'string') {
193
- return <Icon>{scope.getIcon()}</Icon>;
194
- }
195
- return <>{original.icon}</>;
196
- };
197
-
198
- const getLabelClass = (type: string) => {
199
- let clss = `ui-text ui-${type}-text`;
200
- let icon = scope.getIcon();
201
-
202
- if (icon) {
203
- clss = clss + ` ui-icon ui-${type}-icon`;
204
- }
205
- return clss;
206
- };
207
-
208
- let hasCustomRoute = () => {
209
- if (router[type]) return true;
210
- return false;
211
- };
212
-
213
- scope.open = (args: any) => {
214
- Linking.openURL(args.url);
215
- };
216
-
217
- if (scope.isType('dialog')) {
218
- let name = original.name;
219
-
220
- if (!crud.dialogs[name]) {
221
- let dlg: any = { config: { ...original } };
222
-
223
- dlg.component = (args: any) => {
224
- return <UIChildren {...props} scope={scope} crud={crud} />;
225
- };
226
-
227
- crud.dialogs[name] = dlg;
228
- }
229
- return <></>;
230
- }
231
-
232
- useLayoutEffect(() => {
233
- if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
234
- let el: any = ref?.current;
235
-
236
- if (el?.classList) {
237
- let bg = HtmlUtils.getBGColor(el);
238
-
239
- if (bg === 'rgb(255, 255, 255)') {
240
- el.classList.add('ui-dark');
241
- } else {
242
- el.classList.add('ui-light');
243
- }
244
- }
245
- }
246
- });
247
-
248
- const isShowLabel = () => {
249
- if (typeof original.label !== 'undefined') {
250
- return true;
251
- }
252
-
253
- return false;
254
- };
255
-
256
- const isShowInner = () => {
257
- if (hasChildren() || hasCustomRoute()) {
258
- return false;
259
- }
260
- return true;
261
- };
262
-
263
- return (
264
- <>
265
- <View ref={ref} style={getStyle()}>
266
- <>
267
- {isShowLabel() && (
268
- <Text style={getStyle('label')}>{scope.getLabel()}</Text>
269
- )}
270
- {isShowInner() && (
271
- <>
272
- <View style={getStyle('inner')}>
273
- {scope.is('type', 'button') && (
274
- <Button
275
- {...defaultsUI}
276
- onClick={onClick}
277
- variant={scope.attr('variant', 'outlined')}
278
- >
279
- {original.icon && <CustomIcon />}
280
- {original.label && (
281
- <Text style={scope.getPart('label', 'button')}>
282
- {scope.getLabel()}
283
- </Text>
284
- )}
285
- </Button>
286
- )}
287
- {scope.is('type', 'icon') && (
288
- <Icon
289
- {...defaultsUI}
290
- onClick={onClick}
291
- variant={scope.attr('variant', 'outlined')}
292
- >
293
- {scope.getDisplayValue()}
294
- </Icon>
295
- )}
296
- {scope.is('type', 'link') && (
297
- <Link
298
- {...defaultsUI}
299
- onClick={onClick}
300
- variant={scope.attr('variant', 'outlined')}
301
- >
302
- {original.icon && <CustomIcon />}
303
- {original.label && (
304
- <Text style={scope.getPart('label', 'link')}>
305
- {scope.getLabel()}
306
- </Text>
307
- )}
308
- </Link>
309
- )}
310
- {scope.is(
311
- 'type',
312
- 'text',
313
- 'number',
314
- 'phone',
315
- 'postalCode',
316
- 'money',
317
- 'password',
318
- 'email'
319
- ) && (
320
- <Input
321
- {...defaultsInput}
322
- {...defaultsUI}
323
- InputProps={{ ...original.inputProps }}
324
- />
325
- )}
326
- {scope.is('type', 'complete', 'autocomplete') && (
327
- <UIComplete
328
- scope={scope}
329
- defaultsInput={defaultsInput}
330
- defaultsUI={defaultsUI}
331
- />
332
- )}
333
- {scope.is('type', 'checkbox', 'boolean', 'switch') && (
334
- <Switch
335
- checked={isChecked()}
336
- {...defaultsInput}
337
- onChange={onCheck}
338
- />
339
- )}
340
- {scope.is('type', 'select') && (
341
- <Select
342
- {...defaultsInput}
343
- {...defaultsUI}
344
- value={scope.getSelectedValue()}
345
- >
346
- <Option value={''}>Selecione</Option>
347
- {options.map((row: any, i: number) => (
348
- <Option key={'i' + i} value={row.value}>
349
- {row.label}
350
- </Option>
351
- ))}
352
- </Select>
353
- )}
354
- {scope.is('type', 'radio') && (
355
- <Radio {...defaultsInput} {...defaultsUI} row>
356
- {options.map((row: any, i: number) => (
357
- <Option
358
- key={'i' + i}
359
- control={<Radio {...defaultsUI} />}
360
- label={row.label}
361
- value={row.value}
362
- />
363
- ))}
364
- </Radio>
365
- )}
366
- {scope.is('type', 'custom') && <Custom />}
367
- {scope.is('type', 'column') && (
368
- <>
369
- {scope.is('format', 'img') && (
370
- <Image source={scope.getDisplayValue()} />
371
- )}
372
- {scope.is('format', 'icon') && (
373
- <Icon className={scope.getDisplayValue()} />
374
- )}
375
- {!scope.is('format', 'icon', 'img') && (
376
- <Text>{scope.getDisplayValue()}</Text>
377
- )}
378
- </>
379
- )}
380
- {scope.is('type', 'output') && (
381
- <Text>{scope.getDisplayValue()}</Text>
382
- )}
383
- </View>
384
- {error && <View style={getStyle('error')}>{error}</View>}
385
- </>
386
- )}
387
- <CurrentRouter />
388
- {!scope.is('type', 'tabs', 'grid', 'list', 'define', 'repeat') && (
389
- <UIChildren {...props} scope={scope} crud={crud} />
390
- )}
391
- </>
392
- </View>
393
- </>
394
- );
395
- }
396
-
397
- const styles = StyleSheet.create({
398
- root: {
399
- gap: 10,
400
- flexDirection: 'column',
401
- flexWrap: 'wrap',
402
- width: '100%',
403
- alignItems: 'flex-start',
404
- },
405
- label: { width: '100%', fontWeight: 600 },
406
- inner: { width: '100%' },
407
- });
408
-
409
- const withChildStyles = StyleSheet.create({
410
- label: { width: '100%', fontWeight: 500, fontSize: 20 },
411
- });
1
+ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import ElGrid from './grid/ElGrid';
3
+ import UIChildren from './UIChildren';
4
+ import ElTabs from './tabs/ElTabs';
5
+ import ElLabel from './grid/ElLabel';
6
+ import ElChart from './charts/ElChart';
7
+ import UIComplete from './UIComplete';
8
+ import ElRepeat from './grid/ElRepeat';
9
+ import {
10
+ Crud,
11
+ HtmlUtils,
12
+ ScopeUtils,
13
+ Utils,
14
+ ElementType,
15
+ } from 'react-crud-utils';
16
+ import Link from './core/Link';
17
+ import Icon from './core/Icon';
18
+ import Button from './core/Button';
19
+ import Select from './core/Select';
20
+ import Switch from './core/Switch';
21
+ import Option from './core/Option';
22
+ import Radio from './core/Radio';
23
+ import Input from './core/Input';
24
+ import { Image, Linking, StyleSheet, Text, View } from 'react-native';
25
+
26
+ export default function UIElement(props: ElementType) {
27
+ let [scope] = useState(ScopeUtils.create(props));
28
+ let [index, setIndex] = useState(0);
29
+ let [error, setError]: string | any = useState(null);
30
+ let options: any = scope.getOptions();
31
+ let crud: Crud = Utils.nvl(props.crud, scope.crud);
32
+ let original = scope.original;
33
+ let type = original.type;
34
+ let ref = useRef(null);
35
+
36
+ scope.update = () => {
37
+ setIndex(++index);
38
+ };
39
+
40
+ let router: any = {
41
+ list: ElGrid,
42
+ grid: ElGrid,
43
+ label: ElLabel,
44
+ repeat: ElRepeat,
45
+ tabs: ElTabs,
46
+ chart: ElChart,
47
+ };
48
+
49
+ let CurrentRouter = () => {
50
+ if (router[type]) {
51
+ let Aux = router[type];
52
+
53
+ return <Aux crud={crud} {...props} scope={scope} />;
54
+ }
55
+ return <></>;
56
+ };
57
+
58
+ const Custom = () => {
59
+ let c: any = original.custom;
60
+
61
+ if (c) {
62
+ if (typeof c === 'string') {
63
+ return (
64
+ <UIElement
65
+ element={{ value: c, type: 'dummy' }}
66
+ crud={crud}
67
+ ></UIElement>
68
+ );
69
+ }
70
+
71
+ return (
72
+ <UIElement
73
+ type={c.type}
74
+ tag={c.type}
75
+ {...c.props}
76
+ crud={crud}
77
+ ></UIElement>
78
+ );
79
+ }
80
+
81
+ return <></>;
82
+ };
83
+
84
+ if (scope.is('type', 'dummy')) {
85
+ return <>{scope.getDisplayValue()}</>;
86
+ }
87
+
88
+ let onCheck = () => {
89
+ let v = scope.getValue();
90
+ let check = !(v === true);
91
+
92
+ onChange({ target: { value: check } });
93
+ };
94
+
95
+ let onChange = (e: any) => {
96
+ let val = e.target.value;
97
+
98
+ if (scope.isType('integer', 'int', 'number')) {
99
+ val = parseInt(val);
100
+ } else if (scope.isType('decimal')) {
101
+ val = parseFloat(val);
102
+ }
103
+
104
+ if (scope.isType('select', 'complete')) {
105
+ val = scope.getSelectedItem(val);
106
+ }
107
+
108
+ scope.changeValue(val);
109
+ scope.update();
110
+ };
111
+
112
+ let onClick = (e: any) => {
113
+ scope.call('click');
114
+ };
115
+
116
+ let defaultsInput: any = {
117
+ label: scope.getLabel(),
118
+ value: scope.getValue(),
119
+ onChange: onChange,
120
+ };
121
+
122
+ if (scope.isType('password')) {
123
+ defaultsInput.type = 'password';
124
+ }
125
+
126
+ let isChecked = () => {
127
+ let v = scope.getValue();
128
+
129
+ return v === true;
130
+ };
131
+
132
+ let hasChildren = () => {
133
+ if (scope.isInput()) {
134
+ return false;
135
+ }
136
+
137
+ return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
138
+ };
139
+
140
+ const getStyle = (part?: string) => {
141
+ let key = Utils.nvl(part, 'root');
142
+ let def = styles[key];
143
+ let hasChild = hasChildren();
144
+
145
+ if (!part && !hasChild) {
146
+ def = { ...def, flex: 1 };
147
+ }
148
+
149
+ if (hasChild && part) {
150
+ def = { ...def, ...withChildStyles[part] };
151
+ }
152
+
153
+ return { ...def, ...scope.getStyle(part) };
154
+ };
155
+
156
+ let elStyle = getStyle('element');
157
+
158
+ let defaultsUI: any = {
159
+ required: scope.isRequired(),
160
+ size: 'small',
161
+ scope,
162
+ crud,
163
+ style: elStyle,
164
+ placeholder: scope.attr('placeholder', 'Digite aqui'),
165
+ };
166
+
167
+ if (!scope.isRendered() || scope.is('type', 'define')) {
168
+ return <></>;
169
+ }
170
+
171
+ scope.error = (msg: string) => {
172
+ error = msg;
173
+ setError(msg);
174
+ };
175
+
176
+ useEffect(() => {
177
+ if (!scope.ready) {
178
+ scope.ready = true;
179
+
180
+ scope.call('load');
181
+
182
+ if (scope.isType('list', 'repeat')) {
183
+ scope.search();
184
+ } else if (original.list) {
185
+ scope.call('list');
186
+ }
187
+ scope.start();
188
+ }
189
+ });
190
+
191
+ const CustomIcon = () => {
192
+ if (typeof original.icon === 'string') {
193
+ return <Icon>{scope.getIcon()}</Icon>;
194
+ }
195
+ return <>{original.icon}</>;
196
+ };
197
+
198
+ const getLabelClass = (type: string) => {
199
+ let clss = `ui-text ui-${type}-text`;
200
+ let icon = scope.getIcon();
201
+
202
+ if (icon) {
203
+ clss = clss + ` ui-icon ui-${type}-icon`;
204
+ }
205
+ return clss;
206
+ };
207
+
208
+ let hasCustomRoute = () => {
209
+ if (router[type]) return true;
210
+ return false;
211
+ };
212
+
213
+ scope.open = (args: any) => {
214
+ Linking.openURL(args.url);
215
+ };
216
+
217
+ if (scope.isType('dialog')) {
218
+ let name = original.name;
219
+
220
+ if (!crud.dialogs[name]) {
221
+ let dlg: any = { config: { ...original } };
222
+
223
+ dlg.component = (args: any) => {
224
+ return <UIChildren {...props} scope={scope} crud={crud} />;
225
+ };
226
+
227
+ crud.dialogs[name] = dlg;
228
+ }
229
+ return <></>;
230
+ }
231
+
232
+ useLayoutEffect(() => {
233
+ if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
234
+ let el: any = ref?.current;
235
+
236
+ if (el?.classList) {
237
+ let bg = HtmlUtils.getBGColor(el);
238
+
239
+ if (bg === 'rgb(255, 255, 255)') {
240
+ el.classList.add('ui-dark');
241
+ } else {
242
+ el.classList.add('ui-light');
243
+ }
244
+ }
245
+ }
246
+ });
247
+
248
+ const isShowLabel = () => {
249
+ if (typeof original.label !== 'undefined') {
250
+ return true;
251
+ }
252
+
253
+ return false;
254
+ };
255
+
256
+ const isShowInner = () => {
257
+ if (hasChildren() || hasCustomRoute()) {
258
+ return false;
259
+ }
260
+ return true;
261
+ };
262
+
263
+ return (
264
+ <>
265
+ <View ref={ref} style={getStyle()}>
266
+ <>
267
+ {isShowLabel() && (
268
+ <Text style={getStyle('label')}>{scope.getLabel()}</Text>
269
+ )}
270
+ {isShowInner() && (
271
+ <>
272
+ <View style={getStyle('inner')}>
273
+ {scope.is('type', 'button') && (
274
+ <Button
275
+ {...defaultsUI}
276
+ onClick={onClick}
277
+ variant={scope.attr('variant', 'outlined')}
278
+ >
279
+ {original.icon && <CustomIcon />}
280
+ {original.label && (
281
+ <Text style={scope.getPart('label', 'button')}>
282
+ {scope.getLabel()}
283
+ </Text>
284
+ )}
285
+ </Button>
286
+ )}
287
+ {scope.is('type', 'icon') && (
288
+ <Icon
289
+ {...defaultsUI}
290
+ onClick={onClick}
291
+ variant={scope.attr('variant', 'outlined')}
292
+ >
293
+ {scope.getDisplayValue()}
294
+ </Icon>
295
+ )}
296
+ {scope.is('type', 'link') && (
297
+ <Link
298
+ {...defaultsUI}
299
+ onClick={onClick}
300
+ variant={scope.attr('variant', 'outlined')}
301
+ >
302
+ {original.icon && <CustomIcon />}
303
+ {original.label && (
304
+ <Text style={scope.getPart('label', 'link')}>
305
+ {scope.getLabel()}
306
+ </Text>
307
+ )}
308
+ </Link>
309
+ )}
310
+ {scope.is(
311
+ 'type',
312
+ 'text',
313
+ 'number',
314
+ 'phone',
315
+ 'postalCode',
316
+ 'money',
317
+ 'password',
318
+ 'email'
319
+ ) && (
320
+ <Input
321
+ {...defaultsInput}
322
+ {...defaultsUI}
323
+ InputProps={{ ...original.inputProps }}
324
+ />
325
+ )}
326
+ {scope.is('type', 'complete', 'autocomplete') && (
327
+ <UIComplete
328
+ scope={scope}
329
+ defaultsInput={defaultsInput}
330
+ defaultsUI={defaultsUI}
331
+ />
332
+ )}
333
+ {scope.is('type', 'checkbox', 'boolean', 'switch') && (
334
+ <Switch
335
+ checked={isChecked()}
336
+ {...defaultsInput}
337
+ onChange={onCheck}
338
+ />
339
+ )}
340
+ {scope.is('type', 'select') && (
341
+ <Select
342
+ {...defaultsInput}
343
+ {...defaultsUI}
344
+ value={scope.getSelectedValue()}
345
+ >
346
+ <Option value={''}>Selecione</Option>
347
+ {options.map((row: any, i: number) => (
348
+ <Option key={'i' + i} value={row.value}>
349
+ {row.label}
350
+ </Option>
351
+ ))}
352
+ </Select>
353
+ )}
354
+ {scope.is('type', 'radio') && (
355
+ <Radio {...defaultsInput} {...defaultsUI} row>
356
+ {options.map((row: any, i: number) => (
357
+ <Option
358
+ key={'i' + i}
359
+ control={<Radio {...defaultsUI} />}
360
+ label={row.label}
361
+ value={row.value}
362
+ />
363
+ ))}
364
+ </Radio>
365
+ )}
366
+ {scope.is('type', 'custom') && <Custom />}
367
+ {scope.is('type', 'column') && (
368
+ <>
369
+ {scope.is('format', 'img') && (
370
+ <Image source={scope.getDisplayValue()} />
371
+ )}
372
+ {scope.is('format', 'icon') && (
373
+ <Icon className={scope.getDisplayValue()} />
374
+ )}
375
+ {!scope.is('format', 'icon', 'img') && (
376
+ <Text>{scope.getDisplayValue()}</Text>
377
+ )}
378
+ </>
379
+ )}
380
+ {scope.is('type', 'output') && (
381
+ <Text>{scope.getDisplayValue()}</Text>
382
+ )}
383
+ </View>
384
+ {error && <View style={getStyle('error')}>{error}</View>}
385
+ </>
386
+ )}
387
+ <CurrentRouter />
388
+ {!scope.is('type', 'tabs', 'grid', 'list', 'define', 'repeat') && (
389
+ <UIChildren {...props} scope={scope} crud={crud} />
390
+ )}
391
+ </>
392
+ </View>
393
+ </>
394
+ );
395
+ }
396
+
397
+ const styles = StyleSheet.create({
398
+ root: {
399
+ gap: 5,
400
+ flexDirection: 'column',
401
+ flexWrap: 'wrap',
402
+ width: '100%',
403
+ alignItems: 'flex-start',
404
+ },
405
+ label: { width: '100%', fontWeight: 500 },
406
+ inner: { width: '100%' },
407
+ });
408
+
409
+ const withChildStyles = StyleSheet.create({
410
+ label: { width: '100%', fontWeight: 500, fontSize: 20 },
411
+ });