react-crud-mobile 1.0.41 → 1.0.45

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