@dloizides/ui-tables 1.12.0 → 1.13.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.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import React4, { memo, useState, useMemo, useCallback, useRef, useLayoutEffect, useEffect } from 'react';
1
+ import React4, { memo, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
2
2
  import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable, Switch, TextInput } from 'react-native';
3
3
  import { useUi } from '@dloizides/ui-feedback';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -2037,7 +2037,37 @@ function useFilterDraft({ initial, onApply, onReset }) {
2037
2037
  const dirty = useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
2038
2038
  return { draft, committed, setField, setDraft, apply, reset, dirty };
2039
2039
  }
2040
+ var DEFAULT_PAGE_SIZE = 10;
2041
+ function usePagedRows(rows, options = {}) {
2042
+ const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
2043
+ const [currentPage, setCurrentPage] = useState(0);
2044
+ const totalPages = Math.ceil(rows.length / pageSize);
2045
+ useEffect(() => {
2046
+ const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
2047
+ if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
2048
+ }, [currentPage, totalPages]);
2049
+ const pageRows = useMemo(() => {
2050
+ const start = currentPage * pageSize;
2051
+ return rows.slice(start, start + pageSize);
2052
+ }, [rows, currentPage, pageSize]);
2053
+ const setPage = useCallback(
2054
+ (page) => {
2055
+ const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
2056
+ const clamped = Math.min(Math.max(0, page), lastValidPage);
2057
+ setCurrentPage(clamped);
2058
+ },
2059
+ [totalPages]
2060
+ );
2061
+ return {
2062
+ pageRows,
2063
+ currentPage,
2064
+ totalPages,
2065
+ setPage,
2066
+ hasPages: totalPages > 1,
2067
+ pageSize
2068
+ };
2069
+ }
2040
2070
 
2041
- export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft };
2071
+ export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft, usePagedRows };
2042
2072
  //# sourceMappingURL=index.mjs.map
2043
2073
  //# sourceMappingURL=index.mjs.map