diff --git a/src/formio/components/currency.ts b/src/formio/components/currency.ts index f3323a6..7fa1bbf 100644 --- a/src/formio/components/currency.ts +++ b/src/formio/components/currency.ts @@ -1,7 +1,7 @@ import {InputComponentSchema, MultipleCapable, PrefillConfig} from '..'; -type Validator = 'required' | 'maxLength' | 'pattern'; -type TranslatableKeys = 'label' | 'description' | 'tooltip' | 'defaultValue' | 'placeholder'; +type Validator = 'required' | 'min' | 'max'; +type TranslatableKeys = 'label' | 'description' | 'tooltip' | 'suffix'; type AvailableCurrencies = | 'USD' | 'EUR' @@ -185,7 +185,7 @@ export interface BaseCurrencyComponentSchema PrefillConfig { type: 'currency'; // additional properties - currency?: AvailableCurrencies; + currency: AvailableCurrencies; decimalLimit?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; allowNegative?: boolean; // re-add diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index 70ba81d..0a24cb1 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -2,6 +2,7 @@ export * from './checkbox'; export * from './textfield'; export * from './email'; +export * from './currency'; export * from './date'; export * from './datetime'; export * from './time'; diff --git a/src/formio/index.ts b/src/formio/index.ts index ca346df..0d82d2f 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -1,6 +1,7 @@ import { CheckboxComponentSchema, ContentComponentSchema, + CurrencyComponentSchema, DateComponentSchema, DateTimeComponentSchema, EmailComponentSchema, @@ -51,6 +52,7 @@ export type AnyComponentSchema = | CheckboxComponentSchema | SelectboxesComponentSchema | RadioComponentSchema + | CurrencyComponentSchema // layout | ContentComponentSchema; diff --git a/test-d/formio/components/currency.test-d.ts b/test-d/formio/components/currency.test-d.ts new file mode 100644 index 0000000..e12bfd0 --- /dev/null +++ b/test-d/formio/components/currency.test-d.ts @@ -0,0 +1,136 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {CurrencyComponentSchema} from '../../../lib/'; + +// minimal currency component schema +expectAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', +} as const); + +// with additional, number-component specific properties +expectAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', + decimalLimit: 3, + allowNegative: true, +} as const); + +// multiple false (implicit) and appropriate default value type +expectAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', + defaultValue: 3, +} as const); + +// different component type +expectNotAssignable({ + type: 'textfield', +} as const); + +// using unsupported properties +expectNotAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', + hideLabel: true, +} as const); + +// no multiple support -> no array defaultValue +expectNotAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', + defaultValue: [], +} as const); + +expectNotAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', + multiple: true, + defaultValue: [], +} as const); + +// invalid, only the number validators may be assignable +expectNotAssignable({ + id: '123', + type: 'currency', + key: 'aCurrency', + label: 'A currency', + currency: 'EUR', + validate: { + maxLength: 100, + }, +} as const); + +// full, correct schema +expectAssignable({ + id: '8aosjaw', + type: 'currency', + // basic tab in builder form + label: 'A sample currency', + currency: 'EUR', + key: 'test', + description: 'Sample description', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + // multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: false, + defaultValue: undefined, + decimalLimit: undefined, + allowNegative: false, + // advanced tab in builder form + conditional: { + show: undefined, + when: undefined, + eq: undefined, + }, + // validation tab in builder form + validate: { + required: false, + plugins: undefined, + min: undefined, + max: undefined, + }, + translatedErrors: { + nl: { + required: 'Je moet een waarde opgeven!!!', + min: 'Je kan niet minder dan 1 dag per week bestaan.', + }, + }, + errors: { + // translatedErrors is converted into errors by the backend + required: 'Je moet een waarde opgeven!!!', + min: 'Je kan niet minder dan 1 dag per week bestaan.', + }, + // registration tab in builder form + registration: { + attribute: '', + }, + // translations tab in builder form + openForms: { + translations: { + nl: {suffix: 'foo', tooltip: 'bar'}, + }, + }, +}); diff --git a/test-d/formio/components/radio.test-d.ts b/test-d/formio/components/radio.test-d.ts index 9c6db78..04d0d7e 100644 --- a/test-d/formio/components/radio.test-d.ts +++ b/test-d/formio/components/radio.test-d.ts @@ -6,8 +6,8 @@ import {RadioComponentSchema} from '../../../lib'; expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'manual', translations: {}, @@ -24,8 +24,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'variable', itemsExpression: 'dummy', @@ -37,8 +37,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: false, defaultValue: 'dummy', openForms: { @@ -52,8 +52,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: false, defaultValue: null, openForms: { @@ -67,8 +67,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: false, defaultValue: 'dummy', openForms: { @@ -98,8 +98,8 @@ expectAssignable({ id: 'yejak', type: 'radio', // basic tab - label: 'Some radio', - key: 'someRadio', + label: 'A radio', + key: 'aRadio', description: '', tooltip: 'A tooltip', showInSummary: true, @@ -143,16 +143,16 @@ expectAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', }); // multiple true not allowed expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: true, openForms: { dataSrc: 'variable', @@ -165,8 +165,8 @@ expectNotAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', defaultValue: [{dummy: true}], openForms: { dataSrc: 'variable', @@ -179,8 +179,8 @@ expectNotAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'manual', translations: {}, @@ -191,8 +191,8 @@ expectNotAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'variable', translations: {},