intelicoreact 0.0.84 → 0.0.85

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.
@@ -29,22 +29,18 @@ var InputCalendar = function InputCalendar(_ref) {
29
29
  var value = _ref.value,
30
30
  minDate = _ref.minDate,
31
31
  maxDate = _ref.maxDate,
32
- onChange = _ref.onChange;
33
-
34
- var _useState = (0, _react.useState)(value),
32
+ onChange = _ref.onChange,
33
+ _ref$className = _ref.className,
34
+ className = _ref$className === void 0 ? '' : _ref$className,
35
+ _ref$placeholder = _ref.placeholder,
36
+ placeholder = _ref$placeholder === void 0 ? 'mm/dd/yyyy' : _ref$placeholder,
37
+ _ref$mask = _ref.mask,
38
+ mask = _ref$mask === void 0 ? '99/99/9999' : _ref$mask;
39
+
40
+ var _useState = (0, _react.useState)(false),
35
41
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
36
- date = _useState2[0],
37
- setDate = _useState2[1];
38
-
39
- var _useState3 = (0, _react.useState)(date),
40
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
41
- inputValue = _useState4[0],
42
- setInputValue = _useState4[1];
43
-
44
- var _useState5 = (0, _react.useState)(false),
45
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
46
- isOpened = _useState6[0],
47
- setIsOpened = _useState6[1];
42
+ isOpened = _useState2[0],
43
+ setIsOpened = _useState2[1];
48
44
 
49
45
  var calendarRef = (0, _react.useRef)(null);
50
46
  (0, _useClickOutside.useClickOutside)(calendarRef, function () {
@@ -52,28 +48,20 @@ var InputCalendar = function InputCalendar(_ref) {
52
48
  });
53
49
 
54
50
  var changeInputValue = function changeInputValue(val) {
55
- if (!val.includes('_') && val) {
56
- setDate((0, _moment.default)(val).format('L'));
57
- setInputValue((0, _moment.default)(val).format('L'));
58
- } else {
59
- setInputValue(val);
60
- }
61
-
62
- if (onChange) onChange();
51
+ if (onChange) onChange(val);
63
52
  };
64
53
 
65
54
  var changeCalendarDay = function changeCalendarDay(val) {
66
- setDate(val);
67
- setInputValue(val);
68
55
  if (onChange) onChange(val);
69
56
  };
70
57
 
71
58
  return /*#__PURE__*/_react.default.createElement("div", {
72
- className: "calendar-container",
59
+ className: "input__wrap calendar-container ".concat(className),
73
60
  ref: calendarRef
74
61
  }, /*#__PURE__*/_react.default.createElement(_reactInputMask.default, {
75
- mask: "99/99/9999",
76
- value: inputValue,
62
+ mask: mask,
63
+ placeholder: placeholder,
64
+ value: value,
77
65
  onChange: function onChange(e) {
78
66
  return changeInputValue(e.target.value);
79
67
  },
@@ -82,7 +70,7 @@ var InputCalendar = function InputCalendar(_ref) {
82
70
  return setIsOpened(!isOpened);
83
71
  }
84
72
  }), isOpened ? /*#__PURE__*/_react.default.createElement(_Calendar.default, {
85
- date: date,
73
+ date: (0, _moment.default)(value).format('L'),
86
74
  setDate: function setDate(newDate) {
87
75
  return changeCalendarDay(newDate);
88
76
  },
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.Calendar = exports.default = void 0;
11
11
 
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
17
+
12
18
  var _react = _interopRequireWildcard(require("react"));
13
19
 
14
20
  var _yup = require("yup");
@@ -26,14 +32,24 @@ var _default = {
26
32
  };
27
33
  exports.default = _default;
28
34
 
35
+ var _useState = (0, _react.useState)(''),
36
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
+ date = _useState2[0],
38
+ setDate = _useState2[1];
39
+
29
40
  var Template = function Template(args) {
30
- return /*#__PURE__*/_react.default.createElement(_InputCalendar.default, args);
41
+ return /*#__PURE__*/_react.default.createElement(_InputCalendar.default, (0, _extends2.default)({}, args, {
42
+ value: date
43
+ }));
31
44
  };
32
45
 
33
46
  var Calendar = Template.bind({});
34
47
  exports.Calendar = Calendar;
35
48
  Calendar.args = {
36
- value: '10/14/2021',
49
+ value: '',
37
50
  minDate: '10/14/2020',
38
- maxDate: '10/14/2023'
51
+ maxDate: '10/14/2022',
52
+ onChange: function onChange(val) {
53
+ return setDate(val);
54
+ }
39
55
  };
@@ -1,4 +1,4 @@
1
- .range-calendar {
1
+ .range-calendar, .calendar {
2
2
  width: 195px;
3
3
  min-height: 195px;
4
4
  display: flex;
@@ -12,7 +12,7 @@
12
12
  display: flex;
13
13
  justify-content: space-between;
14
14
  align-items: center;
15
-
15
+
16
16
  &__title {
17
17
  line-height: 20px;
18
18
  font-weight: 500;
@@ -27,7 +27,7 @@
27
27
  &__next, &__prev {
28
28
  width: 16px;
29
29
  height: 16px;
30
- background-color: #E2E6F8;
30
+ //background-color: #E2E6F8;
31
31
  border-radius: 5px;
32
32
  color: #171D33;
33
33
  }
@@ -98,4 +98,4 @@
98
98
  }
99
99
  }
100
100
  }
101
- }
101
+ }
@@ -134,7 +134,7 @@ function _default(props) {
134
134
  return /*#__PURE__*/_react.default.createElement("div", {
135
135
  key: "day-of-week_".concat(dayOfWeek),
136
136
  className: "calendar__day calendar__day--title"
137
- }, (0, _moment.default)().weekday(dayOfWeek).format('dd').charAt(0));
137
+ }, (0, _moment.default)().weekday(dayOfWeek).format('dd'));
138
138
  })), Object.keys(days).map(function (week, index) {
139
139
  return /*#__PURE__*/_react.default.createElement("div", {
140
140
  key: "week_".concat(index),
@@ -511,15 +511,20 @@
511
511
  }
512
512
 
513
513
  &-container {
514
- width: 200px;
514
+ min-width: 200px;
515
+ position: relative;
516
+ .calendar {
517
+ position: absolute;
518
+ top: 100%;
519
+ padding: 10px 16px;
520
+ border: 1px solid var(--border-color);
521
+ }
515
522
  }
516
523
 
517
524
  &-dropdown {
518
525
  appearance: none;
519
526
  background-color: white;
520
527
  cursor: pointer;
521
- color: gray;
522
-
523
528
  width: 100%;
524
529
  height: 28px;
525
530
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "0.0.84",
3
+ "version": "0.0.85",
4
4
  "description": "fix input-calendar",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -4,40 +4,31 @@ import InputMask from 'react-input-mask';
4
4
  import Calendar from '../../UI/Calendar/Calendar';
5
5
  import { useClickOutside } from '../../../Functions/useClickOutside';
6
6
 
7
- const InputCalendar = ({ value, minDate, maxDate, onChange }) => {
8
- const [date, setDate] = useState(value);
9
- const [inputValue, setInputValue] = useState(date);
7
+ const InputCalendar = ({ value, minDate, maxDate, onChange, className = '', placeholder = 'mm/dd/yyyy', mask = '99/99/9999' }) => {
10
8
  const [isOpened, setIsOpened] = useState(false);
11
9
  const calendarRef = useRef(null);
12
10
 
13
11
  useClickOutside(calendarRef, () => setIsOpened(false));
14
12
 
15
13
  const changeInputValue = val => {
16
- if (!val.includes('_') && val) {
17
- setDate(moment(val).format('L'));
18
- setInputValue(moment(val).format('L'));
19
- } else {
20
- setInputValue(val);
21
- }
22
- if(onChange) onChange();
14
+ if (onChange) onChange(val);
23
15
  };
24
16
 
25
17
  const changeCalendarDay = val => {
26
- setDate(val);
27
- setInputValue(val);
28
18
  if (onChange) onChange(val);
29
19
  };
30
20
 
31
21
  return (
32
- <div className="calendar-container" ref={calendarRef}>
22
+ <div className={`input__wrap calendar-container ${className}`} ref={calendarRef}>
33
23
  <InputMask
34
- mask="99/99/9999"
35
- value={inputValue}
24
+ mask={mask}
25
+ placeholder={placeholder}
26
+ value={value}
36
27
  onChange={e => changeInputValue(e.target.value)}
37
28
  className="calendar-dropdown"
38
29
  onFocus={() => setIsOpened(!isOpened)}
39
30
  />
40
- {isOpened ? <Calendar date={date} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
31
+ {isOpened ? <Calendar date={moment(value).format('L')} setDate={newDate => changeCalendarDay(newDate)} params={{ minDate, maxDate }} /> : null}
41
32
  </div>
42
33
  );
43
34
  };
@@ -1,3 +1,4 @@
1
+ import moment from 'moment-timezone';
1
2
  import React, { useRef, useState } from 'react';
2
3
  import { ref } from 'yup';
3
4
  import InputCalendar from './InputCalendar';
@@ -9,14 +10,17 @@ export default {
9
10
  component: InputCalendar,
10
11
  };
11
12
 
13
+ const [date, setDate] = useState('');
14
+
12
15
  const Template = args => {
13
- return <InputCalendar {...args} />;
16
+ return <InputCalendar {...args} value={date} />;
14
17
  };
15
18
 
16
19
  export const Calendar = Template.bind({});
17
20
 
18
21
  Calendar.args = {
19
- value: '10/14/2021',
22
+ value: '',
20
23
  minDate: '10/14/2020',
21
- maxDate: '10/14/2023',
24
+ maxDate: '10/14/2022',
25
+ onChange: val => setDate(val)
22
26
  };
@@ -1,4 +1,4 @@
1
- .range-calendar {
1
+ .range-calendar, .calendar {
2
2
  width: 195px;
3
3
  min-height: 195px;
4
4
  display: flex;
@@ -12,7 +12,7 @@
12
12
  display: flex;
13
13
  justify-content: space-between;
14
14
  align-items: center;
15
-
15
+
16
16
  &__title {
17
17
  line-height: 20px;
18
18
  font-weight: 500;
@@ -27,7 +27,7 @@
27
27
  &__next, &__prev {
28
28
  width: 16px;
29
29
  height: 16px;
30
- background-color: #E2E6F8;
30
+ //background-color: #E2E6F8;
31
31
  border-radius: 5px;
32
32
  color: #171D33;
33
33
  }
@@ -98,4 +98,4 @@
98
98
  }
99
99
  }
100
100
  }
101
- }
101
+ }
@@ -92,7 +92,7 @@ export default function (props) {
92
92
  {[...Array(7).keys()].map((dayOfWeek) => {
93
93
  return (
94
94
  <div key={`day-of-week_${dayOfWeek}`} className="calendar__day calendar__day--title">
95
- {moment().weekday(dayOfWeek).format('dd').charAt(0)}
95
+ {moment().weekday(dayOfWeek).format('dd')}
96
96
  </div>
97
97
  );
98
98
  })}
@@ -511,15 +511,20 @@
511
511
  }
512
512
 
513
513
  &-container {
514
- width: 200px;
514
+ min-width: 200px;
515
+ position: relative;
516
+ .calendar {
517
+ position: absolute;
518
+ top: 100%;
519
+ padding: 10px 16px;
520
+ border: 1px solid var(--border-color);
521
+ }
515
522
  }
516
523
 
517
524
  &-dropdown {
518
525
  appearance: none;
519
526
  background-color: white;
520
527
  cursor: pointer;
521
- color: gray;
522
-
523
528
  width: 100%;
524
529
  height: 28px;
525
530