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