@sankhyalabs/ezui 1.1.8 → 1.1.9

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 (141) hide show
  1. package/README.md +72 -72
  2. package/dist/cjs/{DataUnit-28b290cb.js → DataUnit-9a4a35ca.js} +415 -371
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +41 -41
  4. package/dist/cjs/ez-button_14.cjs.entry.js +1911 -1911
  5. package/dist/cjs/ez-label-chip.cjs.entry.js +120 -120
  6. package/dist/cjs/ez-modal.cjs.entry.js +104 -104
  7. package/dist/cjs/ez-number-input.cjs.entry.js +236 -236
  8. package/dist/cjs/ez-time-input.cjs.entry.js +168 -168
  9. package/dist/cjs/form-metadata.cjs.entry.js +65 -65
  10. package/dist/collection/components/ez-action-chip/ez-action-chip.css +82 -82
  11. package/dist/collection/components/ez-action-chip/ez-action-chip.js +109 -109
  12. package/dist/collection/components/ez-button/ez-button.css +94 -94
  13. package/dist/collection/components/ez-button/ez-button.js +125 -125
  14. package/dist/collection/components/ez-calendar/ez-calendar.css +210 -210
  15. package/dist/collection/components/ez-calendar/ez-calendar.js +215 -215
  16. package/dist/collection/components/ez-check/ez-check.css +265 -265
  17. package/dist/collection/components/ez-check/ez-check.js +168 -168
  18. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.css +67 -67
  19. package/dist/collection/components/ez-collapsable-box/ez-collapsable-box.js +108 -108
  20. package/dist/collection/components/ez-combo-box/ez-combo-box-interfaces.js +2 -2
  21. package/dist/collection/components/ez-combo-box/ez-combo-box.css +167 -167
  22. package/dist/collection/components/ez-combo-box/ez-combo-box.js +363 -363
  23. package/dist/collection/components/ez-date-input/ez-date-input.css +38 -38
  24. package/dist/collection/components/ez-date-input/ez-date-input.js +172 -172
  25. package/dist/collection/components/ez-form/ez-form.css +19 -19
  26. package/dist/collection/components/ez-form/ez-form.js +368 -368
  27. package/dist/collection/components/ez-form/store/Form.actions.js +132 -132
  28. package/dist/collection/components/ez-form/store/Form.reducer.js +194 -194
  29. package/dist/collection/components/ez-form/store/Form.selectors.js +44 -44
  30. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +251 -207
  31. package/dist/collection/components/ez-form/subcomponents/FormMetadata.js +16 -16
  32. package/dist/collection/components/ez-form/subcomponents/css/place-holder.css +23 -23
  33. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +173 -173
  34. package/dist/collection/components/ez-form/subcomponents/place-holder.js +14 -14
  35. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +71 -71
  36. package/dist/collection/components/ez-form/subcomponents/structure/FieldSet.js +27 -27
  37. package/dist/collection/components/ez-form/subcomponents/structure/FormSheet.js +40 -40
  38. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +27 -27
  39. package/dist/collection/components/ez-icon/ez-icon.css +36 -36
  40. package/dist/collection/components/ez-icon/ez-icon.js +56 -56
  41. package/dist/collection/components/ez-label-chip/ez-label-chip.css +117 -117
  42. package/dist/collection/components/ez-label-chip/ez-label-chip.js +276 -276
  43. package/dist/collection/components/ez-modal/ez-modal.css +86 -86
  44. package/dist/collection/components/ez-modal/ez-modal.js +224 -224
  45. package/dist/collection/components/ez-number-input/ez-number-input.css +144 -144
  46. package/dist/collection/components/ez-number-input/ez-number-input.js +465 -465
  47. package/dist/collection/components/ez-popover/ez-popover.css +38 -38
  48. package/dist/collection/components/ez-popover/ez-popover.js +323 -323
  49. package/dist/collection/components/ez-search/ez-search.css +295 -295
  50. package/dist/collection/components/ez-search/ez-search.js +527 -527
  51. package/dist/collection/components/ez-tabselector/ez-tabselector.css +125 -125
  52. package/dist/collection/components/ez-tabselector/ez-tabselector.js +283 -283
  53. package/dist/collection/components/ez-text-area/ez-text-area.css +139 -139
  54. package/dist/collection/components/ez-text-area/ez-text-area.js +267 -267
  55. package/dist/collection/components/ez-text-input/ez-text-input.css +169 -169
  56. package/dist/collection/components/ez-text-input/ez-text-input.js +395 -395
  57. package/dist/collection/components/ez-time-input/ez-time-input.css +155 -155
  58. package/dist/collection/components/ez-time-input/ez-time-input.js +326 -326
  59. package/dist/collection/index.js +1 -1
  60. package/dist/collection/servidor.js +100 -100
  61. package/dist/collection/utils/FloatingManager.js +15 -15
  62. package/dist/collection/utils/utils.js +6 -6
  63. package/dist/custom-elements/index.js +3125 -3081
  64. package/dist/esm/{DataUnit-69e518fa.js → DataUnit-d5d4c9a3.js} +415 -371
  65. package/dist/esm/ez-action-chip.entry.js +41 -41
  66. package/dist/esm/ez-button_14.entry.js +1911 -1911
  67. package/dist/esm/ez-label-chip.entry.js +120 -120
  68. package/dist/esm/ez-modal.entry.js +104 -104
  69. package/dist/esm/ez-number-input.entry.js +236 -236
  70. package/dist/esm/ez-time-input.entry.js +168 -168
  71. package/dist/esm/form-metadata.entry.js +65 -65
  72. package/dist/esm/polyfills/core-js.js +0 -0
  73. package/dist/esm/polyfills/dom.js +0 -0
  74. package/dist/esm/polyfills/es5-html-element.js +0 -0
  75. package/dist/esm/polyfills/index.js +0 -0
  76. package/dist/esm/polyfills/system.js +0 -0
  77. package/dist/ezui/ezui.esm.js +1 -1
  78. package/dist/ezui/{p-b0974f4f.entry.js → p-0fcdfb51.entry.js} +1 -1
  79. package/dist/ezui/p-dac7a6c2.js +1 -0
  80. package/dist/ezui/{p-db11c600.entry.js → p-dbef7060.entry.js} +1 -1
  81. package/dist/types/components/ez-action-chip/ez-action-chip.d.ts +16 -16
  82. package/dist/types/components/ez-button/ez-button.d.ts +20 -20
  83. package/dist/types/components/ez-calendar/ez-calendar.d.ts +42 -42
  84. package/dist/types/components/ez-check/ez-check.d.ts +32 -32
  85. package/dist/types/components/ez-collapsable-box/ez-collapsable-box.d.ts +18 -18
  86. package/dist/types/components/ez-combo-box/ez-combo-box-interfaces.d.ts +4 -4
  87. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +68 -68
  88. package/dist/types/components/ez-date-input/ez-date-input.d.ts +31 -31
  89. package/dist/types/components/ez-form/ez-form.d.ts +26 -31
  90. package/dist/types/components/ez-form/store/Form.actions.d.ts +111 -111
  91. package/dist/types/components/ez-form/store/Form.reducer.d.ts +20 -20
  92. package/dist/types/components/ez-form/store/Form.selectors.d.ts +14 -14
  93. package/dist/types/components/ez-form/subcomponents/DataUnit.d.ts +60 -55
  94. package/dist/types/components/ez-form/subcomponents/FormMetadata.d.ts +41 -41
  95. package/dist/types/components/ez-form/subcomponents/form-metadata.d.ts +15 -15
  96. package/dist/types/components/ez-form/subcomponents/place-holder.d.ts +3 -3
  97. package/dist/types/components/ez-form/subcomponents/structure/Field.d.ts +10 -10
  98. package/dist/types/components/ez-form/subcomponents/structure/FieldSet.d.ts +12 -12
  99. package/dist/types/components/ez-form/subcomponents/structure/FormSheet.d.ts +13 -13
  100. package/dist/types/components/ez-form/subcomponents/structure/NavigationBar.d.ts +17 -17
  101. package/dist/types/components/ez-icon/ez-icon.d.ts +5 -5
  102. package/dist/types/components/ez-label-chip/ez-label-chip.d.ts +40 -40
  103. package/dist/types/components/ez-modal/ez-modal.d.ts +32 -32
  104. package/dist/types/components/ez-number-input/ez-number-input.d.ts +73 -73
  105. package/dist/types/components/ez-popover/ez-popover.d.ts +52 -52
  106. package/dist/types/components/ez-search/ez-search.d.ts +95 -95
  107. package/dist/types/components/ez-tabselector/ez-tabselector.d.ts +31 -31
  108. package/dist/types/components/ez-text-area/ez-text-area.d.ts +49 -49
  109. package/dist/types/components/ez-text-input/ez-text-input.d.ts +64 -64
  110. package/dist/types/components/ez-time-input/ez-time-input.d.ts +53 -53
  111. package/dist/types/index.d.ts +1 -1
  112. package/dist/types/utils/utils.d.ts +2 -2
  113. package/package.json +114 -114
  114. package/dist/ezui/p-10ef58b3.js +0 -1
  115. package/react/components.d.ts +0 -22
  116. package/react/components.js +0 -25
  117. package/react/components.js.map +0 -1
  118. package/react/react-component-lib/createComponent.d.ts +0 -10
  119. package/react/react-component-lib/createComponent.js +0 -59
  120. package/react/react-component-lib/createComponent.js.map +0 -1
  121. package/react/react-component-lib/createOverlayComponent.d.ts +0 -20
  122. package/react/react-component-lib/createOverlayComponent.js +0 -89
  123. package/react/react-component-lib/createOverlayComponent.js.map +0 -1
  124. package/react/react-component-lib/index.d.ts +0 -2
  125. package/react/react-component-lib/index.js +0 -3
  126. package/react/react-component-lib/index.js.map +0 -1
  127. package/react/react-component-lib/interfaces.d.ts +0 -29
  128. package/react/react-component-lib/interfaces.js +0 -1
  129. package/react/react-component-lib/interfaces.js.map +0 -1
  130. package/react/react-component-lib/utils/attachProps.d.ts +0 -12
  131. package/react/react-component-lib/utils/attachProps.js +0 -96
  132. package/react/react-component-lib/utils/attachProps.js.map +0 -1
  133. package/react/react-component-lib/utils/case.d.ts +0 -2
  134. package/react/react-component-lib/utils/case.js +0 -7
  135. package/react/react-component-lib/utils/case.js.map +0 -1
  136. package/react/react-component-lib/utils/dev.d.ts +0 -2
  137. package/react/react-component-lib/utils/dev.js +0 -13
  138. package/react/react-component-lib/utils/dev.js.map +0 -1
  139. package/react/react-component-lib/utils/index.d.ts +0 -7
  140. package/react/react-component-lib/utils/index.js +0 -21
  141. package/react/react-component-lib/utils/index.js.map +0 -1
