@dilicorp/ui 2.0.0 → 2.0.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.
@@ -1,19 +1,33 @@
1
1
  import { FastField, Field } from 'formik';
2
- import React, { useCallback } from 'react';
2
+ import React, { useCallback, useRef } from 'react';
3
3
  import numberHelper from '../../../utils/number-helper';
4
4
  export const InputCurrency = ({ attrs, handleChange, currency, name }) => {
5
5
  const { maxLength = 20, fastField = true, ...restAttrs } = attrs;
6
6
  const { format, locale } = currency;
7
7
  const Tag = fastField ? FastField : Field;
8
+ // Rastreia se o evento de mudança foi originado por uma tecla de deleção
9
+ const isDeletingRef = useRef(false);
10
+ const handleKeyDown = useCallback((event) => {
11
+ isDeletingRef.current = event.key === 'Backspace' || event.key === 'Delete';
12
+ }, []);
8
13
  const handleChangeCurrency = useCallback((event) => {
9
14
  const rawValue = event.currentTarget.value;
10
15
  const numericValue = numberHelper.currencySanitize(rawValue, locale, format);
11
- const formatted = numericValue === null
12
- ? ''
13
- : numberHelper.currency(Number(numericValue), locale, format);
14
- handleChange({
15
- currentTarget: { name, value: formatted }
16
- });
16
+ // Nenhum dígito restante campo foi completamente limpo
17
+ if (numericValue === null) {
18
+ handleChange({ currentTarget: { name, value: '' } });
19
+ return;
20
+ }
21
+ // Usuário está apagando e o valor resultante seria zero — limpa o campo
22
+ if (isDeletingRef.current && Number(numericValue) === 0) {
23
+ handleChange({ currentTarget: { name, value: '' } });
24
+ return;
25
+ }
26
+ const formatted = numberHelper.currency(Number(numericValue), locale, format);
27
+ handleChange({ currentTarget: { name, value: formatted } });
17
28
  }, [locale, format, name, handleChange]);
18
- return (React.createElement(Tag, { name: name }, ({ field }) => (React.createElement("input", { ...field, ...restAttrs, maxLength: maxLength, onChange: handleChangeCurrency }))));
29
+ return (React.createElement(Tag, { name: name }, ({ field }) => {
30
+ var _a;
31
+ return (React.createElement("input", { ...field, ...restAttrs, value: (_a = field.value) !== null && _a !== void 0 ? _a : '', maxLength: maxLength, onKeyDown: handleKeyDown, onChange: handleChangeCurrency }));
32
+ }));
19
33
  };
@@ -38,8 +38,6 @@ class NumberHelper {
38
38
  const padded = digits.padStart(fractionDigits + 1, '0');
39
39
  const intPart = Number.parseInt(padded.slice(0, -fractionDigits), 10);
40
40
  const decPart = padded.slice(-fractionDigits);
41
- if (intPart === 0 && Number.parseInt(decPart, 10) === 0)
42
- return null;
43
41
  return `${intPart}.${decPart}`;
44
42
  }
45
43
  percentageSanitize(value, decimals = 2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dilicorp/ui",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A simple UI design for Dilicorp",
5
5
  "repository": {
6
6
  "type": "git",
@@ -84,6 +84,10 @@
84
84
  "react-dom": ">=17.0.2",
85
85
  "react-router-dom": ">=6.0.2"
86
86
  },
87
+ "publishConfig": {
88
+ "access": "public",
89
+ "registry": "https://registry.npmjs.org/"
90
+ },
87
91
  "scripts": {
88
92
  "sass:pluxee": "sass src/assets/sass/themes/pluxee.scss:src/assets/css/styles.css",
89
93
  "sass:gopass": "sass src/assets/sass/themes/gopass.scss:src/assets/css/styles.css",