11import React , { useMemo , useState } from "react" ;
22import { Box , Text , useFocus , useFocusManager , useInput } from "ink" ;
3- import { Field } from "./interfaces.js" ;
3+ import { Field , Validate } from "./interfaces.js" ;
44import { BooleanInput } from "../BooleanInput.js" ;
55import { MultiSelectInput } from "../MultiSelectInput.js" ;
66import { Button } from "../Button.js" ;
77import { InputWithLabel } from "../InputWithLabel.js" ;
88import { useArrowFocus } from "../../hooks/useArrowFocus.js" ;
99import figlet from "figlet" ;
10+ import { IntNumbersRegExp , NumberRegExp } from "../../utils/regexps.js" ;
1011
1112interface Props {
1213 title ?: string ;
@@ -44,7 +45,7 @@ export const Form: React.FC<Props> = (props) => {
4445 const onSubmit = ( ) => {
4546 const errors : Record < string , string > = { } ;
4647 for ( const field of props . fields ) {
47- if ( field . required && ! result [ field . name ] ) {
48+ if ( field . required && field . type === "string" && ! result [ field . name ] ) {
4849 errors [ field . name ] = "This field is required" ;
4950 }
5051
@@ -56,8 +57,8 @@ export const Form: React.FC<Props> = (props) => {
5657 errors [ field . name ] = "This field is required" ;
5758 }
5859
59- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
60- const errorMessage = field . validate ?.( result [ field . name ] as any ) ;
60+ const validate = field . validate as Validate < unknown > | undefined ;
61+ const errorMessage = validate ?.( result [ field . name ] ) ;
6162
6263 if ( errorMessage ) {
6364 errors [ field . name ] = errorMessage ;
@@ -182,6 +183,21 @@ const FieldView = <T extends Field>(field: FieldViewProps<T>) => {
182183 ) ;
183184 }
184185
186+ if ( field . type === "number" ) {
187+ return (
188+ < Box borderColor = { borderColor } borderStyle = "round" flexDirection = "column" >
189+ < InputWithLabel
190+ validateRegExp = { field . int ? IntNumbersRegExp : NumberRegExp }
191+ label = { field . label }
192+ focus = { field . focused }
193+ value = { ( field . value as number ) ?. toString ( ) || "" }
194+ onChange = { field . onChange }
195+ />
196+ { ErrorText }
197+ </ Box >
198+ ) ;
199+ }
200+
185201 if ( field . type === "boolean" ) {
186202 return (
187203 < Box
0 commit comments