forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectScreen.tsx
More file actions
81 lines (78 loc) · 2.15 KB
/
Copy pathSelectScreen.tsx
File metadata and controls
81 lines (78 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { HELP_TEXT } from '../constants';
import { useListNavigation } from '../hooks';
import { Panel } from './Panel';
import { Screen } from './Screen';
import { SelectList, type SelectableItem } from './SelectList';
import type { ReactNode } from 'react';
interface SelectScreenProps<T extends SelectableItem> {
/** Screen title */
title: string;
/** Title color (default: cyan) */
color?: string;
/** Optional header content below the title */
headerContent?: ReactNode;
/** Optional custom help text (default: HELP_TEXT.NAVIGATE_SELECT) */
helpText?: string;
/** Items to display in the list */
items: T[];
/** Called when an item is selected */
onSelect: (item: T, index: number) => void;
/** Called when exiting (Escape or Ctrl+Q) */
onExit: () => void;
/** Whether navigation is active (default: true) */
isActive?: boolean;
/** Optional hotkey extractor */
getHotkeys?: (item: T) => string[] | undefined;
/** Message to show when items is empty */
emptyMessage?: string;
/** Optional content to render below the list */
children?: ReactNode;
/** Optional function to check if an item is disabled */
isDisabled?: (item: T) => boolean;
}
/**
* A complete screen for simple selection lists.
* Combines Screen, Panel, SelectList, and useListNavigation.
*
* @example
* ```tsx
* <SelectScreen
* title="Add Resource"
* items={RESOURCES}
* onSelect={(item) => handleAdd(item.id)}
* onExit={goBack}
* />
* ```
*/
export function SelectScreen<T extends SelectableItem>({
title,
color,
headerContent,
helpText = HELP_TEXT.NAVIGATE_SELECT,
items,
onSelect,
onExit,
isActive = true,
getHotkeys,
emptyMessage,
children,
isDisabled,
}: SelectScreenProps<T>) {
const { selectedIndex } = useListNavigation({
items,
onSelect,
onExit,
isActive,
getHotkeys,
onHotkeySelect: onSelect,
isDisabled,
});
return (
<Screen title={title} color={color} onExit={onExit} helpText={helpText} headerContent={headerContent}>
<Panel>
<SelectList items={items} selectedIndex={selectedIndex} emptyMessage={emptyMessage} />
</Panel>
{children}
</Screen>
);
}