linear-react-components-ui 2.1.0-beta.0 → 2.1.0-beta.2

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 (85) hide show
  1. package/lib/assets/styles/datepicker2.css +77 -4
  2. package/lib/inputs/number/Currency.js +19 -17
  3. package/lib/inputs/number/Currency.js.map +1 -1
  4. package/lib/inputs/number/Decimal.js +19 -17
  5. package/lib/inputs/number/Decimal.js.map +1 -1
  6. package/lib/inputs/number/index.js +17 -15
  7. package/lib/inputs/number/index.js.map +1 -1
  8. package/lib/inputs2/date/calendarbox.d.ts +23 -0
  9. package/lib/inputs2/date/calendarbox.js +254 -0
  10. package/lib/inputs2/date/calendarbox.js.map +1 -0
  11. package/lib/inputs2/date/datefield/base.js +590 -214
  12. package/lib/inputs2/date/datefield/base.js.map +1 -1
  13. package/lib/inputs2/date/datefield/triggers.js +4 -4
  14. package/lib/inputs2/date/datefield/triggers.js.map +1 -1
  15. package/lib/inputs2/date/datefield/types.d.ts +5 -12
  16. package/lib/inputs2/date/dateperiodfield/base.js +543 -674
  17. package/lib/inputs2/date/dateperiodfield/base.js.map +1 -1
  18. package/lib/inputs2/date/dateperiodfield/triggers.js +21 -9
  19. package/lib/inputs2/date/dateperiodfield/triggers.js.map +1 -1
  20. package/lib/inputs2/date/dateperiodfield/types.d.ts +7 -23
  21. package/lib/inputs2/date/helpers.d.ts +21 -4
  22. package/lib/inputs2/date/helpers.js +64 -4
  23. package/lib/inputs2/date/helpers.js.map +1 -1
  24. package/lib/inputs2/date/{base/constants.d.ts → hooks/useCalendarPosition.d.ts} +1 -1
  25. package/lib/inputs2/date/hooks/useCalendarPosition.js +93 -0
  26. package/lib/inputs2/date/hooks/useCalendarPosition.js.map +1 -0
  27. package/lib/inputs2/date/hooks/useDateCalendarState.d.ts +14 -0
  28. package/lib/inputs2/date/hooks/useDateCalendarState.js +250 -0
  29. package/lib/inputs2/date/hooks/useDateCalendarState.js.map +1 -0
  30. package/lib/inputs2/date/hooks/useDateMask.d.ts +20 -0
  31. package/lib/inputs2/date/hooks/useDateMask.js +178 -0
  32. package/lib/inputs2/date/hooks/useDateMask.js.map +1 -0
  33. package/lib/inputs2/date/timeselector.d.ts +15 -0
  34. package/lib/inputs2/date/timeselector.js +228 -0
  35. package/lib/inputs2/date/timeselector.js.map +1 -0
  36. package/lib/inputs2/date/types.d.ts +16 -1
  37. package/lib/inputs2/date/types.js.map +1 -1
  38. package/lib/inputs2/selectfield/base.js +1 -1
  39. package/lib/inputs2/selectfield/base.js.map +1 -1
  40. package/lib/menus/float/SubMenuContainer.d.ts +10 -28
  41. package/lib/menus/float/SubMenuContainer.js +97 -83
  42. package/lib/menus/float/SubMenuContainer.js.map +1 -1
  43. package/lib/node_modules/moment/dist/locale/pt-br.js +54 -0
  44. package/lib/node_modules/moment/dist/locale/pt-br.js.map +1 -0
  45. package/lib/treetable/helpers.d.ts +0 -2
  46. package/lib/treetable/helpers.js.map +1 -1
  47. package/package.json +1 -1
  48. package/lib/_virtual/index.js +0 -8
  49. package/lib/_virtual/index.js.map +0 -1
  50. package/lib/_virtual/index2.js +0 -5
  51. package/lib/_virtual/index2.js.map +0 -1
  52. package/lib/_virtual/index3.js +0 -5
  53. package/lib/_virtual/index3.js.map +0 -1
  54. package/lib/_virtual/react-is.development.js +0 -5
  55. package/lib/_virtual/react-is.development.js.map +0 -1
  56. package/lib/_virtual/react-is.production.min.js +0 -5
  57. package/lib/_virtual/react-is.production.min.js.map +0 -1
  58. package/lib/inputs2/date/base/constants.js +0 -69
  59. package/lib/inputs2/date/base/constants.js.map +0 -1
  60. package/lib/inputs2/date/datefield/calendarbox.d.ts +0 -6
  61. package/lib/inputs2/date/datefield/calendarbox.js +0 -228
  62. package/lib/inputs2/date/datefield/calendarbox.js.map +0 -1
  63. package/lib/inputs2/date/dateperiodfield/calendarbox.d.ts +0 -6
  64. package/lib/inputs2/date/dateperiodfield/calendarbox.js +0 -282
  65. package/lib/inputs2/date/dateperiodfield/calendarbox.js.map +0 -1
  66. package/lib/node_modules/object-assign/index.js +0 -79
  67. package/lib/node_modules/object-assign/index.js.map +0 -1
  68. package/lib/node_modules/prop-types/checkPropTypes.js +0 -69
  69. package/lib/node_modules/prop-types/checkPropTypes.js.map +0 -1
  70. package/lib/node_modules/prop-types/factoryWithThrowingShims.js +0 -59
  71. package/lib/node_modules/prop-types/factoryWithThrowingShims.js.map +0 -1
  72. package/lib/node_modules/prop-types/factoryWithTypeCheckers.js +0 -452
  73. package/lib/node_modules/prop-types/factoryWithTypeCheckers.js.map +0 -1
  74. package/lib/node_modules/prop-types/index.js +0 -21
  75. package/lib/node_modules/prop-types/index.js.map +0 -1
  76. package/lib/node_modules/prop-types/lib/ReactPropTypesSecret.js +0 -13
  77. package/lib/node_modules/prop-types/lib/ReactPropTypesSecret.js.map +0 -1
  78. package/lib/node_modules/prop-types/lib/has.js +0 -12
  79. package/lib/node_modules/prop-types/lib/has.js.map +0 -1
  80. package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js +0 -166
  81. package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.development.js.map +0 -1
  82. package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js +0 -107
  83. package/lib/node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js.map +0 -1
  84. package/lib/node_modules/prop-types/node_modules/react-is/index.js +0 -18
  85. package/lib/node_modules/prop-types/node_modules/react-is/index.js.map +0 -1
@@ -741,7 +741,7 @@
741
741
  background-position: -135% 0%;
742
742
  }
743
743
  }
