@synerise/ds-date-range-picker 2.1.7 → 2.2.0
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 +24 -0
- package/CLAUDE.md +11 -1
- package/README.md +51 -0
- package/dist/DateRangePicker.js +6 -3
- package/dist/DateRangePicker.types.d.ts +8 -1
- package/dist/Footer/Footer.d.ts +1 -1
- package/dist/Footer/Footer.js +8 -6
- package/dist/Footer/Footer.types.d.ts +6 -0
- package/dist/RangeFilter/Filters/MonthlyFilter/MonthlyFilter.js +2 -2
- package/dist/RangeFilter/Filters/new/Monthly/Monthly.js +2 -2
- package/dist/RangeFilter/Filters/new/Weekly/Weekly.js +2 -2
- package/dist/RangeFilter/RangeFilter.js +2 -2
- package/dist/RangeFilter/Shared/TimeWindow/Day/Day.js +1 -1
- package/dist/RangeFilter/constants.js +2 -2
- package/dist/RangePicker/RangePicker.js +22 -15
- package/dist/RangePicker/RangePicker.types.d.ts +6 -0
- package/dist/RangePicker/utils.d.ts +2 -2
- package/dist/RangePicker/utils.js +4 -5
- package/dist/RangePickerInput/RangePickerInput.d.ts +1 -1
- package/dist/RangePickerInput/RangePickerInput.js +14 -9
- package/dist/RangePickerInput/RangePickerInput.types.d.ts +6 -0
- package/dist/RawDateRangePicker.d.ts +1 -1
- package/dist/RawDateRangePicker.js +45 -24
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.d.ts +1 -1
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.js +5 -4
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/CustomRangeForm.types.d.ts +2 -0
- package/dist/RelativeRangePicker/Elements/CustomRangeForm/DurationField/DurationField.js +2 -2
- package/dist/RelativeRangePicker/Elements/RangeButtons/RangeButtons.js +2 -2
- package/dist/RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.js +3 -3
- package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampRange.js +15 -12
- package/dist/RelativeRangePicker/Elements/TimestampRange/TimestampRange.types.d.ts +2 -0
- package/dist/RelativeRangePicker/RelativeRangePicker.js +15 -8
- package/dist/RelativeRangePicker/RelativeRangePicker.types.d.ts +2 -0
- package/dist/RelativeRangePicker/utils/setDurationValue.utils.js +2 -2
- package/dist/RelativeRangePicker/utils/setFuture.utils.js +2 -2
- package/dist/RelativeRangePicker/utils/setOffsetValue.utils.js +2 -2
- package/dist/date.types.d.ts +1 -0
- package/dist/dateUtils/displayDate.d.ts +19 -0
- package/dist/dateUtils/displayDate.js +10 -0
- package/dist/dateUtils/getNow.d.ts +11 -0
- package/dist/dateUtils/getNow.js +5 -0
- package/dist/dateUtils/relativeToAbsolute.d.ts +1 -1
- package/dist/dateUtils/relativeToAbsolute.js +3 -2
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +12 -5
- package/package.json +28 -25
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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.2.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-date-range-picker@2.1.8...@synerise/ds-date-range-picker@2.2.0) (2026-10-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **popover:** add stickyPlacement option, enable it in date-range-picker ([03d3017](https://github.com/Synerise/synerise-design/commit/03d3017450512e958b5bf9d598a87c789b176037))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [2.1.8](https://github.com/Synerise/synerise-design/compare/@synerise/ds-date-range-picker@2.1.7...@synerise/ds-date-range-picker@2.1.8) (2026-10-26)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* add explicit .js to extensionless bare subpath imports ([b38cba6](https://github.com/Synerise/synerise-design/commit/b38cba6bae5c5aa10276e714bb6fb67c479bbde6))
|
|
23
|
+
* drop vitest peer dependency and bump vulnerable runtime deps ([2467d36](https://github.com/Synerise/synerise-design/commit/2467d3606aa97141a3a2d80c3ef396e78bee285c))
|
|
24
|
+
* remove per-render random keys and guard against them with a Biome plugin ([fcea7c5](https://github.com/Synerise/synerise-design/commit/fcea7c5d60b80c28cbbd191bfa2792379782a0e8))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [2.1.7](https://github.com/Synerise/synerise-design/compare/@synerise/ds-date-range-picker@2.1.6...@synerise/ds-date-range-picker@2.1.7) (2026-10-22)
|
|
7
31
|
|
|
8
32
|
**Note:** Version bump only for package @synerise/ds-date-range-picker
|
package/CLAUDE.md
CHANGED
|
@@ -116,6 +116,8 @@ Re-export of `format` from `date-fns` — use for consistent date formatting acr
|
|
|
116
116
|
|
|
117
117
|
Namespace export: `normalizeRange`, `toIsoString` (re-exported from `@synerise/ds-core`), `toIsoStringWithoutZone`, `getDefaultTexts`, `DEFAULT_RANGE`, `START_OF`, `END_OF`.
|
|
118
118
|
|
|
119
|
+
> `toIsoString` is re-exported from `@synerise/ds-core`, which owns the wall-clock convention. This package used to carry its own copy with wrong arithmetic for non-whole-hour offsets; the name is kept so consumers get the fix without a migration.
|
|
120
|
+
|
|
119
121
|
### `CONST`
|
|
120
122
|
|
|
121
123
|
Namespace export: all constants (`MODES`, `COLUMNS`, `RELATIVE_PRESETS`, `ABSOLUTE_PRESETS`, `TIME_OPTIONS`, mode strings, etc.).
|
|
@@ -208,6 +210,7 @@ Addons (relative picker, filter) appear below the calendar and are toggled via `
|
|
|
208
210
|
|
|
209
211
|
## Implementation notes
|
|
210
212
|
|
|
213
|
+
- The popover is opened with `autoUpdate` and `stickyPlacement`: it keeps the side it opened on while its content changes height (expanding the custom relative range, collapsing an addon) and chooses again on scroll, viewport resize or a move of the trigger. `popoverProps={{ stickyPlacement: false }}` restores the old behaviour.
|
|
211
214
|
- `disabled` and `readOnly` both suppress the popover entirely — the component renders just the trigger element without `<Popover>`.
|
|
212
215
|
- `renderPopoverTrigger` takes precedence if it returns a non-undefined value; `popoverTrigger` is checked before that; the default `RangePickerInput` is used otherwise.
|
|
213
216
|
- `valueTransformer` is applied inside `RawDateRangePicker` before calling `onApply` — default transformer strips `ALL_TIME`-specific props.
|
|
@@ -216,4 +219,11 @@ Addons (relative picker, filter) appear below the calendar and are toggled via `
|
|
|
216
219
|
- `getModifiers()` in `RangePicker/utils.ts` returns react-day-picker `Matcher`s keyed by modifier name; each key becomes a `DayPicker-Day--<key>` class. It normalises the `Date | string | null` range bounds to `Date`, which the v7 code did with casts.
|
|
217
220
|
- `RelativeRangePicker` is also a class-based `PureComponent`.
|
|
218
221
|
- The `SINCE` mode is a variant of relative dating anchored to a specific timestamp rather than "now".
|
|
219
|
-
- `
|
|
222
|
+
- **`timeZone` prop — the only switch for timezone behaviour.** Set it and the panel decodes incoming bounds by their own offset, works in the resolved zone, and emits `from` / `to` as **`TZDate`**s carrying that zone instead of offset-carrying ISO strings. `true` uses the provider's `timeZone`; a string names an IANA zone directly. Same contract as `ds-date-picker` and `ds-time-picker`. `TZDate.toISOString()` gives the offset form; use `new Date(bound.getTime()).toISOString()` for a `Z` instant.
|
|
223
|
+
- **Without the prop nothing is timezone-aware, including a `timeZone` on the provider.** A zone on the `IntlProvider` must not switch any of this on: every unmigrated consumer already has one, so reading it re-bases all of them at once. Opted out, bounds are decoded by `rmvTZOffset` (strip `±hh:mm`, read the rest as a browser wall clock — the offset is *discarded*, which is the bug the prop fixes), the panel renders on the browser clock, and `onApply` emits ISO strings whose offset comes from the provider zone. That last half was always zone-aware; `encodeTimeZone` in `RawDateRangePicker` is what keeps it so, and dropping its `?? intl.timeZone` would emit `+00:00` and move every saved instant.
|
|
224
|
+
- **The resolved zone is passed down as a prop, never read from `useIntl` in a child.** `Footer`, `RangePickerInput`, `RangePicker`, `RelativeRangePicker`, `CustomRangeForm` and `TimestampRange` all take `timeZone?: string`, which is `undefined` when the prop is absent. `dateUtils/getNow` takes the same value rather than an `IntlShape`. A `useIntl().timeZone` read in any of them silently re-introduces the ungated behaviour, and the `without the timeZone prop` block in `DateRangePicker.timezones.spec.tsx` is what catches it.
|
|
225
|
+
- **Internal date convention:** inside the panel a `Date` holds the *wall clock of the provider timezone* in its local fields — `toIsoString` (ds-core) is the encoder of that convention, `getValueAsLocalDate` / `getLocalDateInTimeZone` the decoders. Conversion happens only at the boundaries: values coming in (`normalizeRange(value, timeZone)`, and the time panel's ISO strings in `handleRangeChange`) and values going out (`toEmittedLimit` in `handleApply` / `onValueChange`). Display sites re-anchor to a real instant via `getDateToDisplay` and force `applyTimeZoneOffset: true` through `getFormatOptionsToDisplay` (`dateUtils/displayDate.ts`), because `formatValue` only projects an instant into the provider timezone when that flag is set and it defaults to `false` in `DataFormatConfig`. Mixing the two representations shifts values by the browser-to-provider timezone delta.
|
|
226
|
+
- **`value` accepts a `Date` as a true instant**, an ISO string as offset-carrying. A day selected in the calendar is `00:00:00`–`23:59:59` in the *provider* timezone, so consumers must read the calendar day back in that timezone rather than from browser-local fields.
|
|
227
|
+
- **Everything that means "now" goes through `dateUtils/getNow.ts`** — `getNow(intl)` returns the provider's clock as a wall-clock date. It backs the relative presets (`TODAY`/`YESTERDAY`/`LAST_MONTH` resolve on the provider's day, which across the date line is not the browser's), the circled `today` calendar modifier, the month the calendars open on, the "Now" button and the SINCE anchor. Nothing in the package may capture `new Date()` at module load — the one remaining case, `RangeFilter/Shared/TimeWindow/utils.tsx`, is a deliberate date carrier for time-of-day strings and is commented as such.
|
|
228
|
+
- `normalizeRange(range, timeZone?)` from `utils` converts relative ranges to absolute `Date` objects and optionally adjusts for timezone — used internally and safe to call from consuming code. The `timeZone` argument means two different things by branch: for a **relative** range it is the clock "now" is read from; for an **absolute** one it decodes incoming bounds (a `Date` there is read as a real instant). Internal call sites therefore use `normalizeLocalRange(range, timeZone)`, which passes the timezone only on the relative branch — handing it to the absolute branch would re-decode bounds that are already wall clock and shift them by the timezone delta.
|
|
229
|
+
- **`utils.toIsoString` is a re-export of ds-core's**, not a local implementation. Do not reintroduce a copy here: the one that used to live in `src/utils.ts` dropped the minutes of every non-whole-hour offset and read the offset off the wrong clock.
|
package/README.md
CHANGED
|
@@ -180,3 +180,54 @@ const value = {
|
|
|
180
180
|
### Undocumented props
|
|
181
181
|
|
|
182
182
|
- min in `MonthlyFilter` - controls minimal amount of entires in monthly filter, disable with `undefined`, default is `1`
|
|
183
|
+
|
|
184
|
+
## Timezone support
|
|
185
|
+
|
|
186
|
+
Timezone handling is **opt-in, behind the `timeZone` prop**. Set it and the picker:
|
|
187
|
+
|
|
188
|
+
- decodes incoming `from`/`to` by their own offset and displays them in the resolved timezone
|
|
189
|
+
- resolves relative ranges, the circled "today" and the "Now" button on that timezone's clock
|
|
190
|
+
- emits `from`/`to` as **`TZDate`**s carrying the instant and the zone
|
|
191
|
+
|
|
192
|
+
`true` resolves to the provider's `timeZone`; a string names an IANA zone directly. Display then
|
|
193
|
+
does not depend on `dataFormatConfig.applyTimeZoneOffset` — the picker asks for that projection
|
|
194
|
+
itself.
|
|
195
|
+
|
|
196
|
+
### Without the prop
|
|
197
|
+
|
|
198
|
+
Behaviour is unchanged from before the prop existed, and a `timeZone` on the provider does **not**
|
|
199
|
+
switch it on. That is deliberate: every unmigrated consumer already sits under an `IntlProvider`
|
|
200
|
+
carrying a zone, so reading it would re-base all of them at once.
|
|
201
|
+
|
|
202
|
+
Specifically, without the prop:
|
|
203
|
+
|
|
204
|
+
- incoming bounds are decoded by stripping a `±hh:mm` suffix and reading the rest as a **browser**
|
|
205
|
+
wall clock — the offset is discarded, not honoured. A `Z`-terminated string or a `Date` does not
|
|
206
|
+
match that pattern at all and is read as a real instant in the browser's zone.
|
|
207
|
+
- the calendar, the trigger and the footer render on the browser clock, and formatting is
|
|
208
|
+
whatever `dataFormatConfig` does with it
|
|
209
|
+
- `onApply` still emits offset-carrying **ISO strings**, with the offset taken from the provider's
|
|
210
|
+
timezone — that half was always zone-aware and stays so
|
|
211
|
+
|
|
212
|
+
The first point is a bug; `timeZone` is how it is fixed. Migrating a consumer means adding the
|
|
213
|
+
prop and updating whatever reads `onApply`, since the bounds change from strings to `TZDate`s.
|
|
214
|
+
|
|
215
|
+
### The `value` contract
|
|
216
|
+
|
|
217
|
+
A day selected in the calendar spans `00:00:00`–`23:59:59` **of the provider's timezone**, so
|
|
218
|
+
the two ends of a one-day range are different instants than the OS-local day would be. Read the
|
|
219
|
+
calendar day back in the provider timezone (`utcToZonedTime` or `getValueAsLocalDate` from
|
|
220
|
+
`@synerise/ds-core`) — reading local fields of the emitted instant moves a full-day range to the
|
|
221
|
+
neighbouring day.
|
|
222
|
+
|
|
223
|
+
`value.from` / `value.to` accept both forms:
|
|
224
|
+
|
|
225
|
+
| Form | Interpretation |
|
|
226
|
+
|---|---|
|
|
227
|
+
| ISO string (`'2026-08-11T00:00:00+09:00'`) | Decoded by its own offset. Preferred — it is unambiguous and it is what the component emits. |
|
|
228
|
+
| `Date` | A **real instant**, projected into the provider timezone for display. `new Date(emittedIsoString)` is therefore safe; a `Date` built from local calendar fields (e.g. `startOfDay(new Date())`) means "that instant", not "that day in the provider timezone". |
|
|
229
|
+
|
|
230
|
+
## Breaking changes
|
|
231
|
+
|
|
232
|
+
- **`utils.toIsoString` now re-exports the `@synerise/ds-core` implementation.** The name and signature are unchanged, but the offset arithmetic is corrected: zones that are not a whole number of hours ahead of UTC (`+05:30`, `+09:30`, `+05:45`, `+12:45`, `-03:30`) previously encoded with `:00` minutes, and the offset was read off the date's UTC fields rather than the wall clock it carries, which picked the wrong side of a DST transition.
|
|
233
|
+
- **`normalizeRange` signature changed:** Now accepts an optional second parameter `timeZone?: string`.
|
package/dist/DateRangePicker.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import isEqual from "lodash.isequal";
|
|
3
3
|
import { forwardRef, useState, useMemo, useEffect, useCallback } from "react";
|
|
4
4
|
import { useIntl } from "react-intl";
|
|
5
|
+
import { getTimeZone } from "@synerise/ds-core";
|
|
5
6
|
import { getPlacement, Popover, PopoverContent } from "@synerise/ds-popover";
|
|
6
7
|
import { POPOVER_SHIFT_CONFIG, POPOVER_FLIP_CONFIG, POPOVER_OFFSET_CONFIG } from "./constants.js";
|
|
7
8
|
import { PickerWrapper, DateRangePickerOverlay, PickerTrigger } from "./DateRangePicker.styles.js";
|
|
@@ -26,9 +27,11 @@ const DateRangePicker = forwardRef((props, forwardedRef) => {
|
|
|
26
27
|
renderPopoverTrigger = () => void 0,
|
|
27
28
|
readOnly = false,
|
|
28
29
|
disabled,
|
|
29
|
-
getPopupContainer
|
|
30
|
+
getPopupContainer,
|
|
31
|
+
timeZone: timeZoneProp
|
|
30
32
|
} = props;
|
|
31
33
|
const intl = useIntl();
|
|
34
|
+
const resolvedTimeZone = getTimeZone(timeZoneProp, intl);
|
|
32
35
|
const selectedRange = value || defaultValue;
|
|
33
36
|
const [popupVisible, setPopupVisible] = useState(false);
|
|
34
37
|
const [selectedDate, setSelectedDate] = useState(selectedRange);
|
|
@@ -58,7 +61,7 @@ const DateRangePicker = forwardRef((props, forwardedRef) => {
|
|
|
58
61
|
}, [popupVisible, onVisibleChange]);
|
|
59
62
|
const triggerElement = popoverTrigger || renderPopoverTrigger({
|
|
60
63
|
setPopupVisible
|
|
61
|
-
}) || /* @__PURE__ */ jsx(RangePickerInput, { onClick: readOnly ? void 0 : togglePopup, value: selectedDate, showTime, texts: allTexts, valueFormatOptions, onChange: onApplyCallback, active: inputActive, ...rangePickerInputProps, readOnly, disabled });
|
|
64
|
+
}) || /* @__PURE__ */ jsx(RangePickerInput, { onClick: readOnly ? void 0 : togglePopup, value: selectedDate, showTime, texts: allTexts, valueFormatOptions, onChange: onApplyCallback, active: inputActive, timeZone: resolvedTimeZone, ...rangePickerInputProps, readOnly, disabled });
|
|
62
65
|
const hasCustomTrigger = Boolean(popoverTrigger || renderPopoverTrigger);
|
|
63
66
|
const handleTriggerClick = hasCustomTrigger ? () => {
|
|
64
67
|
if (hasCustomTrigger) {
|
|
@@ -72,7 +75,7 @@ const DateRangePicker = forwardRef((props, forwardedRef) => {
|
|
|
72
75
|
setPopupVisible(openState);
|
|
73
76
|
setInputActive(openState);
|
|
74
77
|
onVisibleChange && onVisibleChange(openState);
|
|
75
|
-
}, placement: floatingPlacement, testId: "date-range-picker", componentId: "date-range-picker", returnFocus: false, offsetConfig: POPOVER_OFFSET_CONFIG, flipConfig: POPOVER_FLIP_CONFIG, shiftConfig: POPOVER_SHIFT_CONFIG, autoUpdate: true, ...conditionalVisibilityProps, ...popoverProps, children: [
|
|
78
|
+
}, placement: floatingPlacement, testId: "date-range-picker", componentId: "date-range-picker", returnFocus: false, offsetConfig: POPOVER_OFFSET_CONFIG, flipConfig: POPOVER_FLIP_CONFIG, shiftConfig: POPOVER_SHIFT_CONFIG, autoUpdate: true, stickyPlacement: true, ...conditionalVisibilityProps, ...popoverProps, children: [
|
|
76
79
|
/* @__PURE__ */ jsx(PopoverContent, { children: /* @__PURE__ */ jsx(DateRangePickerOverlay, { className: "ds-date-range-popover", "data-testid": "ds-date-range-picker-overlay", children: /* @__PURE__ */ jsx(RawDateRangePicker, { ...props, showTime, onApply: onApplyCallback, value: selectedDate, texts: allTexts, forceAdjacentMonths }) }) }),
|
|
77
80
|
/* @__PURE__ */ jsx(PickerTrigger, { asChild: false, children: /* @__PURE__ */ jsx(PickerWrapper, { ref: forwardedRef, onClick: handleTriggerClick, children: triggerElement }) })
|
|
78
81
|
] });
|
|
@@ -11,7 +11,7 @@ import { DateLimitMode, RangeDisplayMode } from './RangeFilter/Shared/TimeWindow
|
|
|
11
11
|
import { RangePickerInputProps } from './RangePickerInput/RangePickerInput.types';
|
|
12
12
|
export type DateRangePickerProps = {
|
|
13
13
|
/**
|
|
14
|
-
* @deprecated
|
|
14
|
+
* @deprecated - not used, this prop will be dropped in v1.x
|
|
15
15
|
*/
|
|
16
16
|
intl?: IntlShape;
|
|
17
17
|
/**
|
|
@@ -27,6 +27,13 @@ export type DateRangePickerProps = {
|
|
|
27
27
|
forceAbsolute?: boolean;
|
|
28
28
|
footerProps?: Partial<FooterProps>;
|
|
29
29
|
onValueChange?: (value: Partial<DateFilter> | undefined) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Opts into timezone-aware values: the emitted `from` / `to` become `TZDate`s carrying the
|
|
32
|
+
* resolved zone instead of offset-carrying ISO strings, and the panel works in that zone.
|
|
33
|
+
* `true` uses the provider's `timeZone`; a string names an IANA zone directly. Omitted, the
|
|
34
|
+
* component behaves exactly as before — provider zone, ISO strings out.
|
|
35
|
+
*/
|
|
36
|
+
timeZone?: boolean | string;
|
|
30
37
|
onApply: (value: Partial<DateFilter> | undefined) => void;
|
|
31
38
|
onVisibleChange?: (visible: boolean) => void;
|
|
32
39
|
onFilterSave?: (filters: SavedFilter[]) => void;
|
package/dist/Footer/Footer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Props } from './Footer.types';
|
|
3
|
-
declare const Footer: ({ canApply, onApply, canSwitchMode, onSwitchMode, mode, dateOnly, message, texts, value, valueFormatOptions, showTime, displayDateContainerClass, ...rest }: Props) => React.JSX.Element;
|
|
3
|
+
declare const Footer: ({ canApply, onApply, canSwitchMode, onSwitchMode, mode, dateOnly, message, texts, value, valueFormatOptions, showTime, timeZone, displayDateContainerClass, ...rest }: Props) => React.JSX.Element;
|
|
4
4
|
export default Footer;
|
package/dist/Footer/Footer.js
CHANGED
|
@@ -6,6 +6,7 @@ import { useDataFormat, getDefaultDataTimeOptions } from "@synerise/ds-core";
|
|
|
6
6
|
import Icon, { ArrowRightS } from "@synerise/ds-icon";
|
|
7
7
|
import Tooltip from "@synerise/ds-tooltip";
|
|
8
8
|
import { ALL_TIME } from "../constants.js";
|
|
9
|
+
import { getDateToDisplay, getFormatOptionsToDisplay } from "../dateUtils/displayDate.js";
|
|
9
10
|
import { isLifetime } from "../RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.js";
|
|
10
11
|
import { ChosenRange, InvisibleTextContent, Container, ActionsPlaceholder, Actions } from "./Footer.styles.js";
|
|
11
12
|
const Footer = ({
|
|
@@ -20,6 +21,7 @@ const Footer = ({
|
|
|
20
21
|
value,
|
|
21
22
|
valueFormatOptions,
|
|
22
23
|
showTime,
|
|
24
|
+
timeZone,
|
|
23
25
|
displayDateContainerClass = "ds-date-range-picker-value",
|
|
24
26
|
...rest
|
|
25
27
|
}) => {
|
|
@@ -31,20 +33,20 @@ const Footer = ({
|
|
|
31
33
|
if (!isValid(parsed)) {
|
|
32
34
|
return "";
|
|
33
35
|
}
|
|
34
|
-
return formatValue(parsed, {
|
|
36
|
+
return formatValue(getDateToDisplay(parsed, timeZone), getFormatOptionsToDisplay({
|
|
35
37
|
...getDefaultDataTimeOptions(showTime),
|
|
36
38
|
...valueFormatOptions
|
|
37
|
-
});
|
|
38
|
-
}, [formatValue,
|
|
39
|
+
}, timeZone));
|
|
40
|
+
}, [formatValue, showTime, timeZone, valueFormatOptions]);
|
|
39
41
|
const ChosenRange$1 = useMemo(() => {
|
|
40
42
|
if (value?.key === ALL_TIME || value && isLifetime(value)) {
|
|
41
43
|
return /* @__PURE__ */ jsx(ChosenRange, { className: "ds-date-range-picker-value", children: value?.translationKey ? texts[value.translationKey] ?? value.translationKey : value?.key || "LIFETIME" });
|
|
42
44
|
}
|
|
43
|
-
return /* @__PURE__ */ jsxs(ChosenRange, { className: displayDateContainerClass, children: [
|
|
44
|
-
value && value.from ? footerDateToString(value?.from) : texts.startDatePlaceholder,
|
|
45
|
+
return /* @__PURE__ */ jsxs(ChosenRange, { className: displayDateContainerClass, "data-testid": "ds-date-range-picker-footer", children: [
|
|
46
|
+
/* @__PURE__ */ jsx("span", { children: value && value.from ? footerDateToString(value?.from) : texts.startDatePlaceholder }),
|
|
45
47
|
/* @__PURE__ */ jsx(InvisibleTextContent, { children: " – " }),
|
|
46
48
|
/* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(ArrowRightS, {}) }),
|
|
47
|
-
value && value.to ? footerDateToString(value?.to) : texts.endDatePlaceholder
|
|
49
|
+
/* @__PURE__ */ jsx("span", { children: value && value.to ? footerDateToString(value?.to) : texts.endDatePlaceholder })
|
|
48
50
|
] });
|
|
49
51
|
}, [value, texts, displayDateContainerClass, footerDateToString]);
|
|
50
52
|
return /* @__PURE__ */ jsxs(Container, { className: "ds-date-range-picker-footer", ...rest, children: [
|
|
@@ -2,6 +2,12 @@ import { DateToFormatOptions } from '@synerise/ds-core';
|
|
|
2
2
|
import { Texts } from '../DateRangePicker.types';
|
|
3
3
|
import { DateRange } from '../date.types';
|
|
4
4
|
export type Props = {
|
|
5
|
+
/**
|
|
6
|
+
* The zone the `timeZone` prop resolved to, or `undefined` when it was not set. Read from a
|
|
7
|
+
* prop rather than `intl`, so a consumer that has not opted in keeps rendering the way it
|
|
8
|
+
* does today.
|
|
9
|
+
*/
|
|
10
|
+
timeZone?: string;
|
|
5
11
|
mode: string;
|
|
6
12
|
dateOnly?: boolean;
|
|
7
13
|
value?: DateRange;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { PureComponent } from "react";
|
|
3
3
|
import { FormattedMessage, injectIntl } from "react-intl";
|
|
4
|
-
import { v4 } from "uuid";
|
|
5
4
|
import Button from "@synerise/ds-button";
|
|
6
5
|
import { theme } from "@synerise/ds-core";
|
|
7
6
|
import { ContentItem } from "@synerise/ds-manageable-list";
|
|
8
7
|
import Tag, { TagShape } from "@synerise/ds-tag";
|
|
8
|
+
import { generateUuid } from "@synerise/ds-utils";
|
|
9
9
|
import { getDefaultTexts } from "../../../utils.js";
|
|
10
10
|
import { defaultId, DEFAULT_DAYS_OF_PERIODS, DEFAULT_COUNTED_FROM, MONTH_DAYS, DAYS_OF_PERIOD_ENUM, COUNTED_FROM_ENUM, SPACE_UNICODE } from "../../constants.js";
|
|
11
11
|
import TimeWindow from "../../Shared/TimeWindow/TimeWindow.js";
|
|
@@ -25,7 +25,7 @@ const _MonthlyFilter = class _MonthlyFilter extends PureComponent {
|
|
|
25
25
|
return onChange(definition);
|
|
26
26
|
};
|
|
27
27
|
this.handleAddRow = () => {
|
|
28
|
-
const id =
|
|
28
|
+
const id = generateUuid();
|
|
29
29
|
const {
|
|
30
30
|
value,
|
|
31
31
|
countedFromPeriods,
|
|
@@ -2,8 +2,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import { useMemo, useState, useRef, useEffect, useCallback } from "react";
|
|
4
4
|
import { useIntl } from "react-intl";
|
|
5
|
-
import { v4 } from "uuid";
|
|
6
5
|
import { useDataFormat } from "@synerise/ds-core";
|
|
6
|
+
import { generateUuid } from "@synerise/ds-utils";
|
|
7
7
|
import { getDefaultTexts } from "../../../../utils.js";
|
|
8
8
|
import { DAYS_OF_PERIOD_ENUM, MONTHLY_SCHEDULER_INTL_KEYS_WEEKDAYS_LONG, MONTHLY_SCHEDULER_INTL_KEYS_NTH_WEEK, MONTHLY_SCHEDULER_INTL_KEYS_WEEKDAYS_SHORT, MONTH_DAYS, COUNTED_FROM_ENUM } from "../../../constants.js";
|
|
9
9
|
import { NewFilterContainer } from "../../../RangeFilter.styles.js";
|
|
@@ -247,7 +247,7 @@ const Monthly = ({
|
|
|
247
247
|
const restOfScheduleObject = guid ? value[guid] : EMPTY_OBJECT;
|
|
248
248
|
const updatedSchedule = {
|
|
249
249
|
...value,
|
|
250
|
-
[guid ||
|
|
250
|
+
[guid || generateUuid()]: {
|
|
251
251
|
...restOfScheduleObject,
|
|
252
252
|
...updatedDay
|
|
253
253
|
}
|
|
@@ -2,8 +2,8 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
3
|
import { useMemo, useState, useRef, useEffect, useCallback } from "react";
|
|
4
4
|
import { useIntl } from "react-intl";
|
|
5
|
-
import { v4 } from "uuid";
|
|
6
5
|
import { useDataFormat } from "@synerise/ds-core";
|
|
6
|
+
import { generateUuid } from "@synerise/ds-utils";
|
|
7
7
|
import { getDefaultTexts } from "../../../../utils.js";
|
|
8
8
|
import { NewFilterContainer } from "../../../RangeFilter.styles.js";
|
|
9
9
|
import AddButton from "../../../Shared/AddButton/AddButton.js";
|
|
@@ -192,7 +192,7 @@ const Weekly = ({
|
|
|
192
192
|
const restOfScheduleObject = guid ? value[guid] : EMPTY_OBJECT;
|
|
193
193
|
const updatedSchedule = {
|
|
194
194
|
...value,
|
|
195
|
-
[guid ||
|
|
195
|
+
[guid || generateUuid()]: {
|
|
196
196
|
...restOfScheduleObject,
|
|
197
197
|
...updatedDay
|
|
198
198
|
}
|
|
@@ -2,9 +2,9 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import cloneDeep from "lodash.clonedeep";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { injectIntl } from "react-intl";
|
|
5
|
-
import { v4 } from "uuid";
|
|
6
5
|
import Button from "@synerise/ds-button";
|
|
7
6
|
import ButtonGroup from "@synerise/ds-button-group";
|
|
7
|
+
import { generateUuid } from "@synerise/ds-utils";
|
|
8
8
|
import { getDefaultTexts } from "../utils.js";
|
|
9
9
|
import { TYPES_DATA, TYPES } from "./constants.js";
|
|
10
10
|
import { Container, Header, Title, Body, MainComponentWrapper, Footer, FooterSeparator } from "./RangeFilter.styles.js";
|
|
@@ -84,7 +84,7 @@ const _RangeFilter = class _RangeFilter extends React.PureComponent {
|
|
|
84
84
|
...currentFilter,
|
|
85
85
|
type: activeType,
|
|
86
86
|
name: filterName,
|
|
87
|
-
id:
|
|
87
|
+
id: generateUuid()
|
|
88
88
|
};
|
|
89
89
|
const filterWithUniqueName = addSuffixToDuplicate(filterList, filter);
|
|
90
90
|
onFilterSave && onFilterSave([...filterList, filterWithUniqueName]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } 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 { memo, useState, useMemo, useCallback } from "react";
|
|
5
5
|
import Button from "@synerise/ds-button";
|
|
6
6
|
import { theme } from "@synerise/ds-core";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import range from "lodash.range";
|
|
2
|
-
import {
|
|
2
|
+
import { generateUuid } from "@synerise/ds-utils";
|
|
3
3
|
import { format, addDays } from "date-fns";
|
|
4
4
|
import DailyFilter from "./Filters/DailyFilter/DailyFilter.js";
|
|
5
5
|
import MonthlyFilter from "./Filters/MonthlyFilter/MonthlyFilter.js";
|
|
@@ -42,7 +42,7 @@ const DEFAULT_COUNTED_FROM = [{
|
|
|
42
42
|
value: "ENDING"
|
|
43
43
|
/* ENDING */
|
|
44
44
|
}];
|
|
45
|
-
const defaultId =
|
|
45
|
+
const defaultId = generateUuid();
|
|
46
46
|
const TYPES_DATA = {
|
|
47
47
|
MONTHLY: {
|
|
48
48
|
labelTranslationKey: "DS.DATE-RANGE-PICKER.MONTHLY",
|
|
@@ -8,7 +8,9 @@ import Icon, { CalendarM, ClockM } from "@synerise/ds-icon";
|
|
|
8
8
|
import Tooltip from "@synerise/ds-tooltip";
|
|
9
9
|
import { ABSOLUTE, COLUMNS, MODES } from "../constants.js";
|
|
10
10
|
import ADD from "../dateUtils/add.js";
|
|
11
|
+
import { getDateToDisplay, getFormatOptionsToDisplay } from "../dateUtils/displayDate.js";
|
|
11
12
|
import getDateFromString from "../dateUtils/getDateFromString.js";
|
|
13
|
+
import { getNow } from "../dateUtils/getNow.js";
|
|
12
14
|
import toDateValue from "../dateUtils/toDateValue.js";
|
|
13
15
|
import { Range } from "../RelativeRangePicker/RelativeRangePicker.styles.js";
|
|
14
16
|
import { Sides, Side, PickerFooter, FooterSeparator, DateTimeModeSwitch } from "./RangePicker.styles.js";
|
|
@@ -192,15 +194,16 @@ class RangePicker extends PureComponent {
|
|
|
192
194
|
const {
|
|
193
195
|
value,
|
|
194
196
|
intl,
|
|
195
|
-
formatValue
|
|
197
|
+
formatValue,
|
|
198
|
+
timeZone
|
|
196
199
|
} = this.props;
|
|
197
200
|
const formatDate = (date) => {
|
|
198
201
|
if (typeof date === "string") {
|
|
199
202
|
return datePickerFormat(toDateValue(date), TOOLTIP_FORMAT, intl.locale);
|
|
200
203
|
}
|
|
201
|
-
return formatValue(date, {
|
|
204
|
+
return formatValue(getDateToDisplay(date, timeZone), getFormatOptionsToDisplay({
|
|
202
205
|
...getDefaultDataTimeOptions(true)
|
|
203
|
-
});
|
|
206
|
+
}, timeZone));
|
|
204
207
|
};
|
|
205
208
|
const {
|
|
206
209
|
from,
|
|
@@ -238,7 +241,8 @@ class RangePicker extends PureComponent {
|
|
|
238
241
|
const {
|
|
239
242
|
value,
|
|
240
243
|
disabledDate,
|
|
241
|
-
forceAdjacentMonths
|
|
244
|
+
forceAdjacentMonths,
|
|
245
|
+
timeZone
|
|
242
246
|
} = this.props;
|
|
243
247
|
const {
|
|
244
248
|
enteredTo,
|
|
@@ -251,7 +255,7 @@ class RangePicker extends PureComponent {
|
|
|
251
255
|
to,
|
|
252
256
|
type
|
|
253
257
|
} = value;
|
|
254
|
-
const modifiers = getModifiers(isValid(from) ? from : null, isValid(to) ? to : null, enteredTo);
|
|
258
|
+
const modifiers = getModifiers(isValid(from) ? from : null, isValid(to) ? to : null, enteredTo, getNow(timeZone));
|
|
255
259
|
const selectedDays = isValid(from) && isValid(to) ? [toDateValue(from), {
|
|
256
260
|
from: toDateValue(from),
|
|
257
261
|
to: toDateValue(to)
|
|
@@ -265,7 +269,8 @@ class RangePicker extends PureComponent {
|
|
|
265
269
|
this.renderTimePicker = (side) => {
|
|
266
270
|
const {
|
|
267
271
|
value,
|
|
268
|
-
is12HoursClock
|
|
272
|
+
is12HoursClock,
|
|
273
|
+
timeZone
|
|
269
274
|
} = this.props;
|
|
270
275
|
const {
|
|
271
276
|
from,
|
|
@@ -277,14 +282,14 @@ class RangePicker extends PureComponent {
|
|
|
277
282
|
const sidesAreAdjacent = isSameDay(toDateValue(from), toDateValue(to));
|
|
278
283
|
switch (side) {
|
|
279
284
|
case COLUMNS.LEFT: {
|
|
280
|
-
return /* @__PURE__ */ jsx(TimePicker, { value: getDateFromString(from), onChange: this.handleFromTimeChange, disabledHours: getDisabledTimeOptions(from, "HOURS", null, to, is12HoursClock), disabledMinutes: getDisabledTimeOptions(from, "MINUTES", null, to, is12HoursClock), disabledSeconds: getDisabledTimeOptions(from, "SECONDS", null, to, is12HoursClock), onShortNext: sidesAreAdjacent ? void 0 : () => {
|
|
285
|
+
return /* @__PURE__ */ jsx(TimePicker, { timeZone, value: getDateFromString(from), onChange: this.handleFromTimeChange, disabledHours: getDisabledTimeOptions(from, "HOURS", null, to, is12HoursClock), disabledMinutes: getDisabledTimeOptions(from, "MINUTES", null, to, is12HoursClock), disabledSeconds: getDisabledTimeOptions(from, "SECONDS", null, to, is12HoursClock), onShortNext: sidesAreAdjacent ? void 0 : () => {
|
|
281
286
|
this.handleAddDay(1, COLUMNS.LEFT);
|
|
282
287
|
}, onShortPrev: () => {
|
|
283
288
|
this.handleAddDay(-1, COLUMNS.LEFT);
|
|
284
289
|
} }, `time-picker-${side}`);
|
|
285
290
|
}
|
|
286
291
|
case COLUMNS.RIGHT: {
|
|
287
|
-
return /* @__PURE__ */ jsx(TimePicker, { value: getDateFromString(to), onChange: this.handleToTimeChange, disabledHours: getDisabledTimeOptions(to, "HOURS", from, null, is12HoursClock), disabledMinutes: getDisabledTimeOptions(to, "MINUTES", from, null, is12HoursClock), disabledSeconds: getDisabledTimeOptions(to, "SECONDS", from, null, is12HoursClock), onShortNext: () => {
|
|
292
|
+
return /* @__PURE__ */ jsx(TimePicker, { timeZone, value: getDateFromString(to), onChange: this.handleToTimeChange, disabledHours: getDisabledTimeOptions(to, "HOURS", from, null, is12HoursClock), disabledMinutes: getDisabledTimeOptions(to, "MINUTES", from, null, is12HoursClock), disabledSeconds: getDisabledTimeOptions(to, "SECONDS", from, null, is12HoursClock), onShortNext: () => {
|
|
288
293
|
this.handleAddDay(1, COLUMNS.RIGHT);
|
|
289
294
|
}, onShortPrev: sidesAreAdjacent ? void 0 : () => {
|
|
290
295
|
this.handleAddDay(-1, COLUMNS.RIGHT);
|
|
@@ -317,14 +322,15 @@ class RangePicker extends PureComponent {
|
|
|
317
322
|
};
|
|
318
323
|
this.state = {
|
|
319
324
|
enteredTo: null,
|
|
320
|
-
...getSidesState(props.value)
|
|
325
|
+
...getSidesState(props.value, void 0, getNow(props.timeZone))
|
|
321
326
|
};
|
|
322
327
|
}
|
|
323
328
|
getSnapshotBeforeUpdate(prevProps) {
|
|
324
329
|
const {
|
|
325
330
|
value,
|
|
326
331
|
forceAdjacentMonths,
|
|
327
|
-
startAlwaysOnTheLeft
|
|
332
|
+
startAlwaysOnTheLeft,
|
|
333
|
+
timeZone
|
|
328
334
|
} = this.props;
|
|
329
335
|
const {
|
|
330
336
|
jumpToStartAndEnd = true
|
|
@@ -339,20 +345,20 @@ class RangePicker extends PureComponent {
|
|
|
339
345
|
const endOnLeft = isSameMonth(toDateValue(value.to), toDateValue(left.month));
|
|
340
346
|
if (fromDateChanged && !endOnLeft || toDateChanged && !endOnLeft || forceAdjacentMonths !== prevProps.forceAdjacentMonths) {
|
|
341
347
|
if (startAlwaysOnTheLeft) {
|
|
342
|
-
this.setState(getSidesState(value, forceAdjacentMonths));
|
|
348
|
+
this.setState(getSidesState(value, forceAdjacentMonths, getNow(timeZone)));
|
|
343
349
|
}
|
|
344
350
|
}
|
|
345
351
|
if (jumpToStartAndEnd && (fromDateChanged || toDateChanged)) {
|
|
346
352
|
const startOnRight = isSameMonth(toDateValue(value.from), toDateValue(right.month));
|
|
347
353
|
const isStartVisible = startOnLeft || startOnRight;
|
|
348
354
|
if (!isStartVisible) {
|
|
349
|
-
this.setState(getSidesState(value, forceAdjacentMonths));
|
|
355
|
+
this.setState(getSidesState(value, forceAdjacentMonths, getNow(timeZone)));
|
|
350
356
|
return null;
|
|
351
357
|
}
|
|
352
358
|
const endOnRight = isSameMonth(toDateValue(value.to), toDateValue(right.month));
|
|
353
359
|
const isEndVisible = endOnLeft || endOnRight;
|
|
354
360
|
if (!isEndVisible) {
|
|
355
|
-
this.setState(getSidesState(value, forceAdjacentMonths));
|
|
361
|
+
this.setState(getSidesState(value, forceAdjacentMonths, getNow(timeZone)));
|
|
356
362
|
return null;
|
|
357
363
|
}
|
|
358
364
|
}
|
|
@@ -366,7 +372,8 @@ class RangePicker extends PureComponent {
|
|
|
366
372
|
canSwitchMode,
|
|
367
373
|
dateOnly,
|
|
368
374
|
onSwitchMode,
|
|
369
|
-
texts
|
|
375
|
+
texts,
|
|
376
|
+
timeZone
|
|
370
377
|
} = this.props;
|
|
371
378
|
const {
|
|
372
379
|
showNowButton = true
|
|
@@ -380,7 +387,7 @@ class RangePicker extends PureComponent {
|
|
|
380
387
|
showNowButton && /* @__PURE__ */ jsx(Range, { onClick: ({
|
|
381
388
|
currentTarget
|
|
382
389
|
}) => {
|
|
383
|
-
const now =
|
|
390
|
+
const now = getNow(timeZone);
|
|
384
391
|
const literallyNow = {
|
|
385
392
|
...value,
|
|
386
393
|
translationKey: "now",
|
|
@@ -11,6 +11,12 @@ export interface RangePickerProps extends WrappedComponentProps {
|
|
|
11
11
|
onSwitchMode?: () => void;
|
|
12
12
|
texts: Texts;
|
|
13
13
|
forceAdjacentMonths?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The zone the `timeZone` prop resolved to, or `undefined` when it was not set. Passed down
|
|
16
|
+
* rather than read from `intl` here, so a consumer that has not opted in keeps the browser
|
|
17
|
+
* clock it renders on today.
|
|
18
|
+
*/
|
|
19
|
+
timeZone?: string;
|
|
14
20
|
showCustomRange?: boolean;
|
|
15
21
|
showNowButton?: boolean;
|
|
16
22
|
startAlwaysOnTheLeft?: boolean;
|
|
@@ -2,5 +2,5 @@ import { Matcher } from 'react-day-picker';
|
|
|
2
2
|
import { DateRange, NullableDateLimit } from '../date.types';
|
|
3
3
|
import { State } from './RangePicker.types';
|
|
4
4
|
export declare const getDisabledTimeOptions: (initialDay: string | Date | undefined, granularity: string, initialLowerLimit?: NullableDateLimit, initialUpperLimit?: NullableDateLimit, is12HoursClock?: boolean) => number[];
|
|
5
|
-
export declare const getSidesState: (value: DateRange, forceAdjacentMonths?: boolean) => State;
|
|
6
|
-
export declare const getModifiers: (from: NullableDateLimit | undefined, to: NullableDateLimit | undefined, enteredTo: NullableDateLimit | undefined) => Record<string, Matcher | undefined>;
|
|
5
|
+
export declare const getSidesState: (value: DateRange, forceAdjacentMonths?: boolean, today?: Date) => State;
|
|
6
|
+
export declare const getModifiers: (from: NullableDateLimit | undefined, to: NullableDateLimit | undefined, enteredTo: NullableDateLimit | undefined, today?: Date) => Record<string, Matcher | undefined>;
|
|
@@ -6,7 +6,6 @@ import ADD from "../dateUtils/add.js";
|
|
|
6
6
|
import GET from "../dateUtils/get.js";
|
|
7
7
|
import SET from "../dateUtils/set.js";
|
|
8
8
|
import toDateValue from "../dateUtils/toDateValue.js";
|
|
9
|
-
const NOW = /* @__PURE__ */ new Date();
|
|
10
9
|
const HOURS_GRANULARITY = "HOURS";
|
|
11
10
|
const getAmOrPmFromDate = (date) => {
|
|
12
11
|
return dayjs(date).get(HOUR) >= HOUR_12 ? PM : AM;
|
|
@@ -79,8 +78,8 @@ const getDisabledTimeOptions = (initialDay, granularity, initialLowerLimit = nul
|
|
|
79
78
|
}
|
|
80
79
|
return result;
|
|
81
80
|
};
|
|
82
|
-
const getSidesState = (value, forceAdjacentMonths) => {
|
|
83
|
-
const from = startOfMonth(isValid(value.from) ? toDateValue(value.from) :
|
|
81
|
+
const getSidesState = (value, forceAdjacentMonths, today = /* @__PURE__ */ new Date()) => {
|
|
82
|
+
const from = startOfMonth(isValid(value.from) ? toDateValue(value.from) : today);
|
|
84
83
|
let to = isValid(value.to) ? startOfMonth(toDateValue(value.to)) : from;
|
|
85
84
|
if (isSameMonth(from, to)) {
|
|
86
85
|
to = ADD.MONTHS(to, 1);
|
|
@@ -102,7 +101,7 @@ const toDate = (value) => {
|
|
|
102
101
|
}
|
|
103
102
|
return value instanceof Date ? value : toDateValue(value);
|
|
104
103
|
};
|
|
105
|
-
const getModifiers = (from, to, enteredTo) => {
|
|
104
|
+
const getModifiers = (from, to, enteredTo, today = /* @__PURE__ */ new Date()) => {
|
|
106
105
|
const isSelecting = from && !to && enteredTo;
|
|
107
106
|
const enteredStart = isSelecting ? min([toDateValue(from), toDateValue(enteredTo)]) : enteredTo;
|
|
108
107
|
const enteredEnd = isSelecting ? max([toDateValue(from), toDateValue(enteredTo)]) : enteredTo;
|
|
@@ -116,7 +115,7 @@ const getModifiers = (from, to, enteredTo) => {
|
|
|
116
115
|
start: toDate(startModifier),
|
|
117
116
|
end: toDate(endModifier),
|
|
118
117
|
entered: typeof entered === "function" ? entered : toDate(entered),
|
|
119
|
-
today
|
|
118
|
+
today,
|
|
120
119
|
"entered-start": toDate(enteredStart),
|
|
121
120
|
"entered-end": toDate(enteredEnd),
|
|
122
121
|
"initial-entered": !endModifier ? toDate(startModifier) : void 0,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { RangePickerInputProps } from './RangePickerInput.types';
|
|
3
|
-
declare const RangePickerInput: ({ value, valueFormatOptions, showTime, onChange, onClick, highlight, texts, active, label, description, tooltip, tooltipConfig, disabled, readOnly, onFocus, allowClear, onBlur, error, errorText, preferRelativeDesc, }: RangePickerInputProps) => React.JSX.Element;
|
|
3
|
+
declare const RangePickerInput: ({ value, valueFormatOptions, showTime, onChange, onClick, highlight, texts, active, label, description, tooltip, tooltipConfig, disabled, readOnly, onFocus, allowClear, onBlur, error, errorText, preferRelativeDesc, timeZone, }: RangePickerInputProps) => React.JSX.Element;
|
|
4
4
|
export default RangePickerInput;
|
|
@@ -4,9 +4,13 @@ import { useTheme, useDataFormat, getDefaultDataTimeOptions } from "@synerise/ds
|
|
|
4
4
|
import FormField from "@synerise/ds-form-field";
|
|
5
5
|
import Icon, { ArrowRightS, Close3S, CalendarM } from "@synerise/ds-icon";
|
|
6
6
|
import Tooltip from "@synerise/ds-tooltip";
|
|
7
|
+
import { getDateToDisplay, getFormatOptionsToDisplay } from "../dateUtils/displayDate.js";
|
|
7
8
|
import { isLifetime } from "../RelativeRangePicker/Elements/RangeDropdown/RangeDropdown.js";
|
|
8
9
|
import { normalizeRange } from "../utils.js";
|
|
9
10
|
import { DateValue, DateWrapper, Container, RangeInputWrapper, IconSeparator, ClearIconWrapper, DefaultIconWrapper } from "./RangePickerInput.styles.js";
|
|
11
|
+
const isDateLimit = (dateLimit) => {
|
|
12
|
+
return dateLimit !== void 0 && dateLimit !== null;
|
|
13
|
+
};
|
|
10
14
|
const RangePickerInput = ({
|
|
11
15
|
value,
|
|
12
16
|
valueFormatOptions,
|
|
@@ -27,13 +31,14 @@ const RangePickerInput = ({
|
|
|
27
31
|
onBlur,
|
|
28
32
|
error,
|
|
29
33
|
errorText,
|
|
30
|
-
preferRelativeDesc = false
|
|
34
|
+
preferRelativeDesc = false,
|
|
35
|
+
timeZone
|
|
31
36
|
}) => {
|
|
32
37
|
const theme = useTheme();
|
|
33
38
|
const {
|
|
34
39
|
formatValue
|
|
35
40
|
} = useDataFormat();
|
|
36
|
-
const dateRangeValue = value ? normalizeRange(value) : value;
|
|
41
|
+
const dateRangeValue = value ? normalizeRange(value, timeZone) : value;
|
|
37
42
|
const [hovered, setHovered] = useState(false);
|
|
38
43
|
const showError = error || !!errorText;
|
|
39
44
|
const hasValue = dateRangeValue?.from && dateRangeValue?.to;
|
|
@@ -44,21 +49,21 @@ const RangePickerInput = ({
|
|
|
44
49
|
onChange && onChange(void 0);
|
|
45
50
|
}, [onChange]);
|
|
46
51
|
const getText = useCallback((dateToDisplay) => {
|
|
47
|
-
const
|
|
48
|
-
return formatValue(
|
|
52
|
+
const date = typeof dateToDisplay === "string" ? new Date(dateToDisplay) : dateToDisplay;
|
|
53
|
+
return formatValue(getDateToDisplay(date, timeZone), getFormatOptionsToDisplay({
|
|
49
54
|
...getDefaultDataTimeOptions(showTime),
|
|
50
55
|
...valueFormatOptions
|
|
51
|
-
});
|
|
52
|
-
}, [
|
|
56
|
+
}, timeZone));
|
|
57
|
+
}, [timeZone, formatValue, showTime, valueFormatOptions]);
|
|
53
58
|
const renderFromDate = useCallback(() => {
|
|
54
|
-
const isFromDateDefined = dateRangeValue && dateRangeValue.from;
|
|
55
|
-
const text = dateRangeValue &&
|
|
59
|
+
const isFromDateDefined = dateRangeValue && isDateLimit(dateRangeValue.from);
|
|
60
|
+
const text = dateRangeValue && isDateLimit(dateRangeValue.from) ? /* @__PURE__ */ jsx(DateValue, { children: getText(dateRangeValue.from) }) : texts?.startDatePlaceholder;
|
|
56
61
|
return /* @__PURE__ */ jsx(DateWrapper, { highlight: active && !disabled && !isFromDateDefined && highlight, children: text });
|
|
57
62
|
}, [dateRangeValue, getText, active, disabled, texts, highlight]);
|
|
58
63
|
const renderEndDate = useCallback(() => {
|
|
59
64
|
const isEndDateDefined = dateRangeValue && dateRangeValue.to;
|
|
60
65
|
const isFromDateDefined = dateRangeValue && dateRangeValue.from;
|
|
61
|
-
const text =
|
|
66
|
+
const text = dateRangeValue && isDateLimit(dateRangeValue.to) ? /* @__PURE__ */ jsx(DateValue, { children: getText(dateRangeValue.to) }) : texts?.endDatePlaceholder;
|
|
62
67
|
return /* @__PURE__ */ jsx(DateWrapper, { highlight: active && !!isFromDateDefined && !isEndDateDefined && highlight, children: text });
|
|
63
68
|
}, [dateRangeValue, getText, active, texts, highlight]);
|
|
64
69
|
const placeholder = useMemo(() => {
|