@@ -7,242 +7,242 @@ const RequestMetadata = require('./RequestMetadata-2cd01e8a.js');
7
7
 
8
8
  const ezNumberInputCss = ":host{--ni--height:42px;--ni--width:100%;--ni__icon--width:48px;--ni--border-radius:var(--border--radius-medium, 12px);--ni--font-size:var(--text--medium, 14px);--ni--font-family:var(--font-pattern, Arial);--ni__input--background-color:var(--background--medium, #e0e0e0);--ni__input--border:var(--border--medium, 2px solid);--ni__input--border-color:var(--ni__input--background-color);--ni__input--focus--border-color:var(--color--primary, #008561);--ni__input--disabled--background-color:var(--color--disable-secondary, #F2F5F8);--ni__input--disabled--color:var(--text--disable, #AFB6C0);--ni__input--error--border-color:#CC2936;--ni__placeholder--disabled--color:var(--text--disable, #AFB6C0);--ni__placeholder--color:var(--title--primary, #919191);--ni__placeholder--font-weight:var(--text-weight--large, 500);--ni__message_box--font-size:var(--text--small, 12px);--ni__message_box--info--color:var(--color--success, #22085d);--ni__message_box--error--color:var(--color--error, #FF0000);display:flex;flex-wrap:wrap;position:relative;width:var(--ni--width)}.invisible{visibility:hidden}input{width:100%;box-sizing:border-box;padding:var(--space--medium);height:var(--ni--height);border-radius:var(--ni--border-radius);font-family:var(--ni--font-family);font-size:var(--ni--font-size);border:var(--ni__input--border);border-color:var(--ni__input--border-color);background-color:var(--ni__input--background-color);font-weight:var(--text-weight--large)}input:disabled{background-color:var(--ni__input--disabled--background-color);color:var(--ni__input--disabled--color)}input:focus{outline:none;border-color:var(--ni__input--focus--border-color)}input.icon--left{padding-left:var(--ni__icon--width)}input.icon--right{padding-right:var(--ni__icon--width)}input::placeholder{color:var(--ni__placeholder--color);font-weight:var(--ni__placeholder--font-weight)}input:disabled::placeholder{color:var(--ni__placeholder--disabled--color)}input.hasError{color:inherit;border-color:var(--ni__input--error--border-color)}input.text--right{text-align:right}.message-box{min-height:16px;min-width:100%;margin-top:2px;line-height:12px;font-family:var(--ni--font-family);font-size:var(--ni__message_box--font-size);color:var(--ni__message_box--info--color)}.hasError{color:var(--ni__message_box--error--color)}.input__label{font-size:var(--text--medium);font-weight:var(--text-weight--large);left:var(--space--medium);position:absolute;color:var(--title--primary);top:var(--space--medium);font-family:var(--ni--font-family);-webkit-transition:font-size .3s, top .3s;transition:font-size .3s, top .3s;z-index:var(--visible)}.input__label--floated{font-family:var(--ni--font-family);font-size:var(--text--extra-small);top:var(--space--small);color:var(--text--primary)}.input__label--left{left:var(--ni__icon--width)}.input--with--label{padding-bottom:0}";
