@gntik-ai/blocks 0.6.0 → 0.7.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.d.ts +178 -70
- package/dist/index.js +621 -200
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/feedback/ConfirmDestructive/ConfirmDestructive.examples.test.tsx +25 -0
- package/src/feedback/ConfirmDestructive/ConfirmDestructive.extended.test.tsx +252 -0
- package/src/feedback/ConfirmDestructive/ConfirmDestructive.focus.test.tsx +178 -0
- package/src/feedback/ConfirmDestructive/ConfirmDestructive.tsx +219 -28
- package/src/feedback/ConfirmDestructive/block.meta.ts +2 -2
- package/src/feedback/ConfirmDestructive/examples/FailureStates.tsx +39 -0
- package/src/feedback/ConfirmDestructive/examples/PlainDeletion.tsx +6 -0
- package/src/feedback/ConfirmDestructive/examples/SecretRevocation.tsx +34 -0
- package/src/feedback/EmptyStates/EmptyStates.test.tsx +11 -1
- package/src/feedback/EmptyStates/EmptyStates.tsx +31 -1
- package/src/feedback/EmptyStates/block.meta.ts +1 -1
- package/src/feedback/EmptyStates/fixtures.ts +5 -0
- package/src/feedback/ErrorPanel/ErrorPanel.test.tsx +7 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +8 -3
- package/src/tables/CursorPagerFooter/CursorPagerFooter.examples.test.tsx +33 -0
- package/src/tables/CursorPagerFooter/CursorPagerFooter.test.tsx +51 -0
- package/src/tables/CursorPagerFooter/CursorPagerFooter.tsx +10 -0
- package/src/tables/CursorPagerFooter/block.meta.ts +23 -0
- package/src/tables/CursorPagerFooter/examples/Busy.tsx +7 -0
- package/src/tables/CursorPagerFooter/examples/CursorStack.tsx +40 -0
- package/src/tables/CursorPagerFooter/examples/Hidden.tsx +16 -0
- package/src/tables/CursorPagerFooter/examples/RowsPerPage.tsx +21 -0
- package/src/tables/CursorPagerFooter/fixtures.ts +13 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +173 -0
- package/src/tables/DataTable/DataTable.tsx +20 -12
- package/src/tables/DataTable/block.meta.ts +2 -1
- package/src/tables/DataTable/data-table-props.ts +27 -4
- package/src/tables/DataTable/examples/server-pagination.tsx +68 -0
- package/src/tables/LoadMoreFooter/LoadMoreFooter.announcements.test.tsx +106 -0
- package/src/tables/LoadMoreFooter/LoadMoreFooter.examples.test.tsx +36 -0
- package/src/tables/LoadMoreFooter/LoadMoreFooter.labels.test.tsx +71 -0
- package/src/tables/LoadMoreFooter/LoadMoreFooter.test.tsx +184 -0
- package/src/tables/LoadMoreFooter/LoadMoreFooter.tsx +151 -0
- package/src/tables/LoadMoreFooter/block.meta.ts +28 -0
- package/src/tables/LoadMoreFooter/examples/cards.tsx +22 -0
- package/src/tables/LoadMoreFooter/examples/cursor.tsx +25 -0
- package/src/tables/LoadMoreFooter/examples/exhausted.tsx +6 -0
- package/src/tables/LoadMoreFooter/examples/failed.tsx +13 -0
- package/src/tables/LoadMoreFooter/examples/flag.tsx +33 -0
- package/src/tables/LoadMoreFooter/examples/useMockCursor.ts +30 -0
- package/src/tables/LoadMoreFooter/fixtures.ts +9 -0
- package/src/tables/LoadMoreFooter/useLoadMoreFooter.ts +56 -0
- package/src/tables/index.ts +4 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useAnnounce } from '@gntik-ai/ui';
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Capture focus before React removes the control, then restore it after the replacement commits. */
|
|
5
|
+
export function useLoadMoreFooter(
|
|
6
|
+
control: 'button' | 'retry' | 'none',
|
|
7
|
+
target: 'summary' | 'root',
|
|
8
|
+
loading: boolean,
|
|
9
|
+
error: string,
|
|
10
|
+
) {
|
|
11
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
12
|
+
const summaryRef = useRef<HTMLParagraphElement>(null);
|
|
13
|
+
const currentControl = useRef<HTMLElement | null>(null);
|
|
14
|
+
const moveFocus = useRef(false);
|
|
15
|
+
const inFlightCursorRef = useRef<string | undefined>(undefined);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
// A successful settle releases the cursor; later external failures use nextCursor.
|
|
18
|
+
if (!loading && !error) inFlightCursorRef.current = undefined;
|
|
19
|
+
}, [loading, error]);
|
|
20
|
+
const controlRef = useCallback((node: HTMLElement | null) => {
|
|
21
|
+
if (!node && currentControl.current?.contains(document.activeElement)) moveFocus.current = true;
|
|
22
|
+
currentControl.current = node;
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
useLayoutEffect(() => {
|
|
26
|
+
if (!moveFocus.current) return;
|
|
27
|
+
moveFocus.current = false;
|
|
28
|
+
const nextControl = currentControl.current;
|
|
29
|
+
const next = nextControl?.matches('button') ? nextControl : nextControl?.querySelector('button');
|
|
30
|
+
(next ?? (target === 'root' ? rootRef.current : summaryRef.current))?.focus();
|
|
31
|
+
}, [control, target]);
|
|
32
|
+
|
|
33
|
+
return { rootRef, summaryRef, controlRef, inFlightCursorRef };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Track committed results; mounting and intermediate loading states remain silent. */
|
|
37
|
+
export function useLoadMoreAnnouncements(
|
|
38
|
+
loading: boolean,
|
|
39
|
+
error: string,
|
|
40
|
+
lastAppend: { seq: number; count: number } | undefined,
|
|
41
|
+
loadedAnnouncement: (count: number) => string,
|
|
42
|
+
) {
|
|
43
|
+
const announce = useAnnounce();
|
|
44
|
+
const previous = useRef({ loading, error });
|
|
45
|
+
const lastSeq = useRef(lastAppend?.seq);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const before = previous.current;
|
|
48
|
+
previous.current = { loading, error };
|
|
49
|
+
if (!loading && error && (before.loading || before.error !== error)) announce(error, 'assertive');
|
|
50
|
+
}, [loading, error, announce]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!lastAppend || (lastSeq.current !== undefined && lastAppend.seq <= lastSeq.current)) return;
|
|
53
|
+
lastSeq.current = lastAppend.seq;
|
|
54
|
+
if (lastAppend.count > 0) announce(loadedAnnouncement(lastAppend.count), 'polite');
|
|
55
|
+
}, [lastAppend, loadedAnnouncement, announce]);
|
|
56
|
+
}
|
package/src/tables/index.ts
CHANGED
|
@@ -35,7 +35,11 @@ export * from './FilterBar/FilterBar';
|
|
|
35
35
|
export { meta as filterBarMeta } from './FilterBar/block.meta';
|
|
36
36
|
export { DEPLOYMENT_DEFAULT_FILTERS, DEPLOYMENT_FILTER_FIELDS, DEPLOYMENT_SAVED_VIEWS } from './FilterBar/fixtures';
|
|
37
37
|
export * from './PaginationFooter/PaginationFooter';
|
|
38
|
+
export * from './CursorPagerFooter/CursorPagerFooter';
|
|
39
|
+
export { meta as cursorPagerFooterMeta } from './CursorPagerFooter/block.meta';
|
|
38
40
|
export { meta as paginationFooterMeta } from './PaginationFooter/block.meta';
|
|
41
|
+
export * from './LoadMoreFooter/LoadMoreFooter';
|
|
42
|
+
export { meta as loadMoreFooterMeta } from './LoadMoreFooter/block.meta';
|
|
39
43
|
export * from './TruncatedCollectionFooter/TruncatedCollectionFooter';
|
|
40
44
|
export { meta as truncatedCollectionFooterMeta } from './TruncatedCollectionFooter/block.meta';
|
|
41
45
|
export * from './InlineEditRow/InlineEditRow';
|