Skip to content

Commit

Permalink
Merge pull request #22 from open-formulieren/feature/2-family-members
Browse files Browse the repository at this point in the history
✨ [#2] Implement types for `npFamilyMembers`
  • Loading branch information
sergei-maertens authored Nov 14, 2023
2 parents e6139c9 + 81ad19a commit 25941ad
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './postcode';
export * from './iban';
export * from './licenseplate';
export * from './bsn';
export * from './npFamilyMembers';
export * from './number';
export * from './select';
export * from './checkbox';
Expand Down
21 changes: 21 additions & 0 deletions src/formio/components/npFamilyMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {InputComponentSchema} from '..';

type Validator = 'required';
type TranslatableKeys = 'label' | 'description' | 'tooltip';

export type NpFamilyMembersInputSchema = InputComponentSchema<
never, // No value whatsoever, done by the backend
Validator,
TranslatableKeys
>;

/**
* @group Form.io components
* @category Concrete types
*/
export interface NpFamilyMembersComponentSchema
extends Omit<NpFamilyMembersInputSchema, 'hideLabel' | 'disabled'> {
type: 'npFamilyMembers';
includePartners: boolean;
includeChildren: boolean;
}
2 changes: 2 additions & 0 deletions src/formio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FileComponentSchema,
IbanComponentSchema,
LicensePlateComponentSchema,
NpFamilyMembersComponentSchema,
NumberComponentSchema,
PhoneNumberComponentSchema,
PostcodeComponentSchema,
Expand Down Expand Up @@ -62,6 +63,7 @@ export type AnyComponentSchema =
| IbanComponentSchema
| LicensePlateComponentSchema
| BsnComponentSchema
| NpFamilyMembersComponentSchema
// layout
| ContentComponentSchema;

Expand Down
100 changes: 100 additions & 0 deletions test-d/formio/components/npFamilyMembers.test-d copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {expectAssignable, expectNotAssignable} from 'tsd';

import {NpFamilyMembersComponentSchema} from '../../../lib/';

// minimal npFamilyMembers component schema
expectAssignable<NpFamilyMembersComponentSchema>({
id: '123',
type: 'npFamilyMembers',
key: 'aFamilyMembers',
label: 'A Family Members',
includeChildren: true,
includePartners: true,
} as const);

// multiple false (implicit) and appropriate default value type
expectAssignable<NpFamilyMembersComponentSchema>({
id: '123',
type: 'npFamilyMembers',
key: 'aFamilyMembers',
label: 'A Family Members',
includeChildren: true,
includePartners: true,
} as const);

// different component type
expectNotAssignable<NpFamilyMembersComponentSchema>({
type: 'textfield',
} as const);

// using unsupported properties
expectNotAssignable<NpFamilyMembersComponentSchema>({
id: '123',
type: 'npFamilyMembers',
key: 'aFamilyMembers',
label: 'A Family Members',
includeChildren: true,
includePartners: true,
hideLabel: true,
} as const);

// No defaultValue allowed
expectNotAssignable<NpFamilyMembersComponentSchema>({
id: '123',
type: 'npFamilyMembers',
key: 'aFamilyMembers',
label: 'A Family Members',
includeChildren: true,
includePartners: true,
defaultValue: 1,
});

// full, correct schema
expectAssignable<NpFamilyMembersComponentSchema>({
id: '8aosjaw',
type: 'npFamilyMembers',
// basic tab in builder form
label: 'A label',
key: 'test',
includeChildren: true,
includePartners: true,
description: 'Sample description',
tooltip: 'A tooltip',
showInSummary: true,
showInEmail: false,
showInPDF: true,
// multiple: false,
hidden: false,
clearOnHide: true,
isSensitiveData: false,
// advanced tab in builder form
conditional: {
show: undefined,
when: undefined,
eq: undefined,
},
// validation tab in builder form
validate: {
required: false,
plugins: undefined,
},
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: '',
},
// translations tab in builder form
openForms: {
translations: {
nl: {tooltip: 'bar'},
},
},
});

0 comments on commit 25941ad

Please sign in to comment.