-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFieldRenderer.tsx
More file actions
39 lines (35 loc) · 1.06 KB
/
ArrayFieldRenderer.tsx
File metadata and controls
39 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react';
import { FormFieldArray, SpecificFormFieldRendererProps } from './types.js';
import { Box } from 'ink';
import TextInput from 'ink-text-input';
export const ArrayFieldRenderer: React.FC<
SpecificFormFieldRendererProps<FormFieldArray>
> = props => {
const regex = props.field.regex;
const change = (value: string) => {
if (regex) {
const arr = value.split(/(?<!\\),/);
if (arr.some((i) => !regex.test(i))) {
props.onError(`"${value}" does not pass the regex ${regex}`);
props.onChange(value as any);
}
} else {
props.onChange(value as any);
}
};
return (
<Box borderStyle={'round'} width="100%" flexDirection="column">
<Box>
<TextInput
value={props.value?.toString() ?? ''}
onChange={value => {
props.onClearError();
change(value);
}}
placeholder={props.field.placeholder ?? 'value1, value2, value3...'}
onSubmit={() => props.onSetEditingField(undefined)}
/>
</Box>
</Box>
);
};