import { Colors } from '@island.is/island-ui/theme' ; import type { DatePickerBackgroundColor , InputBackgroundColor , BoxProps , } from '@island.is/island-ui/core/types' ; import { ApolloClient } from '@apollo/client' ; import { FormText , FormTextArray , FormItem } from './Form' ; import { Condition } from './Condition' ; import { CallToAction } from './StateMachine' ; import { Application } from './Application' ; import { FormatInputValueFunction } from 'react-number-format' ; export type RecordObject < T = unknown > = Record < string , T > ; export type MaybeWithApplicationAndField < T > = T | ( ( application : Application , field : Field ) => T ) ; export type ValidAnswers = 'yes' | 'no' | undefined ; export type FieldWidth = 'full' | 'half' ; export type TitleVariants = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' ; export type TextFieldVariant = 'text' | 'email' | 'number' | 'tel' | 'textarea' | 'currency' ; export type Context = { application : Application ; apolloClient : ApolloClient < object > ; } ; export interface Option { value : string ; label : FormText ; subLabel ? : string ; tooltip ? : FormText ; excludeOthers ? : boolean ; illustration ? : React . FC ; disabled ? : boolean ; } export interface SelectOption < T = string | number > { label : string ; value : T ; } export interface BaseField extends FormItem { readonly id : string ; readonly component : FieldComponents | string ; readonly title : FormText ; readonly description ? : FormText ; readonly children : undefined ; disabled ? : boolean ; width ? : FieldWidth ; condition ? : Condition ; isPartOfRepeater ? : boolean ; defaultValue ? : MaybeWithApplicationAndField < unknown > ; doesNotRequireAnswer ? : boolean ; } export enum FieldTypes { CHECKBOX = 'CHECKBOX' , CUSTOM = 'CUSTOM' , DATE = 'DATE' , DESCRIPTION = 'DESCRIPTION' , RADIO = 'RADIO' , EMAIL = 'EMAIL' , SELECT = 'SELECT' , TEXT = 'TEXT' , FILEUPLOAD = 'FILEUPLOAD' , SUBMIT = 'SUBMIT' , DIVIDER = 'DIVIDER' , KEY_VALUE = 'KEY_VALUE' , ASYNC_SELECT = 'ASYNC_SELECT' } export enum FieldComponents { CHECKBOX = 'CheckboxFormField' , DATE = 'DateFormField' , TEXT = 'TextFormField' , DESCRIPTION = 'DescriptionFormField' , RADIO = 'RadioFormField' , SELECT = 'SelectFormField' , FILEUPLOAD = 'FileUploadFormField' , DIVIDER = 'DividerFormField' , KEY_VALUE = 'KeyValueFormField' , SUBMIT = 'SubmitFormField' , ASYNC_SELECT = 'AsyncSelectFormField' } export interface CheckboxField extends BaseField { readonly type : FieldTypes . CHECKBOX ; component : FieldComponents . CHECKBOX ; options : MaybeWithApplicationAndField < Option [ ] > ; large ? : boolean ; strong ? : boolean ; backgroundColor ? : InputBackgroundColor ; } export interface DateField extends BaseField { readonly type : FieldTypes . DATE ; placeholder ? : FormText ; component : FieldComponents . DATE ; maxDate ? : Date ; minDate ? : MaybeWithApplicationAndField < Date > ; excludeDates ? : MaybeWithApplicationAndField < Date [ ] > ; backgroundColor ? : DatePickerBackgroundColor ; onChange ? ( date ) : void ; required ? : boolean ; } export interface DescriptionField extends BaseField { readonly type : FieldTypes . DESCRIPTION ; component : FieldComponents . DESCRIPTION ; readonly description : FormText ; tooltip ? : FormText ; space ? : BoxProps [ 'paddingTop' ] ; titleVariant ? : TitleVariants ; } export interface RadioField extends BaseField { readonly type : FieldTypes . RADIO ; component : FieldComponents . RADIO ; options : MaybeWithApplicationAndField < Option [ ] > ; backgroundColor ? : InputBackgroundColor ; largeButtons ? : boolean ; space ? : BoxProps [ 'paddingTop' ] ; onSelect ? ( s ) : void ; } export interface SelectField extends BaseField { readonly type : FieldTypes . SELECT ; component : FieldComponents . SELECT ; options : MaybeWithApplicationAndField < Option [ ] > ; onSelect ? ( s , cb ) : void ; placeholder ? : FormText ; backgroundColor ? : InputBackgroundColor ; } export interface AsyncSelectField extends BaseField { readonly type : FieldTypes . ASYNC_SELECT ; component : FieldComponents . ASYNC_SELECT ; placeholder ? : FormText ; loadOptions ( c ) : Promise < Option [ ] > ; onSelect ? ( s , cb ) : void ; loadingError ? : FormText ; backgroundColor ? : InputBackgroundColor ; isSearchable ? : boolean ; } export interface TextField extends BaseField { readonly type : FieldTypes . TEXT ; component : FieldComponents . TEXT ; disabled ? : boolean ; minLength ? : number ; maxLength ? : number ; placeholder ? : FormText ; variant ? : TextFieldVariant ; backgroundColor ? : InputBackgroundColor ; format ? : string | FormatInputValueFunction ; suffix ? : string ; rows ? : number ; required ? : boolean ; } export interface FileUploadField extends BaseField { readonly type : FieldTypes . FILEUPLOAD ; component : FieldComponents . FILEUPLOAD ; readonly introduction ? : FormText ; readonly uploadHeader ? : FormText ; readonly uploadDescription ? : FormText ; readonly uploadButtonLabel ? : FormText ; readonly uploadMultiple ? : boolean ; readonly uploadAccept ? : string ; readonly maxSize ? : number ; } export interface SubmitField extends BaseField { readonly type : FieldTypes . SUBMIT ; component : FieldComponents . SUBMIT ; readonly actions : CallToAction [ ] ; readonly placement : 'footer' | 'screen' ; readonly refetchApplicationAfterSubmit ? : boolean ; } export interface DividerField extends BaseField { readonly type : FieldTypes . DIVIDER ; readonly color ? : Colors ; component : FieldComponents . DIVIDER ; } export interface KeyValueField extends BaseField { readonly type : FieldTypes . KEY_VALUE ; label : FormText ; value : FormText | FormTextArray ; component : FieldComponents . KEY_VALUE ; } export interface CustomField extends BaseField { readonly type : FieldTypes . CUSTOM ; readonly component : string ; props ? : RecordObject ; childInputIds ? : string [ ] ; } export type Field = CheckboxField | CustomField | DateField | DescriptionField | RadioField | SelectField | TextField | FileUploadField | KeyValueField | DividerField | SubmitField | AsyncSelectField ;