From 31750eb266e040c27f73bf96906fba889901e803 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 10 Nov 2023 16:43:37 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20[#2]=20Implement=20types=20for?= =?UTF-8?q?=20`textarea`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/components/index.ts | 1 + src/formio/components/textarea.ts | 25 +++ src/formio/index.ts | 2 + test-d/formio/components/textarea.test-d.ts | 169 ++++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 src/formio/components/textarea.ts create mode 100644 test-d/formio/components/textarea.test-d.ts diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index a6d591f..363ee35 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -1,5 +1,6 @@ // Input components export * from './textfield'; +export * from './textarea'; export * from './currency'; export * from './email'; export * from './date'; diff --git a/src/formio/components/textarea.ts b/src/formio/components/textarea.ts new file mode 100644 index 0000000..41d98f7 --- /dev/null +++ b/src/formio/components/textarea.ts @@ -0,0 +1,25 @@ +import {InputComponentSchema, MultipleCapable} from '..'; + +type Validator = 'required' | 'maxLength' | 'pattern'; +type TranslatableKeys = 'label' | 'description' | 'tooltip' | 'defaultValue' | 'placeholder'; + +export type TextareaInputSchema = InputComponentSchema; + +/** + * @group Form.io components + * @category Base types + */ +export interface BaseTextareaComponentSchema extends Omit { + type: 'textarea'; + // additional properties + showCharCount?: boolean; + autocomplete?: string; + // OF custom properties + rows: number; +} + +/** + * @group Form.io components + * @category Concrete types + */ +export type TextareaComponentSchema = MultipleCapable; diff --git a/src/formio/index.ts b/src/formio/index.ts index 1ada62f..463e4f2 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -14,6 +14,7 @@ import { RadioComponentSchema, SelectboxesComponentSchema, TextFieldComponentSchema, + TextareaComponentSchema, TimeComponentSchema, } from './components'; @@ -50,6 +51,7 @@ export type AnyComponentSchema = | PhoneNumberComponentSchema | PostcodeComponentSchema | FileComponentSchema + | TextareaComponentSchema | NumberComponentSchema | CheckboxComponentSchema | SelectboxesComponentSchema diff --git a/test-d/formio/components/textarea.test-d.ts b/test-d/formio/components/textarea.test-d.ts new file mode 100644 index 0000000..c03da22 --- /dev/null +++ b/test-d/formio/components/textarea.test-d.ts @@ -0,0 +1,169 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {TextareaComponentSchema} from '../../../lib/'; + +// minimal textarea component schema +expectAssignable({ + id: 'yejak', + type: 'textarea', + key: 'someInput', + label: 'Some input', + rows: 3, +}); + +// multiple false and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'textarea', + key: 'someEmail', + label: 'Some input', + rows: 3, + multiple: false, + defaultValue: '', +}); + +// multiple true and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'textarea', + key: 'someEmail', + label: 'Some input', + rows: 3, + multiple: true, + defaultValue: [''], +}); + +// full, correct schema +expectAssignable({ + id: 'yejak', + type: 'textarea', + // basic tab in builder form + label: 'Some input', + rows: 3, + key: 'someInput', + description: 'A description', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: false, + defaultValue: '', + autocomplete: 'name', + disabled: false, + placeholder: '', + showCharCount: true, + // advanced tab in builder form + conditional: { + show: undefined, + when: undefined, + eq: undefined, + }, + // validation tab in builder form + validate: { + required: false, + plugins: undefined, + maxLength: 20, + pattern: '', + }, + translatedErrors: { + nl: { + required: 'Je moet een waarde opgeven!!!', + maxLength: 'Een maximale lengte.', + }, + }, + errors: { + // translatedErrors is converted into errors by the backend + required: 'Je moet een waarde opgeven!!!', + maxLength: 'Een maximale lengte.', + }, + // registration tab in builder form + registration: { + attribute: '', + }, + // translations tab in builder form + openForms: { + translations: { + nl: { + label: 'foo', + description: 'bar', + }, + }, + }, +}); + +// different component type +expectNotAssignable({ + type: 'fieldset', +}); + +// using unsupported properties +expectNotAssignable({ + id: 'yejak', + type: 'textarea', + key: 'someInput', + label: 'Some input', + rows: 3, + hideLabel: true, +}); + +// incorrect, invalid validator key +expectNotAssignable({ + id: 'yejak', + type: 'textarea', + key: 'someInput', + label: 'Some input', + rows: 3, + validate: { + min: 3, + }, +}); + +// invalid, multiple true and non-array default value +expectNotAssignable({ + id: 'yejak', + type: 'textarea', + key: 'textarea', + label: 'Some textarea', + rows: 3, + multiple: true, + defaultValue: '', +}); + +// invalid, multiple false and array default value +expectNotAssignable({ + id: 'yejak', + type: 'textarea', + key: 'textarea', + label: 'Some textarea', + rows: 3, + multiple: false, + defaultValue: [''], +}); + +// invalid, multiple true and wrong default value in array element +expectNotAssignable({ + id: 'yejak', + type: 'textarea', + key: 'textarea', + label: 'Some textarea', + rows: 3, + multiple: true, + defaultValue: [0], +}); + +// invalid, with prefill +expectNotAssignable({ + id: 'yejak', + type: 'textarea', + key: 'someInput', + label: 'Some input', + prefill: { + plugin: '', + attribute: '', + identifierRole: 'main', + }, + rows: 3, +}); From 651d1fc4c92f4f1a016299b7a98138e3e873c71c Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:30:55 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20[#2]=20PR=20Feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/components/textarea.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/formio/components/textarea.ts b/src/formio/components/textarea.ts index 41d98f7..8777b99 100644 --- a/src/formio/components/textarea.ts +++ b/src/formio/components/textarea.ts @@ -14,8 +14,9 @@ export interface BaseTextareaComponentSchema extends Omit Date: Tue, 14 Nov 2023 17:20:57 +0100 Subject: [PATCH 3/3] [#2] Fix tests --- src/formio/components/textarea.ts | 1 - test-d/formio/components/textarea.test-d.ts | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/formio/components/textarea.ts b/src/formio/components/textarea.ts index 8777b99..c28c4fe 100644 --- a/src/formio/components/textarea.ts +++ b/src/formio/components/textarea.ts @@ -15,7 +15,6 @@ export interface BaseTextareaComponentSchema extends Omit({ key: 'someInput', label: 'Some input', rows: 3, + autoExpand: true, }); // multiple false and appropriate default value type @@ -18,6 +19,7 @@ expectAssignable({ key: 'someEmail', label: 'Some input', rows: 3, + autoExpand: true, multiple: false, defaultValue: '', }); @@ -29,6 +31,7 @@ expectAssignable({ key: 'someEmail', label: 'Some input', rows: 3, + autoExpand: true, multiple: true, defaultValue: [''], }); @@ -40,6 +43,7 @@ expectAssignable({ // basic tab in builder form label: 'Some input', rows: 3, + autoExpand: true, key: 'someInput', description: 'A description', tooltip: 'A tooltip', @@ -106,6 +110,7 @@ expectNotAssignable({ key: 'someInput', label: 'Some input', rows: 3, + autoExpand: true, hideLabel: true, }); @@ -116,6 +121,7 @@ expectNotAssignable({ key: 'someInput', label: 'Some input', rows: 3, + autoExpand: true, validate: { min: 3, }, @@ -128,6 +134,7 @@ expectNotAssignable({ key: 'textarea', label: 'Some textarea', rows: 3, + autoExpand: true, multiple: true, defaultValue: '', }); @@ -139,6 +146,7 @@ expectNotAssignable({ key: 'textarea', label: 'Some textarea', rows: 3, + autoExpand: true, multiple: false, defaultValue: [''], }); @@ -150,6 +158,7 @@ expectNotAssignable({ key: 'textarea', label: 'Some textarea', rows: 3, + autoExpand: true, multiple: true, defaultValue: [0], }); @@ -166,4 +175,5 @@ expectNotAssignable({ identifierRole: 'main', }, rows: 3, + autoExpand: true, });