@controleonline/ui-default 1.0.278 → 1.0.279
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, {useState} from 'react';
|
|
2
|
-
import { FlatList, Text, View } from 'react-native';
|
|
2
|
+
import { FlatList, Text, View, useWindowDimensions } from 'react-native';
|
|
3
3
|
import { useStore } from '@store';
|
|
4
4
|
import { formatStoreColumnLabel } from '@controleonline/ui-common/src/react/utils/storeColumns';
|
|
5
5
|
import { getColumnKey, resolveCellText } from '../inputs/defaultInputUtils';
|
|
@@ -23,6 +23,15 @@ import useDefaultTableTheme from './useDefaultTableTheme';
|
|
|
23
23
|
// Vertical cards must keep their intrinsic height; zero basis is only for grid rows.
|
|
24
24
|
const intrinsicHeight = {flexBasis: 'auto', flexGrow: 0, flexShrink: 0};
|
|
25
25
|
|
|
26
|
+
/** Responsive card grid (OrderHistory / compact lists). Explicit cardListProps.numColumns wins. */
|
|
27
|
+
export const resolveResponsiveCardColumns = width => {
|
|
28
|
+
const w = Number(width) || 0;
|
|
29
|
+
if (w >= 1280) return 3;
|
|
30
|
+
if (w >= 800) return 2;
|
|
31
|
+
return 1;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
26
35
|
const DefaultTableCards = ({ storeName }) => {
|
|
27
36
|
const [listWidth, setListWidth] = useState(0);
|
|
28
37
|
const {canOpenRow, setRowInteraction} = useDefaultTableRowInteraction();
|
|
@@ -43,12 +52,20 @@ const DefaultTableCards = ({ storeName }) => {
|
|
|
43
52
|
? configs.cardListProps
|
|
44
53
|
: {};
|
|
45
54
|
const compact = configs.appearance === 'compact';
|
|
46
|
-
const
|
|
55
|
+
const {width: windowWidth} = useWindowDimensions();
|
|
56
|
+
const explicitNumColumns = Number(cardListProps.numColumns);
|
|
57
|
+
const hasExplicitNumColumns = Number.isFinite(explicitNumColumns) && explicitNumColumns > 0;
|
|
58
|
+
// Default responsive grid for all card tables (same breakpoints as OrderHistory).
|
|
59
|
+
// Callers may still force a fixed column count via cardListProps.numColumns.
|
|
60
|
+
const gridColumns = hasExplicitNumColumns
|
|
61
|
+
? explicitNumColumns
|
|
62
|
+
: resolveResponsiveCardColumns(windowWidth);
|
|
47
63
|
const compactCardWidth = listWidth ? Math.max(0, (listWidth - 24 - 12 * (gridColumns - 1)) / gridColumns) : undefined;
|
|
48
64
|
const {
|
|
49
65
|
contentContainerStyle,
|
|
50
66
|
key: cardListKey,
|
|
51
67
|
listKey,
|
|
68
|
+
numColumns: _ignoredNumColumns,
|
|
52
69
|
...flatListProps
|
|
53
70
|
} = cardListProps;
|
|
54
71
|
const isLoading = Boolean(store?.getters?.isLoadingList || store?.getters?.isLoading);
|
|
@@ -116,7 +133,7 @@ const DefaultTableCards = ({ storeName }) => {
|
|
|
116
133
|
key={row?.['@id'] || row?.id}
|
|
117
134
|
style={[
|
|
118
135
|
styles.cardItem,
|
|
119
|
-
|
|
136
|
+
gridColumns === 1 ? intrinsicHeight : null,
|
|
120
137
|
hasRowActions ? styles.cardItemWithActions : null,
|
|
121
138
|
rowStyleValue,
|
|
122
139
|
compact ? [compactStyles.cardItem, {flex: 0, flexGrow: 0, flexShrink: 0, flexBasis: 'auto', width: compactCardWidth, maxWidth: compactCardWidth, backgroundColor: palette.cardBackground || palette.panelBackground, borderColor: palette.cardBorder || palette.inputBorder}] : null,
|
|
@@ -181,10 +198,16 @@ const DefaultTableCards = ({ storeName }) => {
|
|
|
181
198
|
);
|
|
182
199
|
};
|
|
183
200
|
|
|
201
|
+
// RN FlatList throws if numColumns changes without remount. Always derive key from numColumns
|
|
202
|
+
// and apply it AFTER the spread so callers cannot override it with a stale key.
|
|
203
|
+
const resolvedNumColumns = gridColumns;
|
|
204
|
+
const resolvedListKey = listKey || cardListKey || `cards-${resolvedNumColumns}`;
|
|
205
|
+
|
|
184
206
|
return (
|
|
185
207
|
<FlatList
|
|
186
|
-
key={listKey || cardListKey || `cards-${flatListProps.numColumns || 1}`}
|
|
187
208
|
{...flatListProps}
|
|
209
|
+
key={resolvedListKey}
|
|
210
|
+
numColumns={resolvedNumColumns}
|
|
188
211
|
onLayout={event => {flatListProps.onLayout?.(event); setListWidth(event.nativeEvent.layout.width);}}
|
|
189
212
|
columnWrapperStyle={compact && gridColumns > 1 ? {gap: 12} : flatListProps.columnWrapperStyle}
|
|
190
213
|
data={sortedData}
|