Files
gemini-cli/packages/cli/src/ui/components/shared/ScopeSelector.tsx
T

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-09-08 11:43:58 -07:00
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type React from 'react';
import { Box, Text } from 'ink';
import type { LoadableSettingScope } from '../../../config/settings.js';
2025-09-08 11:43:58 -07:00
import { getScopeItems } from '../../../utils/dialogScopeUtils.js';
import { RadioButtonSelect } from './RadioButtonSelect.js';
interface ScopeSelectorProps {
/** Callback function when a scope is selected */
onSelect: (scope: LoadableSettingScope) => void;
2025-09-08 11:43:58 -07:00
/** Callback function when a scope is highlighted */
onHighlight: (scope: LoadableSettingScope) => void;
2025-09-08 11:43:58 -07:00
/** Whether the component is focused */
isFocused: boolean;
/** The initial scope to select */
initialScope: LoadableSettingScope;
2025-09-08 11:43:58 -07:00
}
export function ScopeSelector({
onSelect,
onHighlight,
isFocused,
initialScope,
}: ScopeSelectorProps): React.JSX.Element {
2025-09-28 14:50:47 -07:00
const scopeItems = getScopeItems().map((item) => ({
...item,
key: item.value,
}));
2025-09-08 11:43:58 -07:00
const initialIndex = scopeItems.findIndex(
(item) => item.value === initialScope,
);
const safeInitialIndex = initialIndex >= 0 ? initialIndex : 0;
return (
<Box flexDirection="column">
<Text bold={isFocused} wrap="truncate">
{isFocused ? '> ' : ' '}Apply To
</Text>
<RadioButtonSelect
items={scopeItems}
initialIndex={safeInitialIndex}
onSelect={onSelect}
onHighlight={onHighlight}
isFocused={isFocused}
showNumbers={isFocused}
/>
</Box>
);
}