/**
* Settings of file and signature fields.
*/
import React, { useState } from 'react';
import type { FileField, SignatureField } from '@funnelforms/form-schema';
import type { Edit } from './Answers';
import { __ } from './i18n';
import { TextProp } from './texts';
import { NumberInput, TextInput, Toggle } from './ui';
/** "pdf, .JPG docx" as extensions: lower case, without dots, each once. */
export function parseExtensions( text: string ): string[] {
return [ ...new Set( text.toLowerCase().split( /[\s,;|]+/ ).map( ( e ) => e.replace( /^\*?\./, '' ) ).filter( ( e ) => /^[a-z0-9]{1,10}$/.test( e ) ) ) ].slice( 0, 50 );
}
export function FileProps( { field, edit, propText }: { field: FileField; edit: Edit; propText: ( key: string ) => ( value: string ) => void } ) {
const p = field.props;
const props = ( recipe: ( props: FileField[ 'props' ] ) => void, key: string ): void => edit( ( f ) => recipe( ( f as FileField ).props ), 'props.' + key );
const stored = ( p.allowedExtensions ?? [] ).join( ', ' );
// What is typed stays (a trailing comma too) until another field is shown.
const [ draft, setDraft ] = useState( stored );
const [ shown, setShown ] = useState( field.id );
if ( shown !== field.id ) {
setShown( field.id );
setDraft( stored );
}
return (
<>