744
- .date-calendar-box[aria-expanded=true], .date-field-root .container .input {
744
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-column .time-column-options, .date-calendar-box[aria-expanded=true], .date-field-root .container .input {
745
745
  color: #666;
746
746
  font-size: 16px;
747
747
  font-family: Roboto;
@@ -1029,9 +1029,10 @@ input::-webkit-inner-spin-button {
1029
1029
  margin: 5px 0;
1030
1030
  font-size: 87.5%;
1031
1031
  z-index: auto;
1032
- position: fixed;
1033
- display: flex;
1034
- flex-direction: column;
1032
+ display: grid;
1033
+ grid-template-columns: minmax(280px, 1fr) auto;
1034
+ grid-template-areas: "header time" "weekdays time" "grid time";
1035
+ min-width: min-content;
1035
1036
  overflow: hidden;
1036
1037
  border: 1px solid #dae1e8;
1037
1038
  background-color: #fff;
@@ -1039,6 +1040,7 @@ input::-webkit-inner-spin-button {
1039
1040
  box-shadow: -6px 6px 50px -12px rgba(51, 51, 51, 0.4);
1040
1041
  }
1041
1042
  .date-calendar-box[aria-expanded=true] .date-calendar-box-header {
1043
+ grid-area: header;
1042
1044
  width: auto;
1043
1045
  height: auto;
1044
1046
  display: flex;
@@ -1070,6 +1072,7 @@ input::-webkit-inner-spin-button {
1070
1072
  font-size: 87.5%;
1071
1073
  }
1072
1074
  .date-calendar-box[aria-expanded=true] .date-calendar-box-days-of-week {
1075
+ grid-area: weekdays;
1073
1076
  height: 28px;
1074
1077
  display: flex;
1075
1078
  flex-flow: nowrap;
@@ -1086,11 +1089,13 @@ input::-webkit-inner-spin-button {
1086
1089
  vertical-align: middle;
1087
1090
  }
1088
1091
  .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days {
1092
+ grid-area: grid;
1089
1093
  padding: 3px;
1090
1094
  }
1091
1095
  .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days table {
1092
1096
  width: 100%;
1093
1097
  height: 100%;
1098
+ min-height: 252px;
1094
1099
  }
1095
1100
  .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days table td[role=gridcell] {
1096
1101
  text-align: center;
@@ -1127,6 +1132,13 @@ input::-webkit-inner-spin-button {
1127
1132
  border-color: #d1d3d4;
1128
1133
  border-style: dashed;
1129
1134
  }
1135
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days table .day-button[data-state-out-of-bounds=true] {
1136
+ color: #cacaca !important;
1137
+ cursor: not-allowed;
1138
+ }
1139
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days table .day-button[data-state-out-of-bounds=true]:hover {
1140
+ background-color: transparent;
1141
+ }
1130
1142
  .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days table .day-button[data-state-is-today=true] {
1131
1143
  position: relative;
1132
1144
  }
@@ -1144,4 +1156,65 @@ input::-webkit-inner-spin-button {
1144
1156
  }
1145
1157
  .date-calendar-box[aria-expanded=true] .date-calendar-box-grid-of-days table .day-button[data-state-is-today=true][aria-selected=true]::after {
1146
1158
  background-color: #fff;
1159
+ }
1160
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector {
1161
+ grid-area: time;
1162
+ display: flex;
1163
+ flex-direction: row;
1164
+ height: 0;
1165
+ min-height: 100%;
1166
+ }
1167
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-column {
1168
+ display: flex;
1169
+ flex-direction: column;
1170
+ min-height: 0;
1171
+ width: 52px;
1172
+ border-left: 1px solid #dae1e8;
1173
+ }
1174
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-column .time-column-label {
1175
+ padding: 6px 0;
1176
+ font-size: 87.5%;
1177
+ text-align: center;
1178
+ white-space: nowrap;
1179
+ background-color: #f0f0f0;
1180
+ border-bottom: 1px solid #e1e1e1;
1181
+ }
1182
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-column .time-column-options {
1183
+ flex: 1 1 auto;
1184
+ min-height: 0;
1185
+ font-size: 87.5%;
1186
+ overflow: hidden auto;
1187
+ scrollbar-width: none;
1188
+ }
1189
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-column .time-column-options::-webkit-scrollbar {
1190
+ display: none;
1191
+ }
1192
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-unit-button {
1193
+ width: 100%;
1194
+ padding: 6px 0;
1195
+ border: none;
1196
+ cursor: pointer;
1197
+ text-align: center;
1198
+ background-color: transparent;
1199
+ }
1200
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-unit-button:hover {
1201
+ background-color: #dae1e8;
1202
+ }
1203
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-unit-button[aria-selected=true], .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-unit-button[aria-selected=true]:hover {
1204
+ color: #fff;
1205
+ background-color: #6C757D;
1206
+ }
1207
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-unit-button[data-state-out-of-bounds=true] {
1208
+ color: #cacaca !important;
1209
+ cursor: not-allowed;
1210
+ }
1211
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector .time-unit-button[data-state-out-of-bounds=true]:hover {
1212
+ background-color: transparent;
1213
+ }
1214
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector[data-state-disabled=true] .time-unit-button {
1215
+ color: #cacaca !important;
1216
+ cursor: not-allowed;
1217
+ }
1218
+ .date-calendar-box[aria-expanded=true] .date-calendar-box-time-selector[data-state-disabled=true] .time-unit-button:hover {
1219
+ background-color: transparent;
1147
1220
  }
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
2
2
  import { useRef, useEffect } from "react";
3
3
  import _ from "../../_virtual/lodash.js";
4
4
  import { useIMask } from "react-imask";
5
- import { numberToEnUS, numberToPtBR } from "./format_number.js";
5
+ import { numberToPtBR } from "./format_number.js";
6
6
  import InputTextBase from "../base/InputTextBase.js";
7
7
  import { mergeRefs } from "../../form2/helpers.js";
8
8
  const CurrencyField = (props) => {
@@ -22,11 +22,12 @@ const CurrencyField = (props) => {
22
22
  displayCurrencySymbol = true
23
23
  } = props;
24
24
  const currencyNumberInputRef = useRef(null);
25
- const isResetting = useRef(false);
26
25
  const leftElements = displayCurrencySymbol ? /* @__PURE__ */ jsx("span", { className: "currency-symbol", children: currencySymbol }) : [];
27
26
  const {
27
+ maskRef: maskRef_0,
28
28
  value: maskedValue,
29
- setValue: setMaskedValue
29
+ setValue: setMaskedValue,
30
+ typedValue
30
31
  } = useIMask({
31
32
  mask: Number,
32
33
  unmask,
@@ -40,26 +41,22 @@ const CurrencyField = (props) => {
40
41
  thousandsSeparator: "."
41
42
  }, {
42
43
  ref: currencyNumberInputRef,
43
- onAccept: (__, options, event) => {
44
- if (isResetting.current) {
45
- isResetting.current = false;
46
- return;
47
- }
48
- const parsedValue = numberToEnUS(options.unmaskedValue);
44
+ onAccept: (__, maskRef, event) => {
45
+ if (!event) return;
49
46
  props?.onChange?.({
50
47
  ...event,
51
48
  target: {
52
49
  ...event?.target,
53
50
  name: props?.name,
54
- value: parsedValue
51
+ value: maskRef.typedValue
55
52
  }
56
53
  });
57
54
  }
58
55
  });
59
56
  const handleBlur = (event_0) => {
57
+ const currentValue = maskRef_0.current?.typedValue ?? typedValue;
60
58
  if (!_.isNil(min)) {
61
- const currentValue = numberToEnUS(maskedValue);
62
- if (_.isNaN(currentValue) || currentValue < min) {
59
+ if (_.isNil(currentValue) || _.isNaN(currentValue) || currentValue < min) {
63
60
  setMaskedValue(numberToPtBR(min) ?? _.toString(min));
64
61
  props?.onChange?.({
65
62
  ...event_0,
@@ -71,19 +68,24 @@ const CurrencyField = (props) => {
71
68
  });
72
69
  }
73
70
  }
74
- props?.onBlur?.(event_0);
71
+ props?.onBlur?.({
72
+ ...event_0,
73
+ target: {
74
+ ...event_0?.target,
75
+ value: currentValue
76
+ }
77
+ });
75
78
  };
76
79
  useEffect(() => {
77
80
  if (_.isNil(props?.value)) {
78
81
  if (maskedValue !== "") {
79
- isResetting.current = true;
80
82
  setMaskedValue("");
81
83
  }
82
84
  return;
83
85
  }
84
- const valueToPtBR = numberToPtBR(props?.value) ?? "";
85
- if (!_.isEqual(parseFloat(_.toString(props?.value)), numberToEnUS(maskedValue))) {
86
- setMaskedValue(valueToPtBR);
86
+ const numericValue = typeof props.value === "string" ? parseFloat(props.value) : props.value;
87
+ if (!_.isEqual(typedValue, numericValue)) {
88
+ setMaskedValue(numberToPtBR(props?.value) ?? "");
87
89
  }
88
90
  }, [props?.value]);
89
91
  return /* @__PURE__ */ jsx(InputTextBase, { ...props, inputRef: mergeRefs(currencyNumberInputRef, inputRef), type: "text", onChange: () => {
@@ -1 +1 @@
1
- {"version":3,"file":"Currency.js","sources":["../../../src/lib/inputs/number/Currency.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\nimport _ from 'lodash';\nimport { useIMask } from 'react-imask';\nimport { ICurrencyProps } from './types';\nimport { numberToEnUS, numberToPtBR } from './format_number';\nimport InputTextBase from '../base/InputTextBase';\nimport { mergeRefs } from '../../form2/helpers';\nimport type { CustomInputEvent } from '../base/types';\n\nconst CurrencyField = (props: ICurrencyProps) => {\n const {\n inputRef = undefined, textAlign = 'left', themePopover = 'light', popoverAlign = 'left',\n min = undefined, max = undefined, allowNegative = false, scale = 2, normalizeZeros = true,\n padFractionalZeros = true, unmask = true, currencySymbol = 'R$', displayCurrencySymbol = true,\n } = props;\n const currencyNumberInputRef = useRef<HTMLInputElement | null>(null);\n const isResetting = useRef(false);\n const leftElements = displayCurrencySymbol ?\n <span className=\"currency-symbol\">{currencySymbol}</span>\n : [];\n\n const { value: maskedValue, setValue: setMaskedValue } = useIMask({\n mask: Number,\n unmask,\n scale,\n normalizeZeros,\n padFractionalZeros,\n max,\n min: !_.isNil(min) ? min : (allowNegative ? undefined : 0),\n radix: ',',\n mapToRadix: ['.'],\n thousandsSeparator: '.',\n }, {\n ref: currencyNumberInputRef,\n onAccept: (__, options, event) => {\n if (isResetting.current) {\n isResetting.current = false;\n return;\n }\n const parsedValue = numberToEnUS(options.unmaskedValue);\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: parsedValue as any,\n },\n } as React.ChangeEvent<HTMLInputElement>);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n if (!_.isNil(min)) {\n const currentValue = numberToEnUS(maskedValue) as number;\n if (_.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(numberToPtBR(min) ?? _.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.(event);\n };\n\n useEffect(() => {\n if (_.isNil(props?.value)) {\n if (maskedValue !== '') {\n isResetting.current = true;\n setMaskedValue('');\n }\n return;\n }\n const valueToPtBR = numberToPtBR(props?.value) ?? '';\n if (!_.isEqual(\n parseFloat(_.toString(props?.value)), numberToEnUS(maskedValue),\n )) {\n setMaskedValue(valueToPtBR);\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(currencyNumberInputRef, inputRef) as any}\n type=\"text\"\n onChange={() => { }}\n leftElements={leftElements}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default CurrencyField;\n"],"names":["CurrencyField","props","inputRef","undefined","textAlign","themePopover","popoverAlign","min","max","allowNegative","scale","normalizeZeros","padFractionalZeros","unmask","currencySymbol","displayCurrencySymbol","currencyNumberInputRef","useRef","isResetting","leftElements","value","maskedValue","setValue","setMaskedValue","useIMask","mask","Number","_","isNil","radix","mapToRadix","thousandsSeparator","ref","onAccept","__","options","event","current","parsedValue","numberToEnUS","unmaskedValue","onChange","target","name","handleBlur","currentValue","isNaN","numberToPtBR","toString","onBlur","useEffect","valueToPtBR","isEqual","parseFloat","mergeRefs"],"mappings":";;;;;;;AASA,MAAMA,gBAAgBA,CAACC,UAA0B;AAC/C,QAAM;AAAA,IACJC,WAAWC;AAAAA,IAAWC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IACjFC,MAAMJ;AAAAA,IAAWK,MAAML;AAAAA,IAAWM,gBAAgB;AAAA,IAAOC,QAAQ;AAAA,IAAGC,iBAAiB;AAAA,IACrFC,qBAAqB;AAAA,IAAMC,SAAS;AAA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,UACHM,QAAQ;AAAA,YACN,GAAGN,SAAOM;AAAAA,YACVC,MAAM1C,OAAO0C;AAAAA,YACbvB,OAAOb;AAAAA,UAAAA;AAAAA,QACT,CACmB;AAAA,MACvB;AAAA,IACF;AACAN,WAAOgD,SAASb,OAAK;AAAA,EACvB;AAEAc,YAAU,MAAM;AACd,QAAIvB,EAAEC,MAAM3B,OAAOmB,KAAK,GAAG;AACzB,UAAIC,gBAAgB,IAAI;AACtBH,oBAAYmB,UAAU;AACtBd,uBAAe,EAAE;AAAA,MACnB;AACA;AAAA,IACF;AACA,UAAM4B,cAAcJ,aAAa9C,OAAOmB,KAAK,KAAK;AAClD,QAAI,CAACO,EAAEyB,QACLC,WAAW1B,EAAEqB,SAAS/C,OAAOmB,KAAK,CAAC,GAAGmB,aAAalB,WAAW,CAChE,GAAG;AACDE,qBAAe4B,WAAW;AAAA,IAC5B;AAAA,EACF,GAAG,CAAClD,OAAOmB,KAAK,CAAC;AAEjB,SACE,oBAAC,eAAA,EACC,GAAInB,OACJ,UAAUqD,UAAUtC,wBAAwBd,QAAQ,GACpD,MAAK,QACL,UAAU,MAAM;AAAA,EAAE,GAClB,cACA,QAAQ0C,YACR,OAAOvB,aACP,WACA,cACA,cAA2B;AAEjC;"}
1
+ {"version":3,"file":"Currency.js","sources":["../../../src/lib/inputs/number/Currency.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport _ from 'lodash';\nimport { useIMask } from 'react-imask';\nimport { ICurrencyProps } from './types';\nimport { numberToPtBR } from './format_number';\nimport InputTextBase from '../base/InputTextBase';\nimport { mergeRefs } from '../../form2/helpers';\nimport type { CustomInputEvent } from '../base/types';\n\nconst CurrencyField = (props: ICurrencyProps) => {\n const {\n inputRef = undefined, textAlign = 'left', themePopover = 'light', popoverAlign = 'left',\n min = undefined, max = undefined, allowNegative = false, scale = 2, normalizeZeros = true,\n padFractionalZeros = true, unmask = true, currencySymbol = 'R$', displayCurrencySymbol = true,\n } = props;\n const currencyNumberInputRef = useRef<HTMLInputElement | null>(null);\n const leftElements = displayCurrencySymbol ?\n <span className=\"currency-symbol\">{currencySymbol}</span>\n : [];\n\n const { maskRef, value: maskedValue, setValue: setMaskedValue, typedValue } = useIMask({\n mask: Number,\n unmask,\n scale,\n normalizeZeros,\n padFractionalZeros,\n max,\n min: !_.isNil(min) ? min : (allowNegative ? undefined : 0),\n radix: ',',\n mapToRadix: ['.'],\n thousandsSeparator: '.',\n }, {\n ref: currencyNumberInputRef,\n onAccept: (__, maskRef, event) => {\n if (!event) return;\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: maskRef.typedValue as any,\n },\n } as CustomInputEvent);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n const currentValue = (maskRef.current?.typedValue ?? typedValue) as number;\n if (!_.isNil(min)) {\n if (_.isNil(currentValue) || _.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(numberToPtBR(min) ?? _.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.({ \n ...event, \n target: { \n ...event?.target, \n value: currentValue as any, \n }, \n });\n };\n\n useEffect(() => {\n if (_.isNil(props?.value)) {\n if (maskedValue !== '') {\n setMaskedValue('');\n }\n return;\n }\n const numericValue = typeof props.value === 'string' ? parseFloat(props.value) : props.value;\n if (!_.isEqual(typedValue, numericValue)) {\n setMaskedValue(numberToPtBR(props?.value) ?? '');\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(currencyNumberInputRef, inputRef) as any}\n type=\"text\"\n onChange={() => { }}\n leftElements={leftElements}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default CurrencyField;\n"],"names":["CurrencyField","props","inputRef","undefined","textAlign","themePopover","popoverAlign","min","max","allowNegative","scale","normalizeZeros","padFractionalZeros","unmask","currencySymbol","displayCurrencySymbol","currencyNumberInputRef","useRef","leftElements","maskRef","value","maskedValue","setValue","setMaskedValue","typedValue","useIMask","mask","Number","_","isNil","radix","mapToRadix","thousandsSeparator","ref","onAccept","__","event","onChange","target","name","handleBlur","currentValue","current","isNaN","numberToPtBR","toString","onBlur","useEffect","numericValue","parseFloat","isEqual","mergeRefs"],"mappings":";;;;;;;AASA,MAAMA,gBAAgBA,CAACC,UAA0B;AAC/C,QAAM;AAAA,IACJC,WAAWC;AAAAA,IAAWC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IACjFC,MAAMJ;AAAAA,IAAWK,MAAML;AAAAA,IAAWM,gBAAgB;AAAA,IAAOC,QAAQ;AAAA,IAAGC,iBAAiB;AAAA,IACrFC,qBAAqB;AAAA,IAAMC,SAAS;AAAA,IAAMC,iBAAiB;AAAA,IAAMC,wBAAwB;AAAA,EAAA,IACvFd;AACJ,QAAMe,yBAAyBC,OAAgC,IAAI;AACnE,QAAMC,eAAeH,wBACnB,oBAAC,QAAA,EAAK,WAAU,mBAAmBD,UAAAA,eAAAA,CAAe,IAChD,CAAA;AAEJ,QAAM;AAAA,IAAEK,SAAAA;AAAAA,IAASC,OAAOC;AAAAA,IAAaC,UAAUC;AAAAA,IAAgBC;AAAAA,EAAAA,IAAeC,SAAS;AAAA,IACrFC,MAAMC;AAAAA,IACNd;AAAAA,IACAH;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAJ;AAAAA,IACAD,KAAK,CAACqB,EAAEC,MAAMtB,GAAG,IAAIA,MAAOE,gBAAgBN,SAAY;AAAA,IACxD2B,OAAO;AAAA,IACPC,YAAY,CAAC,GAAG;AAAA,IAChBC,oBAAoB;AAAA,EAAA,GACnB;AAAA,IACDC,KAAKjB;AAAAA,IACLkB,UAAUA,CAACC,IAAIhB,S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GAAG,CAACnB,OAAOmB,KAAK,CAAC;AAEjB,SACE,oBAAC,eAAA,EACC,GAAInB,OACJ,UAAUkD,UAAUnC,wBAAwBd,QAAQ,GACpD,MAAK,QACL,UAAU,MAAM;AAAA,EAAE,GAClB,cACA,QAAQsC,YACR,OAAOnB,aACP,WACA,cACA,cAA2B;AAEjC;"}
@@ -2,7 +2,7 @@ import { jsx } from "react/jsx-runtime";
2
2
  import _ from "../../_virtual/lodash.js";
3
3
  import { useRef, useEffect } from "react";
4
4
  import { useIMask } from "react-imask";
5
- import { numberToEnUS, numberToPtBR } from "./format_number.js";
5
+ import { numberToPtBR } from "./format_number.js";
6
6
  import InputTextBase from "../base/InputTextBase.js";
7
7
  import { mergeRefs } from "../../form2/helpers.js";
8
8
  const DecimalField = (props) => {
@@ -20,10 +20,11 @@ const DecimalField = (props) => {
20
20
  inputRef = void 0
21
21
  } = props;
22
22
  const decimalNumberInputRef = useRef(null);
23
- const isResetting = useRef(false);
24
23
  const {
24
+ maskRef: maskRef_0,
25
25
  value: maskedValue,
26
- setValue: setMaskedValue
26
+ setValue: setMaskedValue,
27
+ typedValue
27
28
  } = useIMask({
28
29
  mask: Number,
29
30
  unmask,
@@ -37,26 +38,22 @@ const DecimalField = (props) => {
37
38
  thousandsSeparator: "."
38
39
  }, {
39
40
  ref: decimalNumberInputRef,
40
- onAccept: (__, options, event) => {
41
- if (isResetting.current) {
42
- isResetting.current = false;
43
- return;
44
- }
45
- const parsedValue = numberToEnUS(options.unmaskedValue);
41
+ onAccept: (__, maskRef, event) => {
42
+ if (!event) return;
46
43
  props?.onChange?.({
47
44
  ...event,
48
45
  target: {
49
46
  ...event?.target,
50
47
  name: props?.name,
51
- value: parsedValue
48
+ value: maskRef.typedValue
52
49
  }
53
50
  });
54
51
  }
55
52
  });
56
53
  const handleBlur = (event_0) => {
54
+ const currentValue = maskRef_0.current?.typedValue ?? typedValue;
57
55
  if (!_.isNil(min)) {
58
- const currentValue = numberToEnUS(maskedValue);
59
- if (_.isNaN(currentValue) || currentValue < min) {
56
+ if (_.isNil(currentValue) || _.isNaN(currentValue) || currentValue < min) {
60
57
  setMaskedValue(numberToPtBR(min) ?? _.toString(min));
61
58
  props?.onChange?.({
62
59
  ...event_0,
@@ -68,19 +65,24 @@ const DecimalField = (props) => {
68
65
  });
69
66
  }
70
67
  }
71
- props?.onBlur?.(event_0);
68
+ props?.onBlur?.({
69
+ ...event_0,
70
+ target: {
71
+ ...event_0?.target,
72
+ value: currentValue
73
+ }
74
+ });
72
75
  };
73
76
  useEffect(() => {
74
77
  if (_.isNil(props?.value)) {
75
78
  if (maskedValue !== "") {
76
- isResetting.current = true;
77
79
  setMaskedValue("");
78
80
  }
79
81
  return;
80
82
  }
81
- const valueToPtBR = numberToPtBR(props?.value) ?? "";
82
- if (!_.isEqual(parseFloat(_.toString(props?.value)), numberToEnUS(maskedValue))) {
83
- setMaskedValue(valueToPtBR);
83
+ const numericValue = typeof props.value === "string" ? parseFloat(props.value) : props.value;
84
+ if (!_.isEqual(typedValue, numericValue)) {
85
+ setMaskedValue(numberToPtBR(props?.value) ?? "");
84
86
  }
85
87
  }, [props?.value]);
86
88
  return /* @__PURE__ */ jsx(InputTextBase, { ...props, inputRef: mergeRefs(decimalNumberInputRef, inputRef), type: "text", onChange: () => {
@@ -1 +1 @@
1
- {"version":3,"file":"Decimal.js","sources":["../../../src/lib/inputs/number/Decimal.tsx"],"sourcesContent":["import _ from 'lodash';\nimport React, { useEffect, useRef } from 'react';\nimport { useIMask } from 'react-imask';\nimport { IDecimalProps } from './types';\nimport { numberToEnUS, numberToPtBR } from './format_number';\nimport InputTextBase from '../base/InputTextBase';\nimport type { CustomInputEvent } from '../base/types';\nimport { mergeRefs } from '../../form2/helpers';\n\nconst DecimalField = (props: IDecimalProps) => {\n const {\n textAlign = 'left', themePopover = 'light', popoverAlign = 'left', min = undefined,\n max = undefined, allowNegative = false, scale = 2, normalizeZeros = true,\n padFractionalZeros = true, unmask = true, inputRef = undefined,\n } = props;\n const decimalNumberInputRef = useRef<HTMLInputElement | null>(null);\n const isResetting = useRef(false);\n\n const { value: maskedValue, setValue: setMaskedValue } = useIMask({\n mask: Number,\n unmask,\n scale,\n normalizeZeros,\n padFractionalZeros,\n max,\n min: !_.isNil(min) ? min : (allowNegative ? undefined : 0),\n radix: ',',\n mapToRadix: ['.'],\n thousandsSeparator: '.',\n }, {\n ref: decimalNumberInputRef,\n onAccept: (__, options, event) => {\n if (isResetting.current) {\n isResetting.current = false;\n return;\n }\n const parsedValue = numberToEnUS(options.unmaskedValue);\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: parsedValue as any,\n },\n } as React.ChangeEvent<HTMLInputElement>);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n if (!_.isNil(min)) {\n const currentValue = numberToEnUS(maskedValue) as number;\n if (_.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(numberToPtBR(min) ?? _.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.(event);\n };\n\n useEffect(() => {\n if (_.isNil(props?.value)) {\n if (maskedValue !== '') {\n isResetting.current = true;\n setMaskedValue('');\n }\n return;\n }\n const valueToPtBR = numberToPtBR(props?.value) ?? '';\n if (!_.isEqual(\n parseFloat(_.toString(props?.value)), numberToEnUS(maskedValue),\n )) {\n setMaskedValue(valueToPtBR);\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(decimalNumberInputRef, inputRef) as any}\n type=\"text\"\n onChange={() => { }}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default DecimalField;\n"],"names":["DecimalField","props","textAlign","themePopover","popoverAlign","min","undefined","max","allowNegative","scale","normalizeZeros","padFractionalZeros","unmask","inputRef","decimalNumberInputRef","useRef","isResetting","value","maskedValue","setValue","setMaskedValue","useIMask","mask","Number","_","isNil","radix","mapToRadix","thousandsSeparator","ref","onAccept","__","options","event","current","parsedValue","numberToEnUS","unmaskedValue","onChange","target","name","handleBlur","currentValue","isNaN","numberToPtBR","toString","onBlur","useEffect","valueToPtBR","isEqual","parseFloat","mergeRefs"],"mappings":";;;;;;;AASA,MAAMA,eAAeA,CAACC,UAAyB;AAC7C,QAAM;AAAA,IACJC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IAAQC,MAAMC;AAAAA,IACzEC,MAAMD;AAAAA,IAAWE,gBAAgB;AAAA,IAAOC,QAAQ;AAAA,IAAGC,iBAAiB;AAAA,IACpEC,qBAAqB;AAAA,IAAMC,SAAS;AAAA,IAAMC,WAAWP;AAAAA,EAAAA,IACnDL;AACJ,QAAMa,wBAAwBC,OAAgC,IAAI;AAClE,QAAMC,cAAcD,OAAO,KAAK;AAEhC,QAAM;AAAA,IAAEE,OAAOC;AAAAA,IAAaC,UAAUC;AAAAA,EAAAA,IAAmBC,SAAS;AAAA,IAChEC,MAAMC;AAAAA,IACNX;AAAAA,IACAH;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAJ;AAAAA,IACAF,KAAK,CAACmB,EAAEC,MAAMpB,GAAG,IAAIA,MAAOG,gBAAgBF,SAAY;AAAA,IACxDoB,OAAO;AAAA,IACPC,YAAY,CAAC,GAAG;AAAA,IAChBC,oBAAoB;AAAA,EAAA,GACnB;AAAA,IACDC,KAAKf;AAAAA,IACLgB,UAAUA,CAACC,IAAIC,SAASC,UAAU;AAChC,UAAIjB,YAAYkB,SAAS;AACvBlB,oBAAYkB,UAAU;AACtB;AAAA,MACF;AACA,YAAMC,cAAcC,aAAaJ,QAAQK,aAAa;AACtDpC,aAAOqC,WAAW;AAAA,QAChB,GAAGL;AAAAA,QACHM,QAAQ;AA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":["../../../src/lib/inputs/number/Decimal.tsx"],"sourcesContent":["import _ from 'lodash';\nimport { useEffect, useRef } from 'react';\nimport { useIMask } from 'react-imask';\nimport { IDecimalProps } from './types';\nimport { numberToPtBR } from './format_number';\nimport InputTextBase from '../base/InputTextBase';\nimport type { CustomInputEvent } from '../base/types';\nimport { mergeRefs } from '../../form2/helpers';\n\nconst DecimalField = (props: IDecimalProps) => {\n const {\n textAlign = 'left', themePopover = 'light', popoverAlign = 'left', min = undefined,\n max = undefined, allowNegative = false, scale = 2, normalizeZeros = true,\n padFractionalZeros = true, unmask = true, inputRef = undefined,\n } = props;\n const decimalNumberInputRef = useRef<HTMLInputElement | null>(null);\n\n const { maskRef, value: maskedValue, setValue: setMaskedValue, typedValue } = useIMask({\n mask: Number,\n unmask,\n scale,\n normalizeZeros,\n padFractionalZeros,\n max,\n min: !_.isNil(min) ? min : (allowNegative ? undefined : 0),\n radix: ',',\n mapToRadix: ['.'],\n thousandsSeparator: '.',\n }, {\n ref: decimalNumberInputRef,\n onAccept: (__, maskRef, event) => {\n if (!event) return;\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: maskRef.typedValue as any,\n },\n } as CustomInputEvent);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n const currentValue = (maskRef.current?.typedValue ?? typedValue) as number;\n if (!_.isNil(min)) {\n if (_.isNil(currentValue) || _.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(numberToPtBR(min) ?? _.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.({ \n ...event, \n target: { \n ...event?.target, \n value: currentValue as any, \n }, \n });\n };\n\n useEffect(() => {\n if (_.isNil(props?.value)) {\n if (maskedValue !== '') {\n setMaskedValue('');\n }\n return;\n }\n const numericValue = typeof props.value === 'string' ? parseFloat(props.value) : props.value;\n if (!_.isEqual(typedValue, numericValue)) {\n setMaskedValue(numberToPtBR(props?.value) ?? '');\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(decimalNumberInputRef, inputRef) as any}\n type=\"text\"\n onChange={() => { }}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default DecimalField;\n"],"names":["DecimalField","props","textAlign","themePopover","popoverAlign","min","undefined","max","allowNegative","scale","normalizeZeros","padFractionalZeros","unmask","inputRef","decimalNumberInputRef","useRef","maskRef","value","maskedValue","setValue","setMaskedValue","typedValue","useIMask","mask","Number","_","isNil","radix","mapToRadix","thousandsSeparator","ref","onAccept","__","event","onChange","target","name","handleBlur","currentValue","current","isNaN","numberToPtBR","toString","onBlur","useEffect","numericValue","parseFloat","isEqual","mergeRefs"],"mappings":";;;;;;;AASA,MAAMA,eAAeA,CAACC,UAAyB;AAC7C,QAAM;AAAA,IACJC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IAAQC,MAAMC;AAAAA,IACzEC,MAAMD;AAAAA,IAAWE,gBAAgB;AAAA,IAAOC,QAAQ;AAAA,IAAGC,iBAAiB;AAAA,IACpEC,qBAAqB;AAAA,IAAMC,SAAS;AAAA,IAAMC,WAAWP;AAAAA,EAAAA,IACnDL;AACJ,QAAMa,wBAAwBC,OAAgC,IAAI;AAElE,QAAM;AAAA,IAAEC,SAAAA;AAAAA,IAASC,OAAOC;AAAAA,IAAaC,UAAUC;AAAAA,IAAgBC;AAAAA,EAAAA,IAAeC,SAAS;AAAA,IACrFC,MAAMC;AAAAA,IACNZ;AAAAA,IACAH;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAJ;AAAAA,IACAF,KAAK,CAACoB,EAAEC,MAAMrB,GAAG,IAAIA,MAAOG,gBAAgBF,SAAY;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,IAAIhB,MAAMgB;AACvF,QAAI,CAACQ,EAAEsB,QAAQ1B,YAAYwB,YAAY,GAAG;AACxCzB,qBAAeqB,aAAaxC,OAAOgB,KAAK,KAAK,EAAE;AAAA,IACjD;AAAA,EACF,GAAG,CAAChB,OAAOgB,KAAK,CAAC;AAEjB,SACE,oBAAC,eAAA,EACC,GAAIhB,OACJ,UAAU+C,UAAUlC,uBAAuBD,QAAQ,GACnD,MAAK,QACL,UAAU,MAAM;AAAA,EAAE,GAClB,QAAQwB,YACR,OAAOnB,aACP,WACA,cACA,cAA2B;AAEjC;"}
@@ -17,10 +17,11 @@ const NumberField = (props) => {
17
17
  inputRef = void 0
18
18
  } = props;
19
19
  const numberInputRef = useRef(null);
20
- const isResetting = useRef(false);
21
20
  const {
21
+ maskRef: maskRef_0,
22
22
  value: maskedValue,
23
- setValue: setMaskedValue
23
+ setValue: setMaskedValue,
24
+ typedValue
24
25
  } = useIMask({
25
26
  mask: Number,
26
27
  max,
@@ -33,26 +34,22 @@ const NumberField = (props) => {
33
34
  padFractionalZeros: false
34
35
  }, {
35
36
  ref: numberInputRef,
36
- onAccept: (value, __, event) => {
37
- if (isResetting.current) {
38
- isResetting.current = false;
39
- return;
40
- }
41
- const parsedValue = parseInt(value, 10);
37
+ onAccept: (__, maskRef, event) => {
38
+ if (!event) return;
42
39
  props?.onChange?.({
43
40
  ...event,
44
41
  target: {
45
42
  ...event?.target,
46
43
  name: props?.name,
47
- value: parsedValue
44
+ value: maskRef.typedValue
48
45
  }
49
46
  });
50
47
  }
51
48
  });
52
49
  const handleBlur = (event_0) => {
50
+ const currentValue = maskRef_0.current?.typedValue ?? typedValue;
53
51
  if (!_.isNil(min)) {
54
- const currentValue = parseInt(maskedValue, 10);
55
- if (_.isNaN(currentValue) || currentValue < min) {
52
+ if (_.isNil(currentValue) || _.isNaN(currentValue) || currentValue < min) {
56
53
  setMaskedValue(_.toString(min));
57
54
  props?.onChange?.({
58
55
  ...event_0,
@@ -64,18 +61,23 @@ const NumberField = (props) => {
64
61
  });
65
62
  }
66
63
  }
67
- props?.onBlur?.(event_0);
64
+ props?.onBlur?.({
65
+ ...event_0,
66
+ target: {
67
+ ...event_0?.target,
68
+ value: currentValue
69
+ }
70
+ });
68
71
  };
69
72
  useEffect(() => {
70
73
  if (_.isNil(props?.value)) {
71
74
  if (maskedValue !== "") {
72
- isResetting.current = true;
73
75
  setMaskedValue("");
74
76
  }
75
77
  return;
76
78
  }
77
- const floatMaskedValue = Number(maskedValue || "0");
78
- if (!_.isEqual(props?.value, floatMaskedValue) || _.isEqual(props?.value, 0)) {
79
+ const numericValue = typeof props.value === "string" ? Number(props.value) : props.value;
80
+ if (!_.isEqual(typedValue, numericValue)) {
79
81
  setMaskedValue(_.toString(props?.value));
80
82
  }
81
83
  }, [props?.value]);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/lib/inputs/number/index.tsx"],"sourcesContent":["import '../../assets/styles/numbers.scss';\n\nimport React, { useEffect, useRef } from 'react';\nimport _ from 'lodash';\nimport { useIMask } from 'react-imask';\nimport DecimalField from './Decimal';\nimport CurrencyField from './Currency';\nimport { INumberFieldProps } from './types';\nimport InputTextBase from '../base/InputTextBase';\nimport { CustomInputEvent } from '../base/types';\nimport { mergeRefs } from '../../form2/helpers';\n\nconst NumberField = (props: INumberFieldProps) => {\n const {\n textAlign = 'left', themePopover = 'light', popoverAlign = 'left', min = undefined, \n max = undefined, inputRef = undefined,\n } = props;\n const numberInputRef = useRef<HTMLInputElement | null>(null);\n const isResetting = useRef(false);\n\n const { value: maskedValue, setValue: setMaskedValue } = useIMask({\n mask: Number,\n max,\n min,\n scale: 0,\n enum: undefined,\n to: undefined,\n from: undefined,\n normalizeZeros: true,\n padFractionalZeros: false,\n }, {\n ref: numberInputRef,\n onAccept: (value, __, event) => {\n if (isResetting.current) {\n isResetting.current = false;\n return;\n }\n const parsedValue = parseInt(value, 10);\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: parsedValue as any,\n },\n } as CustomInputEvent);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n if (!_.isNil(min)) {\n const currentValue = parseInt(maskedValue, 10) as number;\n if (_.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(_.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.(event);\n };\n\n useEffect(() => {\n if (_.isNil(props?.value)) {\n if (maskedValue !== '') {\n isResetting.current = true;\n setMaskedValue('');\n }\n return;\n }\n const floatMaskedValue = Number(maskedValue || '0');\n if (!_.isEqual(props?.value, floatMaskedValue) || _.isEqual(props?.value, 0)) {\n setMaskedValue(_.toString(props?.value));\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(numberInputRef, inputRef) as any}\n type=\"number\"\n onChange={() => {}}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default NumberField;\nexport {\n CurrencyField,\n DecimalField,\n};\n"],"names":["NumberField","props","textAlign","themePopover","popoverAlign","min","undefined","max","inputRef","numberInputRef","useRef","isResetting","value","maskedValue","setValue","setMaskedValue","useIMask","mask","Number","scale","enum","to","from","normalizeZeros","padFractionalZeros","ref","onAccept","__","event","current","parsedValue","parseInt","onChange","target","name","handleBlur","_","isNil","currentValue","isNaN","toString","onBlur","useEffect","floatMaskedValue","isEqual","mergeRefs"],"mappings":";;;;;;;;;AAYA,MAAMA,cAAcA,CAACC,UAA6B;AAChD,QAAM;AAAA,IACJC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IAAQC,MAAMC;AAAAA,IACzEC,MAAMD;AAAAA,IAAWE,WAAWF;AAAAA,EAAAA,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C,MAAMpC,OAAOW,KAAK,GAAG;AACzB,UAAIC,gBAAgB,IAAI;AACtBF,oBAAYkB,UAAU;AACtBd,uBAAe,EAAE;AAAA,MACnB;AACA;AAAA,IACF;AACA,UAAM4B,mBAAmBzB,OAAOL,eAAe,GAAG;AAClD,QAAI,CAACuB,EAAEQ,QAAQ3C,OAAOW,OAAO+B,gBAAgB,KAAKP,EAAEQ,QAAQ3C,OAAOW,OAAO,CAAC,GAAG;AAC5EG,qBAAeqB,EAAEI,SAASvC,OAAOW,KAAK,CAAC;AAAA,IACzC;AAAA,EACF,GAAG,CAACX,OAAOW,KAAK,CAAC;AAEjB,SACE,oBAAC,eAAA,EACC,GAAIX,OACJ,UAAU4C,UAAUpC,gBAAgBD,QAAQ,GAC5C,MAAK,UACL,UAAU,MAAM;AAAA,EAAC,GACjB,QAAQ2B,YACR,OAAOtB,aACP,WACA,cACA,cAA2B;AAEjC;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/lib/inputs/number/index.tsx"],"sourcesContent":["import '../../assets/styles/numbers.scss';\n\nimport { useEffect, useRef } from 'react';\nimport _ from 'lodash';\nimport { useIMask } from 'react-imask';\nimport DecimalField from './Decimal';\nimport CurrencyField from './Currency';\nimport { INumberFieldProps } from './types';\nimport InputTextBase from '../base/InputTextBase';\nimport { CustomInputEvent } from '../base/types';\nimport { mergeRefs } from '../../form2/helpers';\n\nconst NumberField = (props: INumberFieldProps) => {\n const {\n textAlign = 'left', themePopover = 'light', popoverAlign = 'left', min = undefined, \n max = undefined, inputRef = undefined,\n } = props;\n const numberInputRef = useRef<HTMLInputElement | null>(null);\n\n const { maskRef, value: maskedValue, setValue: setMaskedValue, typedValue } = useIMask({\n mask: Number,\n max,\n min,\n scale: 0,\n enum: undefined,\n to: undefined,\n from: undefined,\n normalizeZeros: true,\n padFractionalZeros: false,\n }, {\n ref: numberInputRef,\n onAccept: (__, maskRef, event) => {\n if (!event) return;\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: maskRef.typedValue as any,\n },\n } as CustomInputEvent);\n },\n });\n\n /**\n * Função sobrescrevendo o evento onBlur para tratar o valor mínimo ao sair do campo, \n * garantindo que o valor não seja menor que o mínimo definido.\n */\n const handleBlur = (event: CustomInputEvent) => {\n const currentValue = (maskRef.current?.typedValue ?? typedValue) as number;\n if (!_.isNil(min)) {\n if (_.isNil(currentValue) || _.isNaN(currentValue) || currentValue < min) {\n setMaskedValue(_.toString(min));\n props?.onChange?.({\n ...event,\n target: {\n ...event?.target,\n name: props?.name,\n value: min as any,\n },\n } as CustomInputEvent);\n }\n }\n props?.onBlur?.({ \n ...event, \n target: { \n ...event?.target, \n value: currentValue as any, \n }, \n });\n };\n\n useEffect(() => {\n if (_.isNil(props?.value)) {\n if (maskedValue !== '') {\n setMaskedValue('');\n }\n return;\n }\n const numericValue = typeof props.value === 'string' ? Number(props.value) : props.value;\n if (!_.isEqual(typedValue, numericValue)) {\n setMaskedValue(_.toString(props?.value));\n }\n }, [props?.value]);\n\n return (\n <InputTextBase\n {...props}\n inputRef={mergeRefs(numberInputRef, inputRef) as any}\n type=\"number\"\n onChange={() => {}}\n onBlur={handleBlur}\n value={maskedValue}\n textAlign={textAlign}\n themePopover={themePopover}\n popoverAlign={popoverAlign} />\n );\n};\n\nexport default NumberField;\nexport {\n CurrencyField,\n DecimalField,\n};\n"],"names":["NumberField","props","textAlign","themePopover","popoverAlign","min","undefined","max","inputRef","numberInputRef","useRef","maskRef","value","maskedValue","setValue","setMaskedValue","typedValue","useIMask","mask","Number","scale","enum","to","from","normalizeZeros","padFractionalZeros","ref","onAccept","__","event","onChange","target","name","handleBlur","currentValue","current","_","isNil","isNaN","toString","onBlur","useEffect","numericValue","isEqual","mergeRefs"],"mappings":";;;;;;;;;AAYA,MAAMA,cAAcA,CAACC,UAA6B;AAChD,QAAM;AAAA,IACJC,YAAY;AAAA,IAAQC,eAAe;AAAA,IAASC,eAAe;AAAA,IAAQC,MAAMC;AAAAA,IACzEC,MA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AGF,SAAOE;AAAAA,QACVnB,OAAOsB;AAAAA,MAAAA;AAAAA,IACT,CACD;AAAA,EACH;AAEAO,YAAU,MAAM;AACd,QAAIL,EAAEC,MAAMpC,OAAOW,KAAK,GAAG;AACzB,UAAIC,gBAAgB,IAAI;AACtBE,uBAAe,EAAE;AAAA,MACnB;AACA;AAAA,IACF;AACA,UAAM2B,eAAe,OAAOzC,MAAMW,UAAU,WAAWO,OAAOlB,MAAMW,KAAK,IAAIX,MAAMW;AACnF,QAAI,CAACwB,EAAEO,QAAQ3B,YAAY0B,YAAY,GAAG;AACxC3B,qBAAeqB,EAAEG,SAAStC,OAAOW,KAAK,CAAC;AAAA,IACzC;AAAA,EACF,GAAG,CAACX,OAAOW,KAAK,CAAC;AAEjB,SACE,oBAAC,eAAA,EACC,GAAIX,OACJ,UAAU2C,UAAUnC,gBAAgBD,QAAQ,GAC5C,MAAK,UACL,UAAU,MAAM;AAAA,EAAC,GACjB,QAAQyB,YACR,OAAOpB,aACP,WACA,cACA,cAA2B;AAEjC;"}
@@ -0,0 +1,23 @@
1
+ import { Moment } from 'moment';
2
+ import { ReactNode, RefObject } from 'react';
3
+ interface CalendarDayState {
4
+ isSelected: boolean;
5
+ isInRange?: boolean;
6
+ isDisabled?: boolean;
7
+ }
8
+ interface CalendarBoxProps {
9
+ testIdPrefix: string;
10
+ headerId: string;
11
+ calendarBoxOpen: boolean;
12
+ activeDescendant: string;
13
+ calendarDisplayDate: Moment;
14
+ containerRef: RefObject<HTMLDivElement | null>;
15
+ onNextMonth: () => void;
16
+ onPreviousMonth: () => void;
17
+ getDayState: (day: Moment) => CalendarDayState;
18
+ onSelectDay: (day: Moment) => void;
19
+ children?: ReactNode;
20
+ }
21
+ declare const CalendarBox: import('react').ForwardRefExoticComponent<CalendarBoxProps & import('react').RefAttributes<HTMLDivElement>>;
22
+ export { CalendarBox };
23
+ export type { CalendarBoxProps, CalendarDayState };