-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from open-formulieren/feature/2-plate-iban
✨ [#2] Add `licenseplate` and `iban` component
- Loading branch information
Showing
6 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {InputComponentSchema, MultipleCapable} from '..'; | ||
|
||
type Validator = 'required'; | ||
type TranslatableKeys = 'label' | 'description' | 'tooltip'; | ||
|
||
export type IbanInputSchema = InputComponentSchema<string, Validator, TranslatableKeys>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
export interface BaseIbanComponentSchema extends Omit<IbanInputSchema, 'hideLabel' | 'disabled'> { | ||
type: 'iban'; | ||
validateOn: 'blur'; | ||
} | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Concrete types | ||
*/ | ||
export type IbanComponentSchema = MultipleCapable<BaseIbanComponentSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {InputComponentSchema, MultipleCapable} from '..'; | ||
|
||
type Validator = 'required' | 'pattern'; | ||
type TranslatableKeys = 'label' | 'description' | 'tooltip'; | ||
|
||
export type LicensePlateInputSchema = InputComponentSchema<string, Validator, TranslatableKeys>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
export interface LicensePlateProperties { | ||
type: 'licenseplate'; | ||
validate: { | ||
pattern: '^[a-zA-Z0-9]{1,3}\\-[a-zA-Z0-9]{1,3}\\-[a-zA-Z0-9]{1,3}$'; | ||
}; | ||
validateOn: 'blur'; | ||
} | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
export type BaseLicensePlateComponentSchema = Omit< | ||
LicensePlateInputSchema, | ||
'hideLabel' | 'placeholder' | ||
> & | ||
LicensePlateProperties; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Concrete types | ||
*/ | ||
export type LicensePlateComponentSchema = MultipleCapable<BaseLicensePlateComponentSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import {expectAssignable, expectNotAssignable} from 'tsd'; | ||
|
||
import {IbanComponentSchema} from '../../../lib'; | ||
|
||
// minimal textfield component schema | ||
expectAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'blur', | ||
}); | ||
|
||
|
||
// multiple false and appropriate default value type | ||
expectAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'blur', | ||
multiple: false, | ||
defaultValue: '', | ||
}); | ||
|
||
// multiple true and appropriate default value type | ||
expectAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'blur', | ||
multiple: true, | ||
defaultValue: [''], | ||
}); | ||
|
||
// full, correct schema | ||
expectAssignable<IbanComponentSchema>({ | ||
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 IBAN.'}}, | ||
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<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'change', | ||
}); | ||
|
||
// missing validateOn | ||
expectNotAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
}); | ||
|
||
// invalid, multiple true and non-array default value | ||
expectNotAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'blur', | ||
multiple: true, | ||
defaultValue: '', | ||
}); | ||
|
||
// invalid, multiple false and array default value | ||
expectNotAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'blur', | ||
multiple: false, | ||
defaultValue: [''], | ||
}); | ||
|
||
// invalid, multiple true and wrong default value in array element | ||
expectNotAssignable<IbanComponentSchema>({ | ||
id: 'yejak', | ||
type: 'iban', | ||
key: 'someIban', | ||
label: 'Some IBAN', | ||
validateOn: 'blur', | ||
multiple: true, | ||
defaultValue: [0], | ||
}); |
Oops, something went wrong.