linear-react-components-ui 1.1.7 → 1.1.8
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/.eslintcache +1 -1
- package/lib/form/FieldPeriod.js +1 -1
- package/lib/inputs/base/types.d.ts +2 -0
- package/lib/inputs/date/index.js +1 -2
- package/lib/inputs/errorMessage/index.d.ts +0 -1
- package/lib/inputs/inputHOC.d.ts +0 -1
- package/lib/inputs/mask/BaseMask.d.ts +2 -6
- package/lib/inputs/mask/BaseMask.js +91 -10
- package/lib/inputs/mask/Cnpj.d.ts +0 -1
- package/lib/inputs/mask/Cpf.d.ts +0 -1
- package/lib/inputs/mask/Cpf.js +1 -1
- package/lib/inputs/mask/Phone.d.ts +0 -1
- package/lib/inputs/mask/ZipCode.d.ts +0 -1
- package/lib/inputs/mask/helpers.d.ts +48 -12
- package/lib/inputs/mask/helpers.js +56 -12
- package/lib/inputs/mask/index.d.ts +2 -3
- package/lib/inputs/mask/types.d.ts +16 -19
- package/lib/inputs/number/BaseNumber.d.ts +0 -1
- package/lib/inputs/number/Currency.d.ts +0 -1
- package/lib/inputs/number/Decimal.d.ts +0 -1
- package/lib/inputs/number/index.d.ts +0 -1
- package/lib/inputs/number/types.d.ts +1 -2
- package/lib/inputs/period/index.js +44 -25
- package/lib/inputs/search/index.d.ts +0 -1
- package/lib/inputs/select/ActionButtons.d.ts +0 -1
- package/lib/inputs/select/Dropdown.d.ts +0 -1
- package/lib/inputs/select/helper.d.ts +0 -1
- package/lib/inputs/types.d.ts +2 -3
- package/package.json +2 -2
- package/lib/inputs/mask/imaskHOC.d.ts +0 -20
- package/lib/inputs/mask/imaskHOC.js +0 -205
package/lib/form/FieldPeriod.js
CHANGED
|
@@ -50,7 +50,7 @@ const FieldPeriod = props => {
|
|
|
50
50
|
if (Component) {
|
|
51
51
|
content = /*#__PURE__*/_react.default.createElement(Component, _extends({}, props, {
|
|
52
52
|
errorMessages: errorMessages,
|
|
53
|
-
onChange: (
|
|
53
|
+
onChange: (__, ___, _ref) => {
|
|
54
54
|
let {
|
|
55
55
|
initial,
|
|
56
56
|
final
|
package/lib/inputs/date/index.js
CHANGED
|
@@ -111,7 +111,6 @@ const DatePicker = props => {
|
|
|
111
111
|
if (typeof valueInput === 'string') {
|
|
112
112
|
var _event$target$value;
|
|
113
113
|
const date = (_event$target$value = event.target.value) !== null && _event$target$value !== void 0 ? _event$target$value : '';
|
|
114
|
-
console.log('date >>>', props.onChange);
|
|
115
114
|
if (props.onChange) {
|
|
116
115
|
if (isValidDate(date)) {
|
|
117
116
|
const newValue = (0, _moment.default)(date, _helpers.PT_BR_FORMAT).format(_helpers.EN_US_FORMAT);
|
|
@@ -153,7 +152,7 @@ const DatePicker = props => {
|
|
|
153
152
|
const getButtonOpen = () => {
|
|
154
153
|
if (!showButtonOpen) return undefined;
|
|
155
154
|
return /*#__PURE__*/_react.default.createElement(_buttons.default, {
|
|
156
|
-
key: "button-",
|
|
155
|
+
key: "button-1313414141",
|
|
157
156
|
boxShadow: false,
|
|
158
157
|
icon: /*#__PURE__*/_react.default.createElement(_icons.default, {
|
|
159
158
|
name: "calendar",
|
package/lib/inputs/inputHOC.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IBaseMaskProps } from './types.js';
|
|
2
2
|
import 'react';
|
|
3
|
-
import 'imask';
|
|
4
3
|
import '../../@types/Align.js';
|
|
5
4
|
import '../../@types/PermissionAttr.js';
|
|
6
5
|
import '../base/types.js';
|
|
@@ -8,9 +7,6 @@ import '../../@types/Period.js';
|
|
|
8
7
|
import '../../internals/types.js';
|
|
9
8
|
import '../../@types/Position.js';
|
|
10
9
|
|
|
11
|
-
declare const
|
|
12
|
-
(props: IBaseMaskProps): JSX.Element;
|
|
13
|
-
displayName: string;
|
|
14
|
-
};
|
|
10
|
+
declare const BaseMask: ({ value: valueProp, defaultValue, inputRef, onChange, onComplete, permissionAttr, ...rest }: IBaseMaskProps) => JSX.Element;
|
|
15
11
|
|
|
16
|
-
export {
|
|
12
|
+
export { BaseMask as default };
|
|
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _react =
|
|
8
|
-
var _imaskHOC = _interopRequireDefault(require("./imaskHOC"));
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _InputTextBase = _interopRequireDefault(require("../base/InputTextBase"));
|
|
10
9
|
var _format_number = require("../number/format_number");
|
|
11
|
-
|
|
10
|
+
var _reactImask = require("react-imask");
|
|
11
|
+
var _permissionValidations = require("../../permissionValidations");
|
|
12
|
+
var _helpers = require("./helpers");
|
|
13
|
+
const _excluded = ["value", "defaultValue", "inputRef", "onChange", "onComplete", "permissionAttr"];
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
13
17
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
14
18
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
19
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -37,10 +41,27 @@ const returnEventFormattedValue = (props, event) => {
|
|
|
37
41
|
}
|
|
38
42
|
return event;
|
|
39
43
|
};
|
|
40
|
-
const getEventProps = props => {
|
|
44
|
+
const getEventProps = (props, setValue, maskRef) => {
|
|
41
45
|
if (props.isNumeric) return {};
|
|
42
46
|
return {
|
|
43
47
|
onBlur: e => {
|
|
48
|
+
if (maskRef.unmaskedValue.trim().length && props.autoCompleteMask) {
|
|
49
|
+
const currentValue = maskRef.unmaskedValue;
|
|
50
|
+
const sizeMask = maskRef.mask.toString().replace(/\D+/g, '').length;
|
|
51
|
+
if (sizeMask > currentValue.length) {
|
|
52
|
+
switch (props.autoCompleteMask) {
|
|
53
|
+
case 'left':
|
|
54
|
+
setValue(currentValue.padStart(sizeMask, '0'));
|
|
55
|
+
break;
|
|
56
|
+
case 'right':
|
|
57
|
+
setValue(currentValue.padEnd(sizeMask, '0'));
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
setValue(currentValue);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
44
65
|
if (props.onBlur) {
|
|
45
66
|
const {
|
|
46
67
|
value
|
|
@@ -72,13 +93,73 @@ const getEventProps = props => {
|
|
|
72
93
|
}
|
|
73
94
|
};
|
|
74
95
|
};
|
|
96
|
+
const options = [_permissionValidations.OPTIONS_ON_DENIED.disabled, _permissionValidations.OPTIONS_ON_DENIED.unvisible, _permissionValidations.OPTIONS_ON_DENIED.readOnly, _permissionValidations.OPTIONS_ON_DENIED.hideContent];
|
|
75
97
|
const BaseMask = _ref => {
|
|
76
98
|
let {
|
|
77
|
-
|
|
99
|
+
value: valueProp,
|
|
100
|
+
defaultValue,
|
|
101
|
+
inputRef,
|
|
102
|
+
onChange,
|
|
103
|
+
onComplete,
|
|
104
|
+
permissionAttr
|
|
78
105
|
} = _ref,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
107
|
+
const onDenied = (0, _permissionValidations.actionsOnPermissionDenied)(options, permissionAttr);
|
|
108
|
+
const {
|
|
109
|
+
disabled,
|
|
110
|
+
readOnly
|
|
111
|
+
} = onDenied;
|
|
112
|
+
const disableCallbacks = disabled || readOnly;
|
|
113
|
+
const maskOptions = (0, _helpers.getMaskOptions)(rest);
|
|
114
|
+
const {
|
|
115
|
+
ref,
|
|
116
|
+
setValue,
|
|
117
|
+
maskRef
|
|
118
|
+
} = (0, _reactImask.useIMask)(maskOptions, {
|
|
119
|
+
defaultValue: defaultValue,
|
|
120
|
+
onAccept: (_, r) => {
|
|
121
|
+
if (!disableCallbacks && onChange) {
|
|
122
|
+
const event = {
|
|
123
|
+
target: {
|
|
124
|
+
name: r.el.input.name,
|
|
125
|
+
value: r.unmaskedValue,
|
|
126
|
+
maskedValue: r.value,
|
|
127
|
+
typedValue: r.typedValue
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
onChange(event);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
onComplete: (_, r) => {
|
|
134
|
+
if (!disableCallbacks && onComplete) {
|
|
135
|
+
const event = {
|
|
136
|
+
target: {
|
|
137
|
+
name: r.el.input.name,
|
|
138
|
+
value: r.unmaskedValue,
|
|
139
|
+
maskedValue: r.value,
|
|
140
|
+
typedValue: r.typedValue
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
onComplete(event);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
(0, _react.useEffect)(() => {
|
|
148
|
+
if (valueProp) {
|
|
149
|
+
setValue(String(valueProp));
|
|
150
|
+
}
|
|
151
|
+
}, [valueProp]);
|
|
152
|
+
return /*#__PURE__*/_react.default.createElement(_InputTextBase.default, _extends({
|
|
153
|
+
inputRef: r => {
|
|
154
|
+
ref.current = r;
|
|
155
|
+
if (inputRef) {
|
|
156
|
+
if (typeof inputRef === 'function') {
|
|
157
|
+
inputRef(r);
|
|
158
|
+
} else {
|
|
159
|
+
inputRef.current = r;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, rest, getEventProps(rest, setValue, maskRef.current)));
|
|
83
164
|
};
|
|
84
|
-
var _default = exports.default =
|
|
165
|
+
var _default = exports.default = BaseMask;
|
package/lib/inputs/mask/Cpf.d.ts
CHANGED
package/lib/inputs/mask/Cpf.js
CHANGED
|
@@ -30,7 +30,7 @@ const CpfField = props => {
|
|
|
30
30
|
}, 300), [handlerSetComponentValidator]);
|
|
31
31
|
(0, _react.useEffect)(() => debouncedOnChange.cancel, []);
|
|
32
32
|
const onChange = e => {
|
|
33
|
-
if (enableValidation
|
|
33
|
+
if (enableValidation) {
|
|
34
34
|
debouncedOnChange(e.target.value);
|
|
35
35
|
if (props.onChange) props.onChange(e);
|
|
36
36
|
} else if (props.onChange) {
|
|
@@ -1,19 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import 'react';
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import '../base/types.js';
|
|
7
|
-
import '../../@types/Align.js';
|
|
1
|
+
import { TextAlign } from '../../@types/Align.js';
|
|
2
|
+
import { OnDenied, PermissionAttr } from '../../@types/PermissionAttr.js';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { CustomInputEvent } from '../base/types.js';
|
|
5
|
+
import { IBaseMaskProps } from './types.js';
|
|
8
6
|
import '../../@types/Period.js';
|
|
9
7
|
import '../../internals/types.js';
|
|
10
8
|
import '../../@types/Position.js';
|
|
11
|
-
import '../../drawer/types.js';
|
|
12
|
-
import '../../@types/Icon.js';
|
|
13
|
-
import '../../icons/helper.js';
|
|
14
9
|
|
|
15
|
-
declare
|
|
10
|
+
declare const getMaskOptions: ({ isDateField, placeholderChar, min, max, lazy, rightElements, ...rest }: IBaseMaskProps) => {
|
|
11
|
+
value?: string | undefined;
|
|
12
|
+
onBlur?: ((e: CustomInputEvent) => void) | undefined;
|
|
13
|
+
onKeyDown?: ((e: CustomInputEvent | React.KeyboardEvent<Element>) => void) | undefined;
|
|
14
|
+
defaultValue?: string | undefined;
|
|
15
|
+
isNumeric?: boolean | undefined;
|
|
16
|
+
scale?: number | undefined;
|
|
17
|
+
radix?: string | undefined;
|
|
18
|
+
blocks?: any;
|
|
19
|
+
thousandsSeparator?: string | undefined;
|
|
20
|
+
leftElements?: JSX.Element | JSX.Element[] | undefined;
|
|
21
|
+
handlerSetOnDenied?: ((onDeniedValue: OnDenied) => void) | undefined;
|
|
22
|
+
onChange?: ((e: CustomInputEvent, maskValue?: string | undefined, date?: string | undefined) => void) | undefined;
|
|
23
|
+
padFractionalZeros?: boolean | undefined;
|
|
24
|
+
onComplete?: ((e: CustomInputEvent, maskValue?: string | undefined, date?: string | undefined) => void) | undefined;
|
|
25
|
+
inputRef?: React.MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null> | ((ref: HTMLInputElement | HTMLTextAreaElement | null) => void) | undefined;
|
|
26
|
+
permissionAttr?: PermissionAttr | undefined;
|
|
27
|
+
errorMessages?: string[] | undefined;
|
|
28
|
+
rounded?: boolean | undefined;
|
|
29
|
+
textAlign?: TextAlign | undefined;
|
|
30
|
+
customClassForInputContent?: string | undefined;
|
|
31
|
+
label?: string | undefined;
|
|
32
|
+
name?: string | undefined;
|
|
33
|
+
customClassForLabel?: string | undefined;
|
|
34
|
+
customClass?: string | undefined;
|
|
35
|
+
gridLayout?: string | undefined;
|
|
36
|
+
placeHolder?: string | undefined;
|
|
37
|
+
readOnly?: boolean | undefined;
|
|
38
|
+
labelUppercase?: boolean | undefined;
|
|
39
|
+
disabled?: boolean | undefined;
|
|
40
|
+
unmask?: boolean | undefined;
|
|
41
|
+
onFocus?: ((e: CustomInputEvent) => void) | undefined;
|
|
42
|
+
required?: boolean | undefined;
|
|
43
|
+
returnFormattedValueOnBlur?: boolean | undefined;
|
|
44
|
+
returnFormattedValueOnKeyDown?: boolean | undefined;
|
|
45
|
+
autoCompleteMask?: "left" | "right" | undefined;
|
|
46
|
+
definitions?: any;
|
|
47
|
+
mask?: any;
|
|
48
|
+
placeholderChar: string;
|
|
49
|
+
min: any;
|
|
50
|
+
max: any;
|
|
51
|
+
};
|
|
16
52
|
declare function CPFValidation(cpf?: string, returnMessage?: (msg: string) => void): void | "CPF inválido";
|
|
17
53
|
declare function CNPJValidation(cnpj?: string, returnMessage?: (msg: string) => void): void | "CNPJ inválido";
|
|
18
54
|
|
|
19
|
-
export { CNPJValidation, CPFValidation,
|
|
55
|
+
export { CNPJValidation, CPFValidation, getMaskOptions };
|
|
@@ -5,23 +5,67 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.CNPJValidation = CNPJValidation;
|
|
7
7
|
exports.CPFValidation = CPFValidation;
|
|
8
|
-
exports.
|
|
8
|
+
exports.getMaskOptions = void 0;
|
|
9
9
|
var _lodash = require("lodash");
|
|
10
|
+
const _excluded = ["isDateField", "placeholderChar", "min", "max", "lazy", "rightElements"];
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
13
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
14
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
14
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
18
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
19
|
+
const momentFormat = 'DD/MM/YYYY';
|
|
20
|
+
const getMaskOptions = _ref => {
|
|
21
|
+
let {
|
|
22
|
+
isDateField,
|
|
23
|
+
placeholderChar = '_',
|
|
24
|
+
min,
|
|
25
|
+
max,
|
|
26
|
+
lazy,
|
|
27
|
+
rightElements
|
|
28
|
+
} = _ref,
|
|
29
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
30
|
+
// TODO: essa etapa deverá ser feita junto com o refactory dos componentes Date e Period.
|
|
31
|
+
// if (isDateField) {
|
|
32
|
+
// return {
|
|
33
|
+
// mask: Date,
|
|
34
|
+
// min: min || new Date(1900, 0, 1),
|
|
35
|
+
// max: max || new Date(9999, 0, 1),
|
|
36
|
+
// pattern: momentFormat,
|
|
37
|
+
// lazy,
|
|
38
|
+
// format: (date: moment.MomentInput) => moment(date).format(momentFormat),
|
|
39
|
+
// parse: (str) => moment(str, momentFormat).toDate(),
|
|
40
|
+
// blocks: {
|
|
41
|
+
// DD: {
|
|
42
|
+
// mask: IMask.MaskedRange,
|
|
43
|
+
// from: 1,
|
|
44
|
+
// to: 31,
|
|
45
|
+
// maxLength: 2,
|
|
46
|
+
// },
|
|
47
|
+
// MM: {
|
|
48
|
+
// mask: IMask.MaskedRange,
|
|
49
|
+
// from: 1,
|
|
50
|
+
// to: 12,
|
|
51
|
+
// maxLength: 2,
|
|
52
|
+
// },
|
|
53
|
+
// YYYY: {
|
|
54
|
+
// mask: IMask.MaskedRange,
|
|
55
|
+
// from: 1900,
|
|
56
|
+
// to: 9999,
|
|
57
|
+
// },
|
|
58
|
+
// },
|
|
59
|
+
// } satisfies ReactMaskOpts;
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
return _objectSpread({
|
|
63
|
+
placeholderChar: placeholderChar === '' ? ' ' : placeholderChar,
|
|
64
|
+
min,
|
|
65
|
+
max
|
|
66
|
+
}, rest);
|
|
67
|
+
};
|
|
68
|
+
exports.getMaskOptions = getMaskOptions;
|
|
25
69
|
const allEqualDigits = input => input.split('').every(char => char === input[0]);
|
|
26
70
|
function CPFValidation(cpf, returnMessage) {
|
|
27
71
|
const stringCpf = cpf ? cpf.replace(/[^\d]+/g, '') : '';
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseMask from './BaseMask.js';
|
|
2
2
|
export { default as CpfField } from './Cpf.js';
|
|
3
3
|
export { default as CnpjField } from './Cnpj.js';
|
|
4
4
|
export { default as PhoneField } from './Phone.js';
|
|
5
5
|
export { default as ZipCodeField } from './ZipCode.js';
|
|
6
6
|
import './types.js';
|
|
7
7
|
import 'react';
|
|
8
|
-
import 'imask';
|
|
9
8
|
import '../../@types/Align.js';
|
|
10
9
|
import '../../@types/PermissionAttr.js';
|
|
11
10
|
import '../base/types.js';
|
|
@@ -15,4 +14,4 @@ import '../../@types/Position.js';
|
|
|
15
14
|
|
|
16
15
|
|
|
17
16
|
|
|
18
|
-
export {
|
|
17
|
+
export { BaseMask as default };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { KeyboardEvent, MutableRefObject } from 'react';
|
|
2
|
-
import IMask from 'imask';
|
|
3
2
|
import { TextAlign } from '../../@types/Align.js';
|
|
4
3
|
import { OnDenied, PermissionAttr } from '../../@types/PermissionAttr.js';
|
|
5
4
|
import { CustomInputEvent } from '../base/types.js';
|
|
@@ -7,23 +6,20 @@ import '../../@types/Period.js';
|
|
|
7
6
|
import '../../internals/types.js';
|
|
8
7
|
import '../../@types/Position.js';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
type IBaseMaskProps = {
|
|
11
10
|
value?: string;
|
|
12
11
|
onBlur?: (e: CustomInputEvent) => void;
|
|
13
12
|
onKeyDown?: (e: CustomInputEvent | KeyboardEvent<Element>) => void;
|
|
14
13
|
defaultValue?: string;
|
|
15
|
-
mask?: IMask.AnyMask;
|
|
16
14
|
isNumeric?: boolean;
|
|
17
15
|
scale?: number;
|
|
18
16
|
radix?: string;
|
|
17
|
+
blocks?: any;
|
|
19
18
|
thousandsSeparator?: string;
|
|
20
19
|
rightElements?: JSX.Element | JSX.Element[];
|
|
21
20
|
leftElements?: JSX.Element | JSX.Element[];
|
|
22
21
|
handlerSetOnDenied?: (onDeniedValue: OnDenied) => void;
|
|
23
|
-
onChange?: (e: CustomInputEvent, maskValue?: string, date?: string
|
|
24
|
-
initial: string;
|
|
25
|
-
final: string;
|
|
26
|
-
}) => void;
|
|
22
|
+
onChange?: (e: CustomInputEvent, maskValue?: string, date?: string) => void;
|
|
27
23
|
padFractionalZeros?: boolean;
|
|
28
24
|
onComplete?: (e: CustomInputEvent, maskValue?: string, date?: string) => void;
|
|
29
25
|
inputRef?: MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null> | ((ref: HTMLInputElement | HTMLTextAreaElement | null) => void);
|
|
@@ -50,26 +46,27 @@ interface IBaseMaskProps {
|
|
|
50
46
|
returnFormattedValueOnKeyDown?: boolean;
|
|
51
47
|
isDateField?: boolean;
|
|
52
48
|
autoCompleteMask?: 'left' | 'right';
|
|
53
|
-
definitions?:
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
definitions?: any;
|
|
50
|
+
mask?: any;
|
|
51
|
+
min?: any;
|
|
52
|
+
max?: any;
|
|
53
|
+
};
|
|
54
|
+
type ICnpjFieldProps = IBaseMaskProps & {
|
|
56
55
|
value?: string;
|
|
57
56
|
enableValidation?: boolean;
|
|
58
57
|
handlerSetComponentValidator?: (validator: () => void) => void;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
interface ICpfProps extends IBaseMaskProps {
|
|
58
|
+
};
|
|
59
|
+
type ICpfProps = IBaseMaskProps & {
|
|
62
60
|
value?: string;
|
|
63
61
|
enableValidation?: boolean;
|
|
64
62
|
handlerSetComponentValidator?: (validator: () => void) => void;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
interface IPhoneFieldProps extends IBaseMaskProps {
|
|
63
|
+
};
|
|
64
|
+
type IPhoneFieldProps = IBaseMaskProps & {
|
|
68
65
|
value?: string;
|
|
69
66
|
cellNumber?: boolean;
|
|
70
|
-
}
|
|
71
|
-
|
|
67
|
+
};
|
|
68
|
+
type IZipCode = IBaseMaskProps & {
|
|
72
69
|
value?: string;
|
|
73
|
-
}
|
|
70
|
+
};
|
|
74
71
|
|
|
75
72
|
export { IBaseMaskProps, ICnpjFieldProps, ICpfProps, IPhoneFieldProps, IZipCode };
|
|
@@ -6,7 +6,6 @@ import '../../@types/Align.js';
|
|
|
6
6
|
import '../../@types/Period.js';
|
|
7
7
|
import '../../internals/types.js';
|
|
8
8
|
import '../../@types/Position.js';
|
|
9
|
-
import 'imask';
|
|
10
9
|
import '../../@types/DataCombo.js';
|
|
11
10
|
import '../../drawer/types.js';
|
|
12
11
|
import '../../@types/Icon.js';
|
|
@@ -16,7 +15,7 @@ interface INumberFieldProps extends IMaskHOCProps {
|
|
|
16
15
|
value?: string;
|
|
17
16
|
permissionAttr?: PermissionAttr;
|
|
18
17
|
disabled?: boolean;
|
|
19
|
-
onChange?: (e?: CustomInputEvent, maskValue?: string, date?: string | {
|
|
18
|
+
onChange?: (e?: CustomInputEvent | InputEvent, maskValue?: string, date?: string | {
|
|
20
19
|
initial: string;
|
|
21
20
|
final: string;
|
|
22
21
|
}) => void;
|
|
@@ -93,19 +93,6 @@ const PeriodPicker = props => {
|
|
|
93
93
|
document.removeEventListener('keydown', onCloseCalendarWithoutFocus);
|
|
94
94
|
};
|
|
95
95
|
}, []);
|
|
96
|
-
(0, _react.useEffect)(() => {
|
|
97
|
-
if (valueFinal && valueInitial && (0, _moment.default)(valueFinal).isBefore((0, _moment.default)(valueInitial))) {
|
|
98
|
-
setValueInitial(valueFinal);
|
|
99
|
-
setValueFinal(valueInitial);
|
|
100
|
-
} else if (props.onChange) {
|
|
101
|
-
const initial = valueInitial ? valueInitial.format('YYYY-MM-DD') : '';
|
|
102
|
-
const final = valueFinal ? valueFinal.format('YYYY-MM-DD') : '';
|
|
103
|
-
props.onChange(undefined, '', {
|
|
104
|
-
initial,
|
|
105
|
-
final
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}, [valueInitial, valueFinal]);
|
|
109
96
|
(0, _react.useEffect)(() => {
|
|
110
97
|
if (props.value && !((0, _moment.default)(props.value.initial).isSame(valueInitial) || (0, _moment.default)(props.value.final).isSame(valueFinal))) {
|
|
111
98
|
const {
|
|
@@ -161,6 +148,16 @@ const PeriodPicker = props => {
|
|
|
161
148
|
}
|
|
162
149
|
}
|
|
163
150
|
};
|
|
151
|
+
const onDateChange = date => {
|
|
152
|
+
if (props.onChange) {
|
|
153
|
+
const initial = date.initial ? date.initial.format('YYYY-MM-DD') : '';
|
|
154
|
+
const final = date.final ? date.final.format('YYYY-MM-DD') : '';
|
|
155
|
+
props.onChange(undefined, '', {
|
|
156
|
+
initial,
|
|
157
|
+
final
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
164
161
|
const setValue = function (event, value) {
|
|
165
162
|
var _inputInitialRef$curr, _inputFinalRef$curren;
|
|
166
163
|
let shouldOpenDropdown = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
@@ -168,10 +165,32 @@ const PeriodPicker = props => {
|
|
|
168
165
|
const dateObj = (0, _moment.default)(value, 'DD/MM/YYYY');
|
|
169
166
|
if (showCalendarValueInitial) (_inputInitialRef$curr = inputInitialRef.current) === null || _inputInitialRef$curr === void 0 ? void 0 : _inputInitialRef$curr.focus();
|
|
170
167
|
if (showCalendarValueFinal) (_inputFinalRef$curren = inputFinalRef.current) === null || _inputFinalRef$curren === void 0 ? void 0 : _inputFinalRef$curren.focus();
|
|
171
|
-
if (valueDateName === 'valueInitial
|
|
168
|
+
if (valueDateName === 'valueFinal' && valueInitial && dateObj.isBefore(valueInitial)) {
|
|
169
|
+
setValueInitial(dateObj);
|
|
170
|
+
setValueFinal(valueInitial);
|
|
171
|
+
onDateChange({
|
|
172
|
+
initial: dateObj,
|
|
173
|
+
final: valueInitial
|
|
174
|
+
});
|
|
175
|
+
} else if (valueDateName === 'valueInitial' && valueFinal && dateObj.isAfter(valueFinal)) {
|
|
176
|
+
setValueInitial(valueFinal);
|
|
177
|
+
setValueFinal(dateObj);
|
|
178
|
+
onDateChange({
|
|
179
|
+
initial: valueFinal,
|
|
180
|
+
final: dateObj
|
|
181
|
+
});
|
|
182
|
+
} else if (valueDateName === 'valueInitial') {
|
|
172
183
|
setValueInitial(dateObj);
|
|
184
|
+
onDateChange({
|
|
185
|
+
initial: dateObj,
|
|
186
|
+
final: valueFinal
|
|
187
|
+
});
|
|
173
188
|
} else {
|
|
174
189
|
setValueFinal(dateObj);
|
|
190
|
+
onDateChange({
|
|
191
|
+
initial: valueInitial,
|
|
192
|
+
final: dateObj
|
|
193
|
+
});
|
|
175
194
|
}
|
|
176
195
|
if (valueDateName === 'valueInitial' && !valueFinal && shouldOpenDropdown) {
|
|
177
196
|
var _inputFinalRef$curren2;
|
|
@@ -239,11 +258,13 @@ const PeriodPicker = props => {
|
|
|
239
258
|
});
|
|
240
259
|
const getCalendar = (value, calendarColorStyleCalendar, valueDateName) => /*#__PURE__*/_react.default.createElement(_calendar.default, {
|
|
241
260
|
currentDate: value !== undefined ? (0, _moment.default)(value) : (0, _moment.default)(),
|
|
242
|
-
onDateChange: date =>
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
261
|
+
onDateChange: date => {
|
|
262
|
+
setValue({
|
|
263
|
+
target: {
|
|
264
|
+
name: valueDateName
|
|
265
|
+
}
|
|
266
|
+
}, date);
|
|
267
|
+
},
|
|
247
268
|
colorStyle: calendarColorStyleCalendar
|
|
248
269
|
});
|
|
249
270
|
const setPeriodDates = (selected, dates) => {
|
|
@@ -337,12 +358,11 @@ const PeriodPicker = props => {
|
|
|
337
358
|
name: "valueInitial",
|
|
338
359
|
value: !valueInitial ? '' : (0, _moment.default)(valueInitial).format('DD/MM/YYYY'),
|
|
339
360
|
mask: "00/00/0000",
|
|
340
|
-
onComplete:
|
|
341
|
-
setValue(e,
|
|
361
|
+
onComplete: e => {
|
|
362
|
+
setValue(e, e.target.value, true);
|
|
342
363
|
},
|
|
343
364
|
onFocus: onInputFocus,
|
|
344
365
|
onBlur: e => onInputBlur(e),
|
|
345
|
-
isDateField: true,
|
|
346
366
|
onChange: onInputChange,
|
|
347
367
|
inputRef: el => {
|
|
348
368
|
inputInitialRef.current = el;
|
|
@@ -359,9 +379,8 @@ const PeriodPicker = props => {
|
|
|
359
379
|
name: "valueFinal",
|
|
360
380
|
value: !valueFinal ? '' : (0, _moment.default)(valueFinal).format('DD/MM/YYYY'),
|
|
361
381
|
mask: "00/00/0000",
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
setValue(e, date, true);
|
|
382
|
+
onComplete: e => {
|
|
383
|
+
setValue(e, e.target.value, true);
|
|
365
384
|
},
|
|
366
385
|
onFocus: onInputFocus,
|
|
367
386
|
onBlur: e => onInputBlur(e),
|