@synerise/ds-time-picker 1.2.22 → 1.2.24

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 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.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)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-time-picker
9
+
10
+ ## [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)
11
+
12
+ **Note:** Version bump only for package @synerise/ds-time-picker
13
+
6
14
  ## [1.2.22](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@1.2.21...@synerise/ds-time-picker@1.2.22) (2026-03-09)
7
15
 
8
16
  **Note:** Version bump only for package @synerise/ds-time-picker
package/README.md CHANGED
@@ -11,6 +11,8 @@ TimePicker UI Component
11
11
  npm i @synerise/ds-time-picker
12
12
  or
13
13
  yarn add @synerise/ds-time-picker
14
+ or
15
+ pnpm add @synerise/ds-time-picker
14
16
  ```
15
17
 
16
18
  ## Usage
@@ -41,9 +43,13 @@ import TimePicker from '@synerise/ds-time-picker'
41
43
  | placement | placement of dropdown | `topLeft` / `topCenter` / `topRight` / `bottomLeft` / `bottomCenter` / `bottomRight` | `bottomLeft` |
42
44
  | overlayClassName | class name passed down to the overlay container | string | - |
43
45
  | onChange | event fired when date has changed | (value: `Date` or `undefined`, timeString: string) => void | - |
44
- | units | show only desired units | string[] | ['hour', 'minute', 'second'] |
45
- | use12HourClock | use 12 hour clock instead of 24 | boolean | - |
46
- | placeholder | Placeholder of Timepicker input | `string` | `Select time` |
47
- | timeFormat | format of date displayed in input (see: https://github.com/iamkun/dayjs/blob/dev/docs/en/API-reference.md#list-of-all-available-formats) | string | `'HH:mm:ss'` |
48
- | trigger | trigger that opens the dropdown | ['click'] / ['hover'] | ['click'] |
46
+ | units | show only desired units | `dayjs.UnitType[]` | ['hour', 'minute', 'second'] |
47
+ | use12HourClock | use 12 hour clock instead of 24 (**deprecated** — prefer `DSProvider::dataFormatConfig`) | boolean | - |
48
+ | valueFormatOptions | format options passed to ds-core `formatValue` for display string | `DateToFormatOptions` | - |
49
+ | placeholder | Placeholder of Timepicker input | `string` | i18n `DS.TIME-PICKER.PLACEHOLDER` |
50
+ | timeFormat | dayjs format of date displayed in input — **deprecated**, prefer `valueFormatOptions` (see: https://github.com/iamkun/dayjs/blob/dev/docs/en/API-reference.md#list-of-all-available-formats) | string | `'HH:mm:ss'` / `'hh:mm:ss A'` in 12-hour mode |
51
+ | trigger | trigger that opens the dropdown | `PopoverTriggerType[]` | ['click'] |
49
52
  | value | selected value | Date | - |
53
+ | errorText | error message shown on the input (hidden while dropdown is open) | `React.ReactNode` | - |
54
+ | onClockModeChange | fired when user switches AM/PM | `(mode: string) => void` | - |
55
+ | raw | render only the overlay panel, without input wrapper or dropdown | boolean | - |
@@ -1,6 +1,6 @@
1
- import dayjs from 'dayjs';
2
- import React from 'react';
3
- import { type TimePickerProps } from './types/TimePicker.types';
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: {
@@ -1,81 +1,76 @@
1
- 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); }
2
- import dayjs from 'dayjs';
3
- import customParseFormatPlugin from 'dayjs/plugin/customParseFormat';
4
- import range from 'lodash.range';
5
- import React, { Fragment, useCallback, useMemo, useState } from 'react';
6
- import { FormattedMessage, useIntl } from 'react-intl';
7
- import { useDataFormat } from '@synerise/ds-core';
8
- import Dropdown from '@synerise/ds-dropdown';
9
- import Icon, { ClockM, Close3S } from '@synerise/ds-icon';
10
- import Tooltip from '@synerise/ds-tooltip';
11
- import * as S from './TimePicker.styles';
12
- import Unit from './Unit';
13
- import { AM, CLOCK_MODES, DISABLE_CLOCK_MODE_HOUR, HOUR, HOUR_12, MINUTE, PM, SECOND } from './constants/timePicker.constants';
14
- import { getClockModeFromDate, getOppositeClockMode } from './utils/clockMode.utils';
15
- import { handleTimeChange } from './utils/timePicker.utils';
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
- var defaultUnits = [HOUR, MINUTE, SECOND];
18
- var TimePicker = function TimePicker(_ref) {
19
- var placement = _ref.placement,
20
- placeholder = _ref.placeholder,
21
- trigger = _ref.trigger,
22
- value = _ref.value,
23
- units = _ref.units,
24
- defaultOpen = _ref.defaultOpen,
25
- onChange = _ref.onChange,
26
- _ref$containerStyle = _ref.containerStyle,
27
- containerStyle = _ref$containerStyle === void 0 ? {} : _ref$containerStyle,
28
- timeFormat = _ref.timeFormat,
29
- valueFormatOptions = _ref.valueFormatOptions,
30
- use12HourClock = _ref.use12HourClock,
31
- alwaysOpen = _ref.alwaysOpen,
32
- _ref$dropdownProps = _ref.dropdownProps,
33
- dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps,
34
- _ref$inputProps = _ref.inputProps,
35
- inputProps = _ref$inputProps === void 0 ? {} : _ref$inputProps,
36
- disabled = _ref.disabled,
37
- disabledHours = _ref.disabledHours,
38
- disabledMinutes = _ref.disabledMinutes,
39
- disabledSeconds = _ref.disabledSeconds,
40
- overlayClassName = _ref.overlayClassName,
41
- className = _ref.className,
42
- _ref$clearTooltip = _ref.clearTooltip,
43
- clearTooltip = _ref$clearTooltip === void 0 ? /*#__PURE__*/React.createElement(FormattedMessage, {
44
- id: "DS.TIME-PICKER.CLEAR-TOOLTIP",
45
- defaultMessage: "Clear"
46
- }) : _ref$clearTooltip,
47
- raw = _ref.raw,
48
- onClockModeChange = _ref.onClockModeChange,
49
- errorText = _ref.errorText;
50
- var _useDataFormat = useDataFormat(),
51
- formatValue = _useDataFormat.formatValue,
52
- is12HoursClockFromDataFormat = _useDataFormat.is12HoursClock;
53
- var _useState = useState(defaultOpen || false),
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
- var timeFormatByClockMode = useMemo(function () {
65
- return timeFormat != null ? timeFormat : is12HourClock ? 'hh:mm:ss A' : 'HH:mm:ss';
66
- }, [timeFormat, is12HourClock]);
67
- var getTimeString = useCallback(function (date) {
68
- if (timeFormat) {
69
- return dayjs(date).format(timeFormatByClockMode);
70
- }
71
- return formatValue(date, _extends({
72
- targetFormat: 'time',
73
- second: 'numeric'
74
- }, valueFormatOptions));
75
- },
76
- // eslint-disable-next-line react-hooks/exhaustive-deps
77
- [timeFormat, timeFormatByClockMode, formatValue]);
78
- var unitConfig = [{
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
- var availableUnits = units != null && units.length ? units : defaultUnits;
95
- var unitsToRender = unitConfig.filter(function (u) {
96
- return availableUnits && availableUnits.includes(u.unit);
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
- var handleChange = function handleChange(unit, newValue, clockModeChanged) {
103
- if (clockModeChanged === void 0) {
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
- var newDate = handleTimeChange(value, unit, newValue, clockModeChanged, is12HourClock, clockMode, unitConfig);
100
+ const newDate = handleTimeChange(value, unit, newValue, clockModeChanged, is12HourClock, clockMode, unitConfig);
111
101
  onChange && onChange(newDate, getTimeString(newDate));
112
102
  };
113
- var toggleClockModeChange = function toggleClockModeChange() {
114
- handleChange(undefined, undefined, true);
103
+ const toggleClockModeChange = () => {
104
+ handleChange(void 0, void 0, true);
115
105
  };
116
- var isAmOrPmModeDisabled = useCallback(function (mode) {
117
- var clockMode = getClockModeFromDate(value);
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 != null && disabledHours.includes(HOUR_12) || disabledHours != null && disabledHours.includes(DISABLE_CLOCK_MODE_HOUR))) {
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 != null && disabledHours.includes(DISABLE_CLOCK_MODE_HOUR)) {
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
- var renderClockSwitch = function renderClockSwitch() {
136
- var currentClockMode = getClockModeFromDate(value);
137
- return /*#__PURE__*/React.createElement(S.Unit, null, Object.values(CLOCK_MODES).map(function (mode) {
138
- return /*#__PURE__*/React.createElement(S.Cell, {
139
- key: mode,
140
- active: currentClockMode === mode,
141
- onClick: function onClick() {
142
- if (currentClockMode !== mode) {
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
- var overlay = /*#__PURE__*/React.createElement(S.OverlayContainer, {
152
- "data-testid": "tp-overlay-container",
153
- className: overlayClassName
154
- }, unitsToRender.map(function (u, index) {
155
- return /*#__PURE__*/React.createElement(Fragment, {
156
- key: u.unit
157
- }, /*#__PURE__*/React.createElement(Unit, _extends({}, u, {
158
- value: value,
159
- onSelect: function onSelect(newValue) {
160
- return handleChange(u.unit, newValue);
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(undefined, '');
145
+ onChange && onChange(void 0, "");
170
146
  }, [setOpen, onChange]);
171
- var timePickerIcon = useMemo(function () {
172
- return (alwaysOpen || open) && dateString ? /*#__PURE__*/React.createElement(S.ClearIcon, {
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
- var placeholderValue = useMemo(function () {
150
+ const placeholderValue = useMemo(() => {
186
151
  if (value) {
187
152
  return getTimeString(value);
188
153
  }
189
154
  return placeholder || formatMessage({
190
- id: 'DS.TIME-PICKER.PLACEHOLDER'
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 /*#__PURE__*/React.createElement(S.Container, {
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: 'bottomLeft',
222
- trigger: ['click'],
164
+ placement: "bottomLeft",
165
+ trigger: ["click"],
223
166
  units: defaultUnits
224
167
  };
225
- export default TimePicker;
168
+ export {
169
+ TimePicker as default
170
+ };
@@ -1,8 +1,8 @@
1
- import { type ForwardRefExoticComponent } from 'react';
2
- import { type StyledComponent } from 'styled-components';
3
- import { type DropdownProps } from '@synerise/ds-dropdown';
4
- import { type StyledIcon } from '@synerise/ds-icon';
5
- import { type StyledInput } from '@synerise/ds-input';
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 '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
- export var Dropdown = styled(DSDropdown).withConfig({
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
- export var Container = styled.div.withConfig({
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
- export var OverlayContainer = styled.div.withConfig({
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;"], function (props) {
18
- return props.theme.palette.white;
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
- export var UnitSeperator = styled.div.withConfig({
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:", ";"], function (props) {
28
- return props.theme.palette['grey-200'];
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;}"], function (props) {
34
- return props.theme.palette['grey-600'];
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;}}", ";"], function (props) {
40
- return props.theme.palette.white;
41
- }, function (props) {
42
- return props.theme.palette['grey-050'];
43
- }, CellText, function (props) {
44
- return props.theme.palette['blue-600'];
45
- }, function (props) {
46
- return props.theme.palette.white;
47
- }, function (props) {
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:", ";}}"], function (props) {
56
- return props.theme.palette['red-600'];
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:", ";}}}"], function (props) {
64
- return props.theme.palette.white;
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
- export var Placeholder = styled.div.withConfig({
53
+ const Placeholder = /* @__PURE__ */ styled.div.withConfig({
73
54
  displayName: "TimePickerstyles__Placeholder",
74
55
  componentId: "sc-5k0z0v-10"
75
- })(["height:", "px;"], function (props) {
76
- return props.height;
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
@@ -1,5 +1,5 @@
1
- import type dayjs from 'dayjs';
2
- import React from 'react';
1
+ import { default as dayjs } from 'dayjs';
2
+ import { default as React } from 'react';
3
3
  export type UnitConfig = {
4
4
  unit: dayjs.UnitType;
5
5
  options: number[];
package/dist/Unit.js CHANGED
@@ -1,32 +1,26 @@
1
- import { debounce } from 'debounce';
2
- import React, { useEffect, useMemo, useRef, useState } from 'react';
3
- import Scrollbar from '@synerise/ds-scrollbar';
4
- import * as S from './TimePicker.styles';
5
- import { getUnitSelectedNumber } from './utils/unit.utils';
6
- var CELL_HEIGHT = 32;
7
- var DEBOUNCE_DELAY = 150;
8
- var Unit = function Unit(_ref) {
9
- var options = _ref.options,
10
- disabled = _ref.disabled,
11
- value = _ref.value,
12
- unit = _ref.unit,
13
- onSelect = _ref.onSelect,
14
- use12HourClock = _ref.use12HourClock;
15
- var selected = useMemo(function () {
16
- return getUnitSelectedNumber(value, unit, use12HourClock);
17
- }, [unit, use12HourClock, value]);
18
- var _useState = useState(false),
19
- forceUpdate = _useState[0],
20
- setForceUpdate = _useState[1];
21
- var selectedCellRef = useRef(null);
22
- var unitContainerRef = useRef(null);
23
- var _useState2 = useState(300),
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
- var scrollHandler = function scrollHandler() {
31
+ const scrollHandler = () => {
38
32
  if (!!unitContainerRef && !!unitContainerRef.current) {
39
- var pixelsScrolled = unitContainerRef.current.scrollTop;
40
- var isScrollBetweenTwoCells = pixelsScrolled % CELL_HEIGHT !== 0;
41
- pixelsScrolled !== 0 && isScrollBetweenTwoCells && typeof unitContainerRef.current.scrollTo === 'function' && 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: 'smooth'
37
+ behavior: "smooth"
44
38
  });
45
39
  }
46
40
  };
47
- var debouncedScrollHandler = debounce(scrollHandler, DEBOUNCE_DELAY);
48
- useEffect(function () {
49
- return function () {
41
+ const debouncedScrollHandler = debounce(scrollHandler, DEBOUNCE_DELAY);
42
+ useEffect(() => {
43
+ return () => {
50
44
  debouncedScrollHandler.clear();
51
45
  };
52
46
  }, [debouncedScrollHandler]);
53
- useEffect(function () {
47
+ useEffect(() => {
54
48
  if (selectedCellRef.current && unitContainerRef.current) {
55
- var offsetToParent = selectedCellRef.current.offsetTop - unitContainerRef.current.offsetTop;
56
- var scrollBehaviour = isFirstRender || !containerHeight ? 'auto' : 'smooth';
57
- if (typeof unitContainerRef.current.scrollTo === 'function') {
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 /*#__PURE__*/React.createElement(S.Unit, {
67
- "data-testid": "ds-time-picker-unit-" + unit
68
- }, /*#__PURE__*/React.createElement(Scrollbar, {
69
- confineScroll: true,
70
- ref: unitContainerRef,
71
- onScroll: debouncedScrollHandler,
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(function () {
83
- // timeout is required to make sure that the ref is updated
67
+ setTimeout(() => {
84
68
  setForceUpdate(!forceUpdate);
85
69
  }, 50);
86
- },
87
- active: isSelected,
88
- ref: isSelected ? selectedCellRef : null
89
- }, /*#__PURE__*/React.createElement(S.CellText, null, normalizedStringValue));
90
- }), !!containerHeight && /*#__PURE__*/React.createElement(S.PlaceholderWrapper, null, /*#__PURE__*/React.createElement(S.Placeholder, {
91
- height: containerHeight - CELL_HEIGHT
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 type dayjs from 'dayjs';
2
- import { type ClockModes } from '../types/TimePicker.types';
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
- export var HOUR = 'hour';
2
- export var MINUTE = 'minute';
3
- export var SECOND = 'second';
4
- export var CLOCK_MODES = ['AM', 'PM'];
5
- export var PM = 'PM';
6
- export var AM = 'AM';
7
- export var HOUR_12 = 12;
8
- export var DISABLE_CLOCK_MODE_HOUR = -1;
9
- export var MAP_12_AM_TO_24_HOUR = {
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
- export var MAP_12_PM_TO_24_HOUR = {
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
- export var MAP_24_HOUR_TO_12 = {
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
- export { default } from './TimePicker';
2
- export { AM, PM, HOUR_12, HOUR, CLOCK_MODES, MAP_12_AM_TO_24_HOUR, MAP_12_PM_TO_24_HOUR, MAP_24_HOUR_TO_12, DISABLE_CLOCK_MODE_HOUR } from './constants/timePicker.constants';
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 '@testing-library/jest-dom';
1
+ import "@testing-library/jest-dom";
File without changes
@@ -1,9 +1,9 @@
1
- import type dayjs from 'dayjs';
2
- import type { CSSProperties, ReactNode } from 'react';
3
- import type { DateToFormatOptions } from '@synerise/ds-core';
4
- import type { DropdownSharedProps } from '@synerise/ds-dropdown';
5
- import type { InputProps } from '@synerise/ds-input';
6
- import { type PopoverTriggerType } from '@synerise/ds-popover';
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
- export {};
1
+
@@ -1,10 +1,14 @@
1
- import dayjs from 'dayjs';
2
- import { AM, HOUR, HOUR_12, PM } from '../constants/timePicker.constants';
3
- export var getClockModeFromDate = function getClockModeFromDate(date) {
4
- var initialDate = dayjs(date);
5
- var initialHour = initialDate.get(HOUR);
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
- export var getOppositeClockMode = function getOppositeClockMode(clockMode) {
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 { type UnitConfig } from '../Unit';
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 'dayjs';
2
- import { AM, HOUR, HOUR_12, MAP_12_AM_TO_24_HOUR, MAP_12_PM_TO_24_HOUR, PM } from '../constants/timePicker.constants';
3
- export var handleTimeChange = function handleTimeChange(value, unit, newValue, clockModeChanged, use12HourClock, clockMode, unitConfig) {
4
- if (clockModeChanged === void 0) {
5
- clockModeChanged = false;
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
- var hourToMap = dateBuilder.get(HOUR);
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
- // set remaining time fields to 0, HH:00:00, 00:mm:00, 00:00:ss
22
- unitConfig.filter(function (unitDefinition) {
23
- return unitDefinition.unit !== unit;
24
- }).forEach(
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;
@@ -1,10 +1,10 @@
1
- import dayjs from 'dayjs';
2
- import { HOUR, HOUR_12, MAP_24_HOUR_TO_12 } from '../constants/timePicker.constants';
3
- export var getUnitSelectedNumber = function getUnitSelectedNumber(value, unit, use12HourClock) {
4
- if (value === undefined) {
5
- return undefined;
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
- var result = value && dayjs(value).get(unit);
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.22",
3
+ "version": "1.2.24",
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": "pnpm run build:js && pnpm run build:css && pnpm run defs",
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": "pnpm run build:js -- --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.0",
39
- "@synerise/ds-icon": "^1.14.1",
40
- "@synerise/ds-input": "^1.6.8",
41
- "@synerise/ds-popover": "^1.5.1",
42
- "@synerise/ds-scrollbar": "^1.2.15",
43
- "@synerise/ds-tooltip": "^1.4.8",
44
- "@synerise/ds-typography": "^1.1.11",
38
+ "@synerise/ds-dropdown": "^1.3.2",
39
+ "@synerise/ds-icon": "^1.15.1",
40
+ "@synerise/ds-input": "^1.6.10",
41
+ "@synerise/ds-popover": "^1.5.3",
42
+ "@synerise/ds-scrollbar": "^1.2.17",
43
+ "@synerise/ds-tooltip": "^1.4.10",
44
+ "@synerise/ds-typography": "^1.1.13",
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": "8dfafc5d7278f09d430f1e7499782d05c76b47c0"
59
+ "gitHead": "e4ecca8944fc9b41c1b9d59c8bcad5e5e2013225"
60
60
  }