| |
| |
| |
| |
| |
|
|
| import type React from 'react'; |
| import { Text, Box } from 'ink'; |
| import { theme } from '../../semantic-colors.js'; |
| import { |
| BaseSelectionList, |
| type RenderItemContext, |
| } from './BaseSelectionList.js'; |
| import type { SelectionListItem } from '../../hooks/useSelectionList.js'; |
|
|
| |
| |
| |
| |
| export interface RadioSelectItem<T> extends SelectionListItem<T> { |
| label: string; |
| sublabel?: string; |
| themeNameDisplay?: string; |
| themeTypeDisplay?: string; |
| } |
|
|
| |
| |
| |
| |
| export interface RadioButtonSelectProps<T> { |
| |
| items: Array<RadioSelectItem<T>>; |
| |
| initialIndex?: number; |
| |
| onSelect: (value: T) => void; |
| |
| onHighlight?: (value: T) => void; |
| |
| isFocused?: boolean; |
| |
| showScrollArrows?: boolean; |
| |
| maxItemsToShow?: number; |
| |
| showNumbers?: boolean; |
| |
| priority?: boolean; |
| |
| renderItem?: ( |
| item: RadioSelectItem<T>, |
| context: RenderItemContext, |
| ) => React.ReactNode; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function RadioButtonSelect<T>({ |
| items, |
| initialIndex = 0, |
| onSelect, |
| onHighlight, |
| isFocused = true, |
| showScrollArrows = false, |
| maxItemsToShow = 10, |
| showNumbers = true, |
| priority, |
| renderItem, |
| }: RadioButtonSelectProps<T>): React.JSX.Element { |
| return ( |
| <BaseSelectionList<T, RadioSelectItem<T>> |
| items={items} |
| initialIndex={initialIndex} |
| onSelect={onSelect} |
| onHighlight={onHighlight} |
| isFocused={isFocused} |
| showNumbers={showNumbers} |
| showScrollArrows={showScrollArrows} |
| maxItemsToShow={maxItemsToShow} |
| priority={priority} |
| renderItem={ |
| renderItem || |
| ((item, { titleColor }) => { |
| |
| if (item.themeNameDisplay && item.themeTypeDisplay) { |
| return ( |
| <Text color={titleColor} wrap="truncate" key={item.key}> |
| {item.themeNameDisplay}{' '} |
| <Text color={theme.text.secondary}> |
| {item.themeTypeDisplay} |
| </Text> |
| </Text> |
| ); |
| } |
| |
| return ( |
| <Box flexDirection="column"> |
| <Text color={titleColor} wrap="truncate"> |
| {item.label} |
| </Text> |
| {item.sublabel && ( |
| <Text color={theme.text.secondary} wrap="truncate"> |
| {item.sublabel} |
| </Text> |
| )} |
| </Box> |
| ); |
| }) |
| } |
| /> |
| ); |
| } |
|
|