linear-react-components-ui 1.1.18-beta.16 → 1.1.18-beta.18

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 (55) hide show
  1. package/.eslintcache +1 -1
  2. package/lib/assets/styles/calendar.scss +64 -30
  3. package/lib/assets/styles/datepicker.scss +26 -6
  4. package/lib/assets/styles/periodpicker.scss +60 -20
  5. package/lib/assets/styles/sidenav.scss +1 -1
  6. package/lib/assets/styles/tabs.scss +32 -15
  7. package/lib/calendar/DangerCalendar.d.ts +1 -0
  8. package/lib/calendar/InfoCalendar.d.ts +1 -0
  9. package/lib/calendar/PrimaryCalendar.d.ts +1 -0
  10. package/lib/calendar/SuccessCalendar.d.ts +1 -0
  11. package/lib/calendar/WarningCalendar.d.ts +1 -0
  12. package/lib/calendar/base/Day.d.ts +1 -0
  13. package/lib/calendar/base/Day.js +6 -2
  14. package/lib/calendar/base/Month.d.ts +2 -1
  15. package/lib/calendar/base/Month.js +2 -0
  16. package/lib/calendar/base/Week.d.ts +1 -0
  17. package/lib/calendar/base/index.d.ts +1 -0
  18. package/lib/calendar/base/index.js +63 -13
  19. package/lib/calendar/index.d.ts +1 -0
  20. package/lib/calendar/types.d.ts +5 -0
  21. package/lib/dialog/base/Content.js +5 -4
  22. package/lib/dialog/base/Header.js +0 -1
  23. package/lib/dialog/base/index.js +27 -3
  24. package/lib/drawer/Drawer.js +1 -1
  25. package/lib/inputs/date/Dialog.js +5 -4
  26. package/lib/inputs/date/Dropdown.js +15 -7
  27. package/lib/inputs/date/helpers.d.ts +1 -11
  28. package/lib/inputs/date/helpers.js +1 -11
  29. package/lib/inputs/date/index.js +138 -100
  30. package/lib/inputs/date/types.d.ts +7 -6
  31. package/lib/inputs/period/Dialog.d.ts +1 -1
  32. package/lib/inputs/period/Dialog.js +5 -3
  33. package/lib/inputs/period/Dropdown.js +19 -8
  34. package/lib/inputs/period/PeriodList.js +3 -12
  35. package/lib/inputs/period/index.js +238 -82
  36. package/lib/inputs/period/types.d.ts +10 -8
  37. package/lib/inputs/select/ActionButtons.js +3 -2
  38. package/lib/inputs/select/multiple/index.js +10 -4
  39. package/lib/inputs/select/simple/index.js +10 -4
  40. package/lib/inputs/select/types.d.ts +4 -0
  41. package/lib/inputs/types.d.ts +1 -0
  42. package/lib/list/index.js +2 -2
  43. package/lib/tabs/DropdownTabs.js +21 -7
  44. package/lib/tabs/context.d.ts +1 -1
  45. package/lib/tabs/context.js +3 -3
  46. package/lib/tabs/types.d.ts +2 -1
  47. package/lib/toolbar/types.d.ts +2 -1
  48. package/package.json +1 -1
  49. package/lib/inputs/mask/imaskHOC.js +0 -203
  50. package/lib/menus/sidenav/popup_menu_help/index.js +0 -85
  51. package/lib/tabs/DropdownItems.js +0 -62
  52. package/lib/tabs/MenuItems.js +0 -70
  53. package/lib/treeview_old/Header.js +0 -29
  54. package/lib/treeview_old/Node.js +0 -68
  55. package/lib/treeview_old/index.js +0 -43
@@ -4,18 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  require("../../assets/styles/dialog.scss");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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; }
10
11
  const Content = _ref => {
11
12
  let {
12
13
  children,
13
14
  styleForContent
14
15
  } = _ref;
15
- return /*#__PURE__*/_react.default.createElement("div", {
16
+ return /*#__PURE__*/_react.default.createElement(_react.Suspense, null, /*#__PURE__*/_react.default.createElement("div", {
16
17
  id: "modal-dialog-content",
17
18
  className: "dialog-content",
18
19
  style: styleForContent
19
- }, children);
20
+ }, children));
20
21
  };
21
22
  var _default = exports.default = Content;