9
9
 
10
- const NumberInput = class {
11
- constructor(hostRef) {
12
- index.registerInstance(this, hostRef);
13
- /**
14
- * Deixa o campo disponível ou não para digitação.
15
- */
16
- this.enabled = true;
17
- /**
18
- * Deixa o campo disponível ou não para digitação.
19
- */
20
- this.textleft = false;
21
- /**
22
- * Opção de configurar a transformação de string to number entre formatação pt-BR e en-US
23
- * (formatação de ENTRADA e SAÍDA do componente: pt-BR="###.###,##" en-US="###,###.##"; Default: "pt-BR")
24
- * Qualquer outro valor que não seja "en-US", adotará a formatação "pt-BR"
25
- * Não é case sensitive
26
- */
27
- this.formatnumber = "PT-BR";
28
- //---------------------------------------------
29
- // Private Methods
30
- //---------------------------------------------
31
- this.settingStrValueIntNumber = (strvalue) => {
32
- if (this.precision === 0 && strvalue) {
33
- return strvalue = strvalue.replace(/\./g, '').replace(/\,/g, '');
34
- }
35
- else {
36
- return strvalue;
37
- }
38
- };
39
- this.checkNumberValidation = (valuePtBRorNumber) => {
40
- try {
41
- if (valuePtBRorNumber != "" && RequestMetadata.NumberUtils.format(valuePtBRorNumber, this.precision, this.prettyprecision) === "NaN") {
42
- this.errormessage = `Valor não é um número válido`;
43
- this.value = undefined;
44
- this.strvalue = undefined;
45
- if (this._inputElem) {
46
- this._inputElem.value = "";
47
- }
48
- return false;
49
- }
50
- }
51
- catch (err) {
52
- this.errormessage = err.message;
53
- return false;
54
- }
55
- return true;
56
- };
57
- }
58
- showError() {
59
- const hasError = typeof this.errormessage === 'string' && this.errormessage !== '';
60
- if (this._inputElem) {
61
- if (hasError) {
62
- this._inputElem.classList.add('hasError');
63
- this._messageBoxElem.classList.add('hasError');
64
- }
65
- else {
66
- this._inputElem.classList.remove('hasError');
67
- this._messageBoxElem.classList.remove('hasError');
68
- }
69
- }
70
- }
71
- onPrecisionChanged(newPrecision) {
72
- if (isNaN(newPrecision)) {
73
- this.precision = 0;
74
- }
75
- this.handleFocusout();
76
- }
77
- onPrettyPrecisionChanged(newPrettyPrecision) {
78
- if (isNaN(newPrettyPrecision)) {
79
- this.prettyprecision = 0;
80
- }
81
- this.handleFocusout();
82
- }
83
- onValueChanged(newValue) {
84
- if (isNaN(newValue) && newValue !== undefined) {
85
- this.value = undefined;
86
- this.strvalue = "";
87
- this.errormessage = `Valor não é um número válido`;
88
- this.adjustFloatingLabel();
89
- }
90
- else {
91
- this.settingComponent();
92
- }
93
- }
94
- adjustFloatingLabel() {
95
- if (this._labelElem) {
96
- if (this.label && this._inputElem.value && this._inputElem.value.toString().length > 0) {
97
- if (!this._labelElem.classList.contains("input__label--floated")) {
98
- this._labelElem.classList.add("input__label--floated");
99
- }
100
- if (!this._inputElem.classList.contains("input--with--label")) {
101
- this._inputElem.classList.add("input--with--label");
102
- }
103
- }
104
- else {
105
- this._labelElem.classList.remove("input__label--floated");
106
- }
107
- }
108
- }
109
- //---------------------------------------------
110
- // Public methods
111
- //---------------------------------------------
112
- /**
113
- * Faz o foco no componente de input
114
- */
115
- async setFocus() {
116
- this._inputElem.focus();
117
- }
118
- /**
119
- * Remove o foco no componente de input
120
- */
121
- async setBlur() {
122
- this._inputElem.blur();
123
- }
124
- //---------------------------------------------
125
- // Event handlers
126
- //---------------------------------------------
127
- /**
128
- * Promove a atualização do componente
129
- */
130
- async handleFocusout() {
131
- //Setting value and strvalue by stringinput
132
- if (this._inputElem) {
133
- this.errormessage = "";
134
- if (this._inputElem.value !== "") {
135
- this._inputElem.value = this.settingStrValueIntNumber(this._inputElem.value);
136
- const value = RequestMetadata.NumberUtils.keepOnlyDecimalSeparator(this._inputElem.value, this.formatnumber.toUpperCase());
137
- if (!this.checkNumberValidation(value)) {
138
- return;
139
- }
140
- if (value) {
141
- try {
142
- this._inputElem.value = this.formatnumber.toUpperCase() !== "EN-US" ? RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision) : RequestMetadata.NumberUtils.changeFormat(RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision));
143
- }
144
- catch (e) {
145
- this.errormessage = e.message;
146
- return;
147
- }
148
- }
149
- this.strvalue = this._inputElem.value;
150
- this.value = RequestMetadata.NumberUtils.stringToNumber(value);
151
- }
152
- else {
153
- this.strvalue = undefined;
154
- this.value = undefined;
155
- }
156
- this.adjustFloatingLabel();
157
- }
158
- }
159
- handleChange() {
160
- this._inputElem.value = this.settingStrValueIntNumber(this._inputElem.value);
161
- }
162
- handleSlotChange(ev) {
163
- const slot = ev.target;
164
- const content = slot.assignedElements()[0];
165
- content.style.position = "absolute";
166
- content.style.display = "flex";
167
- content.style.alignItems = "center";
168
- content.style.justifyContent = "center";
169
- content.style.overflow = "hidden";
170
- content.style.top = "0px";
171
- content.style.width = "var(--ni__icon--width)";
172
- content.style.height = "var(--ni--height)";
173
- if (slot.name == "leftIcon") {
174
- content.style.left = "0px";
175
- content.style.borderRadius = "var(--ni--border-radius) 0 0 var(--ni--border-radius)";
176
- this._inputElem.classList.add('icon--left');
177
- if (this._labelElem) {
178
- this._labelElem.classList.add("input__label--left");
179
- }
180
- }
181
- else if (slot.name == "rightIcon") {
182
- content.style.right = "0px";
183
- content.style.borderRadius = "0 var(--ni--border-radius) var(--ni--border-radius) 0";
184
- this._inputElem.classList.add('icon--right');
185
- }
186
- this.showError();
187
- }
188
- doFocus() {
189
- if (this.label && this._labelElem) {
190
- this._labelElem.classList.contains("input__label--floated") ? undefined : this._labelElem.classList.add("input__label--floated");
191
- }
192
- }
193
- settingComponent() {
194
- const value = '' + this.value;
195
- if (this.value !== undefined) {
196
- try {
197
- this._inputElem.value = this.formatnumber.toUpperCase() !== "EN-US" ? RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision) : RequestMetadata.NumberUtils.changeFormat(RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision));
198
- }
199
- catch (e) {
200
- this.errormessage = e.message;
201
- return;
202
- }
203
- this.strvalue = this._inputElem.value;
204
- }
205
- this.adjustFloatingLabel();
206
- }
207
- settingValue() {
208
- //this.value: en-US format => Need to convert
209
- const value = !isNaN(this.value) ? '' + this.value : 'NaN';
210
- if (!this.checkNumberValidation(value)) {
211
- return;
212
- }
213
- //output default from ".format": pt-BR
214
- const tempStrValue = RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision);
215
- //output => depends to formatnumber
216
- this.strvalue = this.formatnumber.toUpperCase() !== 'EN-US' ? tempStrValue : RequestMetadata.NumberUtils.changeFormat(tempStrValue);
217
- RequestMetadata.NumberUtils.format(this.value.toString(), this.precision, this.prettyprecision);
218
- }
219
- //---------------------------------------------
220
- // Lifecycle web component
221
- //---------------------------------------------
222
- componentDidLoad() {
223
- if (!this.textleft) {
224
- this._inputElem.classList.add('text--right');
225
- }
226
- this.showError();
227
- this.adjustFloatingLabel();
228
- }
229
- componentWillLoad() {
230
- this.onPrecisionChanged(this.precision);
231
- this.onPrettyPrecisionChanged(this.prettyprecision);
232
- this.settingValue();
233
- }
234
- render() {
235
- const labelInput = this.label ? index.h("label", { onClick: () => this._inputElem.focus(), class: "input__label", ref: (el) => this._labelElem = el }, this.label) : null;
236
- return (index.h(index.Host, null, index.h("slot", { name: "leftIcon", onSlotchange: (ev) => { this.handleSlotChange(ev); } }), labelInput, index.h("input", { onFocus: () => this.doFocus(), ref: (el) => this._inputElem = el, type: "text", value: this.strvalue, disabled: !this.enabled, onInput: this.handleChange.bind(this), onFocusout: this.handleFocusout.bind(this) }), index.h("slot", { name: "rightIcon", onSlotchange: (ev) => { this.handleSlotChange(ev); } }), index.h("span", { class: "message-box", ref: (el) => this._messageBoxElem = el }, this.errormessage)));
237
- }
238
- get el() { return index.getElement(this); }
239
- static get watchers() { return {
240
- "errormessage": ["showError"],
241
- "precision": ["onPrecisionChanged"],
242
- "prettyprecision": ["onPrettyPrecisionChanged"],
243
- "value": ["onValueChanged"]
244
- }; }
245
- };
10
+ const NumberInput = class {
11
+ constructor(hostRef) {
12
+ index.registerInstance(this, hostRef);
13
+ /**
14
+ * Deixa o campo disponível ou não para digitação.
15
+ */
16
+ this.enabled = true;
17
+ /**
18
+ * Deixa o campo disponível ou não para digitação.
19
+ */
20
+ this.textleft = false;
21
+ /**
22
+ * Opção de configurar a transformação de string to number entre formatação pt-BR e en-US
23
+ * (formatação de ENTRADA e SAÍDA do componente: pt-BR="###.###,##" en-US="###,###.##"; Default: "pt-BR")
24
+ * Qualquer outro valor que não seja "en-US", adotará a formatação "pt-BR"
25
+ * Não é case sensitive
26
+ */
27
+ this.formatnumber = "PT-BR";
28
+ //---------------------------------------------
29
+ // Private Methods
30
+ //---------------------------------------------
31
+ this.settingStrValueIntNumber = (strvalue) => {
32
+ if (this.precision === 0 && strvalue) {
33
+ return strvalue = strvalue.replace(/\./g, '').replace(/\,/g, '');
34
+ }
35
+ else {
36
+ return strvalue;
37
+ }
38
+ };
39
+ this.checkNumberValidation = (valuePtBRorNumber) => {
40
+ try {
41
+ if (valuePtBRorNumber != "" && RequestMetadata.NumberUtils.format(valuePtBRorNumber, this.precision, this.prettyprecision) === "NaN") {
42
+ this.errormessage = `Valor não é um número válido`;
43
+ this.value = undefined;
44
+ this.strvalue = undefined;
45
+ if (this._inputElem) {
46
+ this._inputElem.value = "";
47
+ }
48
+ return false;
49
+ }
50
+ }
51
+ catch (err) {
52
+ this.errormessage = err.message;
53
+ return false;
54
+ }
55
+ return true;
56
+ };
57
+ }
58
+ showError() {
59
+ const hasError = typeof this.errormessage === 'string' && this.errormessage !== '';
60
+ if (this._inputElem) {
61
+ if (hasError) {
62
+ this._inputElem.classList.add('hasError');
63
+ this._messageBoxElem.classList.add('hasError');
64
+ }
65
+ else {
66
+ this._inputElem.classList.remove('hasError');
67
+ this._messageBoxElem.classList.remove('hasError');
68
+ }
69
+ }
70
+ }
71
+ onPrecisionChanged(newPrecision) {
72
+ if (isNaN(newPrecision)) {
73
+ this.precision = 0;
74
+ }
75
+ this.handleFocusout();
76
+ }
77
+ onPrettyPrecisionChanged(newPrettyPrecision) {
78
+ if (isNaN(newPrettyPrecision)) {
79
+ this.prettyprecision = 0;
80
+ }
81
+ this.handleFocusout();
82
+ }
83
+ onValueChanged(newValue) {
84
+ if (isNaN(newValue) && newValue !== undefined) {
85
+ this.value = undefined;
86
+ this.strvalue = "";
87
+ this.errormessage = `Valor não é um número válido`;
88
+ this.adjustFloatingLabel();
89
+ }
90
+ else {
91
+ this.settingComponent();
92
+ }
93
+ }
94
+ adjustFloatingLabel() {
95
+ if (this._labelElem) {
96
+ if (this.label && this._inputElem.value && this._inputElem.value.toString().length > 0) {
97
+ if (!this._labelElem.classList.contains("input__label--floated")) {
98
+ this._labelElem.classList.add("input__label--floated");
99
+ }
100
+ if (!this._inputElem.classList.contains("input--with--label")) {
101
+ this._inputElem.classList.add("input--with--label");
102
+ }
103
+ }
104
+ else {
105
+ this._labelElem.classList.remove("input__label--floated");
106
+ }
107
+ }
108
+ }
109
+ //---------------------------------------------
110
+ // Public methods
111
+ //---------------------------------------------
112
+ /**
113
+ * Faz o foco no componente de input
114
+ */
115
+ async setFocus() {
116
+ this._inputElem.focus();
117
+ }
118
+ /**
119
+ * Remove o foco no componente de input
120
+ */
121
+ async setBlur() {
122
+ this._inputElem.blur();
123
+ }
124
+ //---------------------------------------------
125
+ // Event handlers
126
+ //---------------------------------------------
127
+ /**
128
+ * Promove a atualização do componente
129
+ */
130
+ async handleFocusout() {
131
+ //Setting value and strvalue by stringinput
132
+ if (this._inputElem) {
133
+ this.errormessage = "";
134
+ if (this._inputElem.value !== "") {
135
+ this._inputElem.value = this.settingStrValueIntNumber(this._inputElem.value);
136
+ const value = RequestMetadata.NumberUtils.keepOnlyDecimalSeparator(this._inputElem.value, this.formatnumber.toUpperCase());
137
+ if (!this.checkNumberValidation(value)) {
138
+ return;
139
+ }
140
+ if (value) {
141
+ try {
142
+ this._inputElem.value = this.formatnumber.toUpperCase() !== "EN-US" ? RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision) : RequestMetadata.NumberUtils.changeFormat(RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision));
143
+ }
144
+ catch (e) {
145
+ this.errormessage = e.message;
146
+ return;
147
+ }
148
+ }
149
+ this.strvalue = this._inputElem.value;
150
+ this.value = RequestMetadata.NumberUtils.stringToNumber(value);
151
+ }
152
+ else {
153
+ this.strvalue = undefined;
154
+ this.value = undefined;
155
+ }
156
+ this.adjustFloatingLabel();
157
+ }
158
+ }
159
+ handleChange() {
160
+ this._inputElem.value = this.settingStrValueIntNumber(this._inputElem.value);
161
+ }
162
+ handleSlotChange(ev) {
163
+ const slot = ev.target;
164
+ const content = slot.assignedElements()[0];
165
+ content.style.position = "absolute";
166
+ content.style.display = "flex";
167
+ content.style.alignItems = "center";
168
+ content.style.justifyContent = "center";
169
+ content.style.overflow = "hidden";
170
+ content.style.top = "0px";
171
+ content.style.width = "var(--ni__icon--width)";
172
+ content.style.height = "var(--ni--height)";
173
+ if (slot.name == "leftIcon") {
174
+ content.style.left = "0px";
175
+ content.style.borderRadius = "var(--ni--border-radius) 0 0 var(--ni--border-radius)";
176
+ this._inputElem.classList.add('icon--left');
177
+ if (this._labelElem) {
178
+ this._labelElem.classList.add("input__label--left");
179
+ }
180
+ }
181
+ else if (slot.name == "rightIcon") {
182
+ content.style.right = "0px";
183
+ content.style.borderRadius = "0 var(--ni--border-radius) var(--ni--border-radius) 0";
184
+ this._inputElem.classList.add('icon--right');
185
+ }
186
+ this.showError();
187
+ }
188
+ doFocus() {
189
+ if (this.label && this._labelElem) {
190
+ this._labelElem.classList.contains("input__label--floated") ? undefined : this._labelElem.classList.add("input__label--floated");
191
+ }
192
+ }
193
+ settingComponent() {
194
+ const value = '' + this.value;
195
+ if (this.value !== undefined) {
196
+ try {
197
+ this._inputElem.value = this.formatnumber.toUpperCase() !== "EN-US" ? RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision) : RequestMetadata.NumberUtils.changeFormat(RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision));
198
+ }
199
+ catch (e) {
200
+ this.errormessage = e.message;
201
+ return;
202
+ }
203
+ this.strvalue = this._inputElem.value;
204
+ }
205
+ this.adjustFloatingLabel();
206
+ }
207
+ settingValue() {
208
+ //this.value: en-US format => Need to convert
209
+ const value = !isNaN(this.value) ? '' + this.value : 'NaN';
210
+ if (!this.checkNumberValidation(value)) {
211
+ return;
212
+ }
213
+ //output default from ".format": pt-BR
214
+ const tempStrValue = RequestMetadata.NumberUtils.format(value, this.precision, this.prettyprecision);
215
+ //output => depends to formatnumber
216
+ this.strvalue = this.formatnumber.toUpperCase() !== 'EN-US' ? tempStrValue : RequestMetadata.NumberUtils.changeFormat(tempStrValue);
217
+ RequestMetadata.NumberUtils.format(this.value.toString(), this.precision, this.prettyprecision);
218
+ }
219
+ //---------------------------------------------
220
+ // Lifecycle web component
221
+ //---------------------------------------------
222
+ componentDidLoad() {
223
+ if (!this.textleft) {
224
+ this._inputElem.classList.add('text--right');
225
+ }
226
+ this.showError();
227
+ this.adjustFloatingLabel();
228
+ }
229
+ componentWillLoad() {
230
+ this.onPrecisionChanged(this.precision);
231
+ this.onPrettyPrecisionChanged(this.prettyprecision);
232
+ this.settingValue();
233
+ }
234
+ render() {
235
+ const labelInput = this.label ? index.h("label", { onClick: () => this._inputElem.focus(), class: "input__label", ref: (el) => this._labelElem = el }, this.label) : null;
236
+ return (index.h(index.Host, null, index.h("slot", { name: "leftIcon", onSlotchange: (ev) => { this.handleSlotChange(ev); } }), labelInput, index.h("input", { onFocus: () => this.doFocus(), ref: (el) => this._inputElem = el, type: "text", value: this.strvalue, disabled: !this.enabled, onInput: this.handleChange.bind(this), onFocusout: this.handleFocusout.bind(this) }), index.h("slot", { name: "rightIcon", onSlotchange: (ev) => { this.handleSlotChange(ev); } }), index.h("span", { class: "message-box", ref: (el) => this._messageBoxElem = el }, this.errormessage)));
237
+ }
238
+ get el() { return index.getElement(this); }
239
+ static get watchers() { return {
240
+ "errormessage": ["showError"],
241
+ "precision": ["onPrecisionChanged"],
242
+ "prettyprecision": ["onPrettyPrecisionChanged"],
243
+ "value": ["onValueChanged"]
244
+ }; }
245
+ };
246
246
  NumberInput.style = ezNumberInputCss;
247
247
 
248
248
  exports.ez_number_input = NumberInput;