@controleonline/ui-default 1.0.265 → 1.0.266

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.
@@ -123,11 +123,23 @@ const styles = StyleSheet.create({
123
123
  },
124
124
  toolbarButtonActive: {
125
125
  },
126
- toolbarAddButton: {
127
- minWidth: 30,
128
- width: 30,
129
- paddingHorizontal: 0,
130
- },
126
+ toolbarAddButton: {
127
+ minWidth: 30,
128
+ width: 30,
129
+ paddingHorizontal: 0,
130
+ },
131
+ floatingAddButton: {
132
+ position: 'absolute',
133
+ right: 16,
134
+ bottom: 16,
135
+ width: 52,
136
+ height: 52,
137
+ borderRadius: 26,
138
+ alignItems: 'center',
139
+ justifyContent: 'center',
140
+ zIndex: 30,
141
+ ...shadow,
142
+ },
131
143
  toolbarBadgeText: {
132
144
  fontSize: 10,
133
145
  fontWeight: '900',
@@ -1,208 +1,205 @@
1
- import React from 'react';
2
- import { Text, TouchableOpacity } from 'react-native';
3
- import Icon from 'react-native-vector-icons/Feather';
4
- import { useStore } from '@store';
5
- import DefaultColumnMenu from './DefaultColumnMenu';
6
- import DefaultDebug from './DefaultDebug';
7
- import DefaultFiltersModal from './DefaultFiltersModal';
8
- import DefaultModalButton from './DefaultModalButton';
9
- import styles from './DefaultTable.styles';
10
- import { normalizeText } from '../inputs/defaultInputUtils';
11
- import {
12
- persistTableViewModePreference,
13
- resolveDefaultTablePreferenceScope,
14
- } from '../../utils/tableVisibleColumnsPreferences';
15
- import { shouldIncludeColumn } from './DefaultTable.utils';
16
- import useDefaultTableTheme from './useDefaultTableTheme';
17
-
18
- const DefaultTableControls = ({ storeName }) => {
19
- const store = useStore(storeName);
20
- const configs = store?.getters?.configs || {};
21
- const effectiveViewMode =
22
- configs.effectiveViewMode ||
23
- configs.viewMode ||
24
- configs.initialViewMode ||
25
- 'table';
26
- const tablePreferenceScope =
27
- configs.tablePreferenceScope ||
28
- resolveDefaultTablePreferenceScope({ storeName });
29
- const columns = Array.isArray(store?.getters?.columns) ? store.getters.columns : [];
30
- const filters = store?.getters?.filters || {};
31
- const hasFilterableColumns = columns.some(
32
- column =>
33
- configs.showColumnFiltersButton !== false &&
34
- shouldIncludeColumn(column) &&
35
- column?.filter !== false &&
36
- column?.filters !== false,
37
- );
38
- const tableFiltersVisible = Boolean(configs.tableFiltersVisible);
39
- const activeFilterCount = Object.values(filters).filter(value => normalizeText(value) !== '').length;
40
- const addConfig = store?.getters?.add;
41
- const shouldRenderAddButton =
42
- (addConfig === true || configs.add === true) &&
43
- (typeof configs.onAdd === 'function' || typeof store?.actions?.save === 'function');
44
- const { tableButtonColors } = useDefaultTableTheme();
45
- const {
46
- backgroundColor,
47
- borderColor,
48
- iconColor,
49
- pressedBackgroundColor,
50
- pressedBorderColor,
51
- pressedIconColor,
52
- textColor,
53
- } = tableButtonColors;
54
-
55
- const buttonStyle = [
56
- styles.toolbarButton,
57
- { borderColor, backgroundColor },
58
- ];
59
- const pressedStyle = {
60
- backgroundColor: pressedBackgroundColor,
61
- borderColor: pressedBorderColor,
62
- };
63
- const updateConfigs = nextConfigs => {
64
- if (typeof store?.actions?.setConfigs === 'function') {
65
- store.actions.setConfigs(nextConfigs);
66
- return;
67
- }
68
-
69
- if (store?.getters) {
70
- store.getters.configs = nextConfigs;
71
- }
72
- };
73
-
74
- return (
75
- <>
76
- <DefaultDebug storeName={storeName} />
77
- {hasFilterableColumns && effectiveViewMode === 'table' ? (
78
- <TouchableOpacity
79
- style={[
80
- ...buttonStyle,
81
- tableFiltersVisible ? pressedStyle : null,
82
- ]}
83
- activeOpacity={0.82}
84
- onPress={() =>
85
- updateConfigs({
86
- ...configs,
87
- tableFiltersVisible: !tableFiltersVisible,
88
- })
89
- }
90
- >
91
- <Icon
92
- name="filter"
93
- size={14}
94
- color={tableFiltersVisible ? pressedIconColor : iconColor}
95
- />
96
- {activeFilterCount > 0 ? (
97
- <Text
98
- style={[
99
- styles.toolbarBadgeText,
100
- { color: tableFiltersVisible ? pressedIconColor : iconColor },
101
- ]}
102
- >
103
- {activeFilterCount}
104
- </Text>
105
- ) : null}
106
- </TouchableOpacity>
107
- ) : null}
108
- {hasFilterableColumns && effectiveViewMode === 'cards' ? (
109
- <DefaultModalButton
110
- renderButton={({ isOpen, open }) => (
111
- <TouchableOpacity
112
- style={[
113
- ...buttonStyle,
114
- isOpen ? pressedStyle : null,
115
- ]}
116
- activeOpacity={0.82}
117
- onPress={open}
118
- >
119
- <Icon
120
- name="filter"
121
- size={14}
122
- color={isOpen ? pressedIconColor : iconColor}
123
- />
124
- {activeFilterCount > 0 ? (
125
- <Text
126
- style={[
127
- styles.toolbarBadgeText,
128
- { color: isOpen ? pressedIconColor : iconColor },
129
- ]}>
130
- {activeFilterCount}
131
- </Text>
132
- ) : null}
133
- </TouchableOpacity>
134
- )}
135
- >
136
- {({ close, isOpen }) => (
137
- <DefaultFiltersModal
138
- storeName={storeName}
139
- visible={isOpen}
140
- onClose={close}
141
- />
142
- )}
143
- </DefaultModalButton>
144
- ) : null}
145
- <TouchableOpacity
146
- style={[
147
- ...buttonStyle,
148
- effectiveViewMode !== 'table' ? pressedStyle : null,
149
- ]}
150
- activeOpacity={0.82}
151
- onPress={() => {
152
- const nextViewMode = effectiveViewMode === 'table' ? 'cards' : 'table';
153
- const nextConfigs = {
154
- ...configs,
155
- effectiveViewMode: nextViewMode,
156
- viewMode: nextViewMode,
157
- };
158
-
159
- persistTableViewModePreference(tablePreferenceScope, nextConfigs.viewMode);
160
- updateConfigs(nextConfigs);
161
- }}
162
- >
163
- <Icon
164
- name={effectiveViewMode === 'table' ? 'list' : 'grid'}
165
- size={14}
166
- color={effectiveViewMode !== 'table' ? pressedIconColor : iconColor}
167
- />
168
- </TouchableOpacity>
169
- <DefaultModalButton
170
- renderButton={({ isOpen, toggle }) => (
171
- <TouchableOpacity
172
- style={[
173
- ...buttonStyle,
174
- isOpen ? pressedStyle : null,
175
- ]}
176
- activeOpacity={0.82}
177
- onPress={toggle}
178
- >
179
- <Icon name="columns" size={14} color={isOpen ? pressedIconColor : textColor} />
180
- </TouchableOpacity>
181
- )}
182
- >
183
- {({ close, isOpen }) => (
184
- <DefaultColumnMenu
185
- storeName={storeName}
186
- visible={isOpen}
187
- onClose={close}
188
- />
189
- )}
190
- </DefaultModalButton>
191
- {shouldRenderAddButton ? (
192
- <TouchableOpacity
193
- style={[
194
- styles.toolbarButton,
195
- styles.toolbarAddButton,
196
- { backgroundColor: backgroundColor, borderColor: backgroundColor },
197
- ]}
198
- activeOpacity={0.85}
199
- onPress={() => configs.onAdd?.()}
200
- >
201
- <Icon name="plus" size={16} color={textColor} />
202
- </TouchableOpacity>
203
- ) : null}
204
- </>
205
- );
206
- };
207
-
208
- export default DefaultTableControls;
1
+ import React from 'react';
2
+ import { Text, TouchableOpacity } from 'react-native';
3
+ import Icon from 'react-native-vector-icons/Feather';
4
+ import { useStore } from '@store';
5
+ import DefaultColumnMenu from './DefaultColumnMenu';
6
+ import DefaultDebug from './DefaultDebug';
7
+ import DefaultFiltersModal from './DefaultFiltersModal';
8
+ import DefaultModalButton from './DefaultModalButton';
9
+ import styles from './DefaultTable.styles';
10
+ import { normalizeText } from '../inputs/defaultInputUtils';
11
+ import {
12
+ persistTableViewModePreference,
13
+ resolveDefaultTablePreferenceScope,
14
+ } from '../../utils/tableVisibleColumnsPreferences';
15
+ import { shouldIncludeColumn } from './DefaultTable.utils';
16
+ import useDefaultTableTheme from './useDefaultTableTheme';
17
+
18
+ const DefaultTableControls = ({ storeName }) => {
19
+ const store = useStore(storeName);
20
+ const configs = store?.getters?.configs || {};
21
+ const effectiveViewMode =
22
+ configs.effectiveViewMode ||
23
+ configs.viewMode ||
24
+ configs.initialViewMode ||
25
+ 'table';
26
+ const tablePreferenceScope =
27
+ configs.tablePreferenceScope ||
28
+ resolveDefaultTablePreferenceScope({ storeName });
29
+ const columns = Array.isArray(store?.getters?.columns) ? store.getters.columns : [];
30
+ const filters = store?.getters?.filters || {};
31
+ const hasFilterableColumns = columns.some(
32
+ column =>
33
+ configs.showColumnFiltersButton !== false &&
34
+ shouldIncludeColumn(column) &&
35
+ column?.filter !== false &&
36
+ column?.filters !== false,
37
+ );
38
+ const tableFiltersVisible = Boolean(configs.tableFiltersVisible);
39
+ const activeFilterCount = Object.values(filters).filter(value => normalizeText(value) !== '').length;
40
+ const addConfig = store?.getters?.add;
41
+ const shouldRenderAddButton =
42
+ (addConfig === true || configs.add === true) &&
43
+ (typeof configs.onAdd === 'function' || typeof store?.actions?.save === 'function');
44
+ const { tableButtonColors } = useDefaultTableTheme();
45
+ const {
46
+ backgroundColor,
47
+ borderColor,
48
+ iconColor,
49
+ pressedBackgroundColor,
50
+ pressedBorderColor,
51
+ pressedIconColor,
52
+ textColor,
53
+ } = tableButtonColors;
54
+
55
+ const buttonStyle = [
56
+ styles.toolbarButton,
57
+ { borderColor, backgroundColor },
58
+ ];
59
+ const pressedStyle = {
60
+ backgroundColor: pressedBackgroundColor,
61
+ borderColor: pressedBorderColor,
62
+ };
63
+ const updateConfigs = nextConfigs => {
64
+ if (typeof store?.actions?.setConfigs === 'function') {
65
+ store.actions.setConfigs(nextConfigs);
66
+ return;
67
+ }
68
+
69
+ if (store?.getters) {
70
+ store.getters.configs = nextConfigs;
71
+ }
72
+ };
73
+ const nextViewMode = effectiveViewMode === 'table' ? 'cards' : 'table';
74
+
75
+ return (
76
+ <>
77
+ <DefaultDebug storeName={storeName} />
78
+ {hasFilterableColumns && effectiveViewMode === 'table' ? (
79
+ <TouchableOpacity
80
+ style={[
81
+ ...buttonStyle,
82
+ tableFiltersVisible ? pressedStyle : null,
83
+ ]}
84
+ activeOpacity={0.82}
85
+ onPress={() =>
86
+ updateConfigs({
87
+ ...configs,
88
+ tableFiltersVisible: !tableFiltersVisible,
89
+ })
90
+ }
91
+ >
92
+ <Icon
93
+ name="filter"
94
+ size={14}
95
+ color={tableFiltersVisible ? pressedIconColor : textColor}
96
+ />
97
+ {activeFilterCount > 0 ? (
98
+ <Text
99
+ style={[
100
+ styles.toolbarBadgeText,
101
+ { color: tableFiltersVisible ? pressedIconColor : textColor },
102
+ ]}
103
+ >
104
+ {activeFilterCount}
105
+ </Text>
106
+ ) : null}
107
+ </TouchableOpacity>
108
+ ) : null}
109
+ {hasFilterableColumns && effectiveViewMode === 'cards' ? (
110
+ <DefaultModalButton
111
+ renderButton={({ isOpen, open }) => (
112
+ <TouchableOpacity
113
+ style={[
114
+ ...buttonStyle,
115
+ isOpen ? pressedStyle : null,
116
+ ]}
117
+ activeOpacity={0.82}
118
+ onPress={open}
119
+ >
120
+ <Icon
121
+ name="filter"
122
+ size={14}
123
+ color={isOpen ? pressedIconColor : textColor}
124
+ />
125
+ {activeFilterCount > 0 ? (
126
+ <Text
127
+ style={[
128
+ styles.toolbarBadgeText,
129
+ { color: isOpen ? pressedIconColor : textColor },
130
+ ]}>
131
+ {activeFilterCount}
132
+ </Text>
133
+ ) : null}
134
+ </TouchableOpacity>
135
+ )}
136
+ >
137
+ {({ close, isOpen }) => (
138
+ <DefaultFiltersModal
139
+ storeName={storeName}
140
+ visible={isOpen}
141
+ onClose={close}
142
+ />
143
+ )}
144
+ </DefaultModalButton>
145
+ ) : null}
146
+ <TouchableOpacity
147
+ style={buttonStyle}
148
+ activeOpacity={0.82}
149
+ onPress={() => {
150
+ const nextConfigs = {
151
+ ...configs,
152
+ effectiveViewMode: nextViewMode,
153
+ viewMode: nextViewMode,
154
+ };
155
+
156
+ persistTableViewModePreference(tablePreferenceScope, nextConfigs.viewMode);
157
+ updateConfigs(nextConfigs);
158
+ }}
159
+ >
160
+ <Icon
161
+ name={nextViewMode === 'cards' ? 'grid' : 'list'}
162
+ size={14}
163
+ color={textColor}
164
+ />
165
+ </TouchableOpacity>
166
+ <DefaultModalButton
167
+ renderButton={({ isOpen, toggle }) => (
168
+ <TouchableOpacity
169
+ style={[
170
+ ...buttonStyle,
171
+ isOpen ? pressedStyle : null,
172
+ ]}
173
+ activeOpacity={0.82}
174
+ onPress={toggle}
175
+ >
176
+ <Icon name="columns" size={14} color={isOpen ? pressedIconColor : textColor} />
177
+ </TouchableOpacity>
178
+ )}
179
+ >
180
+ {({ close, isOpen }) => (
181
+ <DefaultColumnMenu
182
+ storeName={storeName}
183
+ visible={isOpen}
184
+ onClose={close}
185
+ />
186
+ )}
187
+ </DefaultModalButton>
188
+ {shouldRenderAddButton ? (
189
+ <TouchableOpacity
190
+ style={[
191
+ styles.toolbarButton,
192
+ styles.toolbarAddButton,
193
+ { backgroundColor: backgroundColor, borderColor: backgroundColor },
194
+ ]}
195
+ activeOpacity={0.85}
196
+ onPress={() => configs.onAdd?.()}
197
+ >
198
+ <Icon name="plus" size={16} color={textColor} />
199
+ </TouchableOpacity>
200
+ ) : null}
201
+ </>
202
+ );
203
+ };
204
+
205
+ export default DefaultTableControls;