@unicef-polymer/etools-form-builder 3.0.0-rc.22 → 3.0.0-rc.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,7 +29,8 @@ const translations = {
29
29
  NUMBER_MUST_BE_GREATER_THAN: 'Number must be greater than {0}',
30
30
  NUMBER_MUST_BE_LOWER_THAN: 'Number must be lower than {0}',
31
31
  DOCUMENT_TYPE: 'Document type',
32
- SELECT_DOCUMENT_TYPE: 'Select Document Type'
32
+ SELECT_DOCUMENT_TYPE: 'Select Document Type',
33
+ PLEASE_ANSWER: 'Important: Please provide the answer if available'
33
34
  },
34
35
  fr: {
35
36
  SAVE: 'Sauvegarder',
@@ -61,7 +62,8 @@ const translations = {
61
62
  NUMBER_MUST_BE_GREATER_THAN: 'Le nombre doit être supérieur à {0}',
62
63
  NUMBER_MUST_BE_LOWER_THAN: 'Le nombre doit être inférieur à {0}',
63
64
  DOCUMENT_TYPE: 'Type de document',
64
- SELECT_DOCUMENT_TYPE: 'Sélectionnez le type de document'
65
+ SELECT_DOCUMENT_TYPE: 'Sélectionnez le type de document',
66
+ PLEASE_ANSWER: 'Important : veuillez fournir la réponse si disponible'
65
67
  },
66
68
  ar: {
67
69
  SAVE: 'يحفظ',
@@ -93,7 +95,8 @@ const translations = {
93
95
  NUMBER_MUST_BE_GREATER_THAN: 'يجب أن يكون الرقم أكبر من {0}',
94
96
  NUMBER_MUST_BE_LOWER_THAN: 'يجب أن يكون الرقم أقل من {0}',
95
97
  DOCUMENT_TYPE: 'نوع الوثيقة',
96
- SELECT_DOCUMENT_TYPE: 'حدد نوع المستند'
98
+ SELECT_DOCUMENT_TYPE: 'حدد نوع المستند',
99
+ PLEASE_ANSWER: 'هام: يرجى تقديم الإجابة إذا كانت متوفرة'
97
100
  },
98
101
  es: {
99
102
  SAVE: 'Guardar',
@@ -125,7 +128,8 @@ const translations = {
125
128
  NUMBER_MUST_BE_GREATER_THAN: 'El número debe ser mayor que {0}',
126
129
  NUMBER_MUST_BE_LOWER_THAN: 'El número debe ser inferior a {0}',
127
130
  DOCUMENT_TYPE: 'Tipo de Documento',
128
- SELECT_DOCUMENT_TYPE: 'Seleccionar tipo de documento'
131
+ SELECT_DOCUMENT_TYPE: 'Seleccionar tipo de documento',
132
+ PLEASE_ANSWER: 'Importante: proporcione la respuesta si está disponible.'
129
133
  }
130
134
  };
131
135
  export default translations;
@@ -10,6 +10,7 @@ export declare abstract class AbstractFieldBaseClass<T> extends LitElement {
10
10
  get isReadonly(): boolean;
11
11
  required: boolean;
12
12
  placeholder: string;
13
+ name: string;
13
14
  value: T | null;
14
15
  validators: FieldValidator[];
15
16
  touched: boolean;
@@ -25,6 +25,7 @@ export class AbstractFieldBaseClass extends LitElement {
25
25
  this.questionText = '';
26
26
  this.required = false;
27
27
  this.placeholder = '';
28
+ this.name = '';
28
29
  this.value = null;
29
30
  this.validators = [];
30
31
  this.touched = false;
@@ -190,6 +191,9 @@ __decorate([
190
191
  __decorate([
191
192
  property()
192
193
  ], AbstractFieldBaseClass.prototype, "placeholder", void 0);
194
+ __decorate([
195
+ property()
196
+ ], AbstractFieldBaseClass.prototype, "name", void 0);
193
197
  __decorate([
194
198
  property()
195
199
  ], AbstractFieldBaseClass.prototype, "value", void 0);
@@ -2,9 +2,12 @@ import { CSSResultArray, LitElement, TemplateResult } from 'lit';
2
2
  import { BlueprintField } from '../lib/types/form-builder.types';
3
3
  import { FieldValidator } from '../lib/utils/validations.helper';
4
4
  import { FieldOption } from './single-fields/scale-field';
5
+ import '@unicef-polymer/etools-unicef/src/etools-icons/etools-icon';
6
+ import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js';
5
7
  export declare class FieldRendererComponent extends LitElement {
6
8
  field: BlueprintField;
7
9
  value: any;
10
+ language: string;
8
11
  errorMessage: string | null;
9
12
  validations: FieldValidator[];
10
13
  readonly: boolean;
@@ -13,8 +16,9 @@ export declare class FieldRendererComponent extends LitElement {
13
16
  defaultValue: any;
14
17
  render(): TemplateResult;
15
18
  renderField(blueprintField: BlueprintField): TemplateResult;
16
- renderStandardField({ input_type, label, help_text, required, placeholder, styling }: BlueprintField): TemplateResult;
17
- renderRepeatableField({ input_type, label, help_text, required, placeholder, styling }: BlueprintField): TemplateResult;
18
- renderFieldLabel(label: string, helperText: string): TemplateResult;
19
+ renderStandardField({ input_type, label, help_text, required, placeholder, styling, name }: BlueprintField, isMandatory?: boolean): TemplateResult;
20
+ renderTooltip(isMandatory: boolean): "" | TemplateResult<1>;
21
+ renderRepeatableField({ input_type, label, help_text, required, placeholder, styling }: BlueprintField, isMandatory?: boolean): TemplateResult;
22
+ renderFieldLabel(label: string, helperText: string, isMandatory?: boolean): TemplateResult;
19
23
  static get styles(): CSSResultArray;
20
24
  }
@@ -4,6 +4,9 @@ import { property, customElement } from 'lit/decorators.js';
4
4
  import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
5
5
  import { FieldTypes, StructureTypes } from '../form-groups';
6
6
  import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
7
+ import '@unicef-polymer/etools-unicef/src/etools-icons/etools-icon';
8
+ import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js';
9
+ import { getTranslation } from '../lib/utils/translate';
7
10
  let FieldRendererComponent = class FieldRendererComponent extends LitElement {
8
11
  constructor() {
9
12
  super(...arguments);
@@ -20,19 +23,22 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
20
23
  return this.renderField(this.field);
21
24
  }
22
25
  renderField(blueprintField) {
23
- const additionalClass = blueprintField.styling.includes(StructureTypes.ADDITIONAL)
24
- ? 'additional-field '
25
- : '';
26
+ let additionalClass = blueprintField.styling.includes(StructureTypes.ADDITIONAL)
27
+ ? `additional-field ${blueprintField.name} `
28
+ : `${blueprintField.name} `;
26
29
  const wideClass = blueprintField.styling.includes(StructureTypes.WIDE) ? 'wide-field-container ' : '';
30
+ const mandatoryClass = blueprintField.styling.includes(StructureTypes.MANDATORY_WARNING)
31
+ ? 'mandatory_warning '
32
+ : '';
27
33
  return html `
28
- <div class="${`${additionalClass}${wideClass}finding-container`}">
34
+ <div class="${`${additionalClass}${wideClass}${mandatoryClass}finding-container`}">
29
35
  ${blueprintField.repeatable
30
- ? this.renderRepeatableField(blueprintField)
31
- : this.renderStandardField(blueprintField)}
36
+ ? this.renderRepeatableField(blueprintField, !!mandatoryClass)
37
+ : this.renderStandardField(blueprintField, !!mandatoryClass)}
32
38
  </div>
33
39
  `;
34
40
  }
35
- renderStandardField({ input_type, label, help_text, required, placeholder, styling }) {
41
+ renderStandardField({ input_type, label, help_text, required, placeholder, styling, name }, isMandatory = false) {
36
42
  var _a, _b, _c, _d;
37
43
  const isWide = styling.includes(StructureTypes.WIDE);
38
44
  switch (input_type) {
@@ -43,12 +49,13 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
43
49
  ?is-readonly="${this.readonly}"
44
50
  ?required="${required}"
45
51
  .placeholder="${placeholder}"
52
+ .name="${name}"
46
53
  .value="${this.value}"
47
54
  .validators="${this.validations}"
48
55
  .errorMessage="${this.errorMessage}"
49
56
  .defaultValue="${(_a = this.field) === null || _a === void 0 ? void 0 : _a.default_value}"
50
57
  >
51
- ${this.renderFieldLabel(label, help_text)}
58
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
52
59
  </text-field>
53
60
  `;
54
61
  case FieldTypes.NUMBER_TYPE:
@@ -60,12 +67,13 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
60
67
  ?required="${required}"
61
68
  .placeholder="${placeholder}"
62
69
  .value="${this.value}"
70
+ .name="${name}"
63
71
  .validators="${this.validations}"
64
72
  .errorMessage="${this.errorMessage}"
65
73
  .isInteger="${Boolean(input_type === FieldTypes.NUMBER_INTEGER_TYPE)}"
66
74
  .defaultValue="${(_b = this.field) === null || _b === void 0 ? void 0 : _b.default_value}"
67
75
  >
68
- ${this.renderFieldLabel(label, help_text)}
76
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
69
77
  </number-field>
70
78
  `;
71
79
  case FieldTypes.BOOL_TYPE:
@@ -74,11 +82,12 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
74
82
  ?is-readonly="${this.readonly}"
75
83
  ?required="${required}"
76
84
  .value="${this.value}"
85
+ .name="${name}"
77
86
  .validators="${this.validations}"
78
87
  .errorMessage="${this.errorMessage}"
79
88
  .defaultValue="${(_c = this.field) === null || _c === void 0 ? void 0 : _c.default_value}"
80
89
  >
81
- ${this.renderFieldLabel(label, help_text)}
90
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
82
91
  </boolean-field>
83
92
  `;
84
93
  case FieldTypes.SCALE_TYPE:
@@ -89,11 +98,12 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
89
98
  ?required="${required}"
90
99
  .placeholder="${placeholder}"
91
100
  .value="${this.value}"
101
+ .name="${name}"
92
102
  .validators="${this.validations}"
93
103
  .errorMessage="${this.errorMessage}"
94
104
  .defaultValue="${(_d = this.field) === null || _d === void 0 ? void 0 : _d.default_value}"
95
105
  >
96
- ${this.renderFieldLabel(label, help_text)}
106
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
97
107
  </scale-field>
98
108
  `;
99
109
  case FieldTypes.FILE_TYPE:
@@ -103,11 +113,12 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
103
113
  ?required="${required}"
104
114
  .placeholder="${placeholder}"
105
115
  .value="${this.value}"
116
+ .name="${name}"
106
117
  .validators="${this.validations}"
107
118
  .errorMessage="${this.errorMessage}"
108
119
  .computedPath="${this.computedPath}"
109
120
  >
110
- ${this.renderFieldLabel(label, help_text)}
121
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
111
122
  </attachments-field>
112
123
  `;
113
124
  default:
@@ -115,7 +126,14 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
115
126
  return html ``;
116
127
  }
117
128
  }
118
- renderRepeatableField({ input_type, label, help_text, required, placeholder, styling }) {
129
+ renderTooltip(isMandatory) {
130
+ return isMandatory
131
+ ? html ` <sl-tooltip placement="top" content="${getTranslation(this.language, 'PLEASE_ANSWER')}">
132
+ <etools-icon id="users-icon" name="info-outline"></etools-icon>
133
+ </sl-tooltip>`
134
+ : ``;
135
+ }
136
+ renderRepeatableField({ input_type, label, help_text, required, placeholder, styling }, isMandatory = false) {
119
137
  var _a, _b, _c;
120
138
  const isWide = styling.includes(StructureTypes.WIDE);
121
139
  switch (input_type) {
@@ -131,7 +149,7 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
131
149
  .errorMessage="${this.errorMessage}"
132
150
  .defaultValue="${(_a = this.field) === null || _a === void 0 ? void 0 : _a.default_value}"
133
151
  >
134
- ${this.renderFieldLabel(label, help_text)}
152
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
135
153
  </repeatable-text-field>
136
154
  `;
137
155
  case FieldTypes.NUMBER_TYPE:
@@ -149,7 +167,7 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
149
167
  .isInteger="${Boolean(input_type === FieldTypes.NUMBER_INTEGER_TYPE)}"
150
168
  .defaultValue="${(_b = this.field) === null || _b === void 0 ? void 0 : _b.default_value}"
151
169
  >
152
- ${this.renderFieldLabel(label, help_text)}
170
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
153
171
  </repeatable-number-field>
154
172
  `;
155
173
  case FieldTypes.SCALE_TYPE:
@@ -165,7 +183,7 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
165
183
  .errorMessage="${this.errorMessage}"
166
184
  .defaultValue="${(_c = this.field) === null || _c === void 0 ? void 0 : _c.default_value}"
167
185
  >
168
- ${this.renderFieldLabel(label, help_text)}
186
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
169
187
  </repeatable-scale-field>
170
188
  `;
171
189
  case FieldTypes.FILE_TYPE:
@@ -179,7 +197,7 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
179
197
  .errorMessage="${this.errorMessage}"
180
198
  .computedPath="${this.computedPath}"
181
199
  >
182
- ${this.renderFieldLabel(label, help_text)}
200
+ ${this.renderFieldLabel(label, help_text, isMandatory)}
183
201
  </repeatable-attachments-field>
184
202
  `;
185
203
  default:
@@ -187,10 +205,10 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
187
205
  return html ``;
188
206
  }
189
207
  }
190
- renderFieldLabel(label, helperText) {
208
+ renderFieldLabel(label, helperText, isMandatory = false) {
191
209
  return html `
192
210
  <div class="layout vertical question-container">
193
- <div class="question-text">${label}</div>
211
+ <div class="question-text">${this.renderTooltip(isMandatory)}${label}</div>
194
212
  <div class="question-details">${helperText}</div>
195
213
  </div>
196
214
  `;
@@ -217,7 +235,17 @@ let FieldRendererComponent = class FieldRendererComponent extends LitElement {
217
235
  color: var(--secondary-text-color);
218
236
  font-weight: 400;
219
237
  }
220
-
238
+ .mandatory_warning etools-icon {
239
+ --etools-icon-fill-color: #f59e0b !important;
240
+ }
241
+ :host(:not([readonly])) {
242
+ .overall {
243
+ background-color: #ffffff;
244
+ border-style: inset;
245
+ border-width: 0 1px 1px 1px;
246
+ border-color: var(--dark-divider-color);
247
+ }
248
+ }
221
249
  @media print {
222
250
  :host {
223
251
  break-inside: avoid;
@@ -233,6 +261,9 @@ __decorate([
233
261
  __decorate([
234
262
  property()
235
263
  ], FieldRendererComponent.prototype, "value", void 0);
264
+ __decorate([
265
+ property()
266
+ ], FieldRendererComponent.prototype, "language", void 0);
236
267
  __decorate([
237
268
  property()
238
269
  ], FieldRendererComponent.prototype, "errorMessage", void 0);
@@ -16,6 +16,7 @@ let TextField = class TextField extends BaseField {
16
16
  @focus="${() => (this.touched = true)}"
17
17
  ?readonly="${this.isReadonly}"
18
18
  ?invalid="${this.errorMessage}"
19
+ name="${this.name}"
19
20
  error-message="${this.errorMessage}"
20
21
  >
21
22
  </etools-textarea>
@@ -21,7 +21,8 @@ export declare enum StructureTypes {
21
21
  CARD = "card",
22
22
  ABSTRACT = "abstract",
23
23
  COLLAPSED = "collapse",
24
- ATTACHMENTS_BUTTON = "floating_attachments"
24
+ ATTACHMENTS_BUTTON = "floating_attachments",
25
+ MANDATORY_WARNING = "mandatory_warning"
25
26
  }
26
27
  export declare class FormAbstractGroup extends LitElement implements IFormBuilderAbstractGroup {
27
28
  groupStructure: BlueprintGroup;
@@ -34,6 +34,7 @@ export var StructureTypes;
34
34
  StructureTypes["ABSTRACT"] = "abstract";
35
35
  StructureTypes["COLLAPSED"] = "collapse";
36
36
  StructureTypes["ATTACHMENTS_BUTTON"] = "floating_attachments";
37
+ StructureTypes["MANDATORY_WARNING"] = "mandatory_warning";
37
38
  })(StructureTypes || (StructureTypes = {}));
38
39
  let FormAbstractGroup = class FormAbstractGroup extends LitElement {
39
40
  /**
@@ -133,6 +134,7 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
133
134
  return html `
134
135
  <field-renderer
135
136
  .field="${blueprintField}"
137
+ .language="${this.language}"
136
138
  ?readonly="${live(this.isReadonly())}"
137
139
  .value="${this.value && this.value[blueprintField.name]}"
138
140
  .validations="${blueprintField.validations.map((validation) => this.metadata.validations[validation])}"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unicef-polymer/etools-form-builder",
3
3
  "description": "Etools FM Form Builder components",
4
- "version": "3.0.0-rc.22",
4
+ "version": "3.0.0-rc.24",
5
5
  "contributors": [
6
6
  "eTools Team"
7
7
  ],
@@ -38,7 +38,7 @@
38
38
  "@unicef-polymer/etools-unicef": ">=1.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@unicef-polymer/etools-unicef": "^1.0.0-rc.80",
41
+ "@unicef-polymer/etools-unicef": "^1.0.0-rc.64",
42
42
  "@typescript-eslint/eslint-plugin": "^5.7.0",
43
43
  "@typescript-eslint/parser": "^5.7.0",
44
44
  "@typescript-eslint/typescript-estree": "^5.7.0",