@@ -14,7 +14,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
14
14
  const getCloseButton = handleClose => /*#__PURE__*/_react.default.createElement("button", {
15
15
  id: "botao-fechar-modal-cabecalho",
16
16
  className: "close-button",
17
- tabIndex: 0,
18
17
  onClick: handleClose
19
18
  }, /*#__PURE__*/_react.default.createElement(_icons.default, {
20
19
  name: "cancel2"
@@ -32,6 +32,7 @@ const BaseDialog = props => {
32
32
  headerRef
33
33
  } = (0, _react.useContext)(_form.FormDialogContext);
34
34
  const wrapperEl = (0, _react.useRef)(null);
35
+ const modalContainerRef = (0, _react.useRef)(null);
35
36
  const [isDragging, setIsDragging] = (0, _react.useState)(false);
36
37
  const [open = true, setOpen] = (0, _react.useState)(openProp);
37
38
  if (openProp !== undefined && openProp !== open) {
@@ -55,11 +56,23 @@ const BaseDialog = props => {
55
56
  handleClose();
56
57
  }
57
58
  };
58
- const handleCloseOnEsc = event => {
59
+ const onKeyDownPress = event => {
59
60
  if (event.key === 'Escape') {
60
61
  handleClose();
61
62
  }
62
63
  };
64
+ const modalContainerWithoutBlur = event => {
65
+ var _modalContainerRef$cu, _wrapperEl$current;
66
+ const focusOnAnotherField = !((_modalContainerRef$cu = modalContainerRef.current) !== null && _modalContainerRef$cu !== void 0 && _modalContainerRef$cu.contains(event.relatedTarget));
67
+ const modalContent = (_wrapperEl$current = wrapperEl.current) === null || _wrapperEl$current === void 0 ? void 0 : _wrapperEl$current.querySelector('#modal-dialog-content');
68
+ const elementsFocusable = modalContent === null || modalContent === void 0 ? void 0 : modalContent.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
69
+ if (focusOnAnotherField && elementsFocusable !== null && elementsFocusable !== void 0 && elementsFocusable.length) {
70
+ const firstElement = elementsFocusable[0];
71
+ setTimeout(() => {
72
+ firstElement.focus();
73
+ }, 150);
74
+ }
75
+ };
63
76
  const onDialogPositionChange = _ref => {
64
77
  let {
65
78
  positionX,
@@ -103,6 +116,8 @@ const BaseDialog = props => {
103
116
  if (wrapperEl.current) setIsDragging(false);
104
117
  };
105
118
  const createdModal = /*#__PURE__*/_react.default.createElement("div", {
119
+ ref: modalContainerRef,
120
+ onBlur: modalContainerWithoutBlur,
106
121
  className: "modalcontainer",
107
122
  onMouseDown: handleClickOutside,
108
123
  style: {
@@ -120,14 +135,23 @@ const BaseDialog = props => {
120
135
  style: (0, _style.default)(props),
121
136
  ref: wrapperEl
122
137
  }, children)));
138
+ (0, _react.useLayoutEffect)(() => {
139
+ const {
140
+ activeElement
141
+ } = document;
142
+ const lastElementActiveBeforeOpen = activeElement;
143
+ return () => {
144
+ lastElementActiveBeforeOpen === null || lastElementActiveBeforeOpen === void 0 ? void 0 : lastElementActiveBeforeOpen.focus();
145
+ };
146
+ }, []);
123
147
  (0, _react.useEffect)(() => {
124
148
  if (open) {
125
149
  if (closeOnEsc) {
126
- document.addEventListener('keydown', handleCloseOnEsc);
150
+ document.addEventListener('keydown', onKeyDownPress);
127
151
  }
128
152
  }
129
153
  return () => {
130
- document.removeEventListener('keydown', handleCloseOnEsc);
154
+ document.removeEventListener('keydown', onKeyDownPress);
131
155
  };
132
156
  }, [open, closeOnEsc]);
133
157
  (0, _react.useEffect)(() => {
@@ -132,7 +132,7 @@ const BaseDrawer = _ref => {
132
132
  className: "drawercontent ".concat(skeletonize ? '-skeletonized' : '', " ").concat(customClassForContent)
133
133
  }, title && /*#__PURE__*/_react.default.createElement(_.DrawerHeader, _extends({}, headerProps, {
134
134
  customClass: customClassForDrawer
135
- })), content ? /*#__PURE__*/_react.default.createElement(_.DrawerContent, null, content) : children, getSpinner())));
135
+ })), /*#__PURE__*/_react.default.createElement(_react.Suspense, null, content ? /*#__PURE__*/_react.default.createElement(_.DrawerContent, null, content) : children), getSpinner())));
136
136
  return /*#__PURE__*/_reactDom.default.createPortal(drawerContent(), drawerContainerEl.current);
