fluent-styles 1.61.0 → 1.62.0

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.
@@ -0,0 +1,650 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StyledTable = StyledTable;
7
+ exports.default = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactNative = require("react-native");
10
+ var _index = require("../stack/index.js");
11
+ var _index2 = require("../text/index.js");
12
+ var _index3 = require("../checkBox/index.js");
13
+ var _index4 = require("../pressable/index.js");
14
+ var _theme = require("../utiles/theme.js");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
17
+ // ─── CompatNode ───────────────────────────────────────────────────────────────
18
+
19
+ // ─── Column definition ────────────────────────────────────────────────────────
20
+
21
+ // ─── Row data ─────────────────────────────────────────────────────────────────
22
+
23
+ // ─── Color tokens ─────────────────────────────────────────────────────────────
24
+
25
+ const DEFAULT_COLORS = {
26
+ background: _theme.palettes.white,
27
+ headerBg: _theme.theme.colors.gray[50],
28
+ headerText: _theme.theme.colors.gray[400],
29
+ rowBg: _theme.palettes.white,
30
+ rowAltBg: _theme.palettes.white,
31
+ rowHoverBg: _theme.theme.colors.gray[50],
32
+ selectedBg: _theme.palettes.indigo[50],
33
+ selectedBorder: _theme.palettes.indigo[200],
34
+ border: _theme.theme.colors.gray[100],
35
+ divider: _theme.theme.colors.gray[100],
36
+ text: _theme.theme.colors.gray[900],
37
+ subText: _theme.theme.colors.gray[400],
38
+ sortActive: _theme.theme.colors.gray[900],
39
+ sortInactive: _theme.theme.colors.gray[300],
40
+ checkboxChecked: _theme.theme.colors.gray[900],
41
+ emptyText: _theme.theme.colors.gray[400]
42
+ };
43
+
44
+ // ─── Props ────────────────────────────────────────────────────────────────────
45
+
46
+ // ─── Sort icon ────────────────────────────────────────────────────────────────
47
+
48
+ const SortIcon = ({
49
+ direction,
50
+ active,
51
+ color,
52
+ inactiveColor
53
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
54
+ gap: 1,
55
+ marginLeft: 4,
56
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
57
+ fontSize: 8,
58
+ lineHeight: 9,
59
+ color: active && direction === "asc" ? color : inactiveColor,
60
+ children: "\u25B2"
61
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
62
+ fontSize: 8,
63
+ lineHeight: 9,
64
+ color: active && direction === "desc" ? color : inactiveColor,
65
+ children: "\u25BC"
66
+ })]
67
+ });
68
+
69
+ // ─── Cell wrapper ─────────────────────────────────────────────────────────────
70
+
71
+ const Cell = ({
72
+ width,
73
+ align = "left",
74
+ children,
75
+ isFirst
76
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
77
+ flex: width ? undefined : 1,
78
+ width: width,
79
+ alignItems: align === "center" ? "center" : align === "right" ? "flex-end" : "flex-start",
80
+ paddingHorizontal: isFirst ? 16 : 12,
81
+ paddingVertical: 14,
82
+ justifyContent: "center",
83
+ children: children
84
+ });
85
+
86
+ // ─── StyledTable ──────────────────────────────────────────────────────────────
87
+
88
+ // ─── Card list (phone layout) ─────────────────────────────────────────────────
89
+
90
+ function CardList({
91
+ columns,
92
+ data,
93
+ selectable,
94
+ selectedIds,
95
+ onSelectionChange,
96
+ cardRender,
97
+ emptyText,
98
+ emptyNode,
99
+ pagination,
100
+ pageSize,
101
+ onRowPress,
102
+ colors: colorOverrides,
103
+ borderRadius
104
+ }) {
105
+ const c = {
106
+ ...DEFAULT_COLORS,
107
+ ...colorOverrides
108
+ };
109
+ const br = borderRadius ?? 16;
110
+
111
+ // internal selection
112
+ const [internalSelected, setInternalSelected] = _react.default.useState([]);
113
+ const selectedIds_ = selectedIds ?? internalSelected;
114
+ const toggle = id => {
115
+ const next = selectedIds_.includes(id) ? selectedIds_.filter(s => s !== id) : [...selectedIds_, id];
116
+ setInternalSelected(next);
117
+ onSelectionChange?.(next);
118
+ };
119
+
120
+ // pagination
121
+ const [page, setPage] = _react.default.useState(0);
122
+ const ps = pageSize ?? 10;
123
+ const totalPages = Math.ceil(data.length / ps);
124
+ const visible = pagination ? data.slice(page * ps, (page + 1) * ps) : data;
125
+ if (visible.length === 0) {
126
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
127
+ paddingVertical: 48,
128
+ alignItems: "center",
129
+ justifyContent: "center",
130
+ children: emptyNode ?? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
131
+ fontSize: 14,
132
+ color: c.emptyText,
133
+ children: emptyText ?? "No data"
134
+ })
135
+ });
136
+ }
137
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
138
+ gap: 10,
139
+ children: [visible.map((row, idx) => {
140
+ const isSelected = selectedIds_.includes(row.id);
141
+ if (cardRender) {
142
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.default.Fragment, {
143
+ children: cardRender(row, idx, isSelected, selectable ? () => toggle(row.id) : undefined)
144
+ }, row.id);
145
+ }
146
+
147
+ // ── Default auto-card ─────────────────────────────────────────────
148
+ // Uses column definitions to render label: value pairs.
149
+ const [primary, ...rest] = columns;
150
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index4.StyledPressable, {
151
+ onPress: () => onRowPress?.(row, idx),
152
+ disabled: !onRowPress && !selectable,
153
+ borderRadius: br,
154
+ borderWidth: 1,
155
+ borderColor: isSelected ? c.selectedBorder : c.border,
156
+ backgroundColor: isSelected ? c.selectedBg : c.rowBg,
157
+ borderLeftWidth: isSelected ? 3 : 1,
158
+ borderLeftColor: isSelected ? c.selectedBorder : c.border,
159
+ overflow: "hidden",
160
+ style: {
161
+ shadowColor: "#000",
162
+ shadowOffset: {
163
+ width: 0,
164
+ height: 1
165
+ },
166
+ shadowOpacity: 0.05,
167
+ shadowRadius: 4,
168
+ elevation: 1
169
+ },
170
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
171
+ horizontal: true,
172
+ alignItems: "center",
173
+ justifyContent: "space-between",
174
+ paddingHorizontal: 14,
175
+ paddingVertical: 12,
176
+ borderBottomWidth: 1,
177
+ borderBottomColor: c.divider,
178
+ backgroundColor: c.headerBg,
179
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
180
+ flex: 1,
181
+ children: primary.render ? primary.render(row[primary.key], row, idx) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
182
+ fontSize: 14,
183
+ fontWeight: "700",
184
+ color: c.text,
185
+ numberOfLines: 1,
186
+ children: row[primary.key]
187
+ })
188
+ }), selectable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.StyledCheckBox, {
189
+ checked: isSelected,
190
+ onCheck: () => toggle(row.id),
191
+ size: 18,
192
+ checkedColor: c.checkboxChecked
193
+ })]
194
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
195
+ paddingHorizontal: 14,
196
+ paddingVertical: 10,
197
+ gap: 8,
198
+ children: rest.map(col => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
199
+ horizontal: true,
200
+ alignItems: "center",
201
+ justifyContent: "space-between",
202
+ gap: 8,
203
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
204
+ fontSize: 12,
205
+ color: c.subText,
206
+ fontWeight: "500",
207
+ children: col.title
208
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
209
+ alignItems: "flex-end",
210
+ children: col.render ? col.render(row[col.key], row, idx) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
211
+ fontSize: 13,
212
+ color: c.text,
213
+ children: row[col.key] ?? "—"
214
+ })
215
+ })]
216
+ }, col.key))
217
+ })]
218
+ }, row.id);
219
+ }), pagination && totalPages > 1 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
220
+ horizontal: true,
221
+ alignItems: "center",
222
+ justifyContent: "space-between",
223
+ paddingVertical: 4,
224
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_index2.StyledText, {
225
+ fontSize: 12,
226
+ color: c.subText,
227
+ children: [page * ps + 1, "\u2013", Math.min((page + 1) * ps, data.length), " of ", data.length]
228
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
229
+ horizontal: true,
230
+ gap: 6,
231
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index4.StyledPressable, {
232
+ onPress: () => setPage(p => Math.max(0, p - 1)),
233
+ disabled: page === 0,
234
+ paddingHorizontal: 12,
235
+ paddingVertical: 6,
236
+ borderRadius: 8,
237
+ borderWidth: 1,
238
+ borderColor: page === 0 ? c.border : c.sortActive,
239
+ opacity: page === 0 ? 0.4 : 1,
240
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
241
+ fontSize: 12,
242
+ fontWeight: "600",
243
+ color: c.text,
244
+ children: "\u2190 Prev"
245
+ })
246
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index4.StyledPressable, {
247
+ onPress: () => setPage(p => Math.min(totalPages - 1, p + 1)),
248
+ disabled: page >= totalPages - 1,
249
+ paddingHorizontal: 12,
250
+ paddingVertical: 6,
251
+ borderRadius: 8,
252
+ borderWidth: 1,
253
+ borderColor: page >= totalPages - 1 ? c.border : c.sortActive,
254
+ opacity: page >= totalPages - 1 ? 0.4 : 1,
255
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
256
+ fontSize: 12,
257
+ fontWeight: "600",
258
+ color: c.text,
259
+ children: "Next \u2192"
260
+ })
261
+ })]
262
+ })]
263
+ })]
264
+ });
265
+ }
266
+ function StyledTable({
267
+ columns,
268
+ data,
269
+ selectable = false,
270
+ selectedIds: controlledSelectedIds,
271
+ onSelectionChange,
272
+ sortKey: controlledSortKey,
273
+ sortDirection: controlledSortDir,
274
+ onSort,
275
+ pagination = false,
276
+ pageSize = 10,
277
+ striped = false,
278
+ showDivider = true,
279
+ scrollable = false,
280
+ emptyText = "No data",
281
+ emptyNode,
282
+ colors: colorOverrides,
283
+ borderRadius = 16,
284
+ bordered = true,
285
+ virtualized,
286
+ cardBreakpoint = 768,
287
+ forceTable,
288
+ forceCards,
289
+ cardRender,
290
+ externalPagination = false,
291
+ currentPage = 0,
292
+ totalPages: externalTotalPages,
293
+ totalCount,
294
+ onPageChange,
295
+ loading = false,
296
+ onRowPress
297
+ }) {
298
+ const {
299
+ width
300
+ } = (0, _reactNative.useWindowDimensions)();
301
+ const isCardMode = forceCards ? true : forceTable ? false : cardBreakpoint > 0 && width < cardBreakpoint;
302
+
303
+ // ── Card mode — render rows as stacked cards ─────────────────────────────
304
+ if (isCardMode) {
305
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(CardList, {
306
+ columns: columns,
307
+ data: data,
308
+ selectable: selectable,
309
+ selectedIds: controlledSelectedIds,
310
+ onSelectionChange: onSelectionChange,
311
+ cardRender: cardRender,
312
+ emptyText: emptyText,
313
+ emptyNode: emptyNode,
314
+ pagination: pagination,
315
+ pageSize: pageSize,
316
+ onRowPress: onRowPress,
317
+ colors: colorOverrides,
318
+ borderRadius: borderRadius
319
+ });
320
+ }
321
+ const c = {
322
+ ...DEFAULT_COLORS,
323
+ ...colorOverrides
324
+ };
325
+
326
+ // ── Internal selection state (uncontrolled fallback) ───────────────────
327
+ const [internalSelected, setInternalSelected] = (0, _react.useState)([]);
328
+ const selectedIds = controlledSelectedIds ?? internalSelected;
329
+ const toggleRow = (0, _react.useCallback)(id => {
330
+ const next = selectedIds.includes(id) ? selectedIds.filter(s => s !== id) : [...selectedIds, id];
331
+ setInternalSelected(next);
332
+ onSelectionChange?.(next);
333
+ }, [selectedIds, onSelectionChange]);
334
+ const toggleAll = (0, _react.useCallback)(() => {
335
+ const allIds = data.map(r => r.id);
336
+ const allSelected = allIds.every(id => selectedIds.includes(id));
337
+ const next = allSelected ? [] : allIds;
338
+ setInternalSelected(next);
339
+ onSelectionChange?.(next);
340
+ }, [data, selectedIds, onSelectionChange]);
341
+ const allSelected = data.length > 0 && data.every(r => selectedIds.includes(r.id));
342
+
343
+ // ── Internal sort state (uncontrolled fallback) ────────────────────────
344
+ const [internalSortKey, setInternalSortKey] = (0, _react.useState)(null);
345
+ const [internalSortDir, setInternalSortDir] = (0, _react.useState)(null);
346
+ const activeSortKey = controlledSortKey ?? internalSortKey;
347
+ const activeSortDir = controlledSortDir ?? internalSortDir;
348
+ const handleSort = (0, _react.useCallback)(key => {
349
+ const next = activeSortKey === key ? activeSortDir === "asc" ? "desc" : activeSortDir === "desc" ? null : "asc" : "asc";
350
+ setInternalSortKey(next === null ? null : key);
351
+ setInternalSortDir(next);
352
+ onSort?.(key, next);
353
+ }, [activeSortKey, activeSortDir, onSort]);
354
+
355
+ // ── Client-side sort (used when onSort not provided) ───────────────────
356
+ const sortedData = _react.default.useMemo(() => {
357
+ if (!activeSortKey || !activeSortDir || onSort) return data;
358
+ return [...data].sort((a, b) => {
359
+ const av = a[activeSortKey];
360
+ const bv = b[activeSortKey];
361
+ const cmp = typeof av === "number" && typeof bv === "number" ? av - bv : String(av ?? "").localeCompare(String(bv ?? ""));
362
+ return activeSortDir === "asc" ? cmp : -cmp;
363
+ });
364
+ }, [data, activeSortKey, activeSortDir, onSort]);
365
+
366
+ // ── Pagination ────────────────────────────────────────────────────────
367
+ const [internalPage, setInternalPage] = (0, _react.useState)(0);
368
+
369
+ // External mode: parent controls page + data
370
+ // Internal mode: we slice sortedData ourselves
371
+ const page = externalPagination ? currentPage : internalPage;
372
+ const totalPages = externalPagination ? externalTotalPages ?? 1 : Math.ceil(sortedData.length / pageSize);
373
+ const visibleData = externalPagination ? sortedData // parent already gave us just this page
374
+ : pagination ? sortedData.slice(page * pageSize, (page + 1) * pageSize) : sortedData;
375
+
376
+ // Auto-enable FlatList virtualisation for large unpaginated datasets
377
+ const useVirtualized = virtualized ?? (!pagination && !externalPagination && visibleData.length > 50);
378
+ const handlePageChange = p => {
379
+ if (externalPagination) {
380
+ onPageChange?.(p);
381
+ } else {
382
+ setInternalPage(p);
383
+ }
384
+ };
385
+
386
+ // Row count label
387
+ const rowStart = page * pageSize + 1;
388
+ const rowEnd = externalPagination ? totalCount != null ? Math.min(rowStart + visibleData.length - 1, totalCount) : rowStart + visibleData.length - 1 : Math.min((page + 1) * pageSize, sortedData.length);
389
+ const rowTotal = externalPagination ? totalCount ?? "?" : sortedData.length;
390
+
391
+ // ── Render ────────────────────────────────────────────────────────────
392
+ const tableContent = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
393
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
394
+ horizontal: true,
395
+ backgroundColor: c.headerBg,
396
+ borderTopLeftRadius: borderRadius,
397
+ borderTopRightRadius: borderRadius,
398
+ borderBottomWidth: 1,
399
+ borderBottomColor: c.border,
400
+ children: [selectable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
401
+ width: 52,
402
+ paddingHorizontal: 16,
403
+ paddingVertical: 14,
404
+ alignItems: "center",
405
+ justifyContent: "center",
406
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.StyledCheckBox, {
407
+ checked: allSelected,
408
+ onCheck: toggleAll,
409
+ size: 18,
410
+ checkedColor: c.checkboxChecked
411
+ })
412
+ }), columns.map((col, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Cell, {
413
+ width: col.width,
414
+ align: col.align,
415
+ isFirst: i === 0 && !selectable,
416
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index4.StyledPressable, {
417
+ flexDirection: "row",
418
+ alignItems: "center",
419
+ onPress: col.sortable ? () => handleSort(col.key) : undefined,
420
+ disabled: !col.sortable,
421
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
422
+ fontSize: 12,
423
+ fontWeight: "600",
424
+ color: c.headerText,
425
+ letterSpacing: 0.3,
426
+ children: col.title
427
+ }), col.sortable && /*#__PURE__*/(0, _jsxRuntime.jsx)(SortIcon, {
428
+ direction: activeSortDir,
429
+ active: activeSortKey === col.key,
430
+ color: c.sortActive,
431
+ inactiveColor: c.sortInactive
432
+ })]
433
+ })
434
+ }, col.key))]
435
+ }), visibleData.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
436
+ paddingVertical: 48,
437
+ alignItems: "center",
438
+ justifyContent: "center",
439
+ backgroundColor: c.rowBg,
440
+ borderBottomLeftRadius: borderRadius,
441
+ borderBottomRightRadius: borderRadius,
442
+ children: emptyNode ?? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
443
+ fontSize: 14,
444
+ color: c.emptyText,
445
+ children: emptyText
446
+ })
447
+ }) : useVirtualized ?
448
+ /*#__PURE__*/
449
+ // ── FlatList path — only mounts rows in the viewport ────────────
450
+ (0, _jsxRuntime.jsx)(_reactNative.FlatList, {
451
+ data: visibleData,
452
+ keyExtractor: row => String(row.id)
453
+ // Pass selectedIds + striped as extraData so FlatList knows to re-render
454
+ // when selection changes (FlatList only re-renders items whose key changes
455
+ // otherwise — extraData forces a full diff)
456
+ ,
457
+ extraData: [selectedIds, striped],
458
+ scrollEnabled: false // outer ScrollView handles scrolling
459
+ ,
460
+ renderItem: ({
461
+ item: row,
462
+ index: rowIndex
463
+ }) => {
464
+ const isSelected = selectedIds.includes(row.id);
465
+ const isLast = rowIndex === visibleData.length - 1;
466
+ const isAlt = striped && rowIndex % 2 !== 0;
467
+ const rowBg = isSelected ? c.selectedBg : isAlt ? c.rowAltBg : c.rowBg;
468
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index4.StyledPressable, {
469
+ flexDirection: "row",
470
+ alignItems: "center",
471
+ backgroundColor: rowBg,
472
+ borderLeftWidth: isSelected ? 3 : 0,
473
+ borderLeftColor: isSelected ? c.selectedBorder : "transparent",
474
+ borderBottomWidth: showDivider && !isLast ? 1 : 0,
475
+ borderBottomColor: c.divider,
476
+ borderBottomLeftRadius: isLast ? borderRadius : 0,
477
+ borderBottomRightRadius: isLast ? borderRadius : 0,
478
+ onPress: () => onRowPress?.(row, rowIndex),
479
+ disabled: !onRowPress && !selectable,
480
+ children: [selectable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
481
+ width: 52,
482
+ paddingHorizontal: 16,
483
+ paddingVertical: 14,
484
+ alignItems: "center",
485
+ justifyContent: "center",
486
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.StyledCheckBox, {
487
+ checked: isSelected,
488
+ onCheck: () => toggleRow(row.id),
489
+ size: 18,
490
+ checkedColor: c.checkboxChecked
491
+ })
492
+ }), columns.map((col, colIndex) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Cell, {
493
+ width: col.width,
494
+ align: col.align,
495
+ isFirst: colIndex === 0 && !selectable,
496
+ children: col.render ? col.render(row[col.key], row, rowIndex) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
497
+ fontSize: 14,
498
+ color: c.text,
499
+ numberOfLines: 1,
500
+ children: row[col.key] ?? "—"
501
+ })
502
+ }, col.key))]
503
+ });
504
+ }
505
+ }) :
506
+ // ── Stack.map path — simple, best for ≤ 50 rows ─────────────────
507
+ visibleData.map((row, rowIndex) => {
508
+ const isSelected = selectedIds.includes(row.id);
509
+ const isLast = rowIndex === visibleData.length - 1;
510
+ const isAlt = striped && rowIndex % 2 !== 0;
511
+ const rowBg = isSelected ? c.selectedBg : isAlt ? c.rowAltBg : c.rowBg;
512
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index4.StyledPressable, {
513
+ flexDirection: "row",
514
+ alignItems: "center",
515
+ backgroundColor: rowBg,
516
+ borderLeftWidth: isSelected ? 3 : 0,
517
+ borderLeftColor: isSelected ? c.selectedBorder : "transparent",
518
+ borderBottomWidth: showDivider && !isLast ? 1 : 0,
519
+ borderBottomColor: c.divider,
520
+ borderBottomLeftRadius: isLast ? borderRadius : 0,
521
+ borderBottomRightRadius: isLast ? borderRadius : 0,
522
+ onPress: () => onRowPress?.(row, rowIndex),
523
+ disabled: !onRowPress && !selectable,
524
+ children: [selectable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
525
+ width: 52,
526
+ paddingHorizontal: 16,
527
+ paddingVertical: 14,
528
+ alignItems: "center",
529
+ justifyContent: "center",
530
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index3.StyledCheckBox, {
531
+ checked: isSelected,
532
+ onCheck: () => toggleRow(row.id),
533
+ size: 18,
534
+ checkedColor: c.checkboxChecked
535
+ })
536
+ }), columns.map((col, colIndex) => /*#__PURE__*/(0, _jsxRuntime.jsx)(Cell, {
537
+ width: col.width,
538
+ align: col.align,
539
+ isFirst: colIndex === 0 && !selectable,
540
+ children: col.render ? col.render(row[col.key], row, rowIndex) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
541
+ fontSize: 14,
542
+ color: c.text,
543
+ numberOfLines: 1,
544
+ children: row[col.key] ?? "—"
545
+ })
546
+ }, col.key))]
547
+ }, row.id);
548
+ }), (pagination || externalPagination) && totalPages > 1 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
549
+ horizontal: true,
550
+ alignItems: "center",
551
+ justifyContent: "space-between",
552
+ paddingHorizontal: 16,
553
+ paddingVertical: 12,
554
+ borderTopWidth: 1,
555
+ borderTopColor: c.border,
556
+ backgroundColor: c.headerBg,
557
+ borderBottomLeftRadius: borderRadius,
558
+ borderBottomRightRadius: borderRadius,
559
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_index2.StyledText, {
560
+ fontSize: 12,
561
+ color: c.subText,
562
+ children: [rowStart, "\u2013", rowEnd, " of ", rowTotal]
563
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_index.Stack, {
564
+ horizontal: true,
565
+ gap: 6,
566
+ children: [Array.from({
567
+ length: totalPages
568
+ }, (_, i) => i).filter(i => i === 0 || i === totalPages - 1 || Math.abs(i - page) <= 1).reduce((acc, i, idx, arr) => {
569
+ if (idx > 0 && i - arr[idx - 1] > 1) acc.push("…");
570
+ acc.push(i);
571
+ return acc;
572
+ }, []).map((item, idx) => item === "…" ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
573
+ fontSize: 12,
574
+ color: c.subText,
575
+ paddingHorizontal: 4,
576
+ children: "\u2026"
577
+ }, `ellipsis-${idx}`) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_index4.StyledPressable, {
578
+ onPress: () => handlePageChange(item),
579
+ disabled: loading,
580
+ paddingHorizontal: 10,
581
+ paddingVertical: 6,
582
+ borderRadius: 8,
583
+ borderWidth: 1,
584
+ borderColor: page === item ? c.sortActive : c.border,
585
+ backgroundColor: page === item ? c.sortActive : "transparent",
586
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
587
+ fontSize: 12,
588
+ fontWeight: "600",
589
+ color: page === item ? c.background : c.text,
590
+ children: item + 1
591
+ })
592
+ }, item)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index4.StyledPressable, {
593
+ onPress: () => handlePageChange(Math.min(totalPages - 1, page + 1)),
594
+ disabled: page >= totalPages - 1 || loading,
595
+ paddingHorizontal: 12,
596
+ paddingVertical: 6,
597
+ borderRadius: 8,
598
+ borderWidth: 1,
599
+ borderColor: page >= totalPages - 1 ? c.border : c.sortActive,
600
+ opacity: page >= totalPages - 1 ? 0.4 : 1,
601
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
602
+ fontSize: 12,
603
+ fontWeight: "600",
604
+ color: c.text,
605
+ children: "\u2192"
606
+ })
607
+ })]
608
+ })]
609
+ }), loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
610
+ position: "absolute",
611
+ top: 0,
612
+ left: 0,
613
+ right: 0,
614
+ bottom: 0,
615
+ backgroundColor: "rgba(255,255,255,0.7)",
616
+ alignItems: "center",
617
+ justifyContent: "center",
618
+ borderRadius: borderRadius,
619
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_index2.StyledText, {
620
+ fontSize: 13,
621
+ color: c.subText,
622
+ children: "Loading\u2026"
623
+ })
624
+ })]
625
+ });
626
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.Stack, {
627
+ borderRadius: borderRadius,
628
+ borderWidth: bordered ? 1 : 0,
629
+ borderColor: c.border,
630
+ overflow: "hidden",
631
+ backgroundColor: c.background,
632
+ style: bordered ? {
633
+ shadowColor: "#000",
634
+ shadowOffset: {
635
+ width: 0,
636
+ height: 1
637
+ },
638
+ shadowOpacity: 0.06,
639
+ shadowRadius: 8,
640
+ elevation: 2
641
+ } : undefined,
642
+ children: scrollable ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ScrollView, {
643
+ horizontal: true,
644
+ showsHorizontalScrollIndicator: false,
645
+ children: tableContent
646
+ }) : tableContent
647
+ });
648
+ }
649
+ var _default = exports.default = StyledTable;
650
+ //# sourceMappingURL=index.js.map