@unicef-polymer/etools-form-builder 1.0.3 → 2.1.0-rc.1

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.
Files changed (56) hide show
  1. package/dist/form-attachments-popup/form-attachments-popup.d.ts +10 -2
  2. package/dist/form-attachments-popup/form-attachments-popup.js +53 -48
  3. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +0 -5
  4. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +79 -85
  5. package/dist/form-fields/abstract-field-base.class.d.ts +28 -0
  6. package/dist/form-fields/{base-field.js → abstract-field-base.class.js} +133 -112
  7. package/dist/form-fields/custom-elements.define.js +17 -5
  8. package/dist/form-fields/field-renderer-component.d.ts +20 -0
  9. package/dist/form-fields/field-renderer-component.js +245 -0
  10. package/dist/form-fields/index.d.ts +9 -5
  11. package/dist/form-fields/index.js +9 -5
  12. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -0
  13. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +198 -0
  14. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -0
  15. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -0
  16. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -0
  17. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +56 -0
  18. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -0
  19. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +104 -0
  20. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -0
  21. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +43 -0
  22. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -0
  23. package/dist/form-fields/single-fields/attachment-field.js +87 -0
  24. package/dist/form-fields/single-fields/base-field.d.ts +11 -0
  25. package/dist/form-fields/single-fields/base-field.js +57 -0
  26. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -0
  27. package/dist/form-fields/single-fields/boolean-field.js +39 -0
  28. package/dist/form-fields/{number-field.d.ts → single-fields/number-field.d.ts} +1 -0
  29. package/dist/form-fields/{number-field.js → single-fields/number-field.js} +34 -21
  30. package/dist/form-fields/{scale-field.d.ts → single-fields/scale-field.d.ts} +4 -2
  31. package/dist/form-fields/{scale-field.js → single-fields/scale-field.js} +66 -54
  32. package/dist/form-fields/{text-field.d.ts → single-fields/text-field.d.ts} +0 -0
  33. package/dist/form-fields/{text-field.js → single-fields/text-field.js} +26 -21
  34. package/dist/form-fields/wide-field.d.ts +1 -1
  35. package/dist/form-fields/wide-field.js +3 -3
  36. package/dist/form-groups/form-abstract-group.d.ts +12 -12
  37. package/dist/form-groups/form-abstract-group.js +189 -166
  38. package/dist/form-groups/form-card.d.ts +1 -0
  39. package/dist/form-groups/form-card.js +35 -10
  40. package/dist/form-groups/form-collapsed-card.d.ts +3 -1
  41. package/dist/form-groups/form-collapsed-card.js +45 -25
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.js +6 -1
  44. package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -0
  45. package/dist/lib/additional-components/confirmation-dialog.js +61 -0
  46. package/dist/lib/additional-components/etools-fb-card.js +135 -128
  47. package/dist/lib/styles/attachments.styles.js +69 -66
  48. package/dist/lib/styles/form-builder-card.styles.js +46 -41
  49. package/dist/lib/styles/input-styles.js +53 -64
  50. package/dist/lib/styles/page-layout-styles.js +198 -198
  51. package/dist/lib/types/form-builder.interfaces.d.ts +2 -2
  52. package/dist/lib/types/form-builder.types.d.ts +8 -2
  53. package/dist/lib/utils/validations.helper.d.ts +3 -3
  54. package/dist/lib/utils/validations.helper.js +7 -7
  55. package/package.json +53 -52
  56. package/dist/form-fields/base-field.d.ts +0 -20
@@ -7,9 +7,11 @@ export declare type FieldOption = {
7
7
  value: any;
8
8
  label: string;
9
9
  };
