Skip to content

Commit 24f14a2

Browse files
feat: custom select options
1 parent e4e26c8 commit 24f14a2

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

source/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import React, { useState, type ReactNode } from 'react'
33
import MainTitle from './import/MainTitle.js'
44
import Step1 from './import/Step1.js'
55
import Step2 from './import/Step2.js'
6-
import Step3, { type ItemProps } from './import/Step3.js'
6+
import Step3, { type Item } from './import/Step3.js'
77
import { canShowStep } from './import/utils.js'
88

99
const App = () => {
1010
const [projectName, setProjectName] = useState<string>('')
1111
const [currentStep, setCurrentStep] = useState(1)
12-
const [setupOption, setSetupOption] = useState<ItemProps | undefined>()
12+
const [setupOption, setSetupOption] = useState<Item | undefined>()
1313

1414
const finishStep = () => setCurrentStep(currentStep + 1)
15-
const onSelect = (item: ItemProps) => setSetupOption(item)
15+
const onSelect = (item: Item) => setSetupOption(item)
1616

1717
const steps: Array<ReactNode> = [
1818
<Step1

source/import/Step3.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
import { Box, Text } from 'ink'
1+
import { Text } from 'ink'
22
import Divider from 'ink-divider'
33
import SelectInput from 'ink-select-input'
4-
import React, { type FC } from 'react'
4+
import React, { useState, type FC } from 'react'
55

6-
export interface ItemProps {
6+
type Installation = 'full' | 'custom'
7+
8+
export interface Item {
79
label: string
8-
value: string
10+
value: Installation
911
}
1012

1113
interface Props {
1214
onCompletion: () => void
13-
onSelect: (item: ItemProps) => void
15+
onSelect: (item: Item) => void
1416
}
1517

1618
const Step3: FC<Props> = ({ onCompletion, onSelect }) => {
17-
const handleSelect = (item: ItemProps) => {
19+
const [isFocused, setIsFocused] = useState(true)
20+
21+
const handleSelect = (item: Item) => {
1822
onSelect(item)
1923
onCompletion()
24+
setIsFocused(false)
2025
}
2126

22-
const items = [
27+
const items: Array<Item> = [
2328
{
2429
label: 'Full',
2530
value: 'full',
@@ -39,6 +44,18 @@ const Step3: FC<Props> = ({ onCompletion, onSelect }) => {
3944
/>
4045
<Text color={'whiteBright'}>Choose installation type</Text>
4146
<SelectInput
47+
indicatorComponent={({ isSelected }) => (
48+
<Text color="green">{isSelected ? '> ' : ' '}</Text>
49+
)}
50+
itemComponent={({ label, isSelected }) => (
51+
<Text
52+
color={isSelected ? 'green' : 'white'}
53+
bold={isSelected}
54+
>
55+
{label}
56+
</Text>
57+
)}
58+
isFocused={isFocused}
4259
items={items}
4360
onSelect={handleSelect}
4461
/>

0 commit comments

Comments
 (0)