-
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 #16 from open-formulieren/feature/2-checkbox-types
✨ [#2] Implement types for several components
- Loading branch information
Showing
13 changed files
with
631 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
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,29 @@ | ||
import {JSONObject} from '@/types'; | ||
|
||
import {ComponentTranslations} from './i18n'; | ||
|
||
/** | ||
* @category Utilities | ||
*/ | ||
export interface Option { | ||
value: string; | ||
label: string; | ||
openForms?: { | ||
translations: ComponentTranslations<'label'>; | ||
}; | ||
} | ||
|
||
/** | ||
* @category Utilities | ||
*/ | ||
export interface ManualValues { | ||
dataSrc: 'manual'; | ||
} | ||
|
||
/** | ||
* @category Utilities | ||
*/ | ||
export interface VariableValues { | ||
dataSrc: 'variable'; | ||
itemsExpression: string | JSONObject; | ||
} |
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,16 @@ | ||
import {InputComponentSchema} from '..'; | ||
|
||
type Validator = 'required'; | ||
type TranslatableKeys = 'label' | 'description' | 'tooltip'; | ||
|
||
export type CheckboxInputSchema = InputComponentSchema<boolean, Validator, TranslatableKeys>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Concrete types | ||
*/ | ||
export interface CheckboxComponentSchema | ||
extends Omit<CheckboxInputSchema, 'hideLabel' | 'disabled'> { | ||
type: 'checkbox'; | ||
defaultValue: boolean; | ||
} |
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
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,42 @@ | ||
import {InputComponentSchema} from '..'; | ||
import {OFExtensions} from '../base'; | ||
import {ManualValues, Option, VariableValues} from '../common'; | ||
|
||
type Validator = 'required'; | ||
type TranslatableKeys = 'label' | 'description' | 'tooltip'; | ||
|
||
export type RadioInputSchema = InputComponentSchema<string | null, Validator, TranslatableKeys>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
interface BaseRadioSchema { | ||
type: 'radio'; | ||
defaultValue: string | null; | ||
} | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
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 | ||
* @category Concrete types | ||
*/ | ||
export type RadioComponentSchema = RadioManualValuesSchema | RadioVariableValuesSchema; |
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,48 @@ | ||
import {InputComponentSchema} from '..'; | ||
import {OFExtensions} from '../base'; | ||
import {ManualValues, Option, VariableValues} from '../common'; | ||
|
||
type Validator = 'required'; | ||
type TranslatableKeys = 'label' | 'description' | 'tooltip'; | ||
|
||
export type SelectboxesInputSchema = InputComponentSchema< | ||
Record<string, boolean>, | ||
Validator, | ||
TranslatableKeys | ||
>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
interface BaseSelectboxesSchema { | ||
type: 'selectboxes'; | ||
defaultValue: Record<string, boolean>; | ||
} | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Base types | ||
*/ | ||
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 | ||
* @category Concrete types | ||
*/ | ||
export type SelectboxesComponentSchema = | ||
| SelectboxesManualValuesSchema | ||
| SelectboxesVariableValuesSchema; |
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,4 @@ | ||
export type JSONPrimitive = string | number | boolean | null; | ||
export type JSONValue = JSONPrimitive | JSONObject | JSONArray; | ||
export type JSONObject = {[member: string]: JSONValue}; | ||
export interface JSONArray extends Array<JSONValue> {} |
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,74 @@ | ||
import {expectAssignable, expectNotAssignable} from 'tsd'; | ||
|
||
import {CheckboxComponentSchema} from '../../../lib'; | ||
|
||
// minimal component schema | ||
expectAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
key: 'someCheckbox', | ||
label: 'Some checkbox', | ||
defaultValue: true, | ||
}); | ||
|
||
|
||
// full, correct schema | ||
expectAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
// basic tab | ||
label: 'Some checkbox', | ||
key: 'someCheckbox', | ||
description: '', | ||
tooltip: 'A tooltip', | ||
showInSummary: true, | ||
showInEmail: false, | ||
showInPDF: true, | ||
hidden: false, | ||
clearOnHide: true, | ||
isSensitiveData: true, | ||
defaultValue: false, | ||
// Advanced tab | ||
conditional: { | ||
show: undefined, | ||
when: '', | ||
eq: '', | ||
}, | ||
// Validation tab | ||
validate: { | ||
required: false, | ||
plugins: [], | ||
}, | ||
translatedErrors: {nl: {required: 'Geef checkbox.'}}, | ||
errors: {required: 'Geef checkbox.'}, | ||
// registration tab | ||
registration: { | ||
attribute: '', | ||
}, | ||
// translations tab in builder form | ||
openForms: { | ||
translations: { | ||
nl: {label: 'foo'}, | ||
}, | ||
}, | ||
// fixed but not editable | ||
validateOn: 'blur', | ||
}); | ||
|
||
// multiple not allowed | ||
expectNotAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
key: 'someCheckbox', | ||
label: 'Some checkbox', | ||
multiple: 'dummy', | ||
}); | ||
|
||
// defaultValue not allowed | ||
expectNotAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
key: 'someCheckbox', | ||
label: 'Some checkbox', | ||
defaultValue: [true], | ||
}); |
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
Oops, something went wrong.