10
- export declare class ScaleField extends BaseField<string | null> {
11
- options: FieldOption[];
10
+ export declare class ScaleField extends BaseField<string | number | null> {
11
+ options: (FieldOption | string | number)[];
12
12
  protected controlTemplate(): TemplateResult;
13
+ protected getLabel(option: FieldOption | string | number): unknown;
14
+ protected getValue(option: FieldOption | string | number): unknown;
13
15
  protected onSelect(item: PaperRadioButtonElement): void;
14
16
  protected customValidation(): string | null;
15
17
  static get styles(): CSSResultArray;
@@ -9,34 +9,46 @@ import { BaseField } from './base-field';
9
9
  import { repeat } from 'lit-html/directives/repeat';
10
10
  import '@polymer/paper-radio-group/paper-radio-group';
11
11
  import '@polymer/paper-radio-button/paper-radio-button';
12
- import { InputStyles } from '../lib/styles/input-styles';
12
+ import { InputStyles } from '../../lib/styles/input-styles';
13
13
  export class ScaleField extends BaseField {
14
14
  constructor() {
15
15
  super(...arguments);
16
16
  this.options = [];
17
17
  }
18
18
  controlTemplate() {
19
- return html `
20
- ${InputStyles}
21
- <div class="container">
22
- <paper-radio-group
23
- class="radio-group"
24
- selected="${this.value}"
25
- @iron-select="${({ detail }) => this.onSelect(detail.item)}"
26
- >
27
- ${repeat(this.options, (option) => html `
28
- <paper-radio-button class="radio-button" name="${option.value}"> ${option.label} </paper-radio-button>
29
- `)}
30
- </paper-radio-group>
31
-
32
- <paper-button ?hidden="${this.isReadonly}" @click="${() => this.valueChanged(null)}" class="clear-button">
33
- <iron-icon icon="clear"></iron-icon>Clear
34
- </paper-button>
35
- </div>
19
+ return html `
20
+ ${InputStyles}
21
+ <div class="container">
22
+ <paper-radio-group
23
+ class="radio-group"
24
+ selected="${this.value}"
25
+ @iron-select="${({ detail }) => this.onSelect(detail.item)}"
26
+ >
27
+ ${repeat(this.options, (option) => html `
28
+ <paper-radio-button class="radio-button" name="${this.getValue(option)}">
29
+ ${this.getLabel(option)}
30
+ </paper-radio-button>
31
+ `)}
32
+ </paper-radio-group>
33
+
34
+ <paper-button ?hidden="${this.isReadonly}" @click="${() => this.valueChanged(null)}" class="clear-button">
35
+ <iron-icon icon="clear"></iron-icon>Clear
36
+ </paper-button>
37
+ </div>
38
+ <div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
36
39
  `;
37
40
  }
41
+ getLabel(option) {
42
+ return typeof option === 'object' ? option.label : option;
43
+ }
44
+ getValue(option) {
45
+ return typeof option === 'object' ? option.value : option;
46
+ }
38
47
  onSelect(item) {
39
48
  const newValue = item.get('name');
49
+ if (newValue !== this.value) {
50
+ this.touched = true;
51
+ }
40
52
  this.valueChanged(newValue);
41
53
  }
42
54
  customValidation() {
@@ -46,42 +58,42 @@ export class ScaleField extends BaseField {
46
58
  // language=CSS
47
59
  return [
48
60
  ...BaseField.styles,
49
- css `
50
- .container {
51
- position: relative;
52
- min-height: 48px;
53
- display: flex;
54
- align-items: center;
55
- flex-direction: row;
56
- }
57
-
58
- .radio-group {
59
- display: flex;
60
- flex-direction: row;
61
- flex-wrap: wrap;
62
- }
63
-
64
- :host([is-readonly]) paper-radio-group {
65
- pointer-events: none;
66
- opacity: 0.55;
67
- }
68
-
69
- @media (max-width: 1080px) {
70
- .container {
71
- flex-direction: column;
72
- align-items: flex-start;
73
- }
74
- .radio-group {
75
- flex-direction: column;
76
- }
77
- .radio-button {
78
- padding-left: 3px;
79
- }
80
- .clear-button {
81
- margin: 0;
82
- padding-left: 0;
83
- }
84
- }
61
+ css `
62
+ .container {
63
+ position: relative;
64
+ min-height: 48px;
65
+ display: flex;
66
+ align-items: center;
67
+ flex-direction: row;
68
+ }
69
+
70
+ .radio-group {
71
+ display: flex;
72
+ flex-direction: row;
73
+ flex-wrap: wrap;
74
+ }
75
+
76
+ :host([is-readonly]) paper-radio-group {
77
+ pointer-events: none;
78
+ opacity: 0.55;
79
+ }
80
+
81
+ @media (max-width: 1080px) {
82
+ .container {
83
+ flex-direction: column;
84
+ align-items: flex-start;
85
+ }
86
+ .radio-group {
87
+ flex-direction: column;
88
+ }
89
+ .radio-button {
90
+ padding-left: 3px;
91
+ }
92
+ .clear-button {
93
+ margin: 0;
94
+ padding-left: 0;
95
+ }
96
+ }
85
97
  `
86
98
  ];
87
99
  }
@@ -1,23 +1,25 @@
1
1
  import { css, html } from 'lit-element';
2
2
  import { BaseField } from './base-field';
3
3
  import '@polymer/paper-input/paper-textarea';
4
- import { InputStyles } from '../lib/styles/input-styles';
4
+ import { InputStyles } from '../../lib/styles/input-styles';
5
5
  export class TextField extends BaseField {
6
6
  controlTemplate() {
7
- return html `
8
- ${InputStyles}
9
- <paper-textarea
10
- id="textarea"
11
- class="no-padding-left form-control"
12
- no-label-float
13
- .value="${this.value}"
14
- @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
15
- placeholder="&#8212;"
16
- ?disabled="${this.isReadonly}"
17
- ?invalid="${this.errorMessage}"
18
- error-message="${this.errorMessage}"
19
- >
20
- </paper-textarea>
7
+ return html `
8
+ ${InputStyles}
9
+ <paper-textarea
10
+ id="textarea"
11
+ class="no-padding-left"
12
+ no-label-float
13
+ placeholder="${this.isReadonly ? '—' : this.placeholder}"
14
+ .value="${this.value}"
15
+ @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
16
+ @focus="${() => (this.touched = true)}"
17
+ placeholder="&#8212;"
18
+ ?readonly="${this.isReadonly}"
19
+ ?invalid="${this.errorMessage}"
20
+ error-message="${this.errorMessage}"
21
+ >
22
+ </paper-textarea>
21
23
  `;
22
24
  }
23
25
  customValidation() {
@@ -27,12 +29,15 @@ export class TextField extends BaseField {
27
29
  // language=CSS
28
30
  return [
29
31
  ...BaseField.styles,
30
- css `
31
- @media (max-width: 380px) {
32
- .no-padding-left {
33
- padding-left: 0;
34
- }
35
- }
32
+ css `
33
+ :host(.wide) paper-textarea {
34
+ padding-left: 0;
35
+ }
36
+ @media (max-width: 380px) {
37
+ .no-padding-left {
38
+ padding-left: 0;
39
+ }
40
+ }
36
41
  `
37
42
  ];
38
43
  }
@@ -1,6 +1,6 @@
1
1
  import { TemplateResult, CSSResultArray } from 'lit-element';
2
- import { BaseField } from './base-field';
3
2
  import '@polymer/paper-input/paper-textarea';
3
+ import { BaseField } from './single-fields/base-field';
4
4
  export declare class WideField extends BaseField<string> {
5
5
  label: string;
6
6
  placeholder: string;
@@ -5,9 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html, property } from 'lit-element';
8
- import { BaseField } from './base-field';
9
8
  import '@polymer/paper-input/paper-textarea';
10
9
  import { InputStyles } from '../lib/styles/input-styles';
10
+ import { BaseField } from './single-fields/base-field';
11
11
  export class WideField extends BaseField {
12
12
  constructor() {
13
13
  super(...arguments);
@@ -18,13 +18,13 @@ export class WideField extends BaseField {
18
18
  return html `
19
19
  ${InputStyles}
20
20
  <paper-textarea
21
- class="wide-input disabled-as-readonly form-control"
21
+ class="wide-input"
22
22
  always-float-label
23
23
  .value="${this.value}"
24
24
  label="${this.label}"
25
25
  placeholder="${this.isReadonly ? '—' : this.placeholder}"
26
26
  ?required="${this.required}"
27
- ?disabled="${this.isReadonly}"
27
+ ?readonly="${this.isReadonly}"
28
28
  ?invalid="${this.errorMessage}"
29
29
  error-message="${this.errorMessage}"
30
30
  @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
@@ -1,11 +1,10 @@
1
1
  import { LitElement, TemplateResult, CSSResultArray } from 'lit-element';
2
- import '../form-fields/text-field';
3
- import '../form-fields/number-field';
4
- import '../form-fields/scale-field';
5
- import '../form-fields/wide-field';
2
+ import '../form-fields/single-fields/text-field';
3
+ import '../form-fields/single-fields/number-field';
4
+ import '../form-fields/single-fields/scale-field';
6
5
  import '@polymer/paper-input/paper-textarea';
7
6
  import { IFormBuilderAbstractGroup } from '../lib/types/form-builder.interfaces';
8
- import { BlueprintField, BlueprintGroup, BlueprintMetadata } from '../lib/types/form-builder.types';
7
+ import { BlueprintField, BlueprintGroup, BlueprintMetadata, Information } from '../lib/types/form-builder.types';
9
8
  import { GenericObject } from '../lib/types/global.types';
10
9
  export declare enum FieldTypes {
11
10
  FILE_TYPE = "file",
@@ -47,14 +46,15 @@ export declare class FormAbstractGroup extends LitElement implements IFormBuilde
47
46
  */
48
47
  set errors(errors: GenericObject | string[] | null);
49
48
  render(): TemplateResult;
50
- renderChild(child: BlueprintGroup | BlueprintField): TemplateResult;
49
+ renderChild(child: BlueprintGroup | BlueprintField | Information): TemplateResult | TemplateResult[];
51
50
  renderField(blueprintField: BlueprintField): TemplateResult;
52
- renderWideField({ name, label, placeholder, required, validations }: BlueprintField): TemplateResult;
53
- renderStandardField({ input_type, name, label, help_text, options_key, required, validations }: BlueprintField): TemplateResult;
54
- renderFieldLabel(label: string, helperText: string): TemplateResult;
55
- renderGroup(groupStructure: BlueprintGroup): TemplateResult;
56
- valueChanged(event: CustomEvent, name: string): void;
57
- errorChanged(event: CustomEvent, name: string): void;
51
+ renderInformation(information: Information): TemplateResult;
52
+ renderGroup(groupStructure: BlueprintGroup): TemplateResult | TemplateResult[];
53
+ getGroupTemplate(groupStructure: BlueprintGroup, index?: number): TemplateResult;
54
+ valueChanged(event: CustomEvent, name: string, index?: number): void;
55
+ errorChanged(event: CustomEvent, name: string, index?: number): void;
56
+ addGroup(name: string): void;
57
+ removeGroup(group: BlueprintGroup, index?: number): void;
58
58
  protected getErrorMessage(fieldName: string): string | null;
59
59
  static get styles(): CSSResultArray;
60
60
  }