@synerise/ds-time-picker 2.0.9 → 2.0.11
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 +20 -0
- package/CLAUDE.md +28 -4
- package/README.md +19 -2
- package/dist/TimePicker.d.ts +1 -9
- package/dist/TimePicker.js +45 -30
- package/dist/Unit.js +3 -1
- package/dist/types/TimePicker.types.d.ts +15 -4
- package/dist/utils/clockMode.utils.d.ts +1 -1
- package/dist/utils/clockMode.utils.js +2 -4
- package/package.json +17 -13
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
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
|
+
## [2.0.11](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@2.0.10...@synerise/ds-time-picker@2.0.11) (2026-10-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* add explicit .js to extensionless bare subpath imports ([b38cba6](https://github.com/Synerise/synerise-design/commit/b38cba6bae5c5aa10276e714bb6fb67c479bbde6))
|
|
12
|
+
* drop vitest peer dependency and bump vulnerable runtime deps ([2467d36](https://github.com/Synerise/synerise-design/commit/2467d3606aa97141a3a2d80c3ef396e78bee285c))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [2.0.10](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@2.0.9...@synerise/ds-time-picker@2.0.10) (2026-10-22)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @synerise/ds-time-picker
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## [2.0.9](https://github.com/Synerise/synerise-design/compare/@synerise/ds-time-picker@2.0.8...@synerise/ds-time-picker@2.0.9) (2026-10-20)
|
|
7
27
|
|
|
8
28
|
**Note:** Version bump only for package @synerise/ds-time-picker
|
package/CLAUDE.md
CHANGED
|
@@ -28,8 +28,9 @@ src/
|
|
|
28
28
|
|
|
29
29
|
| Prop | Type | Default | Description |
|
|
30
30
|
|------|------|---------|-------------|
|
|
31
|
-
| `value` | `Date` | — | Controlled selected time value |
|
|
32
|
-
| `onChange` | `(value: Date \| undefined, timeString: string) => void` | — | Fired on unit select and on dropdown close |
|
|
31
|
+
| `value` | `Date \| string` | — | Controlled selected time value. A `string` is parsed as an ISO 8601 datetime (e.g. `'2024-02-02T14:20:00+02:00'`). |
|
|
32
|
+
| `onChange` | `(value: Date \| undefined, timeString: string) => void` | — | **Required.** Fired on unit select and on dropdown close. |
|
|
33
|
+
| `timeZone` | `boolean \| string` | — | Opts into timezone-aware values: `onChange` emits a **`TZDate`** carrying the resolved zone instead of a plain `Date`. `true` uses the provider's `timeZone`; a string (e.g. `'Asia/Tokyo'`) overrides it. |
|
|
33
34
|
| `units` | `dayjs.UnitType[]` | `['hour', 'minute', 'second']` | Which columns to render |
|
|
34
35
|
| `placeholder` | `string` | i18n `DS.TIME-PICKER.PLACEHOLDER` | Input placeholder text |
|
|
35
36
|
| `placement` | `'topLeft' \| 'topCenter' \| 'topRight' \| 'bottomLeft' \| 'bottomCenter' \| 'bottomRight'` | `'bottomLeft'` | Dropdown placement |
|
|
@@ -68,7 +69,7 @@ src/
|
|
|
68
69
|
|
|
69
70
|
### Named type exports
|
|
70
71
|
- `ClockModes` — `'AM' | 'PM'`
|
|
71
|
-
- `TimePickerProps` — full props interface
|
|
72
|
+
- `TimePickerProps` — full props interface
|
|
72
73
|
|
|
73
74
|
## Usage patterns
|
|
74
75
|
|
|
@@ -79,6 +80,13 @@ import TimePicker from '@synerise/ds-time-picker';
|
|
|
79
80
|
const [time, setTime] = React.useState<Date | undefined>(undefined);
|
|
80
81
|
<TimePicker value={time} onChange={(date) => setTime(date)} />
|
|
81
82
|
|
|
83
|
+
// Timezone-aware usage -- `onChange` hands back a TZDate carrying the resolved zone
|
|
84
|
+
const [isoTime, setIsoTime] = React.useState<string | undefined>('2024-02-02T14:20:00+02:00');
|
|
85
|
+
<TimePicker value={isoTime} onChange={(val) => setIsoTime(val)} timeZone />
|
|
86
|
+
|
|
87
|
+
// Specific timezone override (ignores provider timezone)
|
|
88
|
+
<TimePicker value={isoTime} onChange={(val) => setIsoTime(val)} timeZone="Asia/Tokyo" />
|
|
89
|
+
|
|
82
90
|
// Render just the panel (no input)
|
|
83
91
|
<TimePicker value={time} onChange={(date) => setTime(date)} raw />
|
|
84
92
|
|
|
@@ -125,9 +133,25 @@ All visual elements use styled-components tokens (no hardcoded colours). Key sty
|
|
|
125
133
|
## Implementation notes
|
|
126
134
|
|
|
127
135
|
- **12-hour clock detection:** `use12HourClock` prop overrides, otherwise read from `useDataFormat().is12HoursClock`.
|
|
136
|
+
- **`onChange` is required** — the prop is no longer optional. All consumers must provide an `onChange` handler. This is a **breaking change** from previous versions where `onChange` was optional.
|
|
137
|
+
- **No `ValueType` generic.** `value` takes a `Date` or an ISO string; `onChange` always hands back
|
|
138
|
+
a `Date`. The two used to share one type parameter, which forced a consumer holding a `Date` to
|
|
139
|
+
declare its output as `string`.
|
|
140
|
+
- **`timeZone`:** opts into timezone-aware values. `onChange` then emits a **`TZDate`** — a `Date`
|
|
141
|
+
subclass carrying the resolved zone — rather than a plain `Date`. `true` resolves the provider's
|
|
142
|
+
`timeZone` from `react-intl`; a string names an IANA zone directly. Same contract as
|
|
143
|
+
`ds-date-picker` and `ds-date-range-picker`. Note `TZDate.toISOString()` returns the *offset*
|
|
144
|
+
form (`…+09:00`), not `Z`; for a `Z` instant use `new Date(value.getTime()).toISOString()`.
|
|
145
|
+
- **Without the prop the value passes through as a plain `Date`**, never a `TZDate` — pinned by a
|
|
146
|
+
spec, since widening it would silently change what consumers serialize with no compiler error.
|
|
147
|
+
- **Rendering is gated on the same prop, not on `intl.timeZone`.** `getTimeString` re-anchors and
|
|
148
|
+
forces `applyTimeZoneOffset` only when `timeZone` resolved to something; a zone on the provider
|
|
149
|
+
alone changes nothing, because every unmigrated consumer already has one. It also names
|
|
150
|
+
`timeZone` in the format options rather than relying on the config's — with a *string* prop the
|
|
151
|
+
resolved zone is not the provider's, and the re-anchor and the projection have to agree.
|
|
128
152
|
- **Controlled-only value:** There is no uncontrolled mode. `onChange` is the only way to update the displayed time.
|
|
129
153
|
- **`onChange` fires twice per interaction:** once when a cell is clicked (immediate) and once when the dropdown closes (`onVisibleChange`).
|
|
130
154
|
- **`disabledHours` with AM/PM:** Use sentinel `-1` (`DISABLE_CLOCK_MODE_HOUR`) to disable the entire PM toggle. Use `12` (`HOUR_12`) combined with `-1` to disable the AM toggle.
|
|
131
155
|
- **Scroll snap in `Unit`:** The `Unit` component auto-scrolls to the selected cell and snaps free-scrolling to the nearest 32 px cell boundary via a debounced scroll handler.
|
|
132
|
-
- **Test runner:**
|
|
156
|
+
- **Test runner:** Vitest. Timezone-specific tests are run under multiple TZ env variables (UTC, America/New_York, Europe/Warsaw) via `pnpm test:timezones`.
|
|
133
157
|
- **`timeFormat` / `use12HourClock`:** Both props are deprecated in favour of `valueFormatOptions` and `DSProvider::dataFormatConfig` respectively.
|
package/README.md
CHANGED
|
@@ -42,14 +42,31 @@ import TimePicker from '@synerise/ds-time-picker'
|
|
|
42
42
|
| inputProps | Props object applied to the input component | InputProps | {} |
|
|
43
43
|
| placement | placement of dropdown | `topLeft` / `topCenter` / `topRight` / `bottomLeft` / `bottomCenter` / `bottomRight` | `bottomLeft` |
|
|
44
44
|
| overlayClassName | class name passed down to the overlay container | string | - |
|
|
45
|
-
| onChange |
|
|
45
|
+
| onChange | **Required.** Fired on unit select and dropdown close | (value: `Date` or `undefined`, timeString: string) => void | - |
|
|
46
|
+
| timeZone | Enables timezone-aware mode. `true` = provider TZ; string = specific IANA TZ | `boolean` / `string` | - |
|
|
46
47
|
| units | show only desired units | `dayjs.UnitType[]` | ['hour', 'minute', 'second'] |
|
|
47
48
|
| use12HourClock | use 12 hour clock instead of 24 (**deprecated** — prefer `DSProvider::dataFormatConfig`) | boolean | - |
|
|
48
49
|
| valueFormatOptions | format options passed to ds-core `formatValue` for display string | `DateToFormatOptions` | - |
|
|
49
50
|
| placeholder | Placeholder of Timepicker input | `string` | i18n `DS.TIME-PICKER.PLACEHOLDER` |
|
|
50
51
|
| 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
52
|
| trigger | trigger that opens the dropdown | `PopoverTriggerType[]` | ['click'] |
|
|
52
|
-
| value | selected value
|
|
53
|
+
| value | selected value (Date or ISO 8601 string with offset in timezone mode) | `Date` / `string` | - |
|
|
53
54
|
| errorText | error message shown on the input (hidden while dropdown is open) | `React.ReactNode` | - |
|
|
54
55
|
| onClockModeChange | fired when user switches AM/PM | `(mode: string) => void` | - |
|
|
55
56
|
| raw | render only the overlay panel, without input wrapper or dropdown | boolean | - |
|
|
57
|
+
|
|
58
|
+
## Timezone-aware usage
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
// Uses provider timezone from DSProvider / IntlProvider
|
|
62
|
+
<TimePicker value="2024-02-02T14:20:00+02:00" onChange={handleChange} timeZone />
|
|
63
|
+
|
|
64
|
+
// Uses a specific timezone (overrides provider)
|
|
65
|
+
<TimePicker value="2024-02-02T14:20:00+09:00" onChange={handleChange} timeZone="Asia/Tokyo" />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Breaking changes
|
|
69
|
+
|
|
70
|
+
- **`onChange` is now required.** Previously optional, now mandatory on all usages.
|
|
71
|
+
- **`onChange` always hands back a `Date`.** With `timeZone` set it is a `TZDate` carrying the resolved zone; without it, the plain `Date` it already was.
|
|
72
|
+
- **`defaultProps` removed.** Default values for `placement`, `trigger`, and `units` are now inline parameter defaults.
|
package/dist/TimePicker.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { default as dayjs } from 'dayjs';
|
|
2
1
|
import { default as React } from 'react';
|
|
3
2
|
import { TimePickerProps } from './types/TimePicker.types';
|
|
4
|
-
declare const TimePicker: {
|
|
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
|
-
defaultProps: {
|
|
7
|
-
placement: string;
|
|
8
|
-
trigger: string[];
|
|
9
|
-
units: dayjs.UnitType[];
|
|
10
|
-
};
|
|
11
|
-
};
|
|
3
|
+
declare const TimePicker: ({ placement, placeholder, trigger, value, units, defaultOpen, onChange, containerStyle, timeFormat, valueFormatOptions, use12HourClock, alwaysOpen, dropdownProps, inputProps, disabled, disabledHours, disabledMinutes, disabledSeconds, overlayClassName, className, clearTooltip, raw, onClockModeChange, errorText, timeZone, }: TimePickerProps) => React.JSX.Element;
|
|
12
4
|
export default TimePicker;
|
package/dist/TimePicker.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
|
-
import customParseFormatPlugin from "dayjs/plugin/customParseFormat";
|
|
3
|
+
import customParseFormatPlugin from "dayjs/plugin/customParseFormat.js";
|
|
4
4
|
import range from "lodash.range";
|
|
5
5
|
import { useState, useMemo, useCallback, Fragment } from "react";
|
|
6
6
|
import { useIntl, FormattedMessage } from "react-intl";
|
|
7
|
-
import { useDataFormat } from "@synerise/ds-core";
|
|
7
|
+
import { useDataFormat, getTimeZone, getLocalDateInTimeZone, currentTimeInTimezone, toIsoString, applyTimezoneOffset } from "@synerise/ds-core";
|
|
8
8
|
import DSDropdown from "@synerise/ds-dropdown";
|
|
9
9
|
import Icon, { Close3S, ClockM } from "@synerise/ds-icon";
|
|
10
10
|
import Tooltip from "@synerise/ds-tooltip";
|
|
@@ -16,11 +16,11 @@ import { handleTimeChange } from "./utils/timePicker.utils.js";
|
|
|
16
16
|
dayjs.extend(customParseFormatPlugin);
|
|
17
17
|
const defaultUnits = [HOUR, MINUTE, SECOND];
|
|
18
18
|
const TimePicker = ({
|
|
19
|
-
placement,
|
|
19
|
+
placement = "bottomLeft",
|
|
20
20
|
placeholder,
|
|
21
|
-
trigger,
|
|
21
|
+
trigger = ["click"],
|
|
22
22
|
value,
|
|
23
|
-
units,
|
|
23
|
+
units = defaultUnits,
|
|
24
24
|
defaultOpen,
|
|
25
25
|
onChange,
|
|
26
26
|
containerStyle = {},
|
|
@@ -39,16 +39,26 @@ const TimePicker = ({
|
|
|
39
39
|
clearTooltip = /* @__PURE__ */ jsx(FormattedMessage, { id: "DS.TIME-PICKER.CLEAR-TOOLTIP", defaultMessage: "Clear" }),
|
|
40
40
|
raw,
|
|
41
41
|
onClockModeChange,
|
|
42
|
-
errorText
|
|
42
|
+
errorText,
|
|
43
|
+
timeZone
|
|
43
44
|
}) => {
|
|
44
45
|
const {
|
|
45
46
|
formatValue,
|
|
46
47
|
is12HoursClock: is12HoursClockFromDataFormat
|
|
47
48
|
} = useDataFormat();
|
|
48
49
|
const [open, setOpen] = useState(defaultOpen || false);
|
|
50
|
+
const intl = useIntl();
|
|
49
51
|
const {
|
|
50
52
|
formatMessage
|
|
51
|
-
} =
|
|
53
|
+
} = intl;
|
|
54
|
+
const resolvedTimeZone = getTimeZone(timeZone, intl);
|
|
55
|
+
const valueAsDate = useMemo(() => {
|
|
56
|
+
if (value instanceof Date || value === void 0) {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
return resolvedTimeZone ? getLocalDateInTimeZone(value, resolvedTimeZone) : new Date(value);
|
|
60
|
+
}, [value, resolvedTimeZone]);
|
|
61
|
+
const now = useMemo(() => resolvedTimeZone ? currentTimeInTimezone(resolvedTimeZone) : /* @__PURE__ */ new Date(), [resolvedTimeZone]);
|
|
52
62
|
const is12HourClock = useMemo(() => {
|
|
53
63
|
if (use12HourClock === void 0) {
|
|
54
64
|
return is12HoursClockFromDataFormat;
|
|
@@ -60,12 +70,20 @@ const TimePicker = ({
|
|
|
60
70
|
if (timeFormat) {
|
|
61
71
|
return dayjs(date).format(timeFormatByClockMode);
|
|
62
72
|
}
|
|
63
|
-
return formatValue(date, {
|
|
73
|
+
return formatValue(resolvedTimeZone ? new Date(toIsoString(date, resolvedTimeZone)) : date, {
|
|
64
74
|
targetFormat: "time",
|
|
65
75
|
second: "numeric",
|
|
66
|
-
...valueFormatOptions
|
|
76
|
+
...valueFormatOptions,
|
|
77
|
+
// `timeZone` is named as well as the flag: `formatValue` otherwise projects into the
|
|
78
|
+
// zone on the consumer's `DataFormatConfig`, which is the provider's. The two steps
|
|
79
|
+
// have to agree, and with a string `timeZone` prop the resolved zone is not the
|
|
80
|
+
// provider's.
|
|
81
|
+
...resolvedTimeZone ? {
|
|
82
|
+
applyTimeZoneOffset: true,
|
|
83
|
+
timeZone: resolvedTimeZone
|
|
84
|
+
} : {}
|
|
67
85
|
});
|
|
68
|
-
}, [timeFormat,
|
|
86
|
+
}, [timeFormat, resolvedTimeZone, formatValue, valueFormatOptions, timeFormatByClockMode]);
|
|
69
87
|
const unitConfig = [{
|
|
70
88
|
unit: HOUR,
|
|
71
89
|
options: is12HourClock ? range(1, 13) : range(24),
|
|
@@ -84,23 +102,24 @@ const TimePicker = ({
|
|
|
84
102
|
}];
|
|
85
103
|
const availableUnits = units?.length ? units : defaultUnits;
|
|
86
104
|
const unitsToRender = unitConfig.filter((u) => availableUnits && availableUnits.includes(u.unit));
|
|
105
|
+
const getDateToEmit = (date) => applyTimezoneOffset(date, timeZone, intl);
|
|
87
106
|
const onVisibleChange = (visible) => {
|
|
88
107
|
setOpen(visible);
|
|
89
|
-
!visible && onChange && onChange(
|
|
108
|
+
!visible && onChange && onChange(valueAsDate && getDateToEmit(valueAsDate), valueAsDate ? getTimeString(valueAsDate) : "");
|
|
90
109
|
};
|
|
91
110
|
const handleChange = (unit, newValue, clockModeChanged = false) => {
|
|
92
|
-
let clockMode = getClockModeFromDate(
|
|
111
|
+
let clockMode = getClockModeFromDate(valueAsDate || now);
|
|
93
112
|
if (clockModeChanged) {
|
|
94
113
|
clockMode = getOppositeClockMode(clockMode);
|
|
95
114
|
}
|
|
96
|
-
const newDate = handleTimeChange(
|
|
97
|
-
onChange && onChange(newDate, getTimeString(newDate));
|
|
115
|
+
const newDate = handleTimeChange(valueAsDate, unit, newValue, clockModeChanged, is12HourClock, clockMode, unitConfig);
|
|
116
|
+
onChange && onChange(getDateToEmit(newDate), getTimeString(newDate));
|
|
98
117
|
};
|
|
99
118
|
const toggleClockModeChange = () => {
|
|
100
119
|
handleChange(void 0, void 0, true);
|
|
101
120
|
};
|
|
102
121
|
const isAmOrPmModeDisabled = useCallback((mode) => {
|
|
103
|
-
const clockMode = getClockModeFromDate(
|
|
122
|
+
const clockMode = getClockModeFromDate(valueAsDate || now);
|
|
104
123
|
if (!is12HourClock) {
|
|
105
124
|
return false;
|
|
106
125
|
}
|
|
@@ -117,25 +136,26 @@ const TimePicker = ({
|
|
|
117
136
|
return true;
|
|
118
137
|
}
|
|
119
138
|
return false;
|
|
120
|
-
}, [
|
|
139
|
+
}, [valueAsDate, now, is12HourClock, disabledHours]);
|
|
121
140
|
const renderClockSwitch = () => {
|
|
122
|
-
const currentClockMode = getClockModeFromDate(
|
|
123
|
-
return /* @__PURE__ */ jsx(Unit$1, { children: Object.values(CLOCK_MODES).map((mode) => /* @__PURE__ */ jsx(Cell, { active: currentClockMode === mode, onClick: () => {
|
|
141
|
+
const currentClockMode = getClockModeFromDate(valueAsDate || now);
|
|
142
|
+
return /* @__PURE__ */ jsx(Unit$1, { "data-testid": "ds-time-picker-unit-meridiem", children: Object.values(CLOCK_MODES).map((mode) => /* @__PURE__ */ jsx(Cell, { active: currentClockMode === mode, onClick: () => {
|
|
124
143
|
if (currentClockMode !== mode) {
|
|
125
144
|
toggleClockModeChange();
|
|
126
145
|
onClockModeChange && onClockModeChange(mode);
|
|
127
146
|
}
|
|
128
|
-
}, disabled: isAmOrPmModeDisabled(mode), children: /* @__PURE__ */ jsx(CellText, {
|
|
147
|
+
}, disabled: isAmOrPmModeDisabled(mode), children: /* @__PURE__ */ jsx(CellText, { ...currentClockMode === mode ? {
|
|
148
|
+
"data-selected": true
|
|
149
|
+
} : {}, children: mode }) }, mode)) });
|
|
129
150
|
};
|
|
130
151
|
const overlay = /* @__PURE__ */ jsxs(OverlayContainer, { "data-testid": "tp-overlay-container", className: overlayClassName, children: [
|
|
131
152
|
unitsToRender.map((u, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
132
|
-
/* @__PURE__ */ jsx(Unit, { ...u, value, onSelect: (newValue) => handleChange(u.unit, newValue), use12HourClock: is12HourClock }),
|
|
153
|
+
/* @__PURE__ */ jsx(Unit, { ...u, value: valueAsDate, onSelect: (newValue) => handleChange(u.unit, newValue), use12HourClock: is12HourClock }),
|
|
133
154
|
(index !== unitsToRender.length - 1 || is12HourClock) && /* @__PURE__ */ jsx(UnitSeperator, {})
|
|
134
155
|
] }, u.unit)),
|
|
135
156
|
is12HourClock && renderClockSwitch()
|
|
136
157
|
] });
|
|
137
|
-
const
|
|
138
|
-
const dateString = localValue && getTimeString(localValue);
|
|
158
|
+
const dateString = valueAsDate && getTimeString(valueAsDate);
|
|
139
159
|
const clear = useCallback(() => {
|
|
140
160
|
setOpen(false);
|
|
141
161
|
onChange && onChange(void 0, "");
|
|
@@ -144,23 +164,18 @@ const TimePicker = ({
|
|
|
144
164
|
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) });
|
|
145
165
|
}, [open, dateString, clear, clearTooltip, alwaysOpen, disabled]);
|
|
146
166
|
const placeholderValue = useMemo(() => {
|
|
147
|
-
if (
|
|
148
|
-
return getTimeString(
|
|
167
|
+
if (valueAsDate) {
|
|
168
|
+
return getTimeString(valueAsDate);
|
|
149
169
|
}
|
|
150
170
|
return placeholder || formatMessage({
|
|
151
171
|
id: "DS.TIME-PICKER.PLACEHOLDER"
|
|
152
172
|
});
|
|
153
|
-
}, [placeholder, formatMessage,
|
|
173
|
+
}, [valueAsDate, placeholder, formatMessage, getTimeString]);
|
|
154
174
|
if (raw) {
|
|
155
175
|
return overlay;
|
|
156
176
|
}
|
|
157
177
|
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 }) }) });
|
|
158
178
|
};
|
|
159
|
-
TimePicker.defaultProps = {
|
|
160
|
-
placement: "bottomLeft",
|
|
161
|
-
trigger: ["click"],
|
|
162
|
-
units: defaultUnits
|
|
163
|
-
};
|
|
164
179
|
export {
|
|
165
180
|
TimePicker as default
|
|
166
181
|
};
|
package/dist/Unit.js
CHANGED
|
@@ -67,7 +67,9 @@ const Unit = ({
|
|
|
67
67
|
setTimeout(() => {
|
|
68
68
|
setForceUpdate(!forceUpdate);
|
|
69
69
|
}, 50);
|
|
70
|
-
}, active: isSelected, ref: isSelected ? selectedCellRef : null, children: /* @__PURE__ */ jsx(CellText, {
|
|
70
|
+
}, active: isSelected, ref: isSelected ? selectedCellRef : null, children: /* @__PURE__ */ jsx(CellText, { ...isSelected ? {
|
|
71
|
+
"data-selected": true
|
|
72
|
+
} : {}, "data-testid": `ds-time-picker-${unit}-${normalizedStringValue}`, children: normalizedStringValue }) }, `${unit}-${option}`);
|
|
71
73
|
}),
|
|
72
74
|
!!containerHeight && /* @__PURE__ */ jsx(PlaceholderWrapper, { children: /* @__PURE__ */ jsx(Placeholder, { height: containerHeight - CELL_HEIGHT }) })
|
|
73
75
|
] }) });
|
|
@@ -10,7 +10,19 @@ export type TimePickerDisabledUnits = {
|
|
|
10
10
|
disabledMinutes?: number[];
|
|
11
11
|
disabledHours?: number[];
|
|
12
12
|
};
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* `value` takes a `Date` or an ISO string; `onChange` always hands back a `Date`.
|
|
15
|
+
*
|
|
16
|
+
* With `timeZone` set that `Date` is a `TZDate` carrying the resolved zone — the same contract
|
|
17
|
+
* as `ds-date-picker`. Input and output used to share one `ValueType` parameter, which forced a
|
|
18
|
+
* consumer holding a `Date` to declare its output as `string`.
|
|
19
|
+
*/
|
|
20
|
+
type ValueRelatedProps = {
|
|
21
|
+
onChange?: (date: Date | undefined, timeString: string) => void;
|
|
22
|
+
value?: Date | string;
|
|
23
|
+
timeZone?: boolean | string;
|
|
24
|
+
};
|
|
25
|
+
export type TimePickerProps = ValueRelatedProps & {
|
|
14
26
|
alwaysOpen?: boolean;
|
|
15
27
|
className?: string;
|
|
16
28
|
clearTooltip?: string | ReactNode;
|
|
@@ -19,7 +31,6 @@ export type TimePickerProps = TimePickerDisabledUnits & {
|
|
|
19
31
|
disabled?: boolean;
|
|
20
32
|
dropdownProps?: Partial<Omit<DropdownSharedProps, 'children' | 'overlay' | 'open' | 'onOpenChange' | 'disabled'>>;
|
|
21
33
|
inputProps?: Partial<InputProps>;
|
|
22
|
-
onChange?: (value: Date | undefined, timeString: string) => void;
|
|
23
34
|
onClockModeChange?: (mode: string) => void;
|
|
24
35
|
overlayClassName?: string;
|
|
25
36
|
placeholder?: string;
|
|
@@ -36,6 +47,6 @@ export type TimePickerProps = TimePickerDisabledUnits & {
|
|
|
36
47
|
*/
|
|
37
48
|
use12HourClock?: boolean;
|
|
38
49
|
valueFormatOptions?: DateToFormatOptions;
|
|
39
|
-
value?: Date;
|
|
40
50
|
errorText?: ReactNode;
|
|
41
|
-
};
|
|
51
|
+
} & TimePickerDisabledUnits;
|
|
52
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const getClockModeFromDate: (date: Date
|
|
1
|
+
export declare const getClockModeFromDate: (date: Date) => string;
|
|
2
2
|
export declare const getOppositeClockMode: (clockMode: string) => string;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { HOUR, PM, AM, HOUR_12 } from "../constants/timePicker.constants.js";
|
|
1
|
+
import { PM, AM, HOUR_12 } from "../constants/timePicker.constants.js";
|
|
3
2
|
const getClockModeFromDate = (date) => {
|
|
4
|
-
const
|
|
5
|
-
const initialHour = initialDate.get(HOUR);
|
|
3
|
+
const initialHour = date.getHours();
|
|
6
4
|
return initialHour >= HOUR_12 ? PM : AM;
|
|
7
5
|
};
|
|
8
6
|
const getOppositeClockMode = (clockMode) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-time-picker",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "TimePicker UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -30,8 +30,12 @@
|
|
|
30
30
|
"build:watch": "vite build --watch",
|
|
31
31
|
"pack:ci": "pnpm pack --pack-destination ../../storybook/storybook-static/static",
|
|
32
32
|
"prepublish": "pnpm run build",
|
|
33
|
-
"test": "vitest run",
|
|
33
|
+
"test": "vitest run && pnpm test:timezones",
|
|
34
34
|
"test:watch": "vitest",
|
|
35
|
+
"test:timezone-ny": "TZ=America/New_York vitest run -t TimezoneTesting",
|
|
36
|
+
"test:timezone-utc": "TZ=UTC vitest run -t TimezoneTesting",
|
|
37
|
+
"test:timezone-waw": "TZ=Europe/Warsaw vitest run -t TimezoneTesting",
|
|
38
|
+
"test:timezones": "pnpm test:timezone-utc && pnpm test:timezone-ny && pnpm test:timezone-waw",
|
|
35
39
|
"types": "tsc --noEmit",
|
|
36
40
|
"check:circular-dependencies": "madge --circular --extensions ts,tsx,js,jsx --ts-config tsconfig.json src/ --exclude '/dist/'",
|
|
37
41
|
"upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
|
|
@@ -42,26 +46,26 @@
|
|
|
42
46
|
],
|
|
43
47
|
"types": "dist/index.d.ts",
|
|
44
48
|
"dependencies": {
|
|
45
|
-
"@synerise/ds-dropdown": "^2.1.
|
|
46
|
-
"@synerise/ds-icon": "^2.2.
|
|
47
|
-
"@synerise/ds-input": "^2.0.
|
|
48
|
-
"@synerise/ds-popover": "^2.0.
|
|
49
|
-
"@synerise/ds-scrollbar": "^2.0.
|
|
50
|
-
"@synerise/ds-tooltip": "^2.0.
|
|
51
|
-
"@synerise/ds-typography": "^2.0.
|
|
49
|
+
"@synerise/ds-dropdown": "^2.1.7",
|
|
50
|
+
"@synerise/ds-icon": "^2.2.3",
|
|
51
|
+
"@synerise/ds-input": "^2.0.11",
|
|
52
|
+
"@synerise/ds-popover": "^2.0.4",
|
|
53
|
+
"@synerise/ds-scrollbar": "^2.0.9",
|
|
54
|
+
"@synerise/ds-tooltip": "^2.0.10",
|
|
55
|
+
"@synerise/ds-typography": "^2.0.10",
|
|
52
56
|
"dayjs": "^1.8.19",
|
|
53
57
|
"debounce": "^1.2.0",
|
|
54
58
|
"lodash.range": "^3.2.0"
|
|
55
59
|
},
|
|
56
60
|
"devDependencies": {
|
|
57
|
-
"@types/lodash.range": "^3.2.9"
|
|
61
|
+
"@types/lodash.range": "^3.2.9",
|
|
62
|
+
"vitest": "4"
|
|
58
63
|
},
|
|
59
64
|
"peerDependencies": {
|
|
60
65
|
"@synerise/ds-core": "*",
|
|
61
66
|
"react": ">=16.9.0 <= 18.3.1",
|
|
62
67
|
"react-intl": ">=3.12.0 <= 6.8",
|
|
63
|
-
"styled-components": "^5.3.3"
|
|
64
|
-
"vitest": "4"
|
|
68
|
+
"styled-components": "^5.3.3"
|
|
65
69
|
},
|
|
66
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "5ac0f7dcb7c3995b402c86c087d8f32770f80a1d"
|
|
67
71
|
}
|