@synerise/ds-time-picker 1.2.23 → 1.2.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/CHANGELOG.md +8 -0
- package/dist/TimePicker.d.ts +3 -3
- package/dist/TimePicker.js +109 -164
- package/dist/TimePicker.styles.d.ts +5 -5
- package/dist/TimePicker.styles.js +43 -51
- package/dist/Unit.d.ts +2 -2
- package/dist/Unit.js +49 -66
- package/dist/constants/timePicker.constants.d.ts +2 -2
- package/dist/constants/timePicker.constants.js +25 -12
- package/dist/constants/timePicker.spec.constants.d.ts +17 -0
- package/dist/constants/timePicker.spec.constants.js +20 -0
- package/dist/index.js +14 -2
- package/dist/modules.d.js +1 -1
- package/dist/modules.d.ts +0 -0
- package/dist/types/TimePicker.types.d.ts +6 -6
- package/dist/types/TimePicker.types.js +1 -1
- package/dist/utils/clockMode.utils.js +11 -7
- package/dist/utils/timePicker.utils.d.ts +2 -2
- package/dist/utils/timePicker.utils.js +14 -19
- package/dist/utils/unit.utils.d.ts +1 -1
- package/dist/utils/unit.utils.js +10 -7
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [1.2.25](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@1.2.24...@synerise/ds-time-picker@1.2.25) (2026-04-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-time-picker
|
|
9
|
+
|
|
10
|
+
## [1.2.24](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@1.2.23...@synerise/ds-time-picker@1.2.24) (2026-03-24)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @synerise/ds-time-picker
|
|
13
|
+
|
|
6
14
|
## [1.2.23](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@1.2.22...@synerise/ds-time-picker@1.2.23) (2026-03-20)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @synerise/ds-time-picker
|
package/dist/TimePicker.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import {
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { TimePickerProps } from './types/TimePicker.types';
|
|
4
4
|
declare const TimePicker: {
|
|
5
5
|
({ placement, placeholder, trigger, value, units, defaultOpen, onChange, containerStyle, timeFormat, valueFormatOptions, use12HourClock, alwaysOpen, dropdownProps, inputProps, disabled, disabledHours, disabledMinutes, disabledSeconds, overlayClassName, className, clearTooltip, raw, onClockModeChange, errorText, }: TimePickerProps): React.JSX.Element;
|
|
6
6
|
defaultProps: {
|
package/dist/TimePicker.js
CHANGED
|
@@ -1,81 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
import dayjs from
|
|
3
|
-
import customParseFormatPlugin from
|
|
4
|
-
import range from
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { useDataFormat } from
|
|
8
|
-
import
|
|
9
|
-
import Icon, {
|
|
10
|
-
import Tooltip from
|
|
11
|
-
import
|
|
12
|
-
import Unit from
|
|
13
|
-
import {
|
|
14
|
-
import { getClockModeFromDate, getOppositeClockMode } from
|
|
15
|
-
import { handleTimeChange } from
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import customParseFormatPlugin from "dayjs/plugin/customParseFormat";
|
|
4
|
+
import range from "lodash.range";
|
|
5
|
+
import { useState, useMemo, useCallback, Fragment } from "react";
|
|
6
|
+
import { useIntl, FormattedMessage } from "react-intl";
|
|
7
|
+
import { useDataFormat } from "@synerise/ds-core";
|
|
8
|
+
import DSDropdown from "@synerise/ds-dropdown";
|
|
9
|
+
import Icon, { Close3S, ClockM } from "@synerise/ds-icon";
|
|
10
|
+
import Tooltip from "@synerise/ds-tooltip";
|
|
11
|
+
import { OverlayContainer, UnitSeperator, ClearIcon, Container, TimePickerInput, Unit as Unit$1, Cell, CellText } from "./TimePicker.styles.js";
|
|
12
|
+
import Unit from "./Unit.js";
|
|
13
|
+
import { HOUR, MINUTE, SECOND, AM, PM, HOUR_12, DISABLE_CLOCK_MODE_HOUR, CLOCK_MODES } from "./constants/timePicker.constants.js";
|
|
14
|
+
import { getClockModeFromDate, getOppositeClockMode } from "./utils/clockMode.utils.js";
|
|
15
|
+
import { handleTimeChange } from "./utils/timePicker.utils.js";
|
|
16
16
|
dayjs.extend(customParseFormatPlugin);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
open = _useState[0],
|
|
55
|
-
setOpen = _useState[1];
|
|
56
|
-
var _useIntl = useIntl(),
|
|
57
|
-
formatMessage = _useIntl.formatMessage;
|
|
58
|
-
var is12HourClock = useMemo(function () {
|
|
59
|
-
if (use12HourClock === undefined) {
|
|
17
|
+
const defaultUnits = [HOUR, MINUTE, SECOND];
|
|
18
|
+
const TimePicker = ({
|
|
19
|
+
placement,
|
|
20
|
+
placeholder,
|
|
21
|
+
trigger,
|
|
22
|
+
value,
|
|
23
|
+
units,
|
|
24
|
+
defaultOpen,
|
|
25
|
+
onChange,
|
|
26
|
+
containerStyle = {},
|
|
27
|
+
timeFormat,
|
|
28
|
+
valueFormatOptions,
|
|
29
|
+
use12HourClock,
|
|
30
|
+
alwaysOpen,
|
|
31
|
+
dropdownProps = {},
|
|
32
|
+
inputProps = {},
|
|
33
|
+
disabled,
|
|
34
|
+
disabledHours,
|
|
35
|
+
disabledMinutes,
|
|
36
|
+
disabledSeconds,
|
|
37
|
+
overlayClassName,
|
|
38
|
+
className,
|
|
39
|
+
clearTooltip = /* @__PURE__ */ jsx(FormattedMessage, { id: "DS.TIME-PICKER.CLEAR-TOOLTIP", defaultMessage: "Clear" }),
|
|
40
|
+
raw,
|
|
41
|
+
onClockModeChange,
|
|
42
|
+
errorText
|
|
43
|
+
}) => {
|
|
44
|
+
const {
|
|
45
|
+
formatValue,
|
|
46
|
+
is12HoursClock: is12HoursClockFromDataFormat
|
|
47
|
+
} = useDataFormat();
|
|
48
|
+
const [open, setOpen] = useState(defaultOpen || false);
|
|
49
|
+
const {
|
|
50
|
+
formatMessage
|
|
51
|
+
} = useIntl();
|
|
52
|
+
const is12HourClock = useMemo(() => {
|
|
53
|
+
if (use12HourClock === void 0) {
|
|
60
54
|
return is12HoursClockFromDataFormat;
|
|
61
55
|
}
|
|
62
56
|
return use12HourClock;
|
|
63
57
|
}, [is12HoursClockFromDataFormat, use12HourClock]);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
58
|
+
const timeFormatByClockMode = useMemo(() => timeFormat ?? (is12HourClock ? "hh:mm:ss A" : "HH:mm:ss"), [timeFormat, is12HourClock]);
|
|
59
|
+
const getTimeString = useCallback(
|
|
60
|
+
(date) => {
|
|
61
|
+
if (timeFormat) {
|
|
62
|
+
return dayjs(date).format(timeFormatByClockMode);
|
|
63
|
+
}
|
|
64
|
+
return formatValue(date, {
|
|
65
|
+
targetFormat: "time",
|
|
66
|
+
second: "numeric",
|
|
67
|
+
...valueFormatOptions
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
+
[timeFormat, timeFormatByClockMode, formatValue]
|
|
72
|
+
);
|
|
73
|
+
const unitConfig = [{
|
|
79
74
|
unit: HOUR,
|
|
80
75
|
options: is12HourClock ? range(1, 13) : range(24),
|
|
81
76
|
disabled: disabledHours,
|
|
@@ -91,30 +86,25 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
91
86
|
disabled: disabledSeconds,
|
|
92
87
|
insertSeperator: is12HourClock
|
|
93
88
|
}];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
98
|
-
var onVisibleChange = function onVisibleChange(visible) {
|
|
89
|
+
const availableUnits = units?.length ? units : defaultUnits;
|
|
90
|
+
const unitsToRender = unitConfig.filter((u) => availableUnits && availableUnits.includes(u.unit));
|
|
91
|
+
const onVisibleChange = (visible) => {
|
|
99
92
|
setOpen(visible);
|
|
100
93
|
!visible && onChange && onChange(value, getTimeString(value));
|
|
101
94
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
clockModeChanged = false;
|
|
105
|
-
}
|
|
106
|
-
var clockMode = getClockModeFromDate(value);
|
|
95
|
+
const handleChange = (unit, newValue, clockModeChanged = false) => {
|
|
96
|
+
let clockMode = getClockModeFromDate(value);
|
|
107
97
|
if (clockModeChanged) {
|
|
108
98
|
clockMode = getOppositeClockMode(clockMode);
|
|
109
99
|
}
|
|
110
|
-
|
|
100
|
+
const newDate = handleTimeChange(value, unit, newValue, clockModeChanged, is12HourClock, clockMode, unitConfig);
|
|
111
101
|
onChange && onChange(newDate, getTimeString(newDate));
|
|
112
102
|
};
|
|
113
|
-
|
|
114
|
-
handleChange(
|
|
103
|
+
const toggleClockModeChange = () => {
|
|
104
|
+
handleChange(void 0, void 0, true);
|
|
115
105
|
};
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
const isAmOrPmModeDisabled = useCallback((mode) => {
|
|
107
|
+
const clockMode = getClockModeFromDate(value);
|
|
118
108
|
if (!is12HourClock) {
|
|
119
109
|
return false;
|
|
120
110
|
}
|
|
@@ -124,102 +114,57 @@ var TimePicker = function TimePicker(_ref) {
|
|
|
124
114
|
if (mode === PM && clockMode === PM) {
|
|
125
115
|
return false;
|
|
126
116
|
}
|
|
127
|
-
if (mode === AM && (disabledHours
|
|
117
|
+
if (mode === AM && (disabledHours?.includes(HOUR_12) || disabledHours?.includes(DISABLE_CLOCK_MODE_HOUR))) {
|
|
128
118
|
return true;
|
|
129
119
|
}
|
|
130
|
-
if (mode === PM && disabledHours
|
|
120
|
+
if (mode === PM && disabledHours?.includes(DISABLE_CLOCK_MODE_HOUR)) {
|
|
131
121
|
return true;
|
|
132
122
|
}
|
|
133
123
|
return false;
|
|
134
124
|
}, [value, disabledHours, is12HourClock]);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
toggleClockModeChange();
|
|
144
|
-
onClockModeChange && onClockModeChange(mode);
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
disabled: isAmOrPmModeDisabled(mode)
|
|
148
|
-
}, /*#__PURE__*/React.createElement(S.CellText, null, mode));
|
|
149
|
-
}));
|
|
125
|
+
const renderClockSwitch = () => {
|
|
126
|
+
const currentClockMode = getClockModeFromDate(value);
|
|
127
|
+
return /* @__PURE__ */ jsx(Unit$1, { children: Object.values(CLOCK_MODES).map((mode) => /* @__PURE__ */ jsx(Cell, { active: currentClockMode === mode, onClick: () => {
|
|
128
|
+
if (currentClockMode !== mode) {
|
|
129
|
+
toggleClockModeChange();
|
|
130
|
+
onClockModeChange && onClockModeChange(mode);
|
|
131
|
+
}
|
|
132
|
+
}, disabled: isAmOrPmModeDisabled(mode), children: /* @__PURE__ */ jsx(CellText, { children: mode }) }, mode)) });
|
|
150
133
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
use12HourClock: is12HourClock
|
|
163
|
-
})), (index !== unitsToRender.length - 1 || is12HourClock) && /*#__PURE__*/React.createElement(S.UnitSeperator, null));
|
|
164
|
-
}), is12HourClock && renderClockSwitch());
|
|
165
|
-
var localValue = value;
|
|
166
|
-
var dateString = localValue && getTimeString(localValue);
|
|
167
|
-
var clear = useCallback(function () {
|
|
134
|
+
const overlay = /* @__PURE__ */ jsxs(OverlayContainer, { "data-testid": "tp-overlay-container", className: overlayClassName, children: [
|
|
135
|
+
unitsToRender.map((u, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
136
|
+
/* @__PURE__ */ jsx(Unit, { ...u, value, onSelect: (newValue) => handleChange(u.unit, newValue), use12HourClock: is12HourClock }),
|
|
137
|
+
(index !== unitsToRender.length - 1 || is12HourClock) && /* @__PURE__ */ jsx(UnitSeperator, {})
|
|
138
|
+
] }, u.unit)),
|
|
139
|
+
is12HourClock && renderClockSwitch()
|
|
140
|
+
] });
|
|
141
|
+
const localValue = value;
|
|
142
|
+
const dateString = localValue && getTimeString(localValue);
|
|
143
|
+
const clear = useCallback(() => {
|
|
168
144
|
setOpen(false);
|
|
169
|
-
onChange && onChange(
|
|
145
|
+
onChange && onChange(void 0, "");
|
|
170
146
|
}, [setOpen, onChange]);
|
|
171
|
-
|
|
172
|
-
return (alwaysOpen || open) && dateString ?
|
|
173
|
-
component: /*#__PURE__*/React.createElement(Tooltip, {
|
|
174
|
-
title: clearTooltip
|
|
175
|
-
}, /*#__PURE__*/React.createElement(Close3S, null)),
|
|
176
|
-
onClick: clear
|
|
177
|
-
}) : /*#__PURE__*/React.createElement(Icon, {
|
|
178
|
-
component: /*#__PURE__*/React.createElement(ClockM, null),
|
|
179
|
-
size: 24,
|
|
180
|
-
onClick: disabled ? undefined : function () {
|
|
181
|
-
return setOpen(true);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
147
|
+
const timePickerIcon = useMemo(() => {
|
|
148
|
+
return (alwaysOpen || open) && dateString ? /* @__PURE__ */ jsx(ClearIcon, { component: /* @__PURE__ */ jsx(Tooltip, { title: clearTooltip, children: /* @__PURE__ */ jsx(Close3S, {}) }), onClick: clear }) : /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(ClockM, {}), size: 24, onClick: disabled ? void 0 : () => setOpen(true) });
|
|
184
149
|
}, [open, dateString, clear, clearTooltip, alwaysOpen, disabled]);
|
|
185
|
-
|
|
150
|
+
const placeholderValue = useMemo(() => {
|
|
186
151
|
if (value) {
|
|
187
152
|
return getTimeString(value);
|
|
188
153
|
}
|
|
189
154
|
return placeholder || formatMessage({
|
|
190
|
-
id:
|
|
155
|
+
id: "DS.TIME-PICKER.PLACEHOLDER"
|
|
191
156
|
});
|
|
192
157
|
}, [placeholder, formatMessage, value, getTimeString]);
|
|
193
158
|
if (raw) {
|
|
194
159
|
return overlay;
|
|
195
160
|
}
|
|
196
|
-
return
|
|
197
|
-
className: "ds-time-picker " + (className || ''),
|
|
198
|
-
"data-testid": "tp-container",
|
|
199
|
-
style: containerStyle
|
|
200
|
-
}, /*#__PURE__*/React.createElement(Dropdown, _extends({
|
|
201
|
-
trigger: trigger,
|
|
202
|
-
open: alwaysOpen || open,
|
|
203
|
-
onOpenChange: onVisibleChange,
|
|
204
|
-
placement: placement,
|
|
205
|
-
overlay: overlay,
|
|
206
|
-
disabled: disabled,
|
|
207
|
-
asChild: true,
|
|
208
|
-
size: "match-trigger"
|
|
209
|
-
}, dropdownProps), /*#__PURE__*/React.createElement(S.TimePickerInput, _extends({
|
|
210
|
-
errorText: !open && errorText,
|
|
211
|
-
disabled: disabled,
|
|
212
|
-
className: "" + (alwaysOpen || open ? 'active' : ''),
|
|
213
|
-
"data-testid": "tp-input",
|
|
214
|
-
value: dateString,
|
|
215
|
-
placeholder: placeholderValue,
|
|
216
|
-
readOnly: true,
|
|
217
|
-
icon1: timePickerIcon
|
|
218
|
-
}, inputProps))));
|
|
161
|
+
return /* @__PURE__ */ jsx(Container, { className: `ds-time-picker ${className || ""}`, "data-testid": "tp-container", style: containerStyle, children: /* @__PURE__ */ jsx(DSDropdown, { trigger, open: alwaysOpen || open, onOpenChange: onVisibleChange, placement, overlay, disabled, asChild: true, size: "match-trigger", ...dropdownProps, children: /* @__PURE__ */ jsx(TimePickerInput, { errorText: !open && errorText, disabled, className: `${alwaysOpen || open ? "active" : ""}`, "data-testid": "tp-input", value: dateString, placeholder: placeholderValue, readOnly: true, icon1: timePickerIcon, ...inputProps }) }) });
|
|
219
162
|
};
|
|
220
163
|
TimePicker.defaultProps = {
|
|
221
|
-
placement:
|
|
222
|
-
trigger: [
|
|
164
|
+
placement: "bottomLeft",
|
|
165
|
+
trigger: ["click"],
|
|
223
166
|
units: defaultUnits
|
|
224
167
|
};
|
|
225
|
-
export
|
|
168
|
+
export {
|
|
169
|
+
TimePicker as default
|
|
170
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
2
|
+
import { StyledComponent } from 'styled-components';
|
|
3
|
+
import { DropdownProps } from '@synerise/ds-dropdown';
|
|
4
|
+
import { StyledIcon } from '@synerise/ds-icon';
|
|
5
|
+
import { StyledInput } from '@synerise/ds-input';
|
|
6
6
|
export declare const Dropdown: StyledComponent<ForwardRefExoticComponent<DropdownProps>, object, object, never>;
|
|
7
7
|
export declare const Container: StyledComponent<"div", any, {}, never>;
|
|
8
8
|
export declare const OverlayContainer: StyledComponent<"div", any, {}, never>;
|
|
@@ -1,77 +1,69 @@
|
|
|
1
|
-
import styled, { css } from
|
|
2
|
-
import DSDropdown from
|
|
3
|
-
import Icon from
|
|
4
|
-
import { Input } from
|
|
5
|
-
import { Label } from
|
|
6
|
-
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import DSDropdown from "@synerise/ds-dropdown";
|
|
3
|
+
import Icon from "@synerise/ds-icon";
|
|
4
|
+
import { Input } from "@synerise/ds-input";
|
|
5
|
+
import { Label } from "@synerise/ds-typography";
|
|
6
|
+
const Dropdown = /* @__PURE__ */ styled(DSDropdown).withConfig({
|
|
7
7
|
displayName: "TimePickerstyles__Dropdown",
|
|
8
8
|
componentId: "sc-5k0z0v-0"
|
|
9
9
|
})(["margin:0;"]);
|
|
10
|
-
|
|
10
|
+
const Container = /* @__PURE__ */ styled.div.withConfig({
|
|
11
11
|
displayName: "TimePickerstyles__Container",
|
|
12
12
|
componentId: "sc-5k0z0v-1"
|
|
13
13
|
})(["min-width:104px;max-width:208px;width:inherit;position:relative;"]);
|
|
14
|
-
|
|
14
|
+
const OverlayContainer = /* @__PURE__ */ styled.div.withConfig({
|
|
15
15
|
displayName: "TimePickerstyles__OverlayContainer",
|
|
16
16
|
componentId: "sc-5k0z0v-2"
|
|
17
|
-
})(["background-color:", ";border-radius:3px;display:flex;flex-direction:row;flex-wrap:nowrap;overflow:hidden;"],
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
export var Unit = styled.div.withConfig({
|
|
17
|
+
})(["background-color:", ";border-radius:3px;display:flex;flex-direction:row;flex-wrap:nowrap;overflow:hidden;"], (props) => props.theme.palette.white);
|
|
18
|
+
const Unit = /* @__PURE__ */ styled.div.withConfig({
|
|
21
19
|
displayName: "TimePickerstyles__Unit",
|
|
22
20
|
componentId: "sc-5k0z0v-3"
|
|
23
21
|
})(["display:flex;flex-direction:column;width:100%;overflow:hidden;.scrollbar-container{margin-right:-11px;}"]);
|
|
24
|
-
|
|
22
|
+
const UnitSeperator = /* @__PURE__ */ styled.div.withConfig({
|
|
25
23
|
displayName: "TimePickerstyles__UnitSeperator",
|
|
26
24
|
componentId: "sc-5k0z0v-4"
|
|
27
|
-
})(["width:1px;height:inherit;display:flex;flex-shrink:0;background-color:", ";"],
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
export var CellText = styled(Label).withConfig({
|
|
25
|
+
})(["width:1px;height:inherit;display:flex;flex-shrink:0;background-color:", ";"], (props) => props.theme.palette["grey-200"]);
|
|
26
|
+
const CellText = /* @__PURE__ */ styled(Label).withConfig({
|
|
31
27
|
displayName: "TimePickerstyles__CellText",
|
|
32
28
|
componentId: "sc-5k0z0v-5"
|
|
33
|
-
})(["&&{width:22px;height:18px;text-align:center;color:", ";transition:color 0.3s;}"],
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
export var Cell = styled.button.withConfig({
|
|
29
|
+
})(["&&{width:22px;height:18px;text-align:center;color:", ";transition:color 0.3s;}"], (props) => props.theme.palette["grey-600"]);
|
|
30
|
+
const Cell = /* @__PURE__ */ styled.button.withConfig({
|
|
37
31
|
displayName: "TimePickerstyles__Cell",
|
|
38
32
|
componentId: "sc-5k0z0v-6"
|
|
39
|
-
})(["height:32px;width:100%;text-align:center;display:flex;flex-shrink:0;align-items:center;justify-content:center;transition:background-color 0.3s;cursor:pointer;background-color:", ";&&{border:none;padding:0;}&:hover{background-color:", ";", "{color:", ";}}&:disabled{&&{cursor:not-allowed;background-color:", ";", "}", "{cursor:not-allowed;opacity:0.4;}}", ";"],
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return props.active && "\n background-color: " + props.theme.palette['blue-600'] + ";\n opacity: 0.2;\n " + CellText + CellText + " {\n opacity: 1;\n color: " + props.theme.palette.white + ";\n }\n ";
|
|
49
|
-
}, CellText, function (props) {
|
|
50
|
-
return props.active && css(["&&{cursor:initial;background-color:", ";}", "", "{cursor:initial;color:", ";}"], props.theme.palette['blue-600'], CellText, CellText, props.theme.palette.white);
|
|
51
|
-
});
|
|
52
|
-
export var ClearIcon = styled(Icon).withConfig({
|
|
33
|
+
})(["height:32px;width:100%;text-align:center;display:flex;flex-shrink:0;align-items:center;justify-content:center;transition:background-color 0.3s;cursor:pointer;background-color:", ";&&{border:none;padding:0;}&:hover{background-color:", ";", "{color:", ";}}&:disabled{&&{cursor:not-allowed;background-color:", ";", "}", "{cursor:not-allowed;opacity:0.4;}}", ";"], (props) => props.theme.palette.white, (props) => props.theme.palette["grey-050"], CellText, (props) => props.theme.palette["blue-600"], (props) => props.theme.palette.white, (props) => props.active && `
|
|
34
|
+
background-color: ${props.theme.palette["blue-600"]};
|
|
35
|
+
opacity: 0.2;
|
|
36
|
+
${CellText}${CellText} {
|
|
37
|
+
opacity: 1;
|
|
38
|
+
color: ${props.theme.palette.white};
|
|
39
|
+
}
|
|
40
|
+
`, CellText, (props) => props.active && css(["&&{cursor:initial;background-color:", ";}", "", "{cursor:initial;color:", ";}"], props.theme.palette["blue-600"], CellText, CellText, props.theme.palette.white));
|
|
41
|
+
const ClearIcon = /* @__PURE__ */ styled(Icon).withConfig({
|
|
53
42
|
displayName: "TimePickerstyles__ClearIcon",
|
|
54
43
|
componentId: "sc-5k0z0v-7"
|
|
55
|
-
})(["&&,&&:hover{svg{color:", ";fill:", ";}}"],
|
|
56
|
-
|
|
57
|
-
}, function (props) {
|
|
58
|
-
return props.theme.palette['red-600'];
|
|
59
|
-
});
|
|
60
|
-
export var TimePickerInput = styled(Input).withConfig({
|
|
44
|
+
})(["&&,&&:hover{svg{color:", ";fill:", ";}}"], (props) => props.theme.palette["red-600"], (props) => props.theme.palette["red-600"]);
|
|
45
|
+
const TimePickerInput = /* @__PURE__ */ styled(Input).withConfig({
|
|
61
46
|
displayName: "TimePickerstyles__TimePickerInput",
|
|
62
47
|
componentId: "sc-5k0z0v-8"
|
|
63
|
-
})(["margin-bottom:0;&:not(.active){input{&:focus{box-shadow:none;background-color:", ";border-color:", ";}}}"],
|
|
64
|
-
|
|
65
|
-
}, function (props) {
|
|
66
|
-
return props.theme.palette['grey-300'];
|
|
67
|
-
});
|
|
68
|
-
export var PlaceholderWrapper = styled.div.withConfig({
|
|
48
|
+
})(["margin-bottom:0;&:not(.active){input{&:focus{box-shadow:none;background-color:", ";border-color:", ";}}}"], (props) => props.theme.palette.white, (props) => props.theme.palette["grey-300"]);
|
|
49
|
+
const PlaceholderWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
69
50
|
displayName: "TimePickerstyles__PlaceholderWrapper",
|
|
70
51
|
componentId: "sc-5k0z0v-9"
|
|
71
52
|
})(["width:100%;position:relative;"]);
|
|
72
|
-
|
|
53
|
+
const Placeholder = /* @__PURE__ */ styled.div.withConfig({
|
|
73
54
|
displayName: "TimePickerstyles__Placeholder",
|
|
74
55
|
componentId: "sc-5k0z0v-10"
|
|
75
|
-
})(["height:", "px;"],
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
})(["height:", "px;"], (props) => props.height);
|
|
57
|
+
export {
|
|
58
|
+
Cell,
|
|
59
|
+
CellText,
|
|
60
|
+
ClearIcon,
|
|
61
|
+
Container,
|
|
62
|
+
Dropdown,
|
|
63
|
+
OverlayContainer,
|
|
64
|
+
Placeholder,
|
|
65
|
+
PlaceholderWrapper,
|
|
66
|
+
TimePickerInput,
|
|
67
|
+
Unit,
|
|
68
|
+
UnitSeperator
|
|
69
|
+
};
|
package/dist/Unit.d.ts
CHANGED
package/dist/Unit.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
containerHeight = _useState2[0],
|
|
25
|
-
setContainerHeight = _useState2[1];
|
|
26
|
-
var _useState3 = useState(true),
|
|
27
|
-
isFirstRender = _useState3[0],
|
|
28
|
-
setFirstRender = _useState3[1];
|
|
29
|
-
useEffect(function () {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { debounce } from "debounce";
|
|
3
|
+
import { useMemo, useState, useRef, useEffect } from "react";
|
|
4
|
+
import Scrollbar from "@synerise/ds-scrollbar";
|
|
5
|
+
import { Unit as Unit$1, Cell, CellText, PlaceholderWrapper, Placeholder } from "./TimePicker.styles.js";
|
|
6
|
+
import { getUnitSelectedNumber } from "./utils/unit.utils.js";
|
|
7
|
+
const CELL_HEIGHT = 32;
|
|
8
|
+
const DEBOUNCE_DELAY = 150;
|
|
9
|
+
const Unit = ({
|
|
10
|
+
options,
|
|
11
|
+
disabled,
|
|
12
|
+
value,
|
|
13
|
+
unit,
|
|
14
|
+
onSelect,
|
|
15
|
+
use12HourClock
|
|
16
|
+
}) => {
|
|
17
|
+
const selected = useMemo(() => getUnitSelectedNumber(value, unit, use12HourClock), [unit, use12HourClock, value]);
|
|
18
|
+
const [forceUpdate, setForceUpdate] = useState(false);
|
|
19
|
+
const selectedCellRef = useRef(null);
|
|
20
|
+
const unitContainerRef = useRef(null);
|
|
21
|
+
const [containerHeight, setContainerHeight] = useState(300);
|
|
22
|
+
const [isFirstRender, setFirstRender] = useState(true);
|
|
23
|
+
useEffect(() => {
|
|
30
24
|
if (isFirstRender) {
|
|
31
25
|
setFirstRender(false);
|
|
32
26
|
if (unitContainerRef.current) {
|
|
@@ -34,27 +28,27 @@ var Unit = function Unit(_ref) {
|
|
|
34
28
|
}
|
|
35
29
|
}
|
|
36
30
|
}, [isFirstRender, unitContainerRef]);
|
|
37
|
-
|
|
31
|
+
const scrollHandler = () => {
|
|
38
32
|
if (!!unitContainerRef && !!unitContainerRef.current) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
pixelsScrolled !== 0 && isScrollBetweenTwoCells && typeof unitContainerRef.current.scrollTo ===
|
|
33
|
+
const pixelsScrolled = unitContainerRef.current.scrollTop;
|
|
34
|
+
const isScrollBetweenTwoCells = pixelsScrolled % CELL_HEIGHT !== 0;
|
|
35
|
+
pixelsScrolled !== 0 && isScrollBetweenTwoCells && typeof unitContainerRef.current.scrollTo === "function" && unitContainerRef.current.scrollTo({
|
|
42
36
|
top: Math.round(pixelsScrolled / CELL_HEIGHT) * CELL_HEIGHT,
|
|
43
|
-
behavior:
|
|
37
|
+
behavior: "smooth"
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
40
|
};
|
|
47
|
-
|
|
48
|
-
useEffect(
|
|
49
|
-
return
|
|
41
|
+
const debouncedScrollHandler = debounce(scrollHandler, DEBOUNCE_DELAY);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
return () => {
|
|
50
44
|
debouncedScrollHandler.clear();
|
|
51
45
|
};
|
|
52
46
|
}, [debouncedScrollHandler]);
|
|
53
|
-
useEffect(
|
|
47
|
+
useEffect(() => {
|
|
54
48
|
if (selectedCellRef.current && unitContainerRef.current) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (typeof unitContainerRef.current.scrollTo ===
|
|
49
|
+
const offsetToParent = selectedCellRef.current.offsetTop - unitContainerRef.current.offsetTop;
|
|
50
|
+
const scrollBehaviour = isFirstRender || !containerHeight ? "auto" : "smooth";
|
|
51
|
+
if (typeof unitContainerRef.current.scrollTo === "function") {
|
|
58
52
|
unitContainerRef.current.scrollTo({
|
|
59
53
|
top: offsetToParent,
|
|
60
54
|
behavior: scrollBehaviour
|
|
@@ -63,32 +57,21 @@ var Unit = function Unit(_ref) {
|
|
|
63
57
|
setContainerHeight(unitContainerRef.current.offsetHeight);
|
|
64
58
|
}
|
|
65
59
|
}, [selectedCellRef, unitContainerRef, isFirstRender, forceUpdate, containerHeight]);
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
maxHeight: 192
|
|
73
|
-
}, options.map(function (option) {
|
|
74
|
-
var normalizedStringValue = option < 10 ? "0" + option : option.toString();
|
|
75
|
-
var isDisabled = disabled && disabled.includes(option);
|
|
76
|
-
var isSelected = selected === option;
|
|
77
|
-
return /*#__PURE__*/React.createElement(S.Cell, {
|
|
78
|
-
key: unit + "-" + option,
|
|
79
|
-
disabled: isDisabled,
|
|
80
|
-
onClick: function onClick() {
|
|
60
|
+
return /* @__PURE__ */ jsx(Unit$1, { "data-testid": `ds-time-picker-unit-${unit}`, children: /* @__PURE__ */ jsxs(Scrollbar, { confineScroll: true, ref: unitContainerRef, onScroll: debouncedScrollHandler, maxHeight: 192, children: [
|
|
61
|
+
options.map((option) => {
|
|
62
|
+
const normalizedStringValue = option < 10 ? `0${option}` : option.toString();
|
|
63
|
+
const isDisabled = disabled && disabled.includes(option);
|
|
64
|
+
const isSelected = selected === option;
|
|
65
|
+
return /* @__PURE__ */ jsx(Cell, { disabled: isDisabled, onClick: () => {
|
|
81
66
|
onSelect(option);
|
|
82
|
-
setTimeout(
|
|
83
|
-
// timeout is required to make sure that the ref is updated
|
|
67
|
+
setTimeout(() => {
|
|
84
68
|
setForceUpdate(!forceUpdate);
|
|
85
69
|
}, 50);
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
}, active: isSelected, ref: isSelected ? selectedCellRef : null, children: /* @__PURE__ */ jsx(CellText, { children: normalizedStringValue }) }, `${unit}-${option}`);
|
|
71
|
+
}),
|
|
72
|
+
!!containerHeight && /* @__PURE__ */ jsx(PlaceholderWrapper, { children: /* @__PURE__ */ jsx(Placeholder, { height: containerHeight - CELL_HEIGHT }) })
|
|
73
|
+
] }) });
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
Unit as default
|
|
93
77
|
};
|
|
94
|
-
export default Unit;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
|
+
import { ClockModes } from '../types/TimePicker.types';
|
|
3
3
|
export declare const HOUR: dayjs.UnitType;
|
|
4
4
|
export declare const MINUTE: dayjs.UnitType;
|
|
5
5
|
export declare const SECOND: dayjs.UnitType;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
const HOUR = "hour";
|
|
2
|
+
const MINUTE = "minute";
|
|
3
|
+
const SECOND = "second";
|
|
4
|
+
const CLOCK_MODES = ["AM", "PM"];
|
|
5
|
+
const PM = "PM";
|
|
6
|
+
const AM = "AM";
|
|
7
|
+
const HOUR_12 = 12;
|
|
8
|
+
const DISABLE_CLOCK_MODE_HOUR = -1;
|
|
9
|
+
const MAP_12_AM_TO_24_HOUR = {
|
|
10
10
|
0: 12,
|
|
11
11
|
1: 1,
|
|
12
12
|
2: 2,
|
|
@@ -33,7 +33,7 @@ export var MAP_12_AM_TO_24_HOUR = {
|
|
|
33
33
|
23: 11,
|
|
34
34
|
24: 0
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
const MAP_12_PM_TO_24_HOUR = {
|
|
37
37
|
0: 12,
|
|
38
38
|
1: 13,
|
|
39
39
|
2: 14,
|
|
@@ -60,7 +60,7 @@ export var MAP_12_PM_TO_24_HOUR = {
|
|
|
60
60
|
23: 23,
|
|
61
61
|
24: 24
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
const MAP_24_HOUR_TO_12 = {
|
|
64
64
|
0: 12,
|
|
65
65
|
1: 1,
|
|
66
66
|
2: 2,
|
|
@@ -86,4 +86,17 @@ export var MAP_24_HOUR_TO_12 = {
|
|
|
86
86
|
22: 10,
|
|
87
87
|
23: 11,
|
|
88
88
|
24: 12
|
|
89
|
-
};
|
|
89
|
+
};
|
|
90
|
+
export {
|
|
91
|
+
AM,
|
|
92
|
+
CLOCK_MODES,
|
|
93
|
+
DISABLE_CLOCK_MODE_HOUR,
|
|
94
|
+
HOUR,
|
|
95
|
+
HOUR_12,
|
|
96
|
+
MAP_12_AM_TO_24_HOUR,
|
|
97
|
+
MAP_12_PM_TO_24_HOUR,
|
|
98
|
+
MAP_24_HOUR_TO_12,
|
|
99
|
+
MINUTE,
|
|
100
|
+
PM,
|
|
101
|
+
SECOND
|
|
102
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const TEST_CASES_FOR_12_HOUR_CLOCK: {
|
|
2
|
+
'00:00:00': string;
|
|
3
|
+
'00:11:22': string;
|
|
4
|
+
'01:00:00': string;
|
|
5
|
+
'02:00:00': string;
|
|
6
|
+
'10:00:00': string;
|
|
7
|
+
'11:00:00': string;
|
|
8
|
+
'11:59:59': string;
|
|
9
|
+
'12:00:00': string;
|
|
10
|
+
'12:11:22': string;
|
|
11
|
+
'13:00:00': string;
|
|
12
|
+
'14:00:00': string;
|
|
13
|
+
'22:00:00': string;
|
|
14
|
+
'23:00:00': string;
|
|
15
|
+
'23:59:59': string;
|
|
16
|
+
'24:00:00': string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const TEST_CASES_FOR_12_HOUR_CLOCK = {
|
|
2
|
+
"00:00:00": "12:00:00 AM",
|
|
3
|
+
"00:11:22": "12:11:22 AM",
|
|
4
|
+
"01:00:00": "1:00:00 AM",
|
|
5
|
+
"02:00:00": "2:00:00 AM",
|
|
6
|
+
"10:00:00": "10:00:00 AM",
|
|
7
|
+
"11:00:00": "11:00:00 AM",
|
|
8
|
+
"11:59:59": "11:59:59 AM",
|
|
9
|
+
"12:00:00": "12:00:00 PM",
|
|
10
|
+
"12:11:22": "12:11:22 PM",
|
|
11
|
+
"13:00:00": "1:00:00 PM",
|
|
12
|
+
"14:00:00": "2:00:00 PM",
|
|
13
|
+
"22:00:00": "10:00:00 PM",
|
|
14
|
+
"23:00:00": "11:00:00 PM",
|
|
15
|
+
"23:59:59": "11:59:59 PM",
|
|
16
|
+
"24:00:00": "12:00:00 AM"
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
TEST_CASES_FOR_12_HOUR_CLOCK
|
|
20
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { default as default2 } from "./TimePicker.js";
|
|
2
|
+
import { AM, CLOCK_MODES, DISABLE_CLOCK_MODE_HOUR, HOUR, HOUR_12, MAP_12_AM_TO_24_HOUR, MAP_12_PM_TO_24_HOUR, MAP_24_HOUR_TO_12, PM } from "./constants/timePicker.constants.js";
|
|
3
|
+
export {
|
|
4
|
+
AM,
|
|
5
|
+
CLOCK_MODES,
|
|
6
|
+
DISABLE_CLOCK_MODE_HOUR,
|
|
7
|
+
HOUR,
|
|
8
|
+
HOUR_12,
|
|
9
|
+
MAP_12_AM_TO_24_HOUR,
|
|
10
|
+
MAP_12_PM_TO_24_HOUR,
|
|
11
|
+
MAP_24_HOUR_TO_12,
|
|
12
|
+
PM,
|
|
13
|
+
default2 as default
|
|
14
|
+
};
|
package/dist/modules.d.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
File without changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import { DateToFormatOptions } from '@synerise/ds-core';
|
|
4
|
+
import { DropdownSharedProps } from '@synerise/ds-dropdown';
|
|
5
|
+
import { InputProps } from '@synerise/ds-input';
|
|
6
|
+
import { PopoverTriggerType } from '@synerise/ds-popover';
|
|
7
7
|
export type ClockModes = 'AM' | 'PM';
|
|
8
8
|
export type TimePickerDisabledUnits = {
|
|
9
9
|
disabledSeconds?: number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { HOUR, PM, AM, HOUR_12 } from "../constants/timePicker.constants.js";
|
|
3
|
+
const getClockModeFromDate = (date) => {
|
|
4
|
+
const initialDate = dayjs(date);
|
|
5
|
+
const initialHour = initialDate.get(HOUR);
|
|
6
6
|
return initialHour >= HOUR_12 ? PM : AM;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const getOppositeClockMode = (clockMode) => {
|
|
9
9
|
return clockMode === PM ? AM : PM;
|
|
10
|
-
};
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
getClockModeFromDate,
|
|
13
|
+
getOppositeClockMode
|
|
14
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import {
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
|
+
import { UnitConfig } from '../Unit';
|
|
3
3
|
export declare const handleTimeChange: (value: Date | undefined, unit: dayjs.UnitType | undefined, newValue: number | undefined, clockModeChanged: boolean | undefined, use12HourClock: boolean | undefined, clockMode: string, unitConfig: UnitConfig[]) => Date;
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
var wasUndefined = value === undefined;
|
|
8
|
-
var dateBuilder = dayjs(value);
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { HOUR, MAP_12_AM_TO_24_HOUR, MAP_12_PM_TO_24_HOUR, AM, PM, HOUR_12 } from "../constants/timePicker.constants.js";
|
|
3
|
+
const handleTimeChange = (value, unit, newValue, clockModeChanged = false, use12HourClock, clockMode, unitConfig) => {
|
|
4
|
+
const wasUndefined = value === void 0;
|
|
5
|
+
let dateBuilder = dayjs(value);
|
|
9
6
|
if (unit) {
|
|
10
|
-
// @ts-expect-error - `unit` const maps to dayjs method
|
|
11
7
|
dateBuilder = dateBuilder[unit](newValue);
|
|
12
8
|
}
|
|
13
|
-
|
|
9
|
+
let hourToMap = dateBuilder.get(HOUR);
|
|
14
10
|
if (use12HourClock) {
|
|
15
11
|
hourToMap = clockMode === AM ? MAP_12_AM_TO_24_HOUR[hourToMap] : MAP_12_PM_TO_24_HOUR[hourToMap];
|
|
16
12
|
if (unit === HOUR || clockModeChanged) {
|
|
@@ -18,17 +14,16 @@ export var handleTimeChange = function handleTimeChange(value, unit, newValue, c
|
|
|
18
14
|
}
|
|
19
15
|
}
|
|
20
16
|
if (wasUndefined) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// @ts-expect-error - `unit` const maps to dayjs method
|
|
26
|
-
function (unitDefinition) {
|
|
27
|
-
return dateBuilder = dateBuilder[unitDefinition.unit](0);
|
|
28
|
-
});
|
|
17
|
+
unitConfig.filter((unitDefinition) => unitDefinition.unit !== unit).forEach(
|
|
18
|
+
// @ts-expect-error - `unit` const maps to dayjs method
|
|
19
|
+
(unitDefinition) => dateBuilder = dateBuilder[unitDefinition.unit](0)
|
|
20
|
+
);
|
|
29
21
|
if (use12HourClock && clockMode === PM && unit !== HOUR) {
|
|
30
22
|
dateBuilder = dateBuilder.set(HOUR, HOUR_12);
|
|
31
23
|
}
|
|
32
24
|
}
|
|
33
25
|
return dateBuilder.toDate();
|
|
34
|
-
};
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
handleTimeChange
|
|
29
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
1
|
+
import { default as dayjs } from 'dayjs';
|
|
2
2
|
export declare const getUnitSelectedNumber: (value: Date | undefined, unit: dayjs.UnitType, use12HourClock: boolean | undefined) => number | undefined;
|
package/dist/utils/unit.utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
import { HOUR,
|
|
3
|
-
|
|
4
|
-
if (value ===
|
|
5
|
-
return
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { HOUR, MAP_24_HOUR_TO_12, HOUR_12 } from "../constants/timePicker.constants.js";
|
|
3
|
+
const getUnitSelectedNumber = (value, unit, use12HourClock) => {
|
|
4
|
+
if (value === void 0) {
|
|
5
|
+
return void 0;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
let result = value && dayjs(value).get(unit);
|
|
8
8
|
if (unit === HOUR && use12HourClock) {
|
|
9
9
|
if (!result) {
|
|
10
10
|
result = HOUR_12;
|
|
@@ -12,4 +12,7 @@ export var getUnitSelectedNumber = function getUnitSelectedNumber(value, unit, u
|
|
|
12
12
|
result = MAP_24_HOUR_TO_12[result];
|
|
13
13
|
}
|
|
14
14
|
return result;
|
|
15
|
-
};
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
getUnitSelectedNumber
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-time-picker",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.25",
|
|
4
4
|
"description": "TimePicker UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "vite build",
|
|
20
20
|
"build:css": "node ../../../scripts/style/less.js",
|
|
21
21
|
"build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx' --ignore '**/*.spec.ts' --ignore '**/*.spec.tsx' --ignore '**/*.spec.constants.ts' --ignore '**/*.spec.constants.tsx'",
|
|
22
|
-
"build:watch": "
|
|
22
|
+
"build:watch": "vite build --watch",
|
|
23
23
|
"defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
|
|
24
24
|
"pack:ci": "pnpm pack --pack-destination ../../storybook/storybook-static/static",
|
|
25
25
|
"prepublish": "pnpm run build",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
],
|
|
36
36
|
"types": "dist/index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@synerise/ds-dropdown": "^1.3.
|
|
39
|
-
"@synerise/ds-icon": "^1.15.
|
|
40
|
-
"@synerise/ds-input": "^1.6.
|
|
41
|
-
"@synerise/ds-popover": "^1.5.
|
|
42
|
-
"@synerise/ds-scrollbar": "^1.2.
|
|
43
|
-
"@synerise/ds-tooltip": "^1.4.
|
|
44
|
-
"@synerise/ds-typography": "^1.1.
|
|
38
|
+
"@synerise/ds-dropdown": "^1.3.3",
|
|
39
|
+
"@synerise/ds-icon": "^1.15.2",
|
|
40
|
+
"@synerise/ds-input": "^1.6.11",
|
|
41
|
+
"@synerise/ds-popover": "^1.5.3",
|
|
42
|
+
"@synerise/ds-scrollbar": "^1.2.18",
|
|
43
|
+
"@synerise/ds-tooltip": "^1.4.11",
|
|
44
|
+
"@synerise/ds-typography": "^1.1.14",
|
|
45
45
|
"dayjs": "^1.8.19",
|
|
46
46
|
"debounce": "^1.2.0",
|
|
47
47
|
"lodash.range": "^3.2.0"
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"react-intl": ">=3.12.0 <= 6.8",
|
|
57
57
|
"styled-components": "^5.3.3"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "c2384982c3533a31eb5e5e0408f8dcecb2b0f399"
|
|
60
60
|
}
|