@controleonline/ui-default 1.0.263 → 1.0.265
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/AGENTS.md +47 -45
- package/package.json +20 -20
- package/src/react/components/errors/DefaultErrors.js +307 -325
- package/src/react/components/files/DefaultFile.js +46 -46
- package/src/react/components/filters/CompactFilterSelector.js +78 -24
- package/src/react/components/filters/CompactFilterSelector.styles.js +17 -5
- package/src/react/components/filters/DefaultColumnFilter.js +191 -57
- package/src/react/components/filters/DefaultExternalFilters.js +245 -182
- package/src/react/components/filters/DefaultSearch.js +131 -92
- package/src/react/components/filters/DefaultSearch.styles.js +65 -70
- package/src/react/components/form/DefaultForm.js +172 -151
- package/src/react/components/form/DefaultForm.styles.js +71 -66
- package/src/react/components/help/DefaultTooltip.js +87 -87
- package/src/react/components/help/DefaultTooltip.styles.js +61 -61
- package/src/react/components/inputs/DefaultDateInput.js +150 -0
- package/src/react/components/inputs/DefaultInput.js +162 -127
- package/src/react/components/inputs/DefaultInput.styles.js +6 -0
- package/src/react/components/inputs/DefaultSelect.js +320 -152
- package/src/react/components/inputs/defaultInputUtils.js +40 -19
- package/src/react/components/map/DefaultGoogleMap.styles.js +115 -9
- package/src/react/components/map/DefaultGoogleMap.web.js +560 -446
- package/src/react/components/map/DefaultMap.native.js +73 -71
- package/src/react/components/map/DefaultMap.styles.js +16 -16
- package/src/react/components/map/DefaultMap.web.js +68 -66
- package/src/react/components/map/DefaultNativeMap.native.js +307 -183
- package/src/react/components/map/DefaultNativeMap.shared.js +439 -340
- package/src/react/components/map/DefaultNativeMap.styles.js +156 -122
- package/src/react/components/table/DefaultColumnMenu.js +108 -0
- package/src/react/components/table/DefaultDebug.js +233 -0
- package/src/react/components/table/DefaultFiltersModal.js +142 -0
- package/src/react/components/table/DefaultModalButton.js +18 -0
- package/src/react/components/table/DefaultSearchModal.js +49 -0
- package/src/react/components/table/DefaultTable.js +345 -1846
- package/src/react/components/table/DefaultTable.styles.js +247 -136
- package/src/react/components/table/DefaultTable.utils.js +502 -0
- package/src/react/components/table/DefaultTableBody.js +26 -0
- package/src/react/components/table/DefaultTableCards.js +171 -0
- package/src/react/components/table/DefaultTableControls.js +208 -0
- package/src/react/components/table/DefaultTableEmptyState.js +22 -0
- package/src/react/components/table/DefaultTableFooter.js +172 -0
- package/src/react/components/table/DefaultTableInput.js +145 -0
- package/src/react/components/table/DefaultTableRows.js +340 -0
- package/src/react/components/table/DefaultTableSearch.js +100 -0
- package/src/react/components/table/DefaultTableToolbar.js +98 -0
- package/src/react/components/table/DefaultToolbarAction.js +56 -0
- package/src/react/components/table/useDefaultTablePagination.js +370 -0
- package/src/react/components/table/useDefaultTableSorting.js +126 -0
- package/src/react/components/table/useDefaultTableTheme.js +58 -0
- package/src/react/index.js +10 -10
- package/src/react/utils/tableVisibleColumnsPreferences.js +239 -211
- package/src/store/default/actions.js +51 -13
- package/src/store/default/getters.js +10 -8
- package/src/store/default/mutation_types.js +4 -2
- package/src/store/default/mutations.js +10 -1
- package/src/tests/react/components/errors/DefaultErrors.test.js +162 -162
- package/src/tests/react/components/files/DefaultFile.test.js +80 -80
- package/src/tests/react/components/form/DefaultForm.test.js +81 -0
- package/src/tests/react/components/inputs/DefaultSelect.test.js +185 -0
- package/src/tests/react/components/table/DefaultTable.test.js +1183 -0
- package/src/tests/react/store/defaultActions.test.js +59 -0
- package/src/tests/react/utils/tableVisibleColumnsPreferences.test.js +247 -168
|
@@ -1,72 +1,107 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
3
|
-
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
-
import {
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Text, TextInput, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
+
import {
|
|
5
5
|
getColumnKey,
|
|
6
|
+
isDateLikeColumn,
|
|
6
7
|
isEditableColumn,
|
|
7
|
-
normalizeText,
|
|
8
|
-
resolveCellText,
|
|
9
|
-
resolveEditValue,
|
|
8
|
+
normalizeText,
|
|
9
|
+
resolveCellText,
|
|
10
|
+
resolveEditValue,
|
|
10
11
|
} from './defaultInputUtils';
|
|
12
|
+
import DefaultDateInput from './DefaultDateInput';
|
|
11
13
|
import DefaultSelect from './DefaultSelect';
|
|
12
|
-
import styles from './DefaultInput.styles';
|
|
13
|
-
|
|
14
|
-
const DefaultInput = ({
|
|
15
|
-
accentColor = '#2563EB',
|
|
16
|
-
autoFocus = true,
|
|
17
|
-
autoSave = true,
|
|
18
|
-
column,
|
|
19
|
-
columns = [],
|
|
20
|
-
containerStyle = null,
|
|
21
|
-
displayValue,
|
|
22
|
-
editing = false,
|
|
23
|
-
getOptionsForColumn = null,
|
|
24
|
-
inputStyle = null,
|
|
25
|
-
label = '',
|
|
26
|
-
numberOfLines = 1,
|
|
14
|
+
import styles from './DefaultInput.styles';
|
|
15
|
+
|
|
16
|
+
const DefaultInput = ({
|
|
17
|
+
accentColor = '#2563EB',
|
|
18
|
+
autoFocus = true,
|
|
19
|
+
autoSave = true,
|
|
20
|
+
column,
|
|
21
|
+
columns = [],
|
|
22
|
+
containerStyle = null,
|
|
23
|
+
displayValue,
|
|
24
|
+
editing = false,
|
|
25
|
+
getOptionsForColumn = null,
|
|
26
|
+
inputStyle = null,
|
|
27
|
+
label = '',
|
|
28
|
+
numberOfLines = 1,
|
|
29
|
+
onBeforeOpen = null,
|
|
27
30
|
onCancelEditing = null,
|
|
28
31
|
onChangeValue = null,
|
|
29
32
|
onSave = null,
|
|
33
|
+
onSearchChange = null,
|
|
30
34
|
onStartEditing = null,
|
|
31
|
-
readTextStyle = null,
|
|
32
|
-
row = {},
|
|
33
|
-
saving = false,
|
|
34
|
-
showLabel = false,
|
|
35
|
-
storeName = '',
|
|
36
|
-
value,
|
|
37
|
-
variant = 'cell',
|
|
38
|
-
}) => {
|
|
39
|
-
const fieldName = getColumnKey(column);
|
|
40
|
-
const isForm = variant === 'form';
|
|
41
|
-
const canEdit = isEditableColumn(column) && typeof onStartEditing === 'function';
|
|
42
|
-
const editValue = useMemo(
|
|
43
|
-
() => normalizeText(value ?? resolveEditValue(column, row)),
|
|
44
|
-
[column, row, value],
|
|
45
|
-
);
|
|
46
|
-
const [draftValue, setDraftValue] = useState(editValue);
|
|
47
|
-
const resolvedLabel =
|
|
48
|
-
displayValue ?? resolveCellText({ column, columns, row, storeName, value });
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
setDraftValue(editValue);
|
|
52
|
-
}, [editValue, editing]);
|
|
53
|
-
|
|
35
|
+
readTextStyle = null,
|
|
36
|
+
row = {},
|
|
37
|
+
saving = false,
|
|
38
|
+
showLabel = false,
|
|
39
|
+
storeName = '',
|
|
40
|
+
value,
|
|
41
|
+
variant = 'cell',
|
|
42
|
+
}) => {
|
|
43
|
+
const fieldName = getColumnKey(column);
|
|
44
|
+
const isForm = variant === 'form';
|
|
45
|
+
const canEdit = isEditableColumn(column) && typeof onStartEditing === 'function';
|
|
46
|
+
const editValue = useMemo(
|
|
47
|
+
() => normalizeText(value ?? resolveEditValue(column, row)),
|
|
48
|
+
[column, row, value],
|
|
49
|
+
);
|
|
50
|
+
const [draftValue, setDraftValue] = useState(editValue);
|
|
51
|
+
const resolvedLabel =
|
|
52
|
+
displayValue ?? resolveCellText({ column, columns, row, storeName, value });
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
setDraftValue(editValue);
|
|
56
|
+
}, [editValue, editing]);
|
|
57
|
+
|
|
54
58
|
if (column?.list) {
|
|
59
|
+
return (
|
|
60
|
+
<DefaultSelect
|
|
61
|
+
accentColor={accentColor}
|
|
62
|
+
autoSave={autoSave}
|
|
63
|
+
column={column}
|
|
64
|
+
columns={columns}
|
|
65
|
+
containerStyle={containerStyle}
|
|
66
|
+
displayValue={displayValue}
|
|
67
|
+
editing={editing}
|
|
68
|
+
getOptionsForColumn={getOptionsForColumn}
|
|
69
|
+
label={label}
|
|
70
|
+
numberOfLines={numberOfLines}
|
|
71
|
+
onBeforeOpen={onBeforeOpen}
|
|
72
|
+
onCancelEditing={onCancelEditing}
|
|
73
|
+
onChangeValue={onChangeValue}
|
|
74
|
+
onSave={onSave}
|
|
75
|
+
onStartEditing={onStartEditing}
|
|
76
|
+
readTextStyle={readTextStyle}
|
|
77
|
+
row={row}
|
|
78
|
+
saving={saving}
|
|
79
|
+
showLabel={showLabel}
|
|
80
|
+
storeName={storeName}
|
|
81
|
+
value={value}
|
|
82
|
+
variant={variant}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isDateLikeColumn(column)) {
|
|
55
88
|
return (
|
|
56
|
-
<
|
|
89
|
+
<DefaultDateInput
|
|
57
90
|
accentColor={accentColor}
|
|
91
|
+
autoFocus={autoFocus}
|
|
58
92
|
autoSave={autoSave}
|
|
59
93
|
column={column}
|
|
60
94
|
columns={columns}
|
|
61
95
|
containerStyle={containerStyle}
|
|
62
96
|
displayValue={displayValue}
|
|
63
97
|
editing={editing}
|
|
64
|
-
|
|
98
|
+
inputStyle={inputStyle}
|
|
65
99
|
label={label}
|
|
66
100
|
numberOfLines={numberOfLines}
|
|
67
101
|
onCancelEditing={onCancelEditing}
|
|
68
102
|
onChangeValue={onChangeValue}
|
|
69
103
|
onSave={onSave}
|
|
104
|
+
onSearchChange={onSearchChange}
|
|
70
105
|
onStartEditing={onStartEditing}
|
|
71
106
|
readTextStyle={readTextStyle}
|
|
72
107
|
row={row}
|
|
@@ -78,83 +113,83 @@ const DefaultInput = ({
|
|
|
78
113
|
/>
|
|
79
114
|
);
|
|
80
115
|
}
|
|
81
|
-
|
|
82
|
-
const saveDraft = () => {
|
|
83
|
-
if (autoSave) {
|
|
84
|
-
onSave?.(draftValue);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
onChangeValue?.(draftValue);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const updateDraft = nextValue => {
|
|
92
|
-
setDraftValue(nextValue);
|
|
93
|
-
if (!autoSave) onChangeValue?.(nextValue);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (!editing && !isForm) {
|
|
97
|
-
return (
|
|
98
|
-
<View style={[styles.wrap, containerStyle]}>
|
|
99
|
-
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
100
|
-
<TouchableOpacity
|
|
101
|
-
style={styles.readButton}
|
|
102
|
-
activeOpacity={canEdit ? 0.78 : 1}
|
|
103
|
-
disabled={!canEdit}
|
|
104
|
-
onPress={() => onStartEditing?.()}
|
|
105
|
-
>
|
|
106
|
-
<Text
|
|
107
|
-
style={[
|
|
108
|
-
styles.readText,
|
|
109
|
-
resolvedLabel === '-' ? styles.mutedText : null,
|
|
110
|
-
readTextStyle,
|
|
111
|
-
]}
|
|
112
|
-
numberOfLines={numberOfLines}
|
|
113
|
-
>
|
|
114
|
-
{column?.prefix || ''}
|
|
115
|
-
{resolvedLabel || '-'}
|
|
116
|
-
{column?.sufix || column?.suffix || ''}
|
|
117
|
-
</Text>
|
|
118
|
-
{saving ? (
|
|
119
|
-
<Text style={[styles.savingText, { color: accentColor }]}>Salvando</Text>
|
|
120
|
-
) : canEdit ? (
|
|
121
|
-
<Icon style={styles.editIcon} name="edit-2" size={13} color="#64748B" />
|
|
122
|
-
) : null}
|
|
123
|
-
</TouchableOpacity>
|
|
124
|
-
</View>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return (
|
|
129
|
-
<View style={[styles.wrap, containerStyle]}>
|
|
130
|
-
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
131
|
-
<View style={styles.editingWrap}>
|
|
132
|
-
<View style={styles.editingRow}>
|
|
133
|
-
<TextInput
|
|
134
|
-
style={[
|
|
135
|
-
styles.input,
|
|
136
|
-
isForm ? styles.formInput : null,
|
|
137
|
-
inputStyle,
|
|
138
|
-
]}
|
|
139
|
-
value={draftValue}
|
|
140
|
-
keyboardType={column?.inputType === 'number' || column?.inputType === 'float' ? 'numeric' : 'default'}
|
|
141
|
-
placeholder={global.t?.t(storeName, 'input', column?.label || fieldName)}
|
|
142
|
-
onBlur={autoSave ? saveDraft : undefined}
|
|
143
|
-
onChangeText={updateDraft}
|
|
144
|
-
onSubmitEditing={saveDraft}
|
|
145
|
-
autoFocus={autoFocus && !isForm}
|
|
146
|
-
selectTextOnFocus
|
|
147
|
-
/>
|
|
148
|
-
{!isForm ? (
|
|
149
|
-
<TouchableOpacity style={styles.cancelButton} activeOpacity={0.8} onPress={onCancelEditing}>
|
|
150
|
-
<Icon name="x" size={14} color="#64748B" />
|
|
151
|
-
</TouchableOpacity>
|
|
152
|
-
) : null}
|
|
153
|
-
</View>
|
|
154
|
-
{saving ? <Text style={styles.savingText}>Salvando</Text> : null}
|
|
155
|
-
</View>
|
|
156
|
-
</View>
|
|
157
|
-
);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
export default DefaultInput;
|
|
116
|
+
|
|
117
|
+
const saveDraft = () => {
|
|
118
|
+
if (autoSave) {
|
|
119
|
+
onSave?.(draftValue);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
onChangeValue?.(draftValue);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const updateDraft = nextValue => {
|
|
127
|
+
setDraftValue(nextValue);
|
|
128
|
+
if (!autoSave) onChangeValue?.(nextValue);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (!editing && !isForm) {
|
|
132
|
+
return (
|
|
133
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
134
|
+
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
135
|
+
<TouchableOpacity
|
|
136
|
+
style={styles.readButton}
|
|
137
|
+
activeOpacity={canEdit ? 0.78 : 1}
|
|
138
|
+
disabled={!canEdit}
|
|
139
|
+
onPress={() => onStartEditing?.()}
|
|
140
|
+
>
|
|
141
|
+
<Text
|
|
142
|
+
style={[
|
|
143
|
+
styles.readText,
|
|
144
|
+
resolvedLabel === '-' ? styles.mutedText : null,
|
|
145
|
+
readTextStyle,
|
|
146
|
+
]}
|
|
147
|
+
numberOfLines={numberOfLines}
|
|
148
|
+
>
|
|
149
|
+
{column?.prefix || ''}
|
|
150
|
+
{resolvedLabel || '-'}
|
|
151
|
+
{column?.sufix || column?.suffix || ''}
|
|
152
|
+
</Text>
|
|
153
|
+
{saving ? (
|
|
154
|
+
<Text style={[styles.savingText, { color: accentColor }]}>Salvando</Text>
|
|
155
|
+
) : canEdit ? (
|
|
156
|
+
<Icon style={styles.editIcon} name="edit-2" size={13} color="#64748B" />
|
|
157
|
+
) : null}
|
|
158
|
+
</TouchableOpacity>
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<View style={[styles.wrap, containerStyle]}>
|
|
165
|
+
{showLabel ? <Text style={styles.fieldLabel}>{label || column?.label || fieldName}</Text> : null}
|
|
166
|
+
<View style={styles.editingWrap}>
|
|
167
|
+
<View style={styles.editingRow}>
|
|
168
|
+
<TextInput
|
|
169
|
+
style={[
|
|
170
|
+
styles.input,
|
|
171
|
+
isForm ? styles.formInput : null,
|
|
172
|
+
inputStyle,
|
|
173
|
+
]}
|
|
174
|
+
value={draftValue}
|
|
175
|
+
keyboardType={column?.inputType === 'number' || column?.inputType === 'float' ? 'numeric' : 'default'}
|
|
176
|
+
placeholder={global.t?.t(storeName, 'input', column?.label || fieldName)}
|
|
177
|
+
onBlur={autoSave ? saveDraft : undefined}
|
|
178
|
+
onChangeText={updateDraft}
|
|
179
|
+
onSubmitEditing={saveDraft}
|
|
180
|
+
autoFocus={autoFocus && !isForm}
|
|
181
|
+
selectTextOnFocus
|
|
182
|
+
/>
|
|
183
|
+
{!isForm ? (
|
|
184
|
+
<TouchableOpacity style={styles.cancelButton} activeOpacity={0.8} onPress={onCancelEditing}>
|
|
185
|
+
<Icon name="x" size={14} color="#64748B" />
|
|
186
|
+
</TouchableOpacity>
|
|
187
|
+
) : null}
|
|
188
|
+
</View>
|
|
189
|
+
{saving ? <Text style={styles.savingText}>Salvando</Text> : null}
|
|
190
|
+
</View>
|
|
191
|
+
</View>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default DefaultInput;
|