@unicef-polymer/etools-form-builder 2.1.8 → 3.0.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 (87) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +1 -1
  3. package/dist/assets/translations.d.ts +6 -6
  4. package/dist/assets/translations.js +67 -67
  5. package/dist/form-attachments-popup/form-attachments-popup.d.ts +84 -86
  6. package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
  7. package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
  8. package/dist/form-attachments-popup/form-attachments-popup.js +249 -255
  9. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +7 -3
  10. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +102 -91
  11. package/dist/form-attachments-popup/index.d.ts +2 -2
  12. package/dist/form-attachments-popup/index.js +2 -2
  13. package/dist/form-fields/abstract-field-base.class.d.ts +33 -33
  14. package/dist/form-fields/abstract-field-base.class.js +209 -213
  15. package/dist/form-fields/field-renderer-component.d.ts +20 -20
  16. package/dist/form-fields/field-renderer-component.js +251 -255
  17. package/dist/form-fields/index.d.ts +12 -12
  18. package/dist/form-fields/index.js +12 -12
  19. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +19 -17
  20. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +212 -209
  21. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +21 -20
  22. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +121 -124
  23. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
  24. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +63 -67
  25. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
  26. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +106 -108
  27. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
  28. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +49 -53
  29. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
  30. package/dist/form-fields/single-fields/attachment-field.js +94 -98
  31. package/dist/form-fields/single-fields/base-field.d.ts +11 -11
  32. package/dist/form-fields/single-fields/base-field.js +53 -58
  33. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
  34. package/dist/form-fields/single-fields/boolean-field.js +45 -49
  35. package/dist/form-fields/single-fields/number-field.d.ts +10 -10
  36. package/dist/form-fields/single-fields/number-field.js +63 -67
  37. package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
  38. package/dist/form-fields/single-fields/scale-field.js +109 -108
  39. package/dist/form-fields/single-fields/text-field.d.ts +8 -8
  40. package/dist/form-fields/single-fields/text-field.js +49 -54
  41. package/dist/form-groups/form-abstract-group.d.ts +71 -71
  42. package/dist/form-groups/form-abstract-group.js +396 -398
  43. package/dist/form-groups/form-card.d.ts +35 -32
  44. package/dist/form-groups/form-card.js +115 -113
  45. package/dist/form-groups/form-collapsed-card.d.ts +72 -71
  46. package/dist/form-groups/form-collapsed-card.js +261 -259
  47. package/dist/form-groups/index.d.ts +3 -3
  48. package/dist/form-groups/index.js +3 -3
  49. package/dist/index.d.ts +3 -3
  50. package/dist/index.js +3 -3
  51. package/dist/lib/additional-components/confirmation-dialog.d.ts +18 -18
  52. package/dist/lib/additional-components/confirmation-dialog.js +68 -72
  53. package/dist/lib/additional-components/etools-fb-card.d.ts +21 -21
  54. package/dist/lib/additional-components/etools-fb-card.js +242 -239
  55. package/dist/lib/styles/attachments.styles.d.ts +2 -2
  56. package/dist/lib/styles/attachments.styles.js +72 -72
  57. package/dist/lib/styles/card-styles.d.ts +2 -2
  58. package/dist/lib/styles/card-styles.js +154 -154
  59. package/dist/lib/styles/dialog.styles.d.ts +2 -2
  60. package/dist/lib/styles/dialog.styles.js +85 -85
  61. package/dist/lib/styles/elevation-styles.d.ts +9 -9
  62. package/dist/lib/styles/elevation-styles.js +43 -43
  63. package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
  64. package/dist/lib/styles/flex-layout-classes.js +319 -319
  65. package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
  66. package/dist/lib/styles/form-builder-card.styles.js +49 -49
  67. package/dist/lib/styles/input-styles.d.ts +2 -2
  68. package/dist/lib/styles/input-styles.js +138 -138
  69. package/dist/lib/styles/page-layout-styles.d.ts +2 -2
  70. package/dist/lib/styles/page-layout-styles.js +201 -201
  71. package/dist/lib/styles/shared-styles.d.ts +2 -2
  72. package/dist/lib/styles/shared-styles.js +70 -70
  73. package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
  74. package/dist/lib/types/form-builder.interfaces.js +1 -0
  75. package/dist/lib/types/form-builder.types.d.ts +59 -59
  76. package/dist/lib/types/form-builder.types.js +1 -0
  77. package/dist/lib/types/global.types.d.ts +4 -4
  78. package/dist/lib/types/global.types.js +1 -0
  79. package/dist/lib/utils/dialog.d.ts +10 -10
  80. package/dist/lib/utils/dialog.js +21 -21
  81. package/dist/lib/utils/fire-custom-event.d.ts +1 -1
  82. package/dist/lib/utils/fire-custom-event.js +7 -7
  83. package/dist/lib/utils/translate.d.ts +1 -1
  84. package/dist/lib/utils/translate.js +9 -9
  85. package/dist/lib/utils/validations.helper.d.ts +26 -26
  86. package/dist/lib/utils/validations.helper.js +42 -42
  87. package/package.json +51 -56
