linear-react-components-ui 1.1.25-rc.8 → 1.1.25
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/{BaseMask-0c14ef51.d.ts → BaseMask-78847f45.d.ts} +1 -1
- package/lib/{Cnpj-bde01dd0.d.ts → Cnpj-8366781f.d.ts} +1 -1
- package/lib/{Cpf-3fa496ad.d.ts → Cpf-3dfd54eb.d.ts} +1 -1
- package/lib/{Phone-2bb0b397.d.ts → Phone-1962c0f2.d.ts} +1 -1
- package/lib/{ZipCode-09460e18.d.ts → ZipCode-be9c5b3b.d.ts} +1 -1
- package/lib/assets/styles/drawers.scss +0 -2
- package/lib/assets/styles/split.scss +1 -1
- package/lib/assets/styles/tooltip.scss +5 -4
- package/lib/drawer/Drawer.js +2 -3
- package/lib/drawer/index.js +1 -1
- package/lib/icons/helper.d.ts +12 -0
- package/lib/icons/helper.js +12 -0
- package/lib/{index-3b70931d.d.ts → index-02a27c19.d.ts} +2 -20
- package/lib/index-053f615b.d.ts +26 -0
- package/lib/{index-7dfa8924.d.ts → index-25b80f32.d.ts} +1 -1
- package/lib/{index-9e576346.d.ts → index-6f5c772d.d.ts} +1 -1
- package/lib/{index-208e7f62.d.ts → index-6fcf446c.d.ts} +2 -20
- package/lib/index-7159df18.d.ts +21 -0
- package/lib/inputs/date/index.js +2 -5
- package/lib/inputs2/checkboxfield/base.d.ts +29 -0
- package/lib/inputs2/checkboxfield/base.js +134 -0
- package/lib/inputs2/checkboxfield/index.d.ts +3 -2
- package/lib/inputs2/checkboxfield/index.js +32 -125
- package/lib/inputs2/colorfield/index.d.ts +6 -5
- package/lib/inputs2/date/datefield/base.d.ts +13 -0
- package/lib/inputs2/date/datefield/base.js +330 -0
- package/lib/inputs2/date/datefield/index.js +34 -322
- package/lib/inputs2/date/datefield/types.d.ts +5 -3
- package/lib/inputs2/date/dateperiodfield/base.d.ts +13 -0
- package/lib/inputs2/date/dateperiodfield/base.js +595 -0
- package/lib/inputs2/date/dateperiodfield/index.js +34 -587
- package/lib/inputs2/date/dateperiodfield/types.d.ts +5 -3
- package/lib/inputs2/filefield/index.d.ts +6 -5
- package/lib/inputs2/index.d.ts +17 -14
- package/lib/inputs2/mask/BaseMask.d.ts +6 -5
- package/lib/inputs2/mask/Cnpj.d.ts +7 -6
- package/lib/inputs2/mask/Cpf.d.ts +7 -6
- package/lib/inputs2/mask/Phone.d.ts +7 -6
- package/lib/inputs2/mask/ZipCode.d.ts +7 -6
- package/lib/inputs2/numberfield/currency.d.ts +5 -4
- package/lib/inputs2/numberfield/decimal.d.ts +5 -4
- package/lib/inputs2/numberfield/index.d.ts +5 -4
- package/lib/inputs2/numberfield/types.d.ts +5 -4
- package/lib/inputs2/radiofield/base.d.ts +12 -0
- package/lib/inputs2/radiofield/base.js +156 -0
- package/lib/inputs2/radiofield/index.js +25 -126
- package/lib/inputs2/radiofield/types.d.ts +6 -4
- package/lib/inputs2/selectfield/base.d.ts +11 -0
- package/lib/inputs2/selectfield/base.js +513 -0
- package/lib/inputs2/selectfield/index.d.ts +1 -1
- package/lib/inputs2/selectfield/index.js +35 -502
- package/lib/inputs2/selectfield/types.d.ts +8 -6
- package/lib/inputs2/textareafield/base.d.ts +26 -0
- package/lib/inputs2/textareafield/base.js +166 -0
- package/lib/inputs2/textareafield/index.d.ts +4 -3
- package/lib/inputs2/textareafield/index.js +30 -154
- package/lib/inputs2/textfield/base.d.ts +26 -0
- package/lib/inputs2/textfield/base.js +131 -0
- package/lib/inputs2/textfield/index.d.ts +5 -4
- package/lib/inputs2/textfield/index.js +30 -120
- package/lib/tooltip/TooltipContent.js +1 -1
- package/lib/tooltip/useTooltip.js +25 -0
- package/package.json +1 -1
- package/lib/index-cd005ed1.d.ts +0 -26
- package/lib/index-f03b97fe.d.ts +0 -42
|
@@ -6,48 +6,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Input = void 0;
|
|
7
7
|
require("../../assets/styles/checkbox2.scss");
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
|
-
var _hint = _interopRequireDefault(require("../../hint"));
|
|
11
|
-
var _icons = _interopRequireDefault(require("../../icons"));
|
|
12
9
|
var _gridlayout = _interopRequireDefault(require("../../gridlayout"));
|
|
13
|
-
var _popover = _interopRequireWildcard(require("../../popover"));
|
|
14
|
-
var _tooltip = require("../../tooltip");
|
|
15
10
|
var _permissionValidations = require("../../permissionValidations");
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
var _base = require("./base");
|
|
12
|
+
const _excluded = ["onDeniedActions", "permissionAttr", "gridLayout", "readOnly", "disabled"];
|
|
18
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
14
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
18
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
19
|
+
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); }
|
|
20
20
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
21
21
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
22
22
|
const options = [_permissionValidations.OPTIONS_ON_DENIED.disabled, _permissionValidations.OPTIONS_ON_DENIED.unvisible, _permissionValidations.OPTIONS_ON_DENIED.readOnly, _permissionValidations.OPTIONS_ON_DENIED.hideContent];
|
|
23
|
-
const Input = exports.Input = /*#__PURE__*/_react.default.forwardRef((
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
permissionAttr = undefined,
|
|
33
|
-
variant = 'default',
|
|
34
|
-
customClass = '',
|
|
35
|
-
customClassLabel = '',
|
|
36
|
-
customClassWrapper = '',
|
|
37
|
-
labelUppercase = false,
|
|
38
|
-
rounded = false,
|
|
39
|
-
customClassInputContainer = '',
|
|
40
|
-
skeletonize = false,
|
|
41
|
-
hintPosition = 'below',
|
|
42
|
-
gridLayout = undefined,
|
|
43
|
-
themePopover = 'light',
|
|
44
|
-
popoverAlign = 'left',
|
|
45
|
-
tooltip,
|
|
46
|
-
tooltipPosition,
|
|
47
|
-
tooltipWidth,
|
|
48
|
-
tabIndex = 0
|
|
49
|
-
} = props,
|
|
50
|
-
rest = _objectWithoutProperties(props, _excluded);
|
|
23
|
+
const Input = exports.Input = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
24
|
+
let {
|
|
25
|
+
onDeniedActions,
|
|
26
|
+
permissionAttr,
|
|
27
|
+
gridLayout,
|
|
28
|
+
readOnly,
|
|
29
|
+
disabled
|
|
30
|
+
} = _ref,
|
|
31
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
51
32
|
const onDenied = _react.default.useMemo(() => {
|
|
52
33
|
return onDeniedActions || (0, _permissionValidations.actionsOnPermissionDenied)(options, permissionAttr);
|
|
53
34
|
}, [onDeniedActions, permissionAttr]);
|
|
@@ -55,96 +36,22 @@ const Input = exports.Input = /*#__PURE__*/_react.default.forwardRef((props, ref
|
|
|
55
36
|
hideContent,
|
|
56
37
|
unvisible
|
|
57
38
|
} = onDenied;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const hasLabel = !_lodash.default.isEmpty(props === null || props === void 0 ? void 0 : props.label);
|
|
62
|
-
const isReadOnly = Boolean(props.readOnly || onDenied.readOnly);
|
|
63
|
-
const isDisabled = Boolean(props.disabled || onDenied.disabled);
|
|
64
|
-
const hasHintMessages = Boolean((_props$hint = props.hint) === null || _props$hint === void 0 ? void 0 : _props$hint.length);
|
|
65
|
-
const hasValidationErrors = Boolean(errors === null || errors === void 0 ? void 0 : errors.length);
|
|
66
|
-
const handleOnChange = _react.default.useCallback(event => {
|
|
67
|
-
if (isReadOnly || isDisabled) return;
|
|
68
|
-
Object.defineProperty(event.target, 'value', {
|
|
69
|
-
value: event.target.checked,
|
|
70
|
-
writable: true,
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true
|
|
73
|
-
});
|
|
74
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
75
|
-
}, [isReadOnly, isDisabled, onChange]);
|
|
76
|
-
if (unvisible || hideContent) return null;
|
|
77
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
|
|
78
|
-
cols: gridLayout
|
|
79
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
80
|
-
ref: inputRootRef,
|
|
81
|
-
"data-testid": "test-chebox-field-root",
|
|
82
|
-
className: "checkbox-field-root ".concat(customClassWrapper),
|
|
83
|
-
"data-state-error": hasValidationErrors
|
|
84
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
85
|
-
"data-state-skeletonize": skeletonize,
|
|
86
|
-
className: "container ".concat(customClassInputContainer)
|
|
87
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
88
|
-
className: "input-root"
|
|
89
|
-
}, /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
90
|
-
ref: ref,
|
|
91
|
-
id: inputId,
|
|
92
|
-
name: name,
|
|
39
|
+
const isReadOnly = Boolean(readOnly || onDenied.readOnly);
|
|
40
|
+
const isDisabled = Boolean(disabled || onDenied.disabled);
|
|
41
|
+
const inputProps = _objectSpread({
|
|
93
42
|
readOnly: isReadOnly,
|
|
94
|
-
disabled: isDisabled
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
onChange: handleOnChange
|
|
108
|
-
})), /*#__PURE__*/_react.default.createElement(_icons.default, {
|
|
109
|
-
customClass: "checkmark",
|
|
110
|
-
name: "checkmark",
|
|
111
|
-
colorStyle: "default"
|
|
112
|
-
})), hasLabel && /*#__PURE__*/_react.default.createElement("label", {
|
|
113
|
-
className: "label ".concat(customClassLabel),
|
|
114
|
-
title: label,
|
|
115
|
-
htmlFor: inputId,
|
|
116
|
-
"aria-readonly": isReadOnly,
|
|
117
|
-
"aria-disabled": isDisabled,
|
|
118
|
-
"data-testid": "test-checkbox-field-label",
|
|
119
|
-
"data-state-skeletonize": skeletonize,
|
|
120
|
-
"data-state-disabled": isDisabled,
|
|
121
|
-
"data-state-read-only": isReadOnly,
|
|
122
|
-
"data-state-uppercase": labelUppercase,
|
|
123
|
-
"data-state-input-required": props.required
|
|
124
|
-
}, label), hasLabel && hasHintMessages && hintPosition === 'onLabelRight' && !skeletonize && /*#__PURE__*/_react.default.createElement(_popover.default, {
|
|
125
|
-
customClass: "label-popover",
|
|
126
|
-
theme: themePopover,
|
|
127
|
-
align: popoverAlign,
|
|
128
|
-
iconColor: "#03bde2"
|
|
129
|
-
}, /*#__PURE__*/_react.default.createElement(_popover.PopoverText, {
|
|
130
|
-
text: props === null || props === void 0 ? void 0 : props.hint
|
|
131
|
-
}))), hintPosition === 'below' && /*#__PURE__*/_react.default.createElement(_hint.default, {
|
|
132
|
-
customClass: "hint",
|
|
133
|
-
description: props.hint,
|
|
134
|
-
disabled: isDisabled,
|
|
135
|
-
skeletonize: skeletonize,
|
|
136
|
-
visible: hasHintMessages
|
|
137
|
-
}), hasValidationErrors && /*#__PURE__*/_react.default.createElement("span", {
|
|
138
|
-
className: "error",
|
|
139
|
-
"data-state-skeletonize": skeletonize,
|
|
140
|
-
"aria-describedby": String(name).concat('-errors')
|
|
141
|
-
}, errors === null || errors === void 0 ? void 0 : errors.map((error, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
142
|
-
key: "".concat(index + 1, "-").concat(error)
|
|
143
|
-
}, error, "\xA0"))))), /*#__PURE__*/_react.default.createElement(_tooltip.Tooltip, {
|
|
144
|
-
targetRef: inputRootRef,
|
|
145
|
-
text: tooltip,
|
|
146
|
-
width: tooltipWidth,
|
|
147
|
-
position: tooltipPosition
|
|
148
|
-
}));
|
|
43
|
+
disabled: isDisabled
|
|
44
|
+
}, props);
|
|
45
|
+
if (unvisible || hideContent) return null;
|
|
46
|
+
if (gridLayout) {
|
|
47
|
+
return /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
|
|
48
|
+
cols: gridLayout
|
|
49
|
+
}, /*#__PURE__*/_react.default.createElement(_base.InputBase, _extends({
|
|
50
|
+
ref: ref
|
|
51
|
+
}, inputProps)));
|
|
52
|
+
}
|
|
53
|
+
return /*#__PURE__*/_react.default.createElement(_base.InputBase, _extends({
|
|
54
|
+
ref: ref
|
|
55
|
+
}, inputProps));
|
|
149
56
|
});
|
|
150
57
|
Input.displayName = 'CheckboxFieldInput';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import 'react';
|
|
2
2
|
export { LeftSlot, RightSlot } from '../slot/index.js';
|
|
3
|
-
import '../../index-
|
|
4
|
-
export { C as ColorFieldInputProps, I as Input } from '../../index-
|
|
5
|
-
import '../../@types/Align.js';
|
|
6
|
-
import '../../@types/ColorStyles.js';
|
|
7
|
-
import '../../@types/Position.js';
|
|
3
|
+
import '../../index-02a27c19.js';
|
|
4
|
+
export { C as ColorFieldInputProps, I as Input } from '../../index-6f5c772d.js';
|
|
8
5
|
import '../../@types/PermissionAttr.js';
|
|
6
|
+
import '../textfield/base.js';
|
|
9
7
|
import '../../tooltip/types.js';
|
|
8
|
+
import '../../@types/Position.js';
|
|
9
|
+
import '../../@types/Align.js';
|
|
10
|
+
import '../../@types/ColorStyles.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { DateFieldInputBaseProps } from './types.js';
|
|
3
|
+
import 'moment';
|
|
4
|
+
import '../../../@types/Align.js';
|
|
5
|
+
import '../../../@types/ColorStyles.js';
|
|
6
|
+
import '../../../tooltip/types.js';
|
|
7
|
+
import '../../../@types/Position.js';
|
|
8
|
+
import '../../../@types/PermissionAttr.js';
|
|
9
|
+
import '../types.js';
|
|
10
|
+
|
|
11
|
+
declare const InputBase: React__default.ForwardRefExoticComponent<DateFieldInputBaseProps & React__default.RefAttributes<HTMLInputElement>>;
|
|
12
|
+
|
|
13
|
+
export { InputBase };
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InputBase = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
var _reactImask = require("react-imask");
|
|
10
|
+
var _uuid = require("uuid");
|
|
11
|
+
var _reactDom = require("react-dom");
|
|
12
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
13
|
+
var _hint = _interopRequireDefault(require("../../../hint"));
|
|
14
|
+
var _tooltip = require("../../../tooltip");
|
|
15
|
+
var _helpers = require("../../../form2/helpers");
|
|
16
|
+
var _types = require("../types");
|
|
17
|
+
var BaseDate = _interopRequireWildcard(require("../base"));
|
|
18
|
+
var _helpers2 = require("../helpers");
|
|
19
|
+
var _triggers = require("./triggers");
|
|
20
|
+
var _calendarbox = require("./calendarbox");
|
|
21
|
+
var _context = require("./context");
|
|
22
|
+
const _excluded = ["label", "errors", "tooltip", "tooltipPosition", "tooltipWidth", "shouldCloseOnSelect", "returnValueType", "customClass", "customClassLabel", "customClassWrapper", "customClassInputContainer", "textAlign", "labelUppercase", "skeletonize", "hintPosition", "themePopover", "popoverAlign", "showCalendarButton", "openCalendarOnFocus", "undigitable", "showClearDateButton", "placeholder", "readOnly", "disabled"];
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
24
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
25
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
26
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
27
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
28
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
29
|
+
const InputBase = exports.InputBase = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
30
|
+
var _props$hint;
|
|
31
|
+
const {
|
|
32
|
+
label,
|
|
33
|
+
errors,
|
|
34
|
+
tooltip,
|
|
35
|
+
tooltipPosition,
|
|
36
|
+
tooltipWidth,
|
|
37
|
+
shouldCloseOnSelect = true,
|
|
38
|
+
returnValueType = 'default',
|
|
39
|
+
customClass = '',
|
|
40
|
+
customClassLabel = '',
|
|
41
|
+
customClassWrapper = '',
|
|
42
|
+
customClassInputContainer = '',
|
|
43
|
+
textAlign = 'left',
|
|
44
|
+
labelUppercase = false,
|
|
45
|
+
skeletonize = false,
|
|
46
|
+
hintPosition = 'below',
|
|
47
|
+
themePopover = 'light',
|
|
48
|
+
popoverAlign = 'left',
|
|
49
|
+
showCalendarButton = true,
|
|
50
|
+
openCalendarOnFocus = true,
|
|
51
|
+
undigitable = false,
|
|
52
|
+
showClearDateButton = true,
|
|
53
|
+
placeholder = _helpers2.TOKEN_PTBR_FORMAT,
|
|
54
|
+
readOnly,
|
|
55
|
+
disabled
|
|
56
|
+
} = props,
|
|
57
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
58
|
+
const [calendarBoxOpen, setCalendarBoxOpen] = _react.default.useState(false);
|
|
59
|
+
const [activeDescendant, setActiveDescendant] = _react.default.useState((0, _moment.default)().format(_helpers2.TOKEN_ISO_FORMAT));
|
|
60
|
+
const [selectedDate, setSelectedDate] = _react.default.useState(null);
|
|
61
|
+
const [calendarDisplayDate, setCalendarDisplayDate] = _react.default.useState(selectedDate !== null && selectedDate !== void 0 ? selectedDate : (0, _moment.default)());
|
|
62
|
+
const calendarRef = _react.default.useRef(null);
|
|
63
|
+
const inputRootRef = _react.default.useRef(null);
|
|
64
|
+
const dateInputRef = _react.default.useRef(null);
|
|
65
|
+
const dateContainerRef = _react.default.useRef(null);
|
|
66
|
+
const {
|
|
67
|
+
setValue: setMaskValue,
|
|
68
|
+
unmaskedValue,
|
|
69
|
+
value: maskedValue
|
|
70
|
+
} = (0, _reactImask.useIMask)({
|
|
71
|
+
mask: _helpers2.TOKEN_MASK,
|
|
72
|
+
lazy: false,
|
|
73
|
+
placeholderChar: '_'
|
|
74
|
+
}, {
|
|
75
|
+
ref: dateInputRef,
|
|
76
|
+
defaultValue: selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.format(_helpers2.TOKEN_PTBR_FORMAT),
|
|
77
|
+
onComplete: value => {
|
|
78
|
+
const date = (0, _moment.default)(value, _helpers2.TOKEN_PTBR_FORMAT);
|
|
79
|
+
if (date.isValid()) {
|
|
80
|
+
handleUpdateDateState(date);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const inputId = _react.default.useMemo(() => props.id || props.name || (0, _uuid.v1)(), [props.id, props.name]);
|
|
85
|
+
const hasLabel = !_lodash.default.isEmpty(props === null || props === void 0 ? void 0 : props.label);
|
|
86
|
+
const hasHintMessages = Boolean((_props$hint = props.hint) === null || _props$hint === void 0 ? void 0 : _props$hint.length);
|
|
87
|
+
const hasValidationErrors = Boolean(errors === null || errors === void 0 ? void 0 : errors.length);
|
|
88
|
+
const hasValidDateSelected = !_lodash.default.isEmpty(props === null || props === void 0 ? void 0 : props.value);
|
|
89
|
+
const handleUpdateDateState = _react.default.useCallback(date => {
|
|
90
|
+
var _props$onChange;
|
|
91
|
+
const nonIsoDateFormat = date.format(_helpers2.TOKEN_ISO_FORMAT);
|
|
92
|
+
const isoDateFormat = date.toISOString();
|
|
93
|
+
setSelectedDate(date.clone());
|
|
94
|
+
setCalendarDisplayDate(date.clone());
|
|
95
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, {
|
|
96
|
+
target: {
|
|
97
|
+
name: props.name,
|
|
98
|
+
value: returnValueType === 'default' ? nonIsoDateFormat : isoDateFormat
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (shouldCloseOnSelect) handleCloseCalendar();
|
|
102
|
+
}, [selectedDate, props.name, props.onChange, shouldCloseOnSelect]);
|
|
103
|
+
const handleOpenCalendar = _react.default.useCallback(() => setCalendarBoxOpen(true), []);
|
|
104
|
+
const handleCloseCalendar = _react.default.useCallback(() => setCalendarBoxOpen(false), []);
|
|
105
|
+
const handleNextMonth = _react.default.useCallback(() => setCalendarDisplayDate(prevDisplayDate => prevDisplayDate.clone().add(1, 'month')), []);
|
|
106
|
+
const handlePreviousMonth = _react.default.useCallback(() => setCalendarDisplayDate(prevDisplayDate => prevDisplayDate.clone().subtract(1, 'month')), []);
|
|
107
|
+
const handleChangeCalendarBoxState = _react.default.useCallback(() => {
|
|
108
|
+
setCalendarBoxOpen(prevState => {
|
|
109
|
+
if (dateInputRef.current !== document.activeElement) {
|
|
110
|
+
var _dateInputRef$current, _dateInputRef$current2;
|
|
111
|
+
dateInputRef === null || dateInputRef === void 0 ? void 0 : (_dateInputRef$current = dateInputRef.current) === null || _dateInputRef$current === void 0 ? void 0 : (_dateInputRef$current2 = _dateInputRef$current.focus) === null || _dateInputRef$current2 === void 0 ? void 0 : _dateInputRef$current2.call(_dateInputRef$current);
|
|
112
|
+
}
|
|
113
|
+
return !prevState;
|
|
114
|
+
});
|
|
115
|
+
}, []);
|
|
116
|
+
const handleNavigateWithDays = _react.default.useCallback(offset => {
|
|
117
|
+
setCalendarDisplayDate(prevDisplayDate => {
|
|
118
|
+
const daySelected = prevDisplayDate.clone().add(offset, 'day');
|
|
119
|
+
setActiveDescendant(daySelected.format(_helpers2.TOKEN_ISO_FORMAT));
|
|
120
|
+
return daySelected;
|
|
121
|
+
});
|
|
122
|
+
}, []);
|
|
123
|
+
const handleNavigateWithWeeks = _react.default.useCallback(when => {
|
|
124
|
+
setCalendarDisplayDate(prevDisplayDate => {
|
|
125
|
+
let daySelected = prevDisplayDate;
|
|
126
|
+
if (when === 'end') daySelected = prevDisplayDate.clone().endOf('week');
|
|
127
|
+
if (when === 'start') daySelected = prevDisplayDate.clone().startOf('week');
|
|
128
|
+
setActiveDescendant(daySelected.format(_helpers2.TOKEN_ISO_FORMAT));
|
|
129
|
+
return daySelected;
|
|
130
|
+
});
|
|
131
|
+
}, []);
|
|
132
|
+
const handleOnClickClearSelectedDate = _react.default.useCallback(() => {
|
|
133
|
+
var _props$onChange2;
|
|
134
|
+
(_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 ? void 0 : _props$onChange2.call(props, {
|
|
135
|
+
target: {
|
|
136
|
+
name: props.name,
|
|
137
|
+
value: ''
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
setSelectedDate(null);
|
|
141
|
+
setMaskValue('');
|
|
142
|
+
handleCloseCalendar();
|
|
143
|
+
}, [props.onChange]);
|
|
144
|
+
const handleOnBlur = event => {
|
|
145
|
+
var _props$onBlur;
|
|
146
|
+
props === null || props === void 0 ? void 0 : (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 ? void 0 : _props$onBlur.call(props, event);
|
|
147
|
+
handleCloseCalendar();
|
|
148
|
+
setActiveDescendant((selectedDate !== null && selectedDate !== void 0 ? selectedDate : (0, _moment.default)()).format(_helpers2.TOKEN_ISO_FORMAT));
|
|
149
|
+
setCalendarDisplayDate(selectedDate !== null && selectedDate !== void 0 ? selectedDate : (0, _moment.default)());
|
|
150
|
+
if (_lodash.default.size(unmaskedValue) !== 8) {
|
|
151
|
+
const date = (0, _moment.default)(_lodash.default.toString(props === null || props === void 0 ? void 0 : props.value), _helpers2.TOKEN_ISO_FORMAT);
|
|
152
|
+
if (date.isValid()) {
|
|
153
|
+
setMaskValue(date.format('DD/MM/YYYY'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const handleOnFocus = event => {
|
|
158
|
+
var _props$onFocus;
|
|
159
|
+
props === null || props === void 0 ? void 0 : (_props$onFocus = props.onFocus) === null || _props$onFocus === void 0 ? void 0 : _props$onFocus.call(props, event);
|
|
160
|
+
setActiveDescendant((selectedDate !== null && selectedDate !== void 0 ? selectedDate : (0, _moment.default)()).format(_helpers2.TOKEN_ISO_FORMAT));
|
|
161
|
+
setCalendarDisplayDate(selectedDate !== null && selectedDate !== void 0 ? selectedDate : (0, _moment.default)());
|
|
162
|
+
if (!readOnly && openCalendarOnFocus) {
|
|
163
|
+
handleOpenCalendar();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const handleOnPaste = event => {
|
|
167
|
+
if (undigitable) {
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
} else {
|
|
170
|
+
var _props$onPaste;
|
|
171
|
+
(_props$onPaste = props.onPaste) === null || _props$onPaste === void 0 ? void 0 : _props$onPaste.call(props, event);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const handleOnBeforeInput = event => {
|
|
175
|
+
if (undigitable) {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
} else {
|
|
178
|
+
var _props$onBeforeInput;
|
|
179
|
+
(_props$onBeforeInput = props.onBeforeInput) === null || _props$onBeforeInput === void 0 ? void 0 : _props$onBeforeInput.call(props, event);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const handleOnKeyDown = event => {
|
|
183
|
+
var _props$onKeyDown;
|
|
184
|
+
props === null || props === void 0 ? void 0 : (_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 ? void 0 : _props$onKeyDown.call(props, event);
|
|
185
|
+
if (calendarBoxOpen && event.key && !event.shiftKey && !event.altKey && _helpers2.NAVIGATION_KEYS.includes(event.key)) {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
switch (event.key) {
|
|
188
|
+
case _types.Keys.arrowLeft:
|
|
189
|
+
handleNavigateWithDays(-1);
|
|
190
|
+
break;
|
|
191
|
+
case _types.Keys.arrowRight:
|
|
192
|
+
handleNavigateWithDays(1);
|
|
193
|
+
break;
|
|
194
|
+
case _types.Keys.arrowUp:
|
|
195
|
+
handleNavigateWithDays(-7);
|
|
196
|
+
break;
|
|
197
|
+
case _types.Keys.arrowDown:
|
|
198
|
+
handleNavigateWithDays(7);
|
|
199
|
+
break;
|
|
200
|
+
case _types.Keys.pageUp:
|
|
201
|
+
handleNextMonth();
|
|
202
|
+
break;
|
|
203
|
+
case _types.Keys.pageDown:
|
|
204
|
+
handlePreviousMonth();
|
|
205
|
+
break;
|
|
206
|
+
case _types.Keys.home:
|
|
207
|
+
handleNavigateWithWeeks('start');
|
|
208
|
+
break;
|
|
209
|
+
case _types.Keys.end:
|
|
210
|
+
handleNavigateWithWeeks('end');
|
|
211
|
+
break;
|
|
212
|
+
case _types.Keys.escape:
|
|
213
|
+
handleCloseCalendar();
|
|
214
|
+
break;
|
|
215
|
+
case _types.Keys.enter:
|
|
216
|
+
handleUpdateDateState((0, _moment.default)(_lodash.default.toString(activeDescendant), _helpers2.TOKEN_ISO_FORMAT));
|
|
217
|
+
break;
|
|
218
|
+
default:
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
_react.default.useEffect(() => {
|
|
224
|
+
var _props$value;
|
|
225
|
+
const currentValue = (_props$value = props === null || props === void 0 ? void 0 : props.value) !== null && _props$value !== void 0 ? _props$value : null;
|
|
226
|
+
const date = (0, _moment.default)(_lodash.default.toString(currentValue), _helpers2.TOKEN_ISO_FORMAT);
|
|
227
|
+
setSelectedDate(date.isValid() ? date : null);
|
|
228
|
+
setMaskValue(date.format(_helpers2.TOKEN_PTBR_FORMAT));
|
|
229
|
+
}, [props === null || props === void 0 ? void 0 : props.value]);
|
|
230
|
+
const contextValues = _react.default.useMemo(() => ({
|
|
231
|
+
label,
|
|
232
|
+
inputFieldId: inputId,
|
|
233
|
+
activeDescendant,
|
|
234
|
+
calendarBoxOpen,
|
|
235
|
+
isReadOnly: Boolean(readOnly),
|
|
236
|
+
isDisabled: Boolean(disabled),
|
|
237
|
+
skeletonize,
|
|
238
|
+
showCalendarButton,
|
|
239
|
+
hasValidDateSelected,
|
|
240
|
+
dateInputRef,
|
|
241
|
+
dateContainerRef,
|
|
242
|
+
handleOpenCalendar,
|
|
243
|
+
handleCloseCalendar,
|
|
244
|
+
handleNextMonth,
|
|
245
|
+
handlePreviousMonth,
|
|
246
|
+
handleSelectDate: handleUpdateDateState,
|
|
247
|
+
selectedDate,
|
|
248
|
+
unmaskedValue,
|
|
249
|
+
maskedValue,
|
|
250
|
+
showClearDateButton,
|
|
251
|
+
handleChangeCalendarBoxState,
|
|
252
|
+
handleOnClickClearSelectedDate,
|
|
253
|
+
calendarDisplayDate,
|
|
254
|
+
calendarRef
|
|
255
|
+
}), [label, activeDescendant, calendarBoxOpen, readOnly, disabled, skeletonize, showCalendarButton, selectedDate, calendarDisplayDate, hasValidDateSelected, unmaskedValue, maskedValue]);
|
|
256
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_context.DateFieldContext.Provider, {
|
|
257
|
+
value: contextValues
|
|
258
|
+
}, /*#__PURE__*/_react.default.createElement(BaseDate.Root, {
|
|
259
|
+
ref: inputRootRef,
|
|
260
|
+
"data-testid": "test-date-field-root",
|
|
261
|
+
customClassWrapper: customClassWrapper,
|
|
262
|
+
hasValidationErrors: hasValidationErrors
|
|
263
|
+
}, hasLabel && /*#__PURE__*/_react.default.createElement(BaseDate.Label, {
|
|
264
|
+
"data-testid": "test-date-field-label",
|
|
265
|
+
label: label,
|
|
266
|
+
inputId: inputId,
|
|
267
|
+
hint: props === null || props === void 0 ? void 0 : props.hint,
|
|
268
|
+
isDisabled: disabled,
|
|
269
|
+
isReadOnly: readOnly,
|
|
270
|
+
skeletonize: skeletonize,
|
|
271
|
+
required: props === null || props === void 0 ? void 0 : props.required,
|
|
272
|
+
hintPosition: hintPosition,
|
|
273
|
+
themePopover: themePopover,
|
|
274
|
+
popoverAlign: popoverAlign,
|
|
275
|
+
labelUppercase: labelUppercase,
|
|
276
|
+
hasHintMessages: hasHintMessages,
|
|
277
|
+
customClassLabel: customClassLabel
|
|
278
|
+
}), /*#__PURE__*/_react.default.createElement(BaseDate.Container, {
|
|
279
|
+
ref: dateContainerRef,
|
|
280
|
+
skeletonize: skeletonize,
|
|
281
|
+
customClassInputContainer: customClassInputContainer
|
|
282
|
+
}, /*#__PURE__*/_react.default.createElement(BaseDate.Input, _extends({}, rest, {
|
|
283
|
+
ref: (0, _helpers.mergeRefs)(ref, dateInputRef),
|
|
284
|
+
id: inputId,
|
|
285
|
+
name: props === null || props === void 0 ? void 0 : props.name,
|
|
286
|
+
value: maskedValue,
|
|
287
|
+
readOnly: readOnly,
|
|
288
|
+
disabled: disabled,
|
|
289
|
+
customClass: customClass,
|
|
290
|
+
tabIndex: !readOnly && !skeletonize ? 0 : -1,
|
|
291
|
+
placeholder: placeholder,
|
|
292
|
+
"aria-activedescendant": activeDescendant,
|
|
293
|
+
"aria-expanded": calendarBoxOpen,
|
|
294
|
+
"aria-controls": inputId,
|
|
295
|
+
"aria-labelledby": inputId,
|
|
296
|
+
"data-state-is-period-input": false,
|
|
297
|
+
"data-testid": "test-date-field-input",
|
|
298
|
+
"data-state-error": hasValidationErrors,
|
|
299
|
+
"data-state-read-only": readOnly,
|
|
300
|
+
"data-state-text-align": textAlign,
|
|
301
|
+
"data-state-undigitable": undigitable,
|
|
302
|
+
"data-state-skeletonize": skeletonize,
|
|
303
|
+
onBlur: handleOnBlur,
|
|
304
|
+
onFocus: handleOnFocus,
|
|
305
|
+
onPaste: handleOnPaste,
|
|
306
|
+
onKeyDown: handleOnKeyDown,
|
|
307
|
+
onBeforeInput: handleOnBeforeInput
|
|
308
|
+
})), /*#__PURE__*/_react.default.createElement(_triggers.Triggers, null)), calendarBoxOpen && /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement(_calendarbox.CalendarBox, {
|
|
309
|
+
ref: calendarRef
|
|
310
|
+
}), document.body), hintPosition === 'below' && /*#__PURE__*/_react.default.createElement(_hint.default, {
|
|
311
|
+
customClass: "hint",
|
|
312
|
+
description: props.hint,
|
|
313
|
+
disabled: disabled,
|
|
314
|
+
skeletonize: skeletonize,
|
|
315
|
+
visible: hasHintMessages
|
|
316
|
+
}), hasValidationErrors && /*#__PURE__*/_react.default.createElement("span", {
|
|
317
|
+
"data-testid": "test-date-field-list-errors",
|
|
318
|
+
className: "error",
|
|
319
|
+
"data-state-skeletonize": skeletonize,
|
|
320
|
+
"aria-describedby": String(props.name).concat('-errors')
|
|
321
|
+
}, errors === null || errors === void 0 ? void 0 : errors.map((error, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
322
|
+
key: "".concat(index + 1, "-").concat(error)
|
|
323
|
+
}, error, "\xA0"))))), /*#__PURE__*/_react.default.createElement(_tooltip.Tooltip, {
|
|
324
|
+
targetRef: inputRootRef,
|
|
325
|
+
text: tooltip,
|
|
326
|
+
width: tooltipWidth,
|
|
327
|
+
position: tooltipPosition
|
|
328
|
+
}));
|
|
329
|
+
});
|
|
330
|
+
InputBase.displayName = 'DateFieldInputBase';
|