linear-react-components-ui 1.1.22-beta.12 → 1.1.22-beta.13
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.
- package/lib/hooks/useSecurity/index.d.ts +13 -0
- package/lib/hooks/useSecurity/index.js +56 -0
- package/lib/inputs/mask/BaseMask.js +7 -4
- package/lib/inputs/mask/helpers.js +1 -1
- package/lib/inputs/number/BaseNumber.js +4 -3
- package/lib/inputs/number/format_number.d.ts +1 -1
- package/lib/inputs/number/format_number.js +4 -2
- package/lib/inputs/number/types.d.ts +1 -1
- package/lib/inputs/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type UseSecurityParams = {
|
|
2
|
+
showSecurity: boolean;
|
|
3
|
+
title?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
};
|
|
7
|
+
type UseSecurityReturn = {
|
|
8
|
+
handleClose: () => void;
|
|
9
|
+
SecurityComponent: () => JSX.Element | null;
|
|
10
|
+
};
|
|
11
|
+
declare function useSecurity({ showSecurity, title, message, onClose, }: UseSecurityParams): UseSecurityReturn;
|
|
12
|
+
|
|
13
|
+
export { useSecurity };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useSecurity = useSecurity;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _dialog = require("../../dialog");
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
function useSecurity(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
showSecurity = false,
|
|
14
|
+
title = 'Dados Alterados',
|
|
15
|
+
message = 'Você possui dados alterados, confirma o fechamento?',
|
|
16
|
+
onClose
|
|
17
|
+
} = _ref;
|
|
18
|
+
const [showDialogAlert, setShowDialogAlert] = (0, _react.useState)(false);
|
|
19
|
+
const handleClose = () => {
|
|
20
|
+
if (showSecurity) {
|
|
21
|
+
setShowDialogAlert(true);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
onClose();
|
|
25
|
+
};
|
|
26
|
+
const onConfirmClick = () => {
|
|
27
|
+
setShowDialogAlert(false);
|
|
28
|
+
onClose();
|
|
29
|
+
};
|
|
30
|
+
const onUnconfirmClick = () => {
|
|
31
|
+
setShowDialogAlert(false);
|
|
32
|
+
};
|
|
33
|
+
const onBeforeUnload = ev => {
|
|
34
|
+
ev.preventDefault();
|
|
35
|
+
};
|
|
36
|
+
const DialogComponent = () => /*#__PURE__*/_react.default.createElement(_dialog.DialogQuestion, {
|
|
37
|
+
zIndex: "99999999",
|
|
38
|
+
title: title,
|
|
39
|
+
text: message,
|
|
40
|
+
visible: showDialogAlert,
|
|
41
|
+
onConfirmClick: onConfirmClick,
|
|
42
|
+
onUnconfirmClick: onUnconfirmClick
|
|
43
|
+
});
|
|
44
|
+
(0, _react.useEffect)(() => {
|
|
45
|
+
if (showSecurity) {
|
|
46
|
+
window.addEventListener('beforeunload', onBeforeUnload);
|
|
47
|
+
}
|
|
48
|
+
return () => {
|
|
49
|
+
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
50
|
+
};
|
|
51
|
+
}, [showSecurity]);
|
|
52
|
+
return {
|
|
53
|
+
handleClose,
|
|
54
|
+
SecurityComponent: DialogComponent
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -34,7 +34,7 @@ const returnEventFormattedValue = (props, event) => {
|
|
|
34
34
|
const value = props.defaultValue || '';
|
|
35
35
|
return _objectSpread(_objectSpread({}, event), {}, {
|
|
36
36
|
target: {
|
|
37
|
-
value: (0, _format_number.numberToEnUS)(value),
|
|
37
|
+
value: String((0, _format_number.numberToEnUS)(value)),
|
|
38
38
|
name
|
|
39
39
|
}
|
|
40
40
|
});
|
|
@@ -151,10 +151,13 @@ const BaseMask = _ref => {
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
(0, _react.useEffect)(() => {
|
|
154
|
-
if (
|
|
155
|
-
|
|
154
|
+
if (mask === Number) {
|
|
155
|
+
const typedValue = (0, _format_number.numberToEnUS)(String(valueProp));
|
|
156
|
+
if (!Number.isNaN(typedValue)) setTypedValue(typedValue);
|
|
157
|
+
return;
|
|
156
158
|
}
|
|
157
|
-
|
|
159
|
+
const updatedValue = valueProp ? String(valueProp) : '';
|
|
160
|
+
setValue(updatedValue);
|
|
158
161
|
}, [valueProp]);
|
|
159
162
|
return /*#__PURE__*/_react.default.createElement(_InputTextBase.default, _extends({
|
|
160
163
|
inputRef: r => {
|
|
@@ -29,7 +29,7 @@ const returnEventFormattedValue = (props, event) => {
|
|
|
29
29
|
} = event.target;
|
|
30
30
|
return _objectSpread(_objectSpread({}, event), {}, {
|
|
31
31
|
target: {
|
|
32
|
-
value: (0, _format_number.numberToEnUS)(value),
|
|
32
|
+
value: String((0, _format_number.numberToEnUS)(value)),
|
|
33
33
|
name
|
|
34
34
|
}
|
|
35
35
|
});
|
|
@@ -67,10 +67,11 @@ const BaseNumber = _ref => {
|
|
|
67
67
|
returnFormattedValueOnKeyDown: true
|
|
68
68
|
});
|
|
69
69
|
return /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({
|
|
70
|
-
|
|
70
|
+
mask: Number,
|
|
71
|
+
value: value ?? 0,
|
|
71
72
|
thousandsSeparator: ".",
|
|
72
73
|
radix: ",",
|
|
73
|
-
|
|
74
|
+
mapToRadix: ['.'],
|
|
74
75
|
isNumeric: true
|
|
75
76
|
}, props, getEventProps(eventProps)));
|
|
76
77
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const numberToPtBR: (value?: string | number) => string | undefined;
|
|
2
|
-
declare const numberToEnUS: (value: string) =>
|
|
2
|
+
declare const numberToEnUS: (value: string) => number;
|
|
3
3
|
declare const formatOnlyNumbers: (value: string) => string;
|
|
4
4
|
|
|
5
5
|
export { formatOnlyNumbers, numberToEnUS, numberToPtBR };
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.numberToPtBR = exports.numberToEnUS = exports.formatOnlyNumbers = void 0;
|
|
7
|
+
const ptBRRegex = /\b\d{1,3}(?:\.\d{3})*,\d+\b/;
|
|
7
8
|
const numberToPtBR = value => {
|
|
8
9
|
if (value !== undefined && typeof value === 'number') {
|
|
9
10
|
return value.toLocaleString('pt-BR');
|
|
@@ -13,11 +14,12 @@ const numberToPtBR = value => {
|
|
|
13
14
|
exports.numberToPtBR = numberToPtBR;
|
|
14
15
|
const numberToEnUS = value => {
|
|
15
16
|
let formattedNumber;
|
|
16
|
-
|
|
17
|
+
const isPTBR = ptBRRegex.test(value);
|
|
18
|
+
if (isPTBR) {
|
|
17
19
|
formattedNumber = value.replaceAll('.', '').replaceAll(',', '.');
|
|
18
20
|
return Number(formattedNumber);
|
|
19
21
|
}
|
|
20
|
-
return value;
|
|
22
|
+
return Number(value);
|
|
21
23
|
};
|
|
22
24
|
exports.numberToEnUS = numberToEnUS;
|
|
23
25
|
const formatOnlyNumbers = value => {
|
package/lib/inputs/types.d.ts
CHANGED