diff --git a/packages/evolution-generator/README.md b/packages/evolution-generator/README.md index 7acb0141..11927354 100644 --- a/packages/evolution-generator/README.md +++ b/packages/evolution-generator/README.md @@ -145,7 +145,7 @@ Widgets are the building blocks of your survey. They define the structure and in | [inputRange](#range) | Input range name for InputRange (optional) | string? | | comments | Additional comments for the question (optional) | string? | -> **Note:** The `inputType` field specifies the type of input for the question and can be one of the following: Checkbox, Custom, NextButton, Number, Radio, Range, String, Text, or TextArea. +> **Note:** The `inputType` field specifies the type of input for the question and can be one of the following: Custom, Radio, Select, String, Number, InfoText, Range, Checkbox, NextButton, or Text > **Note:** The `conditional` field allows you to define conditional logic for displaying the widget based on other responses. For example, you can specify a condition like `nbPersonnesSeptPlusConditional` to show the widget only if the number of people is 7 or more. diff --git a/packages/evolution-generator/src/common/defaultInputBase.tsx b/packages/evolution-generator/src/common/defaultInputBase.tsx index 83d65dbd..99b8103c 100644 --- a/packages/evolution-generator/src/common/defaultInputBase.tsx +++ b/packages/evolution-generator/src/common/defaultInputBase.tsx @@ -49,8 +49,8 @@ export const inputNumberBase: inputTypes.InputStringBase = { numericKeyboard: true }; -// Text default params -export const inputTextBase: inputTypes.InputTextBase = { +// InfoText default params +export const infoTextBase: inputTypes.InfoTextBase = { type: 'text', containsHtml: true }; @@ -96,8 +96,8 @@ export const buttonNextBase: inputTypes.InputButtonBase = { action: surveyHelper.validateButtonActionWithCompleteSection }; -// TextArea default params -export const textAreaBase: inputTypes.TextAreaBase = { +// Text textarea default params +export const textBase: inputTypes.TextBase = { type: 'question', inputType: 'text', datatype: 'text', diff --git a/packages/evolution-generator/src/scripts/generate_widgets.py b/packages/evolution-generator/src/scripts/generate_widgets.py index 4ee6364e..9df1dd5d 100644 --- a/packages/evolution-generator/src/scripts/generate_widgets.py +++ b/packages/evolution-generator/src/scripts/generate_widgets.py @@ -109,16 +109,16 @@ def generate_widget_statement(row): widget = generate_string_widget(question_name, section, path, help_popup, conditional, validation) elif input_type == 'Number': widget = generate_number_widget(question_name, section, path, help_popup, conditional, validation) - elif input_type == 'Text': - widget = generate_text_widget(question_name, section, path, conditional) + elif input_type == 'InfoText': + widget = generate_info_text_widget(question_name, section, path, conditional) elif input_type == 'Range': widget = generate_range_widget(question_name, section, path, input_range, conditional, validation) elif input_type == 'Checkbox': widget = generate_checkbox_widget(question_name, section, path, choices, help_popup, conditional, validation) elif input_type == 'NextButton': widget = generate_next_button_widget(question_name, section, path) - elif input_type == 'TextArea': - widget = generate_text_area_widget(question_name, section, path, conditional, validation) + elif input_type == 'Text': + widget = generate_text_widget(question_name, section, path, conditional, validation) else: widget = f"// {question_name}" @@ -232,11 +232,10 @@ def generate_number_widget(question_name, section, path, help_popup, conditional f"{generate_validation(validation)}\n" \ f"}};" -# Generate Text widget -def generate_text_widget(question_name, section, path, conditional): - return f"{generate_constExport(question_name, 'InputText')}\n" \ - f"{generate_defaultInputBase('inputTextBase')},\n" \ - f"{generate_path(path)},\n" \ +# Generate InfoText widget +def generate_info_text_widget(question_name, section, path, conditional): + return f"{generate_constExport(question_name, 'InfoText')}\n" \ + f"{generate_defaultInputBase('infoTextBase')},\n" \ f"{generate_text(section, path)},\n" \ f"{generate_conditional(conditional)}\n" \ f"}};" @@ -272,10 +271,10 @@ def generate_next_button_widget(question_name, section, path): f"{generate_label(section, path)}\n" \ f"}};" -# Generate TextArea widget -def generate_text_area_widget(question_name, section, path, conditional, validation): - return f"{generate_constExport(question_name, 'TextArea')}\n" \ - f"{generate_defaultInputBase('textAreaBase')},\n" \ +# Generate Text textarea widget +def generate_text_widget(question_name, section, path, conditional, validation): + return f"{generate_constExport(question_name, 'Text')}\n" \ + f"{generate_defaultInputBase('textBase')},\n" \ f"{generate_path(path)},\n" \ f"{generate_label(section, path)},\n" \ f"{generate_conditional(conditional)},\n" \ diff --git a/packages/evolution-generator/src/types/inputTypes.ts b/packages/evolution-generator/src/types/inputTypes.ts index d619e667..a2895a64 100644 --- a/packages/evolution-generator/src/types/inputTypes.ts +++ b/packages/evolution-generator/src/types/inputTypes.ts @@ -15,12 +15,13 @@ type Multiple = boolean; type Columns = 1 | 2; type Path = string; type Placeholder = string; +type Align = 'left' | 'right' | 'center'; type Title = { fr: string; en: string }; -type Text = (t: TFunction) => string; export type InputFilter = (value) => string | number; type LabelFunction = (t: TFunction, interview?, path?) => string; type LabelNotFunction = { en: string | ((interview?, path?) => string); fr: string | ((interview?, path?) => string) }; type Label = LabelFunction | LabelNotFunction; +type TextKey = LabelFunction | LabelNotFunction; export type Labels = { fr: string; en: string; @@ -108,14 +109,14 @@ export type InputString = InputStringBase & { textTransform?: 'uppercase' | 'lowercase' | 'capitalize'; }; -/* InputText widgetConfig Type */ -export type InputTextBase = { +/* Text widgetConfig Type */ +export type InfoTextBase = { type: 'text'; + align?: Align; containsHtml: ContainsHtml; }; -export type InputText = InputTextBase & { - path: Path; - text: Text; +export type InfoText = InfoTextBase & { + text: TextKey; conditional: Conditional; }; @@ -199,7 +200,7 @@ export type InputButtonBase = { color: 'green'; hideWhenRefreshing: boolean; icon: any; // icon: IconDefinition; - align: 'left' | 'right' | 'center'; + align: Align; action: () => void; }; export type InputButton = InputButtonBase & { @@ -216,15 +217,15 @@ export type InputButton = InputButtonBase & { saveCallback?: () => void; }; -/* InputText textArea widgetConfig Type */ -export type TextAreaBase = { +/* InputText widgetConfig Type */ +export type TextBase = { type: 'question'; inputType: 'text'; datatype: 'text'; containsHtml?: ContainsHtml; twoColumns: false; }; -export type TextArea = TextAreaBase & { +export type Text = TextBase & { path: Path; label: Label; conditional: Conditional; @@ -255,7 +256,7 @@ export type InputMapFindPlaceBase = { defaultCenter: { lat: number; lon: number }; refreshGeocodingLabel: Label; showSearchPlaceButton: (interview?, path?) => boolean; - afterRefreshButtonText: Text; + afterRefreshButtonText: TextKey; validations?: Validations; }; export type InputMapFindPlace = InputMapFindPlaceBase & {