137
137
  };
138
138
  var _default = exports.default = BaseDrawer;
@@ -14,12 +14,13 @@ const Dialog = _ref => {
14
14
  dialogSize
15
15
  } = _ref;
16
16
  return /*#__PURE__*/_react.default.createElement(_base.default, {
17
+ closeOnEsc: true,
18
+ closeOnOutsideClick: true,
19
+ handlerClose: () => handlerClose(false),
20
+ wrapperClassName: "",
17
21
  width: dialogSize.width,
18
22
  height: dialogSize.height,
19
- onOpenChange: handlerClose,
20
- closeOnOutsideClick: true,
21
- closeOnEsc: true,
22
- wrapperClassName: ""
23
+ onOpenChange: handlerClose
23
24
  }, children);
24
25
  };
25
26
  var _default = exports.default = Dialog;
@@ -6,26 +6,34 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
8
  var _reactDom = _interopRequireDefault(require("react-dom"));
9
- var _helpers = require("./helpers");
10
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const body = document.getElementsByTagName('body')[0];
10
+ const CALENDAR_BUTTON_WIDTH = 24;
11
+ const CALENDAR_MIN_WIDTH = 250;
12
12
  const Dropdown = props => {
13
13
  const {
14
+ containerRef,
15
+ showButtonOpen,
14
16
  dropdownRef,
15
- children
17
+ children,
18
+ inputDimensions
16
19
  } = props;
17
20
  const elementRef = (0, _react.useRef)(document.createElement('div'));
21
+ const width = inputDimensions && inputDimensions.width + (showButtonOpen ? CALENDAR_BUTTON_WIDTH : 0) + 4 || CALENDAR_MIN_WIDTH;
18
22
  (0, _react.useEffect)(() => {
23
+ var _containerRef$current;
19
24
  elementRef.current.className = 'datepicker-component';
20
- elementRef.current.setAttribute('style', (0, _helpers.getCalendarDropdownStyle)(props));
21
- body.appendChild(elementRef.current);
25
+ elementRef.current.style.width = String(width).concat('px');
26
+ elementRef.current.style.top = String(inputDimensions === null || inputDimensions === void 0 ? void 0 : inputDimensions.bottom).concat('px');
27
+ (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.appendChild(elementRef.current);
22
28
  dropdownRef(elementRef.current);
23
29
  return () => {
24
- body.removeChild(elementRef.current);
30
+ var _containerRef$current2;
31
+ (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.removeChild(elementRef.current);
25
32
  };
26
33
  }, []);
27
34
  (0, _react.useEffect)(() => {
28
- elementRef.current.setAttribute('style', (0, _helpers.getCalendarDropdownStyle)(props));
35
+ elementRef.current.style.width = String(width).concat('px');
36
+ elementRef.current.style.top = String(inputDimensions === null || inputDimensions === void 0 ? void 0 : inputDimensions.bottom).concat('px');
29
37
  }, [props]);
30
38
  return /*#__PURE__*/_reactDom.default.createPortal(children, elementRef.current);
31
39
  };
@@ -1,17 +1,7 @@
1
1
  import moment from 'moment';
2
- import { IDateDropdownProps } from './types.js';
3
- import 'react';
4
- import '../../@types/ColorStyles.js';
5
- import '../../@types/PermissionAttr.js';
6
- import '../base/types.js';
7
- import '../../@types/Align.js';
8
- import '../../@types/Period.js';
9
- import '../../internals/types.js';
10
- import '../../@types/Position.js';
11
2
 
12
3
  declare const PT_BR_FORMAT = "DD/MM/YYYY";
13
4
  declare const EN_US_FORMAT = "YYYY-MM-DD";
14
- declare const getCalendarDropdownStyle: ({ topPosition, leftPosition, width, minWidth, }: IDateDropdownProps) => string;
15
5
  declare const getMomentValue: (value: string) => moment.Moment;
16
6
 
17
- export { EN_US_FORMAT, PT_BR_FORMAT, getCalendarDropdownStyle, getMomentValue };
7
+ export { EN_US_FORMAT, PT_BR_FORMAT, getMomentValue };
@@ -3,21 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getMomentValue = exports.getCalendarDropdownStyle = exports.PT_BR_FORMAT = exports.EN_US_FORMAT = void 0;
6
+ exports.getMomentValue = exports.PT_BR_FORMAT = exports.EN_US_FORMAT = void 0;
7
7
  var _moment = _interopRequireDefault(require("moment"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  const PT_BR_FORMAT = exports.PT_BR_FORMAT = 'DD/MM/YYYY';
10
10
  const EN_US_FORMAT = exports.EN_US_FORMAT = 'YYYY-MM-DD';
11
- const getCalendarDropdownStyle = _ref => {
12
- let {
13
- topPosition,
14
- leftPosition,
15
- width,
16
- minWidth
17
- } = _ref;
18
- return "top: ".concat(topPosition, "px;\n left: ").concat(leftPosition, "px;\n width: ").concat(width, "px;\n min-width: ").concat(minWidth, "px;");
19
- };
20
- exports.getCalendarDropdownStyle = getCalendarDropdownStyle;
21
11
  const getMomentValue = value => {
22
12
  let newValue = value;
23
13
  if ((0, _moment.default)(newValue, PT_BR_FORMAT, true).isValid()) {
@@ -6,23 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _moment = _interopRequireDefault(require("moment"));
9
- var _BaseMask = _interopRequireDefault(require("../mask/BaseMask"));
9
+ var _Dialog = _interopRequireDefault(require("./Dialog"));
10
10
  var _Dropdown = _interopRequireDefault(require("./Dropdown"));
11
- var _calendar = _interopRequireDefault(require("../../calendar"));
12
- require("../../assets/styles/datepicker.scss");
13
- var contants = _interopRequireWildcard(require("../../internals/constants"));
14
11
  var _buttons = _interopRequireDefault(require("../../buttons"));
15
- var _icons = _interopRequireDefault(require("../../icons"));
16
- var _Dialog = _interopRequireDefault(require("./Dialog"));
12
+ var _gridlayout = _interopRequireDefault(require("../../gridlayout"));
13
+ var _calendar = _interopRequireDefault(require("../../calendar"));
14
+ var _BaseMask = _interopRequireDefault(require("../mask/BaseMask"));
17
15
  var _helpers = require("./helpers");
16
+ require("../../assets/styles/datepicker.scss");
18
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
18
  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); }
20
19
  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; }
21
20
  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); }
22
- const CALENDAR_BUTTON_WIDTH = 24;
23
- const CALENDAR_MIN_WIDTH = 250;
24
21
  const DatePicker = props => {
25
- var _window;
26
22
  const {
27
23
  showButtonOpen = true,
28
24
  openOnFocus = true,
@@ -34,69 +30,105 @@ const DatePicker = props => {
34
30
  name = '',
35
31
  inputRef: inputRefProp,
36
32
  dialogSize = {
37
- width: '350px',
38
- height: '350px'
39
- }
33
+ width: '384px',
34
+ height: '384px'
35
+ },
36
+ gridLayout,
37
+ shouldCloseOnEsc = true
40
38
  } = props;
41
39
  const [valueState, setValueState] = (0, _react.useState)(value ? (0, _helpers.getMomentValue)(value) : undefined);
42
- const [valueFromProps, setValueFromProps] = (0, _react.useState)(value);
43
40
  const [showCalendar, setShowCalendar] = (0, _react.useState)(false);
41
+ const [valueFromProps, setValueFromProps] = (0, _react.useState)(value);
44
42
  const [inputDimensions, setInputDimensions] = (0, _react.useState)();
45
- const [formatedLeftPosition, setFormatedLeftPosition] = (0, _react.useState)();
43
+ const [calendarOnDialog, setCalendarOnDialog] = (0, _react.useState)(false);
46
44
  const [onDenied, setOnDenied] = (0, _react.useState)({
47
45
  disabled: false,
48
46
  readOnly: false,
49
47
  unvisible: false,
50
48
  hideContent: false
51
49
  });
52
- const inputRef = (0, _react.useRef)();
50
+ const inputDateRef = (0, _react.useRef)();
53
51
  const buttonOpenRef = (0, _react.useRef)();
54
52
  const dropdownContainer = (0, _react.useRef)();
55
- const [insideDropdown, setInsideDropdown] = (0, _react.useState)(false);
53
+ const currentDateButtonRef = (0, _react.useRef)();
54
+ const calendarContainerRef = (0, _react.useRef)(null);
55
+ const datePickerContainerRef = (0, _react.useRef)(null);
56
56
  const onScreenResize = () => {
57
- var _inputRef$current;
58
- setInputDimensions(inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.getBoundingClientRect());
57
+ var _inputDateRef$current;
58
+ setInputDimensions(inputDateRef === null || inputDateRef === void 0 ? void 0 : (_inputDateRef$current = inputDateRef.current) === null || _inputDateRef$current === void 0 ? void 0 : _inputDateRef$current.getBoundingClientRect());
59
59
  };
60
- const onClickOutside = event => {
61
- var _buttonOpenRef$curren;
62
- const {
63
- target
64
- } = event;
65
- if (!dropdownContainer || target === inputRef.current || target === buttonOpenRef.current) return;
66
- if (target !== dropdownContainer.current && dropdownContainer && dropdownContainer.current && !dropdownContainer.current.contains(target) && buttonOpenRef && !(buttonOpenRef !== null && buttonOpenRef !== void 0 && (_buttonOpenRef$curren = buttonOpenRef.current) !== null && _buttonOpenRef$curren !== void 0 && _buttonOpenRef$curren.contains(target))) {
60
+ const onCloseDateDialog = () => {
61
+ setShowCalendar(false);
62
+ if (showCalendarInDialog) {
63
+ setTimeout(() => {
64
+ var _inputDateRef$current2;
65
+ setCalendarOnDialog(false);
66
+ (_inputDateRef$current2 = inputDateRef.current) === null || _inputDateRef$current2 === void 0 ? void 0 : _inputDateRef$current2.focus();
67
+ }, 100);
68
+ }
69
+ };
70
+ const onCloseWithoutBlur = event => {
71
+ var _datePickerContainerR;
72
+ const focusOnAnotherField = !((_datePickerContainerR = datePickerContainerRef.current) !== null && _datePickerContainerR !== void 0 && _datePickerContainerR.contains(event.relatedTarget));
73
+ if (!showCalendarInDialog && showCalendar && focusOnAnotherField) {
67
74
  setShowCalendar(false);
68
75
  }
69
76
  };
77
+ const onKeyDownPress = event => {
78
+ if (shouldCloseOnEsc && showCalendar && event && event.key && event.key === 'Escape') {
79
+ var _inputDateRef$current3;
80
+ event.preventDefault();
81
+ setShowCalendar(false);
82
+ (_inputDateRef$current3 = inputDateRef.current) === null || _inputDateRef$current3 === void 0 ? void 0 : _inputDateRef$current3.focus();
83
+ }
84
+ if (showCalendar && showCalendarInDialog && event && event.key && event.key === 'Tab') {
85
+ var _calendarContainerRef, _calendarContainerRef2;
86
+ const buttonForNavigateCalendar = (_calendarContainerRef = calendarContainerRef.current) === null || _calendarContainerRef === void 0 ? void 0 : _calendarContainerRef.getElementsByClassName('navbutton');
87
+ const datePicked = (_calendarContainerRef2 = calendarContainerRef.current) === null || _calendarContainerRef2 === void 0 ? void 0 : _calendarContainerRef2.getElementsByClassName('-selectedday');
88
+ const buttonDatePicked = datePicked[0].firstChild;
89
+ const buttonsForFocus = Array.from([...buttonForNavigateCalendar, buttonDatePicked]);
90
+ const firstElement = buttonsForFocus[0];
91
+ const lastElement = buttonsForFocus[buttonsForFocus.length - 1];
92
+ if (event.shiftKey && document.activeElement === firstElement) {
93
+ event.preventDefault();
94
+ lastElement.focus();
95
+ } else if (!event.shiftKey && document.activeElement === lastElement) {
96
+ event.preventDefault();
97
+ firstElement.focus();
98
+ }
99
+ }
100
+ event.stopPropagation();
101
+ };
102
+ const keepPositionCalendarByScroll = () => {
103
+ var _inputDateRef$current4;
104
+ const inputDateDimensions = (_inputDateRef$current4 = inputDateRef.current) === null || _inputDateRef$current4 === void 0 ? void 0 : _inputDateRef$current4.getBoundingClientRect();
105
+ const positionTop = inputDateDimensions && inputDateDimensions.bottom;
106
+ if (dropdownContainer && dropdownContainer.current && inputDateDimensions) {
107
+ dropdownContainer.current.style.top = String(positionTop).concat('px');
108
+ }
109
+ };
70
110
  const openCalendar = () => {
71
111
  setShowCalendar(true);
72
- if (inputRef.current) {
73
- setInputDimensions(inputRef.current.getBoundingClientRect());
112
+ if (inputDateRef.current) {
113
+ var _inputDateRef$current5;
114
+ inputDateRef.current.focus();
115
+ setInputDimensions((_inputDateRef$current5 = inputDateRef.current) === null || _inputDateRef$current5 === void 0 ? void 0 : _inputDateRef$current5.getBoundingClientRect());
74
116
  }
75
- };
76
- const onMouseMove = event => {
77
- const {
78
- target
79
- } = event;
80
- setInsideDropdown(false);
81
- if (dropdownContainer !== undefined && dropdownContainer.current) {
82
- if (target === dropdownContainer.current || dropdownContainer.current.contains(target)) {
83
- setInsideDropdown(true);
84
- }
117
+ if (showCalendarInDialog) {
118
+ setTimeout(() => {
119
+ var _currentDateButtonRef;
120
+ (_currentDateButtonRef = currentDateButtonRef.current) === null || _currentDateButtonRef === void 0 ? void 0 : _currentDateButtonRef.focus();
121
+ }, 100);
85
122
  }
86
123
  };
87
124
  const onInputFocus = e => {
88
125
  if (props.onFocus) props.onFocus(e);
89
- if (openOnFocus) openCalendar();
126
+ if (openOnFocus && !showCalendar && !calendarOnDialog) {
127
+ openCalendar();
128
+ }
90
129
  };
91
130
  const onInputBlur = e => {
92
131
  if (props.onBlur) props.onBlur(e);
93
- if (!insideDropdown) setShowCalendar(false);
94
- };
95
- const onInputKeyDown = event => {
96
- if (Number(event.code) === contants.keyCodes.TAB) {
97
- setInsideDropdown(false);
98
- setShowCalendar(false);
99
- }
100
132
  };
101
133
  const isValidDate = date => {
102
134
  if (typeof date === 'object' && !(date instanceof Date)) {
@@ -135,11 +167,9 @@ const DatePicker = props => {
135
167
  }
136
168
  }
137
169
  };
138
- const setValue = function () {
139
- var _inputRef$current2;
140
- let valueParam = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
141
- let e = arguments.length > 1 ? arguments[1] : undefined;
142
- if (showCalendar && setFocusOnSelect) (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
170
+ const setValue = (valueParam, e) => {
171
+ var _inputDateRef$current6;
172
+ if (showCalendar && setFocusOnSelect) (_inputDateRef$current6 = inputDateRef.current) === null || _inputDateRef$current6 === void 0 ? void 0 : _inputDateRef$current6.focus();
143
173
  if (props.onComplete) props.onComplete(e, valueParam);
144
174
  if (props.onChange) onInputChange({
145
175
  target: {
@@ -154,70 +184,51 @@ const DatePicker = props => {
154
184
  const getButtonOpen = () => {
155
185
  if (!showButtonOpen) return undefined;
156
186
  return /*#__PURE__*/_react.default.createElement(_buttons.default, {
157
- key: "button-1313414141",
158
- boxShadow: false,
159
- icon: /*#__PURE__*/_react.default.createElement(_icons.default, {
160
- name: "calendar",
161
- size: 16
162
- }),
187
+ key: "button-open-date-picker",
188
+ disabled: shouldDisable(),
189
+ tabIndex: -1,
190
+ customClass: "calendar-button",
191
+ iconName: "calendar",
192
+ title: showCalendar ? 'Fechar Calendário' : 'Abrir Calendário',
163
193
  onClick: () => {
164
- openCalendar();
194
+ if (showCalendar) {
195
+ setShowCalendar(false);
196
+ } else openCalendar();
165
197
  },
166
- customClass: "calendar-button",
167
- tabIndex: -1,
168
198
  targetRef: ref => {
169
199
  buttonOpenRef.current = ref;
170
- },
171
- disabled: shouldDisable()
200
+ }
172
201
  });
173
202
  };
174
203
  const getCalendar = (valueCalendar, calendarColorStyle) => /*#__PURE__*/_react.default.createElement(_calendar.default, {
204
+ colorStyle: calendarColorStyle,
175
205
  currentDate: valueCalendar !== undefined ? valueCalendar : (0, _moment.default)(),
176
206
  onDateChange: date => {
177
207
  setValue(date.format(_helpers.PT_BR_FORMAT), undefined);
208
+ if (showCalendarInDialog) setCalendarOnDialog(false);
178
209
  },
179
- colorStyle: calendarColorStyle
210
+ currentDateButton: buttonElement => currentDateButtonRef.current = buttonElement,
211
+ calendarContainer: calendarContainer => {
212
+ calendarContainerRef.current = calendarContainer;
213
+ }
180
214
  });
181
- const getWrapperComponent = () => {
215
+ const getCalendarComponent = () => {
182
216
  if (onDenied && onDenied.readOnly) return null;
183
217
  if (showCalendarInDialog) {
184
218
  return /*#__PURE__*/_react.default.createElement(_Dialog.default, {
185
219
  dialogSize: dialogSize,
186
- handlerClose: setShowCalendar
220
+ handlerClose: onCloseDateDialog
187
221
  }, getCalendar(valueState, props === null || props === void 0 ? void 0 : props.calendarColorStyle));
188
222
  }
189
223
  return /*#__PURE__*/_react.default.createElement(_Dropdown.default, {
190
- topPosition: inputDimensions ? inputDimensions.top + inputDimensions.height + 5 : '',
191
- leftPosition: inputDimensions ? formatedLeftPosition : '',
192
- minWidth: CALENDAR_MIN_WIDTH,
193
- width: inputDimensions ? inputDimensions.width + (showButtonOpen ? CALENDAR_BUTTON_WIDTH : 0) : '',
224
+ showButtonOpen: showButtonOpen,
225
+ inputDimensions: inputDimensions,
226
+ containerRef: datePickerContainerRef,
194
227
  dropdownRef: el => {
195
228
  dropdownContainer.current = el;
196
229
  }
197
230
  }, getCalendar(valueState, props === null || props === void 0 ? void 0 : props.calendarColorStyle));
198
231
  };
199
- (0, _react.useEffect)(() => {
200
- const screenWidth = window.innerWidth;
201
- if (inputDimensions && screenWidth < inputDimensions.left + CALENDAR_MIN_WIDTH) {
202
- setFormatedLeftPosition(inputDimensions.left - (CALENDAR_MIN_WIDTH - inputDimensions.width - CALENDAR_BUTTON_WIDTH));
203
- } else {
204
- setFormatedLeftPosition(inputDimensions === null || inputDimensions === void 0 ? void 0 : inputDimensions.left);
205
- }
206
- }, [(_window = window) === null || _window === void 0 ? void 0 : _window.innerWidth, inputDimensions]);
207
- (0, _react.useEffect)(() => {
208
- window.addEventListener('resize', onScreenResize);
209
- document.addEventListener('click', onClickOutside);
210
- document.addEventListener('mousemove', onMouseMove);
211
- if (inputRef.current) onScreenResize();
212
- return () => {
213
- window.removeEventListener('resize', onScreenResize);
214
- document.removeEventListener('click', onClickOutside);
215
- document.removeEventListener('mousemove', onMouseMove);
216
- };
217
-
218
- // TODO: Procurar solução melhor.
219
- // setTimeout(() => { this.onScreenResize(); }, 300);
220
- }, [inputRef.current]);
221
232
  (0, _react.useEffect)(() => {
222
233
  if (value && (0, _moment.default)(value, _helpers.EN_US_FORMAT).format() !== 'Invalid date' && (0, _moment.default)(valueFromProps, _helpers.EN_US_FORMAT).format() !== (0, _moment.default)(value, _helpers.EN_US_FORMAT).format()) {
223
234
  setValueState((0, _moment.default)(value, _helpers.EN_US_FORMAT));
@@ -227,31 +238,58 @@ const DatePicker = props => {
227
238
  setValueFromProps(value);
228
239
  }
229
240
  }, [value]);
241
+ (0, _react.useEffect)(() => {
242
+ window.addEventListener('resize', onScreenResize);
243
+ document.addEventListener('keydown', onKeyDownPress);
244
+ if (inputDateRef.current) onScreenResize();
245
+ if (showCalendar && showCalendarInDialog) setCalendarOnDialog(true);
246
+ return () => {
247
+ window.removeEventListener('resize', onScreenResize);
248
+ document.removeEventListener('keydown', onKeyDownPress);
249
+ };
250
+ }, [inputDateRef.current, showCalendar]);
251
+ (0, _react.useEffect)(() => {
252
+ var _document$getElementB;
253
+ document.addEventListener('scroll', keepPositionCalendarByScroll);
254
+ (_document$getElementB = document.getElementById('modal-dialog-content')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.addEventListener('scroll', keepPositionCalendarByScroll);
255
+ return () => {
256
+ var _document$getElementB2;
257
+ document.removeEventListener('scroll', keepPositionCalendarByScroll);
258
+ (_document$getElementB2 = document.getElementById('modal-dialog-content')) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.removeEventListener('scroll', keepPositionCalendarByScroll);
259
+ };
260
+ }, []);
230
261
  if (onDenied && onDenied.unvisible) return null;
231
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({}, props, {
262
+ const component = () => /*#__PURE__*/_react.default.createElement("div", {
263
+ ref: datePickerContainerRef,
264
+ onBlur: onCloseWithoutBlur,
265
+ className: "datepicker-container"
266
+ }, /*#__PURE__*/_react.default.createElement(_BaseMask.default, _extends({}, props, {
267
+ gridLayout: undefined,
232
268
  value: !valueState ? ' ' : valueState.format(_helpers.PT_BR_FORMAT),
233
269
  mask: "00/00/0000",
234
- onComplete: e => {
235
- if (e) {
236
- var _e$target;
237
- setValue((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.maskedValue, e);
270
+ onComplete: (e, date) => {
271
+ if (date) {
272
+ setValue(date, e);
238
273
  }
239
274
  },
240
275
  onBlur: onInputBlur,
241
276
  onFocus: e => {
242
277
  onInputFocus(e);
243
278
  },
244
- onKeyDown: onInputKeyDown,
245
- onChange: (e, __, date) => {
246
- if (date) onInputChange(e, e.target.value);
279
+ onChange: (e, date) => {
280
+ if (date) onInputChange(e, date);
247
281
  },
248
282
  inputRef: el => {
249
- inputRef.current = el;
283
+ inputDateRef.current = el;
250
284
  if (inputRefProp) inputRefProp.current = el;
251
285
  },
252
286
  rightElements: getButtonOpen(),
253
287
  required: required,
254
288
  handlerSetOnDenied: () => setOnDenied(onDenied)
255
- })), showCalendar && getWrapperComponent());
289
+ })), showCalendar && getCalendarComponent());
290
+ return !gridLayout ? component() : /*#__PURE__*/_react.default.createElement(_gridlayout.default, {
291
+ customClass: "-withinput",
292
+ cols: gridLayout
293
+ }, component());
256
294
  };
257
295
  var _default = exports.default = DatePicker;
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import { ReactNode, RefObject } from 'react';
2
2
  import { ColorStyles } from '../../@types/ColorStyles.js';
3
3
  import { PermissionAttr } from '../../@types/PermissionAttr.js';
4
4
  import { CustomInputEvent } from '../base/types.js';
@@ -9,10 +9,11 @@ import '../../@types/Position.js';
9
9
 
10
10
  interface IDatePickerProps {
11
11
  value?: string;
12
+ openOnFocus?: boolean;
12
13
  showButtonOpen?: boolean;
14
+ shouldCloseOnEsc?: boolean;
13
15
  shouldCloseOnSelect?: boolean;
14
16
  setFocusOnSelect?: boolean;
15
- openOnFocus?: boolean;
16
17
  showCalendarInDialog?: boolean;
17
18
  inputRef?: React.MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null>;
18
19
  dialogSize?: {
@@ -37,14 +38,14 @@ interface IDatePickerProps {
37
38
  disabled?: boolean;
38
39
  permissionAttr?: PermissionAttr;
39
40
  label?: string;
41
+ gridLayout?: string;
40
42
  }
41
43
  interface IDateDropdownProps {
42
44
  children: ReactNode | ReactNode[];
43
45
  dropdownRef: (el: HTMLDivElement) => void;
44
- topPosition: number | string;
45
- leftPosition?: number | string;
46
- width: number | string;
47
- minWidth: number | string;
46
+ containerRef: RefObject<HTMLDivElement | HTMLElement>;
47
+ showButtonOpen: boolean;
48
+ inputDimensions?: DOMRect;
48
49
  }
49
50
  interface IDateDialogProps {
50
51
  children: ReactNode | ReactNode[];
@@ -9,6 +9,6 @@ import '../../@types/Align.js';
9
9
  import '../../internals/types.js';
10
10
  import '../../@types/Position.js';
11
11
 
12
- declare const Dialog: ({ onOpenChange, children, dialogSize }: IDialogProps) => JSX.Element;
12
+ declare const Dialog: ({ onOpenChange, handlerClose, children, dialogSize }: IDialogProps) => JSX.Element;
13
13
 
14
14
  export { Dialog as default };
@@ -10,16 +10,18 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
10
10
  const Dialog = _ref => {
11
11
  let {
12
12
  onOpenChange,
13
+ handlerClose,
13
14
  children,
14
15
  dialogSize
15
16
  } = _ref;
16
17
  return /*#__PURE__*/_react.default.createElement(_base.default, {
18
+ closeOnOutsideClick: true,
19
+ closeOnEsc: true,
20
+ wrapperClassName: "",
17
21
  width: dialogSize.width,
18
22
  height: dialogSize.height,
19
23
  onOpenChange: onOpenChange,
20
- closeOnOutsideClick: true,
21
- closeOnEsc: true,
22
- wrapperClassName: ""
24
+ handlerClose: () => handlerClose(false)
23
25
  }, children);
24
26
  };
25
27
  var _default = exports.default = Dialog;