From e9103cf458e78bc7e28075cd9da3c748c6fb3227 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:26:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[#2]=20Add=20`iban`=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/components/iban.ts | 21 +++++ src/formio/components/index.ts | 1 + src/formio/index.ts | 2 + test-d/formio/components/iban.test-d.ts | 115 ++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/formio/components/iban.ts create mode 100644 test-d/formio/components/iban.test-d.ts diff --git a/src/formio/components/iban.ts b/src/formio/components/iban.ts new file mode 100644 index 0000000..f7f84ef --- /dev/null +++ b/src/formio/components/iban.ts @@ -0,0 +1,21 @@ +import {InputComponentSchema, MultipleCapable} from '..'; + +type Validator = 'required'; +type TranslatableKeys = 'label' | 'description' | 'tooltip'; + +export type IbanInputSchema = InputComponentSchema; + +/** + * @group Form.io components + * @category Base types + */ +export interface BaseIbanComponentSchema extends Omit { + type: 'iban'; + validateOn?: 'blur'; +} + +/** + * @group Form.io components + * @category Concrete types + */ +export type IbanComponentSchema = MultipleCapable; diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index 8d02311..dd0f9f6 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -6,6 +6,7 @@ export * from './datetime'; export * from './time'; export * from './phonenumber'; export * from './postcode'; +export * from './iban'; export * from './licenseplate'; export * from './number'; export * from './file'; diff --git a/src/formio/index.ts b/src/formio/index.ts index 82a9a7f..132618a 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -4,6 +4,7 @@ import { DateTimeComponentSchema, EmailComponentSchema, FileComponentSchema, + IbanComponentSchema, LicensePlateComponentSchema, NumberComponentSchema, PhoneNumberComponentSchema, @@ -47,6 +48,7 @@ export type AnyComponentSchema = | FileComponentSchema | NumberComponentSchema // special types + | IbanComponentSchema | LicensePlateComponentSchema // layout | ContentComponentSchema; diff --git a/test-d/formio/components/iban.test-d.ts b/test-d/formio/components/iban.test-d.ts new file mode 100644 index 0000000..dd965cd --- /dev/null +++ b/test-d/formio/components/iban.test-d.ts @@ -0,0 +1,115 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {IbanComponentSchema} from '../../../lib'; + +// minimal textfield component schema +expectAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', +}); + + +// multiple false and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', + multiple: false, + defaultValue: '', +}); + +// multiple true and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', + multiple: true, + defaultValue: [''], +}); + +// full, correct schema +expectAssignable({ + id: 'yejak', + type: 'iban', + // basic tab + label: 'Some IBAN', + key: 'someIban', + description: '', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: true, + defaultValue: '', + // Advanced tab + conditional: { + show: undefined, + when: '', + eq: '', + }, + // Validation tab + validate: { + required: false, + plugins: [], + }, + translatedErrors: {nl: {required: 'Geef email.'}}, + errors: {required: 'Geef email.'}, + // registration tab + registration: { + attribute: '', + }, + // translations tab in builder form + openForms: { + translations: { + nl: {label: 'foo'}, + }, + }, + // fixed but not editable + validateOn: 'blur', +}); + +// validateOn not `blur` +expectNotAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', + validateOn: 'change', +}); + +// invalid, multiple true and non-array default value +expectNotAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', + multiple: true, + defaultValue: '', +}); + +// invalid, multiple false and array default value +expectNotAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', + multiple: false, + defaultValue: [''], +}); + +// invalid, multiple true and wrong default value in array element +expectNotAssignable({ + id: 'yejak', + type: 'iban', + key: 'someIban', + label: 'Some IBAN', + multiple: true, + defaultValue: [0], +});