-
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.
✨ [#2] Apply feedback and add
radio
component
- Loading branch information
Showing
12 changed files
with
594 additions
and
9 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,29 @@ | ||
import {JSONObject} from '@/types'; | ||
|
||
import {ComponentTranslations} from './i18n'; | ||
|
||
/** | ||
* @category Utilities | ||
*/ | ||
export interface Option { | ||
value: string; | ||
label: string; | ||
openForms?: { | ||
translations: ComponentTranslations; | ||
}; | ||
} | ||
|
||
/** | ||
* @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
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,39 @@ | ||
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 RadioManualValuesSchema extends Omit<RadioInputSchema, 'hideLabel' | 'disabled'> { | ||
type: 'radio'; | ||
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; | ||
} | ||
|
||
/** | ||
* @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 |
---|---|---|
@@ -1,18 +1,47 @@ | ||
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<string, Validator, TranslatableKeys>; | ||
export type SelectboxesInputSchema = InputComponentSchema< | ||
Record<string, boolean>, | ||
Validator, | ||
TranslatableKeys | ||
>; | ||
|
||
/** | ||
* @group Form.io components | ||
* @category Concrete types | ||
* @category Base types | ||
*/ | ||
export interface SelectboxesComponentSchema | ||
interface SelectboxesManualValuesSchema | ||
extends Omit<SelectboxesInputSchema, 'hideLabel' | 'disabled'> { | ||
type: 'selectboxes'; | ||
// OF custom properties | ||
dataSrc: 'manual' | 'variable'; | ||
itemsExpression?: string; | ||
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; | ||
} | ||
|
||
/** | ||
* @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,84 @@ | ||
import {expectAssignable, expectNotAssignable} from 'tsd'; | ||
|
||
import {CheckboxComponentSchema} from '../../../lib'; | ||
|
||
// minimal component schema | ||
expectAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
key: 'someCheckbox', | ||
label: 'Some checkbox', | ||
}); | ||
|
||
|
||
// multiple false and appropriate default value type | ||
expectAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
key: 'someCheckbox', | ||
label: 'Some checkbox', | ||
multiple: false, | ||
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, | ||
multiple: false, | ||
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 true not allowed | ||
expectNotAssignable<CheckboxComponentSchema>({ | ||
id: 'yejak', | ||
type: 'checkbox', | ||
key: 'someCheckbox', | ||
label: 'Some checkbox', | ||
multiple: true, | ||
}); | ||
|
||
// 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.