/** * Settings of date, time, number, slider and scale fields: formats, limits, periods, ranges, units * and points. */ import React from 'react'; import type { DateField, NumberField, RatingField, SliderField, TimeField } from '@funnelforms/form-schema'; import type { Edit } from './Answers'; import { useEnv } from './context'; import { __, sprintf } from './i18n'; import { put, TextProp } from './texts'; import { Button, ChoiceTiles, Group, Notice, NumberInput, Select, Sketch, TextInput, Toggle } from './ui'; export function DateProps( { field, edit }: { field: DateField; edit: Edit } ) { const p = field.props; const set = ( key: string, value: unknown ): void => edit( ( f ) => { const props = f.props as Record; if ( undefined === value || false === value || '' === value ) { Reflect.deleteProperty( props, key ); } else { props[ key ] = value; } }, 'props.' + key ); return ( <> edit( ( f ) => { const props = ( f as SliderField ).props; props.thousandsSeparator = 'none' !== v; if ( 'none' === v || '.' === v ) { delete props.separator; } else { props.separator = v as SliderField[ 'props' ][ 'separator' ]; } }, 'props.separator' ) } /> edit( ( f ) => void ( ( f as SliderField ).props.manualInput.enabled = v ) ) } /> { p.manualInput.enabled && ! p.range ? ( edit( ( f ) => put( ( f as SliderField ).props.manualInput, 'label', lang, v, ctx.locale ), 'manualInput.label' ) } /> ) : null } ); } export function RatingProps( { field, edit }: { field: RatingField; edit: Edit } ) { const { ctx, lang } = useEnv(); const p = field.props; const points: number[] = []; for ( let n = p.min; n <= p.max; n++ ) { points.push( n ); } const text = ( key: 'lowLabel' | 'highLabel' ) => ( v: string ): void => edit( ( f ) => put( ( f as RatingField ).props, key, lang, v, ctx.locale ), key ); return ( <>