@@ -1,58 +1,53 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { property } from 'lit-element';
8
- import { fireEvent } from '../../lib/utils/fire-custom-event';
9
- import { AbstractFieldBaseClass } from '../abstract-field-base.class';
10
- import { getTranslation } from '../../lib/utils/translate';
11
- export class BaseField extends AbstractFieldBaseClass {
12
- constructor() {
13
- super(...arguments);
14
- this._errorMessage = null;
15
- }
16
- set errorMessage(message) {
17
- this._errorMessage = message;
18
- }
19
- get errorMessage() {
20
- return this.isReadonly ? null : this._errorMessage;
21
- }
22
- valueChanged(newValue) {
23
- if (!newValue && this.value === undefined) {
24
- return;
25
- }
26
- if (!this.isReadonly && newValue !== this.value && this.touched) {
27
- this.validateField(newValue);
28
- }
29
- else if (this.isReadonly || !this.touched) {
30
- this._errorMessage = null;
31
- }
32
- if (newValue !== this.value) {
33
- this.value = newValue;
34
- fireEvent(this, 'value-changed', { value: newValue });
35
- }
36
- }
37
- setValue(newValue) {
38
- this.value = newValue;
39
- fireEvent(this, 'value-changed', { value: newValue });
40
- }
41
- validateField(value) {
42
- let errorMessage;
43
- if (this.required && !value && typeof value !== 'number') {
44
- errorMessage = getTranslation(this.language, 'REQUIRED_FIELD');
45
- }
46
- else {
47
- errorMessage = this.metaValidation(value);
48
- }
49
- if (this._errorMessage !== errorMessage) {
50
- fireEvent(this, 'error-changed', { error: errorMessage });
51
- this._errorMessage = errorMessage;
52
- this.requestUpdate();
53
- }
54
- }
55
- }
56
- __decorate([
57
- property()
58
- ], BaseField.prototype, "_errorMessage", void 0);
1
+ import { __decorate } from "tslib";
2
+ import { property } from 'lit/decorators.js';
3
+ import { fireEvent } from '../../lib/utils/fire-custom-event';
4
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
5
+ import { getTranslation } from '../../lib/utils/translate';
6
+ export class BaseField extends AbstractFieldBaseClass {
7
+ constructor() {
8
+ super(...arguments);
9
+ this._errorMessage = null;
10
+ }
11
+ set errorMessage(message) {
12
+ this._errorMessage = message;
13
+ }
14
+ get errorMessage() {
15
+ return this.isReadonly ? null : this._errorMessage;
16
+ }
17
+ valueChanged(newValue) {
18
+ if (!newValue && this.value === undefined) {
19
+ return;
20
+ }
21
+ if (!this.isReadonly && newValue !== this.value && this.touched) {
22
+ this.validateField(newValue);
23
+ }
24
+ else if (this.isReadonly || !this.touched) {
25
+ this._errorMessage = null;
26
+ }
27
+ if (newValue !== this.value) {
28
+ this.value = newValue;
29
+ fireEvent(this, 'value-changed', { value: newValue });
30
+ }
31
+ }
32
+ setValue(newValue) {
33
+ this.value = newValue;
34
+ fireEvent(this, 'value-changed', { value: newValue });
35
+ }
36
+ validateField(value) {
37
+ let errorMessage;
38
+ if (this.required && !value && typeof value !== 'number') {
39
+ errorMessage = getTranslation(this.language, 'REQUIRED_FIELD');
40
+ }
41
+ else {
42
+ errorMessage = this.metaValidation(value);
43
+ }
44
+ if (this._errorMessage !== errorMessage) {
45
+ fireEvent(this, 'error-changed', { error: errorMessage });
46
+ this._errorMessage = errorMessage;
47
+ this.requestUpdate();
48
+ }
49
+ }
50
+ }
51
+ __decorate([
52
+ property()
53
+ ], BaseField.prototype, "_errorMessage", void 0);
@@ -1,8 +1,8 @@
1
- import { CSSResultArray, TemplateResult } from 'lit-element';
2
- import { BaseField } from './base-field';
3
- import '@polymer/paper-toggle-button';
4
- export declare class BooleanField extends BaseField<boolean> {
5
- protected controlTemplate(): TemplateResult;
6
- protected customValidation(): string | null;
7
- static get styles(): CSSResultArray;
8
- }
1
+ import { CSSResultArray, TemplateResult } from 'lit';
2
+ import { BaseField } from './base-field';
3
+ import '@shoelace-style/shoelace/dist/components/switch/switch.js';
4
+ export declare class BooleanField extends BaseField<boolean> {
5
+ protected controlTemplate(): TemplateResult;
6
+ protected customValidation(): string | null;
7
+ static get styles(): CSSResultArray;
8
+ }
@@ -1,49 +1,45 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { css, customElement, html } from 'lit-element';
8
- import { BaseField } from './base-field';
9
- import '@polymer/paper-toggle-button';
10
- import { InputStyles } from '../../lib/styles/input-styles';
11
- let BooleanField = class BooleanField extends BaseField {
12
- controlTemplate() {
13
- return html `
14
- ${InputStyles}
15
- <paper-toggle-button
16
- class="no-padding-left"
17
- ?checked="${this.value}"
18
- @iron-change="${(event) => this.valueChanged(event.currentTarget.checked)}"
19
- ?disabled="${this.isReadonly}"
20
- >
21
- </paper-toggle-button>
22
-
23
- <div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
24
- `;
25
- }
26
- customValidation() {
27
- return null;
28
- }
29
- static get styles() {
30
- // language=CSS
31
- return [
32
- ...BaseField.styles,
33
- css `
34
- :host(.wide) paper-textarea {
35
- padding-left: 0;
36
- }
37
- @media (max-width: 380px) {
38
- .no-padding-left {
39
- padding-left: 0;
40
- }
41
- }
42
- `
43
- ];
44
- }
45
- };
46
- BooleanField = __decorate([
47
- customElement('boolean-field')
48
- ], BooleanField);
49
- export { BooleanField };
1
+ import { __decorate } from "tslib";
2
+ import { css, html } from 'lit';
3
+ import { customElement } from 'lit/decorators.js';
4
+ import { BaseField } from './base-field';
5
+ import { InputStyles } from '../../lib/styles/input-styles';
6
+ import '@shoelace-style/shoelace/dist/components/switch/switch.js';
7
+ let BooleanField = class BooleanField extends BaseField {
8
+ controlTemplate() {
9
+ return html `
10
+ ${InputStyles}
11
+ <sl-switch
12
+ class="no-padding-left"
13
+ ?checked="${this.value}"
14
+ @sl-change="${(e) => this.valueChanged(e.target.checked)}"
15
+ ?disabled="${this.isReadonly}"
16
+ >
17
+ </sl-switch>
18
+
19
+ <div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
20
+ `;
21
+ }
22
+ customValidation() {
23
+ return null;
24
+ }
25
+ static get styles() {
26
+ // language=CSS
27
+ return [
28
+ ...BaseField.styles,
29
+ css `
30
+ :host(.wide) paper-textarea {
31
+ padding-left: 0;
32
+ }
33
+ @media (max-width: 380px) {
34
+ .no-padding-left {
35
+ padding-left: 0;
36
+ }
37
+ }
38
+ `
39
+ ];
40
+ }
41
+ };
42
+ BooleanField = __decorate([
43
+ customElement('boolean-field')
44
+ ], BooleanField);
45
+ export { BooleanField };
@@ -1,10 +1,10 @@
1
- import { CSSResultArray, TemplateResult } from 'lit-element';
2
- import { BaseField } from './base-field';
3
- import '@polymer/paper-input/paper-input';
4
- export declare class NumberField extends BaseField<number> {
5
- isInteger: boolean;
6
- protected controlTemplate(): TemplateResult;
7
- protected valueChanged(newValue: number): void;
8
- protected customValidation(value: number): string | null;
9
- static get styles(): CSSResultArray;
10
- }
1
+ import { CSSResultArray, TemplateResult } from 'lit';
2
+ import { BaseField } from './base-field';
3
+ import '@unicef-polymer/etools-unicef/src/etools-input/etools-input';
4
+ export declare class NumberField extends BaseField<number> {
5
+ isInteger: boolean;
6
+ protected controlTemplate(): TemplateResult;
7
+ protected valueChanged(newValue: number): void;
8
+ protected customValidation(value: number): string | null;
9
+ static get styles(): CSSResultArray;
10
+ }
@@ -1,67 +1,63 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { css, customElement, html } from 'lit-element';
8
- import { BaseField } from './base-field';
9
- import '@polymer/paper-input/paper-input';
10
- import { InputStyles } from '../../lib/styles/input-styles';
11
- import { getTranslation } from '../../lib/utils/translate';
12
- let NumberField = class NumberField extends BaseField {
13
- constructor() {
14
- super(...arguments);
15
- this.isInteger = false;
16
- }
17
- controlTemplate() {
18
- return html `
19
- ${InputStyles}
20
- <paper-input
21
- class="no-padding-left"
22
- no-label-float
23
- placeholder="${this.isReadonly ? '—' : this.placeholder}"
24
- .value="${this.value}"
25
- @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
26
- @focus="${() => (this.touched = true)}"
27
- placeholder="&#8212;"
28
- ?invalid="${this.errorMessage}"
29
- error-message="${this.errorMessage}"
30
- ?readonly="${this.isReadonly}"
31
- >
32
- </paper-input>
33
- `;
34
- }
35
- valueChanged(newValue) {
36
- const formatted = Number(newValue);
37
- const isNumber = !isNaN(formatted) && `${newValue}` !== '' && `${newValue}` !== 'null';
38
- super.valueChanged(isNumber ? formatted : newValue);
39
- }
40
- customValidation(value) {
41
- if (!value) {
42
- return null;
43
- }
44
- if (isNaN(value)) {
45
- return 'Must be a number';
46
- }
47
- const integerValidation = !this.isInteger || value - Math.floor(value) === 0;
48
- return integerValidation ? null : getTranslation(this.language, 'MUST_BE_INTEGER');
49
- }
50
- static get styles() {
51
- // language=CSS
52
- return [
53
- ...BaseField.styles,
54
- css `
55
- @media (max-width: 380px) {
56
- .no-padding-left {
57
- padding-left: 0;
58
- }
59
- }
60
- `
61
- ];
62
- }
63
- };
64
- NumberField = __decorate([
65
- customElement('number-field')
66
- ], NumberField);
67
- export { NumberField };
1
+ import { __decorate } from "tslib";
2
+ import { css, html } from 'lit';
3
+ import { customElement } from 'lit/decorators.js';
4
+ import { BaseField } from './base-field';
5
+ import '@unicef-polymer/etools-unicef/src/etools-input/etools-input';
6
+ import { InputStyles } from '../../lib/styles/input-styles';
7
+ import { getTranslation } from '../../lib/utils/translate';
8
+ let NumberField = class NumberField extends BaseField {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.isInteger = false;
12
+ }
13
+ controlTemplate() {
14
+ return html `
15
+ ${InputStyles}
16
+ <etools-input
17
+ class="no-padding-left"
18
+ no-label-float
19
+ placeholder="${this.isReadonly ? '—' : this.placeholder}"
20
+ .value="${this.value}"
21
+ @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
22
+ @focus="${() => (this.touched = true)}"
23
+ placeholder="&#8212;"
24
+ ?invalid="${this.errorMessage}"
25
+ error-message="${this.errorMessage}"
26
+ ?readonly="${this.isReadonly}"
27
+ >
28
+ </etools-input>
29
+ `;
30
+ }
31
+ valueChanged(newValue) {
32
+ const formatted = Number(newValue);
33
+ const isNumber = !isNaN(formatted) && `${newValue}` !== '' && `${newValue}` !== 'null';
34
+ super.valueChanged(isNumber ? formatted : newValue);
35
+ }
36
+ customValidation(value) {
37
+ if (!value) {
38
+ return null;
39
+ }
40
+ if (isNaN(value)) {
41
+ return 'Must be a number';
42
+ }
43
+ const integerValidation = !this.isInteger || value - Math.floor(value) === 0;
44
+ return integerValidation ? null : getTranslation(this.language, 'MUST_BE_INTEGER');
45
+ }
46
+ static get styles() {
47
+ // language=CSS
48
+ return [
49
+ ...BaseField.styles,
50
+ css `
51
+ @media (max-width: 380px) {
52
+ .no-padding-left {
53
+ padding-left: 0;
54
+ }
55
+ }
56
+ `
57
+ ];
58
+ }
59
+ };
60
+ NumberField = __decorate([
61
+ customElement('number-field')
62
+ ], NumberField);
63
+ export { NumberField };
@@ -1,18 +1,18 @@
1
- import { TemplateResult, CSSResultArray } from 'lit-element';
2
- import { BaseField } from './base-field';
3
- import '@polymer/paper-radio-group/paper-radio-group';
4
- import '@polymer/paper-radio-button/paper-radio-button';
5
- import { PaperRadioButtonElement } from '@polymer/paper-radio-button/paper-radio-button';
6
- export declare type FieldOption = {
7
- value: any;
8
- label: string;
9
- };
10
- export declare class ScaleField extends BaseField<string | number | null> {
11
- options: (FieldOption | string | number)[];
12
- protected controlTemplate(): TemplateResult;
13
- protected getLabel(option: FieldOption | string | number): unknown;
14
- protected getValue(option: FieldOption | string | number): unknown;
15
- protected onSelect(item: PaperRadioButtonElement): void;
16
- protected customValidation(): string | null;
17
- static get styles(): CSSResultArray;
18
- }
1
+ import { CSSResultArray, TemplateResult } from 'lit';
2
+ import { BaseField } from './base-field';
3
+ import '@shoelace-style/shoelace/dist/components/radio-group/radio-group.js';
4
+ import '@shoelace-style/shoelace/dist/components/radio/radio.js';
5
+ import '@shoelace-style/shoelace/dist/components/button/button.js';
6
+ export type FieldOption = {
7
+ value: any;
8
+ label: string;
9
+ };
10
+ export declare class ScaleField extends BaseField<string | number | null> {
11
+ options: (FieldOption | string | number)[];
12
+ protected controlTemplate(): TemplateResult;
13
+ protected getLabel(option: FieldOption | string | number): unknown;
14
+ protected getValue(option: FieldOption | string | number): unknown;
15
+ protected onSelect(itemValue: string): void;
16
+ protected customValidation(): string | null;
17
+ static get styles(): CSSResultArray;
18
+ }
@@ -1,108 +1,109 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { html, property, css, customElement } from 'lit-element';
8
- import { BaseField } from './base-field';
9
- import { repeat } from 'lit-html/directives/repeat';
10
- import '@polymer/paper-radio-group/paper-radio-group';
11
- import '@polymer/paper-radio-button/paper-radio-button';
12
- import { InputStyles } from '../../lib/styles/input-styles';
13
- import { getTranslation } from '../../lib/utils/translate';
14
- let ScaleField = class ScaleField extends BaseField {
15
- constructor() {
16
- super(...arguments);
17
- this.options = [];
18
- }
19
- controlTemplate() {
20
- return html `
21
- ${InputStyles}
22
- <div class="container">
23
- <paper-radio-group
24
- class="radio-group"
25
- selected="${this.value}"
26
- @iron-select="${({ detail }) => this.onSelect(detail.item)}"
27
- >
28
- ${repeat(this.options, (option) => html `
29
- <paper-radio-button class="radio-button" name="${this.getValue(option)}">
30
- ${this.getLabel(option)}
31
- </paper-radio-button>
32
- `)}
33
- </paper-radio-group>
34
-
35
- <paper-button ?hidden="${this.isReadonly}" @click="${() => this.valueChanged(null)}" class="clear-button">
36
- <iron-icon icon="clear"></iron-icon>${getTranslation(this.language, 'CLEAR')}
37
- </paper-button>
38
- </div>
39
- <div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
40
- `;
41
- }
42
- getLabel(option) {
43
- return typeof option === 'object' ? option.label : option;
44
- }
45
- getValue(option) {
46
- return typeof option === 'object' ? option.value : option;
47
- }
48
- onSelect(item) {
49
- const newValue = item.get('name');
50
- if (newValue !== this.value) {
51
- this.touched = true;
52
- }
53
- this.valueChanged(newValue);
54
- }
55
- customValidation() {
56
- return null;
57
- }
58
- static get styles() {
59
- // language=CSS
60
- return [
61
- ...BaseField.styles,
62
- css `
63
- .container {
64
- position: relative;
65
- min-height: 48px;
66
- display: flex;
67
- align-items: center;
68
- flex-direction: row;
69
- }
70
-
71
- .radio-group {
72
- display: flex;
73
- flex-direction: row;
74
- flex-wrap: wrap;
75
- }
76
-
77
- :host([is-readonly]) paper-radio-group {
78
- pointer-events: none;
79
- opacity: 0.55;
80
- }
81
-
82
- @media (max-width: 1080px) {
83
- .container {
84
- flex-direction: column;
85
- align-items: flex-start;
86
- }
87
- .radio-group {
88
- flex-direction: column;
89
- }
90
- .radio-button {
91
- padding-left: 3px;
92
- }
93
- .clear-button {
94
- margin: 0;
95
- padding-left: 0;
96
- }
97
- }
98
- `
99
- ];
100
- }
101
- };
102
- __decorate([
103
- property({ type: Array })
104
- ], ScaleField.prototype, "options", void 0);
105
- ScaleField = __decorate([
106
- customElement('scale-field')
107
- ], ScaleField);
108
- export { ScaleField };
1
+ import { __decorate } from "tslib";
2
+ import { css, html } from 'lit';
3
+ import { property, customElement } from 'lit/decorators.js';
4
+ import { BaseField } from './base-field';
5
+ import { repeat } from 'lit/directives/repeat.js';
6
+ import '@shoelace-style/shoelace/dist/components/radio-group/radio-group.js';
7
+ import { buttonsStyles } from '@unicef-polymer/etools-unicef/src/styles/button-styles';
8
+ import '@shoelace-style/shoelace/dist/components/radio/radio.js';
9
+ import '@shoelace-style/shoelace/dist/components/button/button.js';
10
+ import { InputStyles } from '../../lib/styles/input-styles';
11
+ import { getTranslation } from '../../lib/utils/translate';
12
+ let ScaleField = class ScaleField extends BaseField {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.options = [];
16
+ }
17
+ controlTemplate() {
18
+ return html `
19
+ ${InputStyles}
20
+ <div class="container">
21
+ <sl-radio-group
22
+ class="radio-group"
23
+ .value="${this.value}"
24
+ @sl-change="${(e) => this.onSelect(e.target.value)}"
25
+ >
26
+ ${repeat(this.options, (option) => html `
27
+ <sl-radio class="radio-button" value="${this.getValue(option)}">${this.getLabel(option)}</sl-radio>
28
+ `)}
29
+ </sl-radio-group>
30
+ <sl-button
31
+ variant="primary"
32
+ ?hidden="${this.isReadonly}"
33
+ @click="${() => this.valueChanged(null)}"
34
+ class="clear-button"
35
+ >
36
+ <etools-icon name="clear" slot="prefix"></etools-icon>
37
+ ${getTranslation(this.language, 'CLEAR')}
38
+ </sl-button>
39
+ </div>
40
+ <div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
41
+ `;
42
+ }
43
+ getLabel(option) {
44
+ return typeof option === 'object' ? option.label : option;
45
+ }
46
+ getValue(option) {
47
+ return typeof option === 'object' ? option.value : option;
48
+ }
49
+ onSelect(itemValue) {
50
+ if (itemValue !== this.value) {
51
+ this.touched = true;
52
+ }
53
+ this.valueChanged(itemValue);
54
+ }
55
+ customValidation() {
56
+ return null;
57
+ }
58
+ static get styles() {
59
+ // language=CSS
60
+ return [
61
+ ...BaseField.styles,
62
+ buttonsStyles,
63
+ css `
64
+ .container {
65
+ position: relative;
66
+ min-height: 48px;
67
+ display: flex;
68
+ align-items: center;
69
+ flex-direction: row;
70
+ }
71
+
72
+ .radio-group {
73
+ display: flex;
74
+ flex-direction: row;
75
+ flex-wrap: wrap;
76
+ }
77
+
78
+ :host([is-readonly]) paper-radio-group {
79
+ pointer-events: none;
80
+ opacity: 0.55;
81
+ }
82
+
83
+ @media (max-width: 1080px) {
84
+ .container {
85
+ flex-direction: column;
86
+ align-items: flex-start;
87
+ }
88
+ .radio-group {
89
+ flex-direction: column;
90
+ }
91
+ .radio-button {
92
+ padding-left: 3px;
93
+ }
94
+ .clear-button {
95
+ margin: 0;
96
+ padding-left: 0;
97
+ }
98
+ }
99
+ `
100
+ ];
101
+ }
102
+ };
103
+ __decorate([
104
+ property({ type: Array })
105
+ ], ScaleField.prototype, "options", void 0);
106
+ ScaleField = __decorate([
107
+ customElement('scale-field')
108
+ ], ScaleField);
109
+ export { ScaleField };