/** * WordPress dependencies */ import { BaseControl, Button } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import type { PostTypeName, WebhookFormField } from '@nelio-content/types'; /** * Internal dependencies */ import { TextFieldControl } from '../text-field-control'; export type FormDataKeyValuesFieldControlProps = { readonly label: string; readonly items: ReadonlyArray< WebhookFormField >; readonly hidePlaceholders?: boolean; readonly type?: PostTypeName; readonly onChange: ( value: ReadonlyArray< WebhookFormField > ) => void; }; export const FormDataKeyValuesFieldControl = ( props: FormDataKeyValuesFieldControlProps ): JSX.Element => { const { label, items, hidePlaceholders, type, onChange } = props; return (
{ items.map( ( item, index ) => ( onChange( [ ...items ].map( ( i, idx ) => idx === index ? value : i ) ) } onRemove={ () => onChange( [ ...items ].filter( ( _: WebhookFormField, idx: number ) => idx !== index ) ) } /> ) ) }
); }; type FormDataKeyValueControlProps = { readonly item: WebhookFormField; readonly hidePlaceholders?: boolean; readonly type?: PostTypeName; readonly onChange: ( value: WebhookFormField ) => void; readonly onRemove: () => void; }; const FormDataKeyValueControl = ( props: FormDataKeyValueControlProps ): JSX.Element => { const { item, hidePlaceholders, type, onChange, onRemove } = props; return (
onChange( { ...item, key: value } ) } /> onChange( { ...item, value } ) } />
); };