Skip to content

Radio

A radio button group for single-select in Ink 5.

Install

Terminal window
npm install @matthesketh/ink-radio

Usage

import React, { useState } from 'react';
import { render } from 'ink';
import { RadioGroup } from '@matthesketh/ink-radio';
const options = [
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
];
function App() {
const [value, setValue] = useState('md');
return <RadioGroup options={options} value={value} onChange={setValue} />;
}
render(<App />);

Props

PropTypeDefaultDescription
optionsRadioOption[]requiredList of options to display
valuestringundefinedCurrently selected value
onChange(value: string) => voidundefinedCalled when selection changes
direction'vertical' | 'horizontal''vertical'Layout direction
colorstring'cyan'Colour of the selected option

RadioOption

interface RadioOption {
label: string;
value: string;
disabled?: boolean;
}

Appearance

Selected options render in bold with the configured colour. Disabled options render dim.

License

MIT