@synerise/ds-time-picker 0.6.17 → 0.6.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.
- package/CHANGELOG.md +28 -0
- package/dist/TimePicker.js +48 -25
- package/dist/Unit.js +13 -8
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.6.18](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@0.6.17...@synerise/ds-time-picker@0.6.18) (2022-06-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **time-picker:** add ts-ignore ([3073779](https://github.com/Synerise/synerise-design/commit/30737798dc2bd6bfe74f4b534427da61af669948))
|
|
12
|
+
* **time-picker:** add ts-ignore ([2389568](https://github.com/Synerise/synerise-design/commit/2389568a57523faf0bd84d3fdb760f25d5c3b8bb))
|
|
13
|
+
* **time-picker:** change to use useMemo ([24cfb11](https://github.com/Synerise/synerise-design/commit/24cfb11566103009404788572bbc47b4478f23d5))
|
|
14
|
+
* **time-picker:** fix changing time ([ab3281d](https://github.com/Synerise/synerise-design/commit/ab3281d093b791715cdea462b7e47f05ee7ad360))
|
|
15
|
+
* **time-picker:** fix changing time ([a1c3507](https://github.com/Synerise/synerise-design/commit/a1c3507db5e361fc055e8e4afc79ad883046c99e))
|
|
16
|
+
* **time-picker:** fix changing time ([ea969ed](https://github.com/Synerise/synerise-design/commit/ea969ed02617cbc9770aee607369b2280bea6544))
|
|
17
|
+
* **time-picker:** fix changing time to not show local time ([7873cd7](https://github.com/Synerise/synerise-design/commit/7873cd76d82512ee5b73f2b72606140b3de5e353))
|
|
18
|
+
* **time-picker:** fix dependencies and add ts-ignore ([4b0be58](https://github.com/Synerise/synerise-design/commit/4b0be584249ab1ba8b669c10c05aa4a11c9e0845))
|
|
19
|
+
* **time-picker:** fix dependencies and add ts-ignore ([1771914](https://github.com/Synerise/synerise-design/commit/17719142d304cc8c11408641e24e7c16ffddac62))
|
|
20
|
+
* **time-picker:** fix dependencies and add ts-ignore ([afee591](https://github.com/Synerise/synerise-design/commit/afee5910c173414d34660362864bf44714b3aabb))
|
|
21
|
+
* **time-picker:** fix dependencies and add ts-ignore ([296476b](https://github.com/Synerise/synerise-design/commit/296476b90111532b82151b566f88222288890c16))
|
|
22
|
+
* **time-picker:** fix prop ([221c648](https://github.com/Synerise/synerise-design/commit/221c64816a87ed371dddd03baaa4f0feb128698f))
|
|
23
|
+
* **time-picker:** fix prop ([236c04e](https://github.com/Synerise/synerise-design/commit/236c04ea1e0aa9f32e0912ae0a646d9f7ea67ac5))
|
|
24
|
+
* **time-picker:** fix scroll on selected time to pop on top in dropdown ([2c2eced](https://github.com/Synerise/synerise-design/commit/2c2eced6f65d022eb60a4edc07ee6c777d50fda3))
|
|
25
|
+
* **time-picker:** fix showing data ([ac0816b](https://github.com/Synerise/synerise-design/commit/ac0816b977fba292f250a0a3b4035b5a70f9bfd2))
|
|
26
|
+
* **time-picker:** fix showing data ([153c1b0](https://github.com/Synerise/synerise-design/commit/153c1b0f647da658c7f6680ac1fc357ebf5c59a9))
|
|
27
|
+
* **time-picker:** remove console logs ([96903a4](https://github.com/Synerise/synerise-design/commit/96903a480933308254d7e9df04a4ff4cd0e0411d))
|
|
28
|
+
* **time-picker:** scroll only if scrollTo is function ([358cd3d](https://github.com/Synerise/synerise-design/commit/358cd3d9e9a360ecc2062693c88e9a688aaffe72))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
## [0.6.17](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@0.6.16...@synerise/ds-time-picker@0.6.17) (2022-04-29)
|
|
7
35
|
|
|
8
36
|
**Note:** Version bump only for package @synerise/ds-time-picker
|
package/dist/TimePicker.js
CHANGED
|
@@ -7,6 +7,7 @@ import Icon, { ClockM, Close3S } from '@synerise/ds-icon';
|
|
|
7
7
|
import Dropdown from '@synerise/ds-dropdown';
|
|
8
8
|
import Tooltip from '@synerise/ds-tooltip/dist/Tooltip';
|
|
9
9
|
import { FormattedMessage, injectIntl } from 'react-intl';
|
|
10
|
+
import { useMemo } from 'react';
|
|
10
11
|
import Unit from './Unit';
|
|
11
12
|
import * as S from './TimePicker.styles';
|
|
12
13
|
var defaultUnits = ['hour', 'minute', 'second'];
|
|
@@ -60,12 +61,37 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
60
61
|
clockMode = _React$useState3[0],
|
|
61
62
|
setClockMode = _React$useState3[1];
|
|
62
63
|
|
|
64
|
+
var _React$useState4 = React.useState(undefined),
|
|
65
|
+
hour = _React$useState4[0],
|
|
66
|
+
setHour = _React$useState4[1];
|
|
67
|
+
|
|
68
|
+
var _React$useState5 = React.useState(undefined),
|
|
69
|
+
minute = _React$useState5[0],
|
|
70
|
+
setMinute = _React$useState5[1];
|
|
71
|
+
|
|
72
|
+
var _React$useState6 = React.useState(undefined),
|
|
73
|
+
second = _React$useState6[0],
|
|
74
|
+
setSecond = _React$useState6[1];
|
|
75
|
+
|
|
76
|
+
var getTimeString = function getTimeString(date) {
|
|
77
|
+
return dayjs(date).format(timeFormat);
|
|
78
|
+
}; // eslint-disable-next-line
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
|
|
81
|
+
|
|
63
82
|
React.useEffect(function () {
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
if (hour !== undefined && minute !== undefined && second !== undefined) {
|
|
84
|
+
var newDate = dayjs().hour(hour).minute(minute).second(second).toDate();
|
|
85
|
+
setLocalValue(newDate);
|
|
86
|
+
onChange && onChange(newDate, getTimeString(newDate));
|
|
87
|
+
} // eslint-disable-next-line
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
|
|
90
|
+
}, [hour, minute, second]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
91
|
+
|
|
66
92
|
var unitConfig = [{
|
|
67
93
|
unit: 'hour',
|
|
68
|
-
options: use12HourClock ? range(12
|
|
94
|
+
options: use12HourClock ? range(12) : range(24),
|
|
69
95
|
disabled: disabledHours,
|
|
70
96
|
insertSeperator: true
|
|
71
97
|
}, {
|
|
@@ -86,36 +112,23 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
86
112
|
});
|
|
87
113
|
}, [units, unitConfig]);
|
|
88
114
|
|
|
89
|
-
var getTimeString = function getTimeString(date) {
|
|
90
|
-
return dayjs(date).format(timeFormat);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
115
|
var onVisibleChange = function onVisibleChange(visible) {
|
|
94
116
|
setOpen(visible);
|
|
95
117
|
!visible && onChange && onChange(localValue, getTimeString(localValue));
|
|
96
118
|
};
|
|
97
119
|
|
|
98
120
|
var handleChange = function handleChange(unit, newValue) {
|
|
99
|
-
if (
|
|
100
|
-
|
|
121
|
+
if (unit === 'hour') {
|
|
122
|
+
setHour(newValue);
|
|
101
123
|
}
|
|
102
124
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return unitsToRender.find(function (val) {
|
|
106
|
-
return val.unit !== u;
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
if (res.length !== defaultUnits.length) {
|
|
111
|
-
res.forEach(function (u) {
|
|
112
|
-
newDateObject = dayjs(newDateObject).set(u, 0);
|
|
113
|
-
});
|
|
125
|
+
if (unit === 'minute') {
|
|
126
|
+
setMinute(newValue);
|
|
114
127
|
}
|
|
115
128
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
129
|
+
if (unit === 'second') {
|
|
130
|
+
setSecond(newValue);
|
|
131
|
+
}
|
|
119
132
|
};
|
|
120
133
|
|
|
121
134
|
var renderClockSwitch = function renderClockSwitch() {
|
|
@@ -131,6 +144,9 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
131
144
|
}));
|
|
132
145
|
};
|
|
133
146
|
|
|
147
|
+
var timeValue = useMemo(function () {
|
|
148
|
+
return localValue || dayjs().hour(hour || 0).minute(minute || 0).second(second || 0).toDate();
|
|
149
|
+
}, [localValue, hour, minute, second]);
|
|
134
150
|
var overlay = /*#__PURE__*/React.createElement(S.OverlayContainer, {
|
|
135
151
|
"data-testid": "tp-overlay-container",
|
|
136
152
|
className: overlayClassName
|
|
@@ -138,7 +154,7 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
138
154
|
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
139
155
|
key: u.unit
|
|
140
156
|
}, /*#__PURE__*/React.createElement(Unit, _extends({}, u, {
|
|
141
|
-
value:
|
|
157
|
+
value: timeValue,
|
|
142
158
|
onSelect: function onSelect(newValue) {
|
|
143
159
|
return handleChange(u.unit, newValue);
|
|
144
160
|
}
|
|
@@ -149,6 +165,9 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
149
165
|
setLocalValue(undefined);
|
|
150
166
|
setOpen(false);
|
|
151
167
|
onChange && onChange(undefined, '');
|
|
168
|
+
setHour(undefined);
|
|
169
|
+
setMinute(undefined);
|
|
170
|
+
setSecond(undefined);
|
|
152
171
|
}, [setOpen, setLocalValue, onChange]);
|
|
153
172
|
var timePickerIcon = React.useMemo(function () {
|
|
154
173
|
return (alwaysOpen || open) && dateString ? /*#__PURE__*/React.createElement(S.ClearIcon, {
|
|
@@ -165,10 +184,14 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
165
184
|
});
|
|
166
185
|
}, [open, dateString, clear, clearTooltip, alwaysOpen, disabled]);
|
|
167
186
|
var placeholderValue = React.useMemo(function () {
|
|
187
|
+
if (hour !== undefined || minute !== undefined || second !== undefined) {
|
|
188
|
+
return dayjs().hour(hour || 0).minute(minute || 0).second(second || 0).format('HH:mm:ss');
|
|
189
|
+
}
|
|
190
|
+
|
|
168
191
|
return placeholder || intl.formatMessage({
|
|
169
192
|
id: 'DS.TIME-PICKER.PLACEHOLDER'
|
|
170
193
|
});
|
|
171
|
-
}, [placeholder, intl]);
|
|
194
|
+
}, [placeholder, intl, hour, minute, second]);
|
|
172
195
|
|
|
173
196
|
if (raw) {
|
|
174
197
|
return overlay;
|
package/dist/Unit.js
CHANGED
|
@@ -20,13 +20,13 @@ var Unit = function Unit(_ref) {
|
|
|
20
20
|
var selectedCellRef = React.useRef(null);
|
|
21
21
|
var unitContainerRef = React.useRef(null);
|
|
22
22
|
|
|
23
|
-
var _React$useState2 = React.useState(
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
var _React$useState2 = React.useState(300),
|
|
24
|
+
containerHeight = _React$useState2[0],
|
|
25
|
+
setContainerHeight = _React$useState2[1];
|
|
26
26
|
|
|
27
|
-
var _React$useState3 = React.useState(
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
var _React$useState3 = React.useState(true),
|
|
28
|
+
isFirstRender = _React$useState3[0],
|
|
29
|
+
setFirstRender = _React$useState3[1];
|
|
30
30
|
|
|
31
31
|
React.useEffect(function () {
|
|
32
32
|
if (isFirstRender) {
|
|
@@ -49,9 +49,11 @@ var Unit = function Unit(_ref) {
|
|
|
49
49
|
}, [unitContainerRef]);
|
|
50
50
|
React.useEffect(function () {
|
|
51
51
|
if (selectedCellRef.current && unitContainerRef.current) {
|
|
52
|
+
var _unitContainerRef$cur, _unitContainerRef$cur2;
|
|
53
|
+
|
|
52
54
|
var offsetToParent = selectedCellRef.current.offsetTop - unitContainerRef.current.offsetTop;
|
|
53
55
|
var scrollBehaviour = isFirstRender || !containerHeight ? 'auto' : 'smooth';
|
|
54
|
-
(unitContainerRef == null ? void 0 : unitContainerRef.current) && unitContainerRef.current.scrollTo({
|
|
56
|
+
(unitContainerRef == null ? void 0 : (_unitContainerRef$cur = unitContainerRef.current) == null ? void 0 : (_unitContainerRef$cur2 = _unitContainerRef$cur.scrollTo) == null ? void 0 : _unitContainerRef$cur2.call) && unitContainerRef.current.scrollTo({
|
|
55
57
|
top: offsetToParent,
|
|
56
58
|
behavior: scrollBehaviour
|
|
57
59
|
});
|
|
@@ -71,7 +73,10 @@ var Unit = function Unit(_ref) {
|
|
|
71
73
|
disabled: isDisabled,
|
|
72
74
|
onClick: function onClick() {
|
|
73
75
|
onSelect(option);
|
|
74
|
-
|
|
76
|
+
setTimeout(function () {
|
|
77
|
+
// timeout is required to make sure that the ref is updated
|
|
78
|
+
setForceUpdate(!forceUpdate);
|
|
79
|
+
}, 50);
|
|
75
80
|
},
|
|
76
81
|
active: isSelected,
|
|
77
82
|
ref: isSelected ? selectedCellRef : null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-time-picker",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.18",
|
|
4
4
|
"description": "TimePicker UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
],
|
|
33
33
|
"types": "dist/index.d.ts",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@synerise/ds-dropdown": "^0.17.
|
|
35
|
+
"@synerise/ds-dropdown": "^0.17.18",
|
|
36
36
|
"@synerise/ds-icon": "^0.49.0",
|
|
37
37
|
"@synerise/ds-input": "^0.18.10",
|
|
38
|
-
"@synerise/ds-search-bar": "^0.
|
|
38
|
+
"@synerise/ds-search-bar": "^0.6.0",
|
|
39
39
|
"@synerise/ds-typography": "^0.12.2",
|
|
40
40
|
"dayjs": "^1.8.19",
|
|
41
41
|
"debounce": "^1.2.0"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/debounce": "^1.2.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d787395998e479858cb58f6d56555e4c51fe45d5"
|
|
51
51
|
}
|