UNPKG

ink-form

Version:

Complex user-friendly form component for React Ink

10 lines (9 loc) 724 B
import React from 'react'; import { Box } from 'ink'; import SelectInput from 'ink-select-input'; export class SelectFormFieldManager { type = 'select'; renderField = props => (React.createElement(Box, { borderStyle: 'round', width: "100%" }, React.createElement(SelectInput, { items: props.field.options.map(option => ({ value: option.value, label: option.label ?? option.value })), onHighlight: option => props.onChange(option.value), initialIndex: props.field.options.findIndex(option => option.value === props.value) ?? 0 }))); renderValue = props => (React.createElement(React.Fragment, null, props.field.options.find(option => option.value === props.value)?.label ?? props.value ?? 'No value')); }