/** * Settings of text and address fields: what may be typed, what the browser may fill in, and * Google suggestions with the map. */ import React from 'react'; import type { AddressField, AutocompleteToken, TextareaField, TextField } from '@funnelforms/form-schema'; import type { Edit } from './Answers'; import { __ } from './i18n'; import { ChoiceTiles, NumberInput, Select, Sketch, Toggle } from './ui'; /** What the browser may fill in, in the order of a contact form. */ function autofillOptions(): Array<{ value: AutocompleteToken | ''; label: string }> { return [ { value: '', label: __( 'Browser decides', 'funnelforms-pro' ) }, { value: 'off', label: __( 'Nothing', 'funnelforms-pro' ) }, { value: 'name', label: __( 'Full name', 'funnelforms-pro' ) }, { value: 'given-name', label: __( 'First name', 'funnelforms-pro' ) }, { value: 'family-name', label: __( 'Last name', 'funnelforms-pro' ) }, { value: 'organization', label: __( 'Company', 'funnelforms-pro' ) }, { value: 'organization-title', label: __( 'Job title', 'funnelforms-pro' ) }, { value: 'street-address', label: __( 'Full street address', 'funnelforms-pro' ) }, { value: 'address-line1', label: __( 'Street and number', 'funnelforms-pro' ) }, { value: 'address-line2', label: __( 'Address addition', 'funnelforms-pro' ) }, { value: 'postal-code', label: __( 'Postcode', 'funnelforms-pro' ) }, { value: 'address-level2', label: __( 'City', 'funnelforms-pro' ) }, { value: 'country-name', label: __( 'Country', 'funnelforms-pro' ) }, { value: 'email', label: __( 'Email', 'funnelforms-pro' ) }, { value: 'tel', label: __( 'Phone', 'funnelforms-pro' ) }, { value: 'bday', label: __( 'Birthday', 'funnelforms-pro' ) }, { value: 'url', label: __( 'Website', 'funnelforms-pro' ) }, { value: 'username', label: __( 'User name', 'funnelforms-pro' ) }, ]; } export function TextFieldProps( { field, edit, num }: { field: TextField | TextareaField; edit: Edit; num: ( key: string ) => ( value: number | undefined ) => void } ) { const props = ( recipe: ( props: Record ) => void, key: string ): void => edit( ( f ) => recipe( f.props as Record ), 'props.' + key ); const choose = ( key: string ) => ( value: string ): void => props( ( p ) => { if ( value ) { p[ key ] = value; } else { Reflect.deleteProperty( p, key ); } }, key ); return ( <>
{ 'text' === field.type ? ( }, { value: 'letters', label: __( 'No digits', 'funnelforms-pro' ), icon: }, { value: 'digits', label: __( 'Digits only', 'funnelforms-pro' ), icon: }, { value: 'birthday', label: __( 'Birthday (dd.mm.yyyy)', 'funnelforms-pro' ), icon: }, ] } onChange={ choose( 'restrict' ) } /> ) : null }