Skip to content

Commit

Permalink
✨ [#2] PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Oct 30, 2023
1 parent f1b23b8 commit ce5b7b5
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/formio/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Option {
value: string;
label: string;
openForms?: {
translations: ComponentTranslations;
translations: ComponentTranslations<'label'>;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/formio/components/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export type CheckboxInputSchema = InputComponentSchema<boolean, Validator, Trans
export interface CheckboxComponentSchema
extends Omit<CheckboxInputSchema, 'hideLabel' | 'disabled'> {
type: 'checkbox';
defaultValue?: boolean;
defaultValue: boolean;
multiple?: false;
}
2 changes: 1 addition & 1 deletion src/formio/components/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type EmailInputSchema = InputComponentSchema<string, Validator, Translata
*/
export interface BaseEmailComponentSchema extends Omit<EmailInputSchema, 'hideLabel' | 'disabled'> {
type: 'email';
validateOn?: 'blur';
validateOn: 'blur';
// additional properties
autocomplete?: string;
// OF custom properties
Expand Down
2 changes: 1 addition & 1 deletion src/formio/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export * from './postcode';
export * from './iban';
export * from './licenseplate';
export * from './radio';
export * from './selectboxes';
export * from './number';
export * from './checkbox';
export * from './selectboxes';
export * from './file';
export * from './radio';

// Layout components
export * from './content';
28 changes: 16 additions & 12 deletions src/formio/components/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@ export type RadioInputSchema = InputComponentSchema<string | null, Validator, Tr
* @group Form.io components
* @category Base types
*/
interface RadioManualValuesSchema extends Omit<RadioInputSchema, 'hideLabel' | 'disabled'> {
interface BaseRadioSchema {
type: 'radio';
defaultValue?: string | null;
defaultValue: string | null;
multiple?: false;
// additional properties
openForms: OFExtensions<TranslatableKeys>['openForms'] & ManualValues;
values: Option[];
}

/**
* @group Form.io components
* @category Base types
*/
interface RadioVariableValuesSchema extends Omit<RadioInputSchema, 'hideLabel' | 'disabled'> {
type: 'radio';
defaultValue?: string | null;
multiple?: false;
// additional properties
openForms: OFExtensions<TranslatableKeys>['openForms'] & VariableValues;
}
type RadioManualValuesSchema = Omit<RadioInputSchema, 'hideLabel' | 'disabled'> &
BaseRadioSchema & {
openForms: OFExtensions<TranslatableKeys>['openForms'] & ManualValues;
values: Option[];
};

/**
* @group Form.io components
* @category Base types
*/
type RadioVariableValuesSchema = Omit<RadioInputSchema, 'hideLabel' | 'disabled'> &
BaseRadioSchema & {
openForms: OFExtensions<TranslatableKeys>['openForms'] & VariableValues;
};

/**
* @group Form.io components
Expand Down
30 changes: 16 additions & 14 deletions src/formio/components/selectboxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@ export type SelectboxesInputSchema = InputComponentSchema<
* @group Form.io components
* @category Base types
*/
interface SelectboxesManualValuesSchema
extends Omit<SelectboxesInputSchema, 'hideLabel' | 'disabled'> {
interface BaseSelectboxesSchema {
type: 'selectboxes';
defaultValue?: Record<string, boolean>;
defaultValue: Record<string, boolean>;
multiple?: false;
// additional properties
openForms: OFExtensions<TranslatableKeys>['openForms'] & ManualValues;
values: Option[];
}

/**
* @group Form.io components
* @category Base types
*/
interface SelectboxesVariableValuesSchema
extends Omit<SelectboxesInputSchema, 'hideLabel' | 'disabled'> {
type: 'selectboxes';
defaultValue?: Record<string, boolean>;
multiple?: false;
// additional properties
openForms: OFExtensions<TranslatableKeys>['openForms'] & VariableValues;
}
type SelectboxesManualValuesSchema = Omit<SelectboxesInputSchema, 'hideLabel' | 'disabled'> &
BaseSelectboxesSchema & {
openForms: OFExtensions<TranslatableKeys>['openForms'] & ManualValues;
values: Option[];
};

/**
* @group Form.io components
* @category Base types
*/
type SelectboxesVariableValuesSchema = Omit<SelectboxesInputSchema, 'hideLabel' | 'disabled'> &
BaseSelectboxesSchema & {
openForms: OFExtensions<TranslatableKeys>['openForms'] & VariableValues;
};

/**
* @group Form.io components
Expand Down
1 change: 1 addition & 0 deletions test-d/formio/components/checkbox.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ expectAssignable<CheckboxComponentSchema>({
type: 'checkbox',
key: 'someCheckbox',
label: 'Some checkbox',
defaultValue: true,
});


Expand Down
15 changes: 15 additions & 0 deletions test-d/formio/components/email.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ expectAssignable<EmailComponentSchema>({
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
});

// with additional, email-component specific properties
Expand All @@ -16,6 +17,7 @@ expectAssignable<EmailComponentSchema>({
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
autocomplete: 'email',
confirmationRecipient: false,
});
Expand All @@ -26,6 +28,7 @@ expectAssignable<EmailComponentSchema>({
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
multiple: false,
defaultValue: '',
});
Expand All @@ -36,6 +39,7 @@ expectAssignable<EmailComponentSchema>({
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
multiple: true,
defaultValue: [''],
});
Expand Down Expand Up @@ -95,12 +99,21 @@ expectNotAssignable<EmailComponentSchema>({
validateOn: 'change',
});

// missing validateOn
expectNotAssignable<EmailComponentSchema>({
id: 'yejak',
type: 'email',
key: 'someEmail',
label: 'Some email',
});

// invalid, multiple true and non-array default value
expectNotAssignable<EmailComponentSchema>({
id: 'yejak',
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
multiple: true,
defaultValue: '',
});
Expand All @@ -111,6 +124,7 @@ expectNotAssignable<EmailComponentSchema>({
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
multiple: false,
defaultValue: [''],
});
Expand All @@ -121,6 +135,7 @@ expectNotAssignable<EmailComponentSchema>({
type: 'email',
key: 'someEmail',
label: 'Some email',
validateOn: 'blur',
multiple: true,
defaultValue: [0],
});
37 changes: 34 additions & 3 deletions test-d/formio/components/radio.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ expectAssignable<RadioComponentSchema>({
type: 'radio',
key: 'aRadio',
label: 'A radio',
defaultValue: null,
openForms: {
dataSrc: 'manual',
translations: {},
Expand All @@ -26,9 +27,10 @@ expectAssignable<RadioComponentSchema>({
type: 'radio',
key: 'aRadio',
label: 'A radio',
defaultValue: null,
openForms: {
dataSrc: 'variable',
itemsExpression: 'dummy',
itemsExpression: {var: 'dummy'},
translations: {},
},
});
Expand Down Expand Up @@ -82,10 +84,10 @@ expectAssignable<RadioComponentSchema>({
openForms: {
translations: {
en: {
dummy: 'dummy_en',
label: 'dummy_en',
},
nl: {
dummy_: 'dummy_nl', // TODO this should not be possible
label: 'dummy_nl',
}
}
}
Expand Down Expand Up @@ -198,3 +200,32 @@ expectNotAssignable<RadioComponentSchema>({
translations: {},
},
});

// manual with both itemsExpression and values
expectNotAssignable<RadioComponentSchema>({
id: 'yejak',
type: 'radio',
key: 'aRadio',
label: 'A radio',
openForms: {
dataSrc: 'manual',
itemsExpression: 'dummy',
translations: {},
},
values: [
{
value: 'dummy',
label: 'dummy',
openForms: {
translations: {
en: {
label: 'dummy_en',
},
nl: {
label: 'dummy_nl',
}
}
}
}
]
});
6 changes: 4 additions & 2 deletions test-d/formio/components/selectboxes.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ expectAssignable<SelectboxesComponentSchema>({
type: 'selectboxes',
key: 'someSelectboxes',
label: 'Some selectboxes',
defaultValue: {},
openForms: {
dataSrc: 'manual',
translations: {},
Expand All @@ -26,6 +27,7 @@ expectAssignable<SelectboxesComponentSchema>({
type: 'selectboxes',
key: 'someSelectboxes',
label: 'Some selectboxes',
defaultValue: {},
openForms: {
dataSrc: 'variable',
itemsExpression: 'dummy',
Expand Down Expand Up @@ -67,10 +69,10 @@ expectAssignable<SelectboxesComponentSchema>({
openForms: {
translations: {
en: {
dummy: 'dummy_en',
label: 'dummy_en',
},
nl: {
dummy_: 'dummy_nl', // TODO this should not be possible
label: 'dummy_nl',
}
}
}
Expand Down

0 comments on commit ce5b7b5

Please sign in to comment.