import { FormikErrors } from 'formik'; import { ButtonSelector } from '@@/form-components/ButtonSelector/ButtonSelector'; import { FormError } from '@@/form-components/FormError'; import { InputGroup } from '@@/form-components/InputGroup'; import { InputList } from '@@/form-components/InputList'; import { ItemProps } from '@@/form-components/InputList/InputList'; import styles from './PortsMappingField.module.css'; type Protocol = 'TCP' | 'UDP'; export interface PortMapping { host?: number; container?: number; protocol: Protocol; } interface Props { value: PortMapping[]; onChange?(value: PortMapping[]): void; errors?: FormikErrors[] | string | string[]; disabled?: boolean; readOnly?: boolean; } export function PortsMappingField({ value, onChange = () => {}, errors, disabled, readOnly, }: Props) { return ( <> label="Port mapping" value={value} onChange={onChange} addLabel="map additional port" itemBuilder={() => ({ host: 0, container: 0, protocol: 'TCP', })} item={Item} errors={errors} disabled={disabled} readOnly={readOnly} /> {typeof errors === 'string' && (
{errors}
)} ); } function Item({ onChange, item, error, disabled, readOnly, }: ItemProps) { return (
host handleChange('host', parseInt(e.target.value || '0', 10)) } disabled={disabled} readOnly={readOnly} type="number" />