diff --git a/src/formio/components/bsn.ts b/src/formio/components/bsn.ts new file mode 100644 index 0000000..d0165a5 --- /dev/null +++ b/src/formio/components/bsn.ts @@ -0,0 +1,30 @@ +import {InputComponentSchema, MultipleCapable, PrefillConfig} from '..'; + +type Validator = 'required'; +type TranslatableKeys = 'label' | 'description' | 'tooltip'; + +export type BsnInputSchema = InputComponentSchema; + +/** + * @group Form.io components + * @category Base types + */ +export interface BsnProperties { + type: 'bsn'; + inputMask: '999999999'; + validateOn: 'blur'; +} + +/** + * @group Form.io components + * @category Base types + */ +export type BaseBsnComponentSchema = Omit & + BsnProperties & + PrefillConfig; + +/** + * @group Form.io components + * @category Concrete types + */ +export type BsnComponentSchema = MultipleCapable; diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index a6d591f..66c243e 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -9,6 +9,7 @@ export * from './phonenumber'; export * from './postcode'; export * from './iban'; export * from './licenseplate'; +export * from './bsn'; export * from './number'; export * from './checkbox'; export * from './selectboxes'; diff --git a/src/formio/index.ts b/src/formio/index.ts index 1ada62f..0088779 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -1,4 +1,5 @@ import { + BsnComponentSchema, CheckboxComponentSchema, ContentComponentSchema, CurrencyComponentSchema, @@ -58,6 +59,7 @@ export type AnyComponentSchema = // special types | IbanComponentSchema | LicensePlateComponentSchema + | BsnComponentSchema // layout | ContentComponentSchema; diff --git a/test-d/formio/components/bsn.test-d.ts b/test-d/formio/components/bsn.test-d.ts new file mode 100644 index 0000000..a4e16f5 --- /dev/null +++ b/test-d/formio/components/bsn.test-d.ts @@ -0,0 +1,177 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {BsnComponentSchema} from '../../../lib/'; + +// minimal bsn component schema +expectAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', +}); + +// multiple false and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', + multiple: false, + defaultValue: '123456789', +}); + +// multiple true and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', + multiple: true, + defaultValue: ['123456789'], +}); + +// full, correct schema +expectAssignable({ + id: 'yejak', + type: 'bsn', + validateOn: 'blur', + // basic tab in builder form + label: 'Some input', + inputMask: '999999999', + key: 'someInput', + description: 'A description', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: true, + defaultValue: '', + disabled: false, + // advanced tab in builder form + conditional: { + show: undefined, + when: undefined, + eq: undefined, + }, + // validation tab in builder form + validate: { + required: false, + plugins: [], + }, + translatedErrors: { + nl: { + required: 'Je moet een waarde opgeven!!!', + }, + }, + errors: { + // translatedErrors is converted into errors by the backend + required: 'Je moet een waarde opgeven!!!', + }, + // registration tab in builder form + registration: { + attribute: '', + }, + // prefill tab in builder form + prefill: { + plugin: '', + attribute: '', + identifierRole: 'main', + }, + // translations tab in builder form + openForms: { + translations: { + nl: { + label: 'foo', + description: 'bar', + }, + }, + }, +}); + +// different component type +expectNotAssignable({ + id: 'yejak', + type: 'textfield', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', +} as const); + +// using unsupported properties +expectNotAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', + placeholder: 'no placeholder', +} as const); + +// incorrect, invalid validator key +expectNotAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validate: { + maxLength: 7, + }, + validateOn: 'blur', +} as const); + +// invalid, multiple true and non-array default value +expectNotAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', + multiple: true, + defaultValue: '', +} as const); + +// invalid, multiple false and array default value +expectNotAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', + multiple: false, + defaultValue: [''], +} as const); + +// invalid, multiple true and wrong default value in array element +expectNotAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', + validateOn: 'blur', + multiple: true, + defaultValue: [123], +} as const); + +// missing validateOn +expectNotAssignable({ + id: 'yejak', + type: 'bsn', + key: 'someInput', + label: 'Some input', + inputMask: '999999999', +});