@controleonline/ui-default 1.0.280 → 1.0.282
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/package.json +2 -2
- package/src/react/components/cards/DefaultEntityCard.js +13 -0
- package/src/react/components/files/DefaultFile.js +11 -24
- package/src/react/components/inputs/DefaultInput.js +417 -414
- package/src/react/components/table/DefaultColumnMenu.js +1 -1
- package/src/react/components/table/DefaultSearchModal.js +14 -5
- package/src/react/components/table/DefaultTable.js +32 -21
- package/src/react/components/table/DefaultTable.layoutUtils.js +1 -0
- package/src/react/components/table/DefaultTableCards.js +5 -2
- package/src/react/components/table/DefaultTableCompactToolbar.js +2 -2
- package/src/react/components/table/DefaultTableControls.js +2 -2
- package/src/react/components/table/DefaultTableInput.js +1 -1
- package/src/react/components/table/DefaultTableRows.js +1 -1
- package/src/react/components/table/DefaultTableToolbar.js +1 -1
- package/src/react/components/table/useDefaultTablePagination.js +48 -6
- package/src/react/components/table/useDefaultTableStoreSync.js +18 -6
- package/src/store/default/actions.js +117 -116
- package/src/tests/react/components/table/defaultTableTestSetup.cjs +1 -0
|
@@ -1,414 +1,417 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { Image, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
3
|
-
import DefaultExtraData from '../extra-data/DefaultExtraData';
|
|
4
|
-
import DefaultFileColumn from '../files/DefaultFileColumn';
|
|
5
|
-
import Icon from 'react-native-vector-icons/Feather';
|
|
6
|
-
import {
|
|
7
|
-
buildReadPresentationStyles,
|
|
8
|
-
getColumnKey,
|
|
9
|
-
isColorColumn,
|
|
10
|
-
isDateLikeColumn,
|
|
11
|
-
isEditableColumn,
|
|
12
|
-
isExtraDataColumn,
|
|
13
|
-
isFileColumn,
|
|
14
|
-
isIconColumn,
|
|
15
|
-
isValidFeatherIcon,
|
|
16
|
-
normalizeText,
|
|
17
|
-
resolveCellPresentation,
|
|
18
|
-
resolveCellText,
|
|
19
|
-
resolveEditValue,
|
|
20
|
-
} from './defaultInputUtils';
|
|
21
|
-
import DefaultColorInput from './DefaultColorInput';
|
|
22
|
-
import DefaultDateInput from './DefaultDateInput';
|
|
23
|
-
import DefaultFeatherIconPicker, {
|
|
24
|
-
normalizeFeatherIconName,
|
|
25
|
-
} from './DefaultFeatherIconPicker';
|
|
26
|
-
import DefaultSelect from './DefaultSelect';
|
|
27
|
-
import styles from './DefaultInput.styles';
|
|
28
|
-
|
|
29
|
-
const DefaultInput = ({
|
|
30
|
-
accentColor = '#2563EB',
|
|
31
|
-
autoFocus = true,
|
|
32
|
-
autoSave = true,
|
|
33
|
-
column,
|
|
34
|
-
columns = [],
|
|
35
|
-
containerStyle = null,
|
|
36
|
-
displayValue,
|
|
37
|
-
defaultColor = '',
|
|
38
|
-
editing = false,
|
|
39
|
-
getOptionsForColumn = null,
|
|
40
|
-
inputStyle = null,
|
|
41
|
-
label = '',
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
<
|
|
190
|
-
) :
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
readPresentationStyles.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
{
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
{
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
readPresentationStyles.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
{
|
|
367
|
-
|
|
368
|
-
{column?.
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
<
|
|
376
|
-
) :
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Image, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import DefaultExtraData from '../extra-data/DefaultExtraData';
|
|
4
|
+
import DefaultFileColumn from '../files/DefaultFileColumn';
|
|
5
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
6
|
+
import {
|
|
7
|
+
buildReadPresentationStyles,
|
|
8
|
+
getColumnKey,
|
|
9
|
+
isColorColumn,
|
|
10
|
+
isDateLikeColumn,
|
|
11
|
+
isEditableColumn,
|
|
12
|
+
isExtraDataColumn,
|
|
13
|
+
isFileColumn,
|
|
14
|
+
isIconColumn,
|
|
15
|
+
isValidFeatherIcon,
|
|
16
|
+
normalizeText,
|
|
17
|
+
resolveCellPresentation,
|
|
18
|
+
resolveCellText,
|
|
19
|
+
resolveEditValue,
|
|
20
|
+
} from './defaultInputUtils';
|
|
21
|
+
import DefaultColorInput from './DefaultColorInput';
|
|
22
|
+
import DefaultDateInput from './DefaultDateInput';
|
|
23
|
+
import DefaultFeatherIconPicker, {
|
|
24
|
+
normalizeFeatherIconName,
|
|
25
|
+
} from './DefaultFeatherIconPicker';
|
|
26
|
+
import DefaultSelect from './DefaultSelect';
|
|
27
|
+
import styles from './DefaultInput.styles';
|
|
28
|
+
|
|
29
|
+
const DefaultInput = ({
|
|
30
|
+
accentColor = '#2563EB',
|
|
31
|
+
autoFocus = true,
|
|
32
|
+
autoSave = true,
|
|
33
|
+
column,
|
|
34
|
+
columns = [],
|
|
35
|
+
containerStyle = null,
|
|
36
|
+
displayValue,
|
|
37
|
+
defaultColor = '',
|
|
38
|
+
editing = false,
|
|
39
|
+
getOptionsForColumn = null,
|
|
40
|
+
inputStyle = null,
|
|
41
|
+
label = '',
|
|
42
|
+
maxLength,
|
|
43
|
+
onSubmitEditing = null,
|
|
44
|
+
numberOfLines = 1,
|
|
45
|
+
onBeforeOpen = null,
|
|
46
|
+
onCancelEditing = null,
|
|
47
|
+
onChangeValue = null,
|
|
48
|
+
onSave = null,
|
|
49
|
+
onSearchChange = null,
|
|
50
|
+
onStartEditing = null,
|
|
51
|
+
readTextStyle = null,
|
|
52
|
+
row = {},
|
|
53
|
+
saving = false,
|
|
54
|
+
showLabel = false,
|
|
55
|
+
storeName = '',
|
|
56
|
+
value,
|
|
57
|
+
variant = 'cell',
|
|
58
|
+
}) => {
|
|
59
|
+
const fieldName = getColumnKey(column);
|
|
60
|
+
const isExtraDataField = isExtraDataColumn(column) || ['extradata', 'extra_data'].includes(
|
|
61
|
+
normalizeText(fieldName).replace(/[^a-zA-Z0-9_]/g, '').toLowerCase(),
|
|
62
|
+
);
|
|
63
|
+
const isForm = variant === 'form';
|
|
64
|
+
const canEdit = isEditableColumn(column) && typeof onStartEditing === 'function';
|
|
65
|
+
const editValue = useMemo(
|
|
66
|
+
() => normalizeText(value ?? resolveEditValue(column, row)),
|
|
67
|
+
[column, row, value],
|
|
68
|
+
);
|
|
69
|
+
const [draftValue, setDraftValue] = useState(editValue);
|
|
70
|
+
const resolvedLabel =
|
|
71
|
+
displayValue ?? resolveCellText({ column, columns, row, storeName, value });
|
|
72
|
+
const readPresentation = useMemo(
|
|
73
|
+
() => resolveCellPresentation({ column, columns, row, storeName, value }),
|
|
74
|
+
[column, columns, row, storeName, value],
|
|
75
|
+
);
|
|
76
|
+
const readPresentationStyles = useMemo(
|
|
77
|
+
() => buildReadPresentationStyles({
|
|
78
|
+
...readPresentation,
|
|
79
|
+
label: resolvedLabel,
|
|
80
|
+
}),
|
|
81
|
+
[readPresentation, resolvedLabel],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setDraftValue(editValue);
|
|
86
|
+
}, [editValue, editing]);
|
|
87
|
+
|
|
88
|
+
if (column?.list) {
|
|
89
|
+
return (
|
|
90
|
+
<DefaultSelect
|
|
91
|
+
accentColor={accentColor}
|
|
92
|
+
autoSave={autoSave}
|
|
93
|
+
column={column}
|
|
94
|
+
columns={columns}
|
|
95
|
+
containerStyle={containerStyle}
|
|
96
|
+
displayValue={displayValue}
|
|
97
|
+
editing={editing}
|
|
98
|
+
getOptionsForColumn={getOptionsForColumn}
|
|
99
|
+
label={label}
|
|
100
|
+
numberOfLines={numberOfLines}
|
|
101
|
+
onBeforeOpen={onBeforeOpen}
|
|
102
|
+
onCancelEditing={onCancelEditing}
|
|
103
|
+
onChangeValue={onChangeValue}
|
|
104
|
+
onSave={onSave}
|
|
105
|
+
onStartEditing={onStartEditing}
|
|
106
|
+
readTextStyle={readTextStyle}
|
|
107
|
+
row={row}
|
|
108
|
+
saving={saving}
|
|
109
|
+
showLabel={showLabel}
|
|
110
|
+
storeName={storeName}
|
|
111
|
+
value={value}
|
|
112
|
+
variant={variant}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (isColorColumn(column)) {
|
|
118
|
+
return (
|
|
119
|
+
<DefaultColorInput
|
|
120
|
+
accentColor={accentColor}
|
|
121
|
+
autoFocus={autoFocus}
|
|
122
|
+
autoSave={autoSave}
|
|
123
|
+
column={column}
|
|
124
|
+
containerStyle={containerStyle}
|
|
125
|
+
defaultColor={defaultColor}
|
|
126
|
+
editing={editing}
|
|
127
|
+
inputStyle={inputStyle}
|
|
128
|
+
label={label}
|
|
129
|
+
onCancelEditing={onCancelEditing}
|
|
130
|
+
onChangeValue={onChangeValue}
|
|
131
|
+
onSave={onSave}
|
|
132
|
+
onStartEditing={onStartEditing}
|
|
133
|
+
row={row}
|
|
134
|
+
saving={saving}
|
|
135
|
+
showLabel={showLabel}
|
|
136
|
+
storeName={storeName}
|
|
137
|
+
value={value}
|
|
138
|
+
variant={variant}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (isIconColumn(column)) {
|
|
144
|
+
const fieldNameIcon = getColumnKey(column);
|
|
145
|
+
const rawIconValue = value ?? row?.[fieldNameIcon];
|
|
146
|
+
const selectedIcon = normalizeFeatherIconName(rawIconValue);
|
|
147
|
+
const isFormIcon = variant === 'form';
|
|
148
|
+
const canEditIcon = isEditableColumn(column) && typeof onStartEditing === 'function';
|
|
149
|
+
|
|
150
|
+
const commitIcon = nextIcon => {
|
|
151
|
+
const normalized = normalizeFeatherIconName(nextIcon);
|
|
152
|
+
if (autoSave) {
|
|
153
|
+
onSave?.(normalized);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
onChangeValue?.(normalized);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
if (!editing && !isFormIcon) {
|
|
160
|
+
return (
|
|
161
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
162
|
+
{showLabel ? (
|
|
163
|
+
<Text style={styles.fieldLabel}>{label || column?.label || fieldNameIcon}</Text>
|
|
164
|
+
) : null}
|
|
165
|
+
<TouchableOpacity
|
|
166
|
+
style={styles.readButton}
|
|
167
|
+
activeOpacity={canEditIcon ? 0.78 : 1}
|
|
168
|
+
disabled={!canEditIcon}
|
|
169
|
+
onPress={() => onStartEditing?.()}
|
|
170
|
+
>
|
|
171
|
+
<View style={styles.readValueWrap}>
|
|
172
|
+
<Icon
|
|
173
|
+
name={selectedIcon || 'search'}
|
|
174
|
+
size={14}
|
|
175
|
+
color={selectedIcon ? '#0F172A' : '#94A3B8'}
|
|
176
|
+
/>
|
|
177
|
+
<Text
|
|
178
|
+
style={[
|
|
179
|
+
styles.readText,
|
|
180
|
+
!selectedIcon ? styles.mutedText : null,
|
|
181
|
+
readTextStyle,
|
|
182
|
+
]}
|
|
183
|
+
numberOfLines={numberOfLines}
|
|
184
|
+
>
|
|
185
|
+
{selectedIcon || '-'}
|
|
186
|
+
</Text>
|
|
187
|
+
</View>
|
|
188
|
+
{saving ? (
|
|
189
|
+
<Text style={[styles.savingText, { color: accentColor }]}>Salvando</Text>
|
|
190
|
+
) : canEditIcon ? (
|
|
191
|
+
<Icon style={styles.editIcon} name="edit-2" size={13} color="#64748B" />
|
|
192
|
+
) : null}
|
|
193
|
+
</TouchableOpacity>
|
|
194
|
+
</View>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
200
|
+
{showLabel ? (
|
|
201
|
+
<Text style={styles.fieldLabel}>{label || column?.label || fieldNameIcon}</Text>
|
|
202
|
+
) : null}
|
|
203
|
+
<View style={styles.editingWrap}>
|
|
204
|
+
<View style={styles.editingRow}>
|
|
205
|
+
<DefaultFeatherIconPicker
|
|
206
|
+
value={selectedIcon}
|
|
207
|
+
onChange={commitIcon}
|
|
208
|
+
placeholder={
|
|
209
|
+
global.t?.t(storeName, 'input', column?.label || fieldNameIcon) ||
|
|
210
|
+
'Buscar icone'
|
|
211
|
+
}
|
|
212
|
+
style={[isFormIcon ? styles.formInput : null, inputStyle, { flex: 1 }]}
|
|
213
|
+
/>
|
|
214
|
+
{!isFormIcon ? (
|
|
215
|
+
<TouchableOpacity
|
|
216
|
+
style={styles.cancelButton}
|
|
217
|
+
activeOpacity={0.8}
|
|
218
|
+
onPress={onCancelEditing}
|
|
219
|
+
>
|
|
220
|
+
<Icon name="x" size={14} color="#64748B" />
|
|
221
|
+
</TouchableOpacity>
|
|
222
|
+
) : null}
|
|
223
|
+
</View>
|
|
224
|
+
{saving ? <Text style={styles.savingText}>Salvando</Text> : null}
|
|
225
|
+
</View>
|
|
226
|
+
</View>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (isDateLikeColumn(column)) {
|
|
231
|
+
return (
|
|
232
|
+
<DefaultDateInput
|
|
233
|
+
accentColor={accentColor}
|
|
234
|
+
autoFocus={autoFocus}
|
|
235
|
+
autoSave={autoSave}
|
|
236
|
+
column={column}
|
|
237
|
+
columns={columns}
|
|
238
|
+
containerStyle={containerStyle}
|
|
239
|
+
displayValue={displayValue}
|
|
240
|
+
editing={editing}
|
|
241
|
+
inputStyle={inputStyle}
|
|
242
|
+
label={label}
|
|
243
|
+
numberOfLines={numberOfLines}
|
|
244
|
+
onCancelEditing={onCancelEditing}
|
|
245
|
+
onChangeValue={onChangeValue}
|
|
246
|
+
onSave={onSave}
|
|
247
|
+
onSearchChange={onSearchChange}
|
|
248
|
+
onStartEditing={onStartEditing}
|
|
249
|
+
readTextStyle={readTextStyle}
|
|
250
|
+
row={row}
|
|
251
|
+
saving={saving}
|
|
252
|
+
showLabel={showLabel}
|
|
253
|
+
storeName={storeName}
|
|
254
|
+
value={value}
|
|
255
|
+
variant={variant}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const saveDraft = () => {
|
|
261
|
+
if (autoSave) {
|
|
262
|
+
onSave?.(draftValue);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
onChangeValue?.(draftValue);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const updateDraft = nextValue => {
|
|
270
|
+
setDraftValue(nextValue);
|
|
271
|
+
if (!autoSave) onChangeValue?.(nextValue);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (!editing && !isForm) {
|
|
275
|
+
if (isExtraDataField) {
|
|
276
|
+
return (
|
|
277
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
278
|
+
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
279
|
+
<DefaultExtraData
|
|
280
|
+
column={column}
|
|
281
|
+
row={row}
|
|
282
|
+
value={value ?? row?.[fieldName]}
|
|
283
|
+
variant={variant}
|
|
284
|
+
/>
|
|
285
|
+
</View>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (isFileColumn(column)) {
|
|
290
|
+
return (
|
|
291
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
292
|
+
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
293
|
+
<DefaultFileColumn
|
|
294
|
+
column={column}
|
|
295
|
+
row={row}
|
|
296
|
+
value={value}
|
|
297
|
+
variant={variant}
|
|
298
|
+
/>
|
|
299
|
+
</View>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const readIconName = isValidFeatherIcon(readPresentation.icon)
|
|
304
|
+
? readPresentation.icon
|
|
305
|
+
: '';
|
|
306
|
+
const shouldRenderIconFallbackText = Boolean(
|
|
307
|
+
readPresentationStyles.hasDecoration &&
|
|
308
|
+
!readIconName &&
|
|
309
|
+
readPresentationStyles.color &&
|
|
310
|
+
normalizeText(resolvedLabel) &&
|
|
311
|
+
resolvedLabel !== '-',
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
return (
|
|
315
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
316
|
+
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
317
|
+
<TouchableOpacity
|
|
318
|
+
style={styles.readButton}
|
|
319
|
+
activeOpacity={canEdit ? 0.78 : 1}
|
|
320
|
+
disabled={!canEdit}
|
|
321
|
+
onPress={() => onStartEditing?.()}
|
|
322
|
+
>
|
|
323
|
+
{shouldRenderIconFallbackText ? (
|
|
324
|
+
<Text
|
|
325
|
+
style={[
|
|
326
|
+
styles.readText,
|
|
327
|
+
styles.readTextBadge,
|
|
328
|
+
readPresentationStyles.color ? { color: readPresentationStyles.color } : null,
|
|
329
|
+
readTextStyle,
|
|
330
|
+
]}
|
|
331
|
+
numberOfLines={numberOfLines}
|
|
332
|
+
>
|
|
333
|
+
{resolvedLabel}
|
|
334
|
+
</Text>
|
|
335
|
+
) : (
|
|
336
|
+
<View
|
|
337
|
+
style={[
|
|
338
|
+
styles.readValueWrap,
|
|
339
|
+
readPresentationStyles.hasDecoration ? styles.readBadge : null,
|
|
340
|
+
readPresentationStyles.badgeStyle,
|
|
341
|
+
]}
|
|
342
|
+
>
|
|
343
|
+
{readPresentation.image ? (
|
|
344
|
+
<Image
|
|
345
|
+
source={readPresentation.image}
|
|
346
|
+
style={styles.readImage}
|
|
347
|
+
resizeMode="contain"
|
|
348
|
+
/>
|
|
349
|
+
) : null}
|
|
350
|
+
{readPresentationStyles.hasDecoration && readIconName && readPresentationStyles.color ? (
|
|
351
|
+
<Icon
|
|
352
|
+
style={styles.readBadgeIcon}
|
|
353
|
+
name={readIconName}
|
|
354
|
+
size={12}
|
|
355
|
+
color={readPresentationStyles.color}
|
|
356
|
+
/>
|
|
357
|
+
) : null}
|
|
358
|
+
<Text
|
|
359
|
+
style={[
|
|
360
|
+
styles.readText,
|
|
361
|
+
readPresentationStyles.hasDecoration ? styles.readBadgeText : null,
|
|
362
|
+
resolvedLabel === '-' ? styles.mutedText : null,
|
|
363
|
+
readPresentationStyles.color ? { color: readPresentationStyles.color } : null,
|
|
364
|
+
readTextStyle,
|
|
365
|
+
]}
|
|
366
|
+
numberOfLines={numberOfLines}
|
|
367
|
+
>
|
|
368
|
+
{column?.prefix || ''}
|
|
369
|
+
{resolvedLabel || '-'}
|
|
370
|
+
{column?.sufix || column?.suffix || ''}
|
|
371
|
+
</Text>
|
|
372
|
+
</View>
|
|
373
|
+
)}
|
|
374
|
+
{saving ? (
|
|
375
|
+
<Text style={[styles.savingText, { color: accentColor }]}>Salvando</Text>
|
|
376
|
+
) : canEdit ? (
|
|
377
|
+
<Icon style={styles.editIcon} name="edit-2" size={13} color="#64748B" />
|
|
378
|
+
) : null}
|
|
379
|
+
</TouchableOpacity>
|
|
380
|
+
</View>
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
386
|
+
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
387
|
+
<View style={styles.editingWrap}>
|
|
388
|
+
<View style={styles.editingRow}>
|
|
389
|
+
<TextInput
|
|
390
|
+
style={[
|
|
391
|
+
styles.input,
|
|
392
|
+
isForm ? styles.formInput : null,
|
|
393
|
+
inputStyle,
|
|
394
|
+
]}
|
|
395
|
+
value={draftValue}
|
|
396
|
+
keyboardType={column?.inputType === 'number' || column?.inputType === 'float' ? 'numeric' : 'default'}
|
|
397
|
+
placeholder={global.t?.t(storeName, 'input', column?.label || fieldName)}
|
|
398
|
+
onBlur={autoSave ? saveDraft : undefined}
|
|
399
|
+
onChangeText={updateDraft}
|
|
400
|
+
maxLength={maxLength}
|
|
401
|
+
onSubmitEditing={() => { saveDraft(); onSubmitEditing?.(draftValue); }}
|
|
402
|
+
autoFocus={autoFocus && !isForm}
|
|
403
|
+
selectTextOnFocus
|
|
404
|
+
/>
|
|
405
|
+
{!isForm ? (
|
|
406
|
+
<TouchableOpacity style={styles.cancelButton} activeOpacity={0.8} onPress={onCancelEditing}>
|
|
407
|
+
<Icon name="x" size={14} color="#64748B" />
|
|
408
|
+
</TouchableOpacity>
|
|
409
|
+
) : null}
|
|
410
|
+
</View>
|
|
411
|
+
{saving ? <Text style={styles.savingText}>Salvando</Text> : null}
|
|
412
|
+
</View>
|
|
413
|
+
</View>
|
|
414
|
+
);
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
export default DefaultInput;
|