@payfit/unity-components 2.21.13 → 2.21.14
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/dist/esm/components/date-calendar/DateCalendar.js +87 -89
- package/dist/esm/components/date-calendar/DateCalendar.variants.d.ts +62 -0
- package/dist/esm/components/date-calendar/DateCalendar.variants.js +42 -0
- package/dist/esm/components/date-picker/parts/DateInput.d.ts +28 -0
- package/dist/esm/components/date-picker/parts/DateInput.js +6 -5
- package/dist/esm/components/date-range-calendar/DateRangeCalendar.d.ts +22 -0
- package/dist/esm/components/date-range-calendar/DateRangeCalendar.js +197 -0
- package/dist/esm/components/date-range-picker/DateRangePicker.d.ts +68 -0
- package/dist/esm/components/date-range-picker/DateRangePicker.js +174 -0
- package/dist/esm/components/date-range-picker/TanstackDateRangePicker.d.ts +22 -0
- package/dist/esm/components/date-range-picker/TanstackDateRangePicker.js +53 -0
- package/dist/esm/components/date-range-picker/parts/DateRangeInput.d.ts +16 -0
- package/dist/esm/components/date-range-picker/parts/DateRangeInput.js +98 -0
- package/dist/esm/components/date-range-picker-field/TanstackDateRangePickerField.d.ts +64 -0
- package/dist/esm/components/date-range-picker-field/TanstackDateRangePickerField.js +41 -0
- package/dist/esm/components/date-range-picker-field/test-utils.d.ts +19 -0
- package/dist/esm/components/date-range-picker-field/test-utils.js +66 -0
- package/dist/esm/hooks/use-tanstack-form.d.ts +36 -0
- package/dist/esm/hooks/use-tanstack-form.js +72 -60
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +462 -458
- package/dist/esm/index.storybook-testing.d.ts +1 -0
- package/dist/esm/storybook-testing.js +10 -8
- package/i18n/en-GB.json +1 -0
- package/i18n/es-ES.json +1 -0
- package/i18n/fr-FR.json +1 -0
- package/package.json +7 -7
|
@@ -1,149 +1,147 @@
|
|
|
1
|
-
import { jsx as a, jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { today as
|
|
4
|
-
import { uyTv as
|
|
5
|
-
import { Calendar as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
1
|
+
import { jsx as a, jsxs as n } from "react/jsx-runtime";
|
|
2
|
+
import { useState as y } from "react";
|
|
3
|
+
import { today as O, getLocalTimeZone as h, isToday as T } from "@internationalized/date";
|
|
4
|
+
import { uyTv as j } from "@payfit/unity-themes";
|
|
5
|
+
import { Calendar as k, Heading as F, CalendarGrid as R, CalendarGridHeader as P, CalendarHeaderCell as W, CalendarGridBody as Z, CalendarCell as $ } from "react-aria-components";
|
|
6
|
+
import { useIntl as q } from "react-intl";
|
|
7
|
+
import { IconButton as g } from "../icon-button/IconButton.js";
|
|
8
|
+
import { calendarBase as w } from "./DateCalendar.variants.js";
|
|
9
|
+
import { useMonthsList as z } from "./hooks/useMonthsList.js";
|
|
10
|
+
import { useYearsList as A } from "./hooks/useYearsList.js";
|
|
11
|
+
import { DateSegmentSelect as C } from "./parts/DateSegmentSelect.js";
|
|
12
|
+
const E = j({
|
|
13
|
+
extend: w,
|
|
11
14
|
slots: {
|
|
12
|
-
|
|
13
|
-
calendarWrapper: "uy:flex uy:flex-col uy:gap-100",
|
|
14
|
-
dialogHeader: "uy:flex uy:items-center uy:h-500 uy:w-full",
|
|
15
|
-
dialogHeaderGroup: "uy:flex uy:items-center",
|
|
16
|
-
calendarGrid: "uy:border-separate uy:border-spacing-25 uy:w-full",
|
|
17
|
-
calendarHeaderCell: "uy:typography-body-small-strong uy:sm:typography-body-strong uy:text-content-neutral-low uy:w-[44px] uy:h-[44px] uy:p-[1px] uy:uppercase",
|
|
15
|
+
calendarGrid: "uy:border-spacing-25",
|
|
18
16
|
calendarCell: [
|
|
19
|
-
// base styles
|
|
20
|
-
"uy:typography-body uy:relative uy:text-content-form-enabled uy:w-[44px] uy:h-[44px] uy:p-[1px] uy:outline-hidden uy:cursor-pointer uy:rounded-circle uy:flex uy:items-center uy:justify-center",
|
|
21
|
-
// interaction states
|
|
22
|
-
"uy:hover:bg-surface-neutral-hover uy:active:bg-surface-form-active uy:data-[pressed]:bg-surface-neutral-pressed uy:focus-visible:outline-2 uy:focus-visible:outline-solid uy:focus-visible:outline-utility-focus-ring uy:focus-visible:outline-offset-2",
|
|
23
|
-
// cells outside of current month
|
|
24
|
-
"uy:data-[outside-month]:text-content-neutral-disabled uy:data-[outside-month]:cursor-not-allowed uy:data-[disabled]:text-content-neutral-disabled uy:data-[disabled]:cursor-not-allowed uy:data-[unavailable]:text-content-neutral-disabled uy:data-[unavailable]:cursor-not-allowed",
|
|
25
17
|
// selected cells
|
|
26
18
|
"uy:data-[selected]:bg-surface-form-active uy:data-[selected]:text-content-inverted",
|
|
27
|
-
//
|
|
28
|
-
"uy:data-[today]:
|
|
19
|
+
// today dot turns white when selected
|
|
20
|
+
"uy:data-[today]:data-[selected]:after:bg-content-inverted"
|
|
29
21
|
]
|
|
30
22
|
},
|
|
31
23
|
variants: {
|
|
32
24
|
isDisabled: {
|
|
33
25
|
true: {
|
|
34
|
-
|
|
26
|
+
calendarCell: "uy:data-[selected]:bg-transparent uy:data-[selected]:text-content-neutral-disabled"
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
|
-
},
|
|
38
|
-
defaultVariants: {
|
|
39
|
-
isDisabled: !1
|
|
40
29
|
}
|
|
41
30
|
});
|
|
42
|
-
function
|
|
43
|
-
value:
|
|
44
|
-
defaultValue:
|
|
45
|
-
minValue:
|
|
46
|
-
maxValue:
|
|
47
|
-
onChange:
|
|
48
|
-
onFocusChange:
|
|
31
|
+
function J({
|
|
32
|
+
value: c,
|
|
33
|
+
defaultValue: d,
|
|
34
|
+
minValue: s,
|
|
35
|
+
maxValue: r,
|
|
36
|
+
onChange: f,
|
|
37
|
+
onFocusChange: b,
|
|
49
38
|
...t
|
|
50
39
|
}) {
|
|
51
|
-
const
|
|
52
|
-
startYear:
|
|
53
|
-
endYear:
|
|
54
|
-
}), [
|
|
55
|
-
const e =
|
|
56
|
-
return
|
|
57
|
-
}),
|
|
58
|
-
|
|
59
|
-
(
|
|
40
|
+
const m = q(), v = O(h()), p = z(), D = A({
|
|
41
|
+
startYear: s?.year,
|
|
42
|
+
endYear: r?.year
|
|
43
|
+
}), [N, G] = y(c ?? d ?? null), [i, o] = y(() => {
|
|
44
|
+
const e = c ?? d ?? v;
|
|
45
|
+
return s && e.compare(s) < 0 ? s : r && e.compare(r) > 0 ? r : e;
|
|
46
|
+
}), H = (e) => {
|
|
47
|
+
o(
|
|
48
|
+
(l) => l.set({ month: parseInt(e, 10) })
|
|
60
49
|
);
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
(
|
|
50
|
+
}, L = (e) => {
|
|
51
|
+
o(
|
|
52
|
+
(l) => l.set({ year: parseInt(e, 10) })
|
|
64
53
|
);
|
|
65
54
|
}, {
|
|
66
|
-
base:
|
|
67
|
-
calendarWrapper:
|
|
68
|
-
dialogHeader:
|
|
69
|
-
dialogHeaderGroup:
|
|
70
|
-
calendarGrid:
|
|
55
|
+
base: M,
|
|
56
|
+
calendarWrapper: S,
|
|
57
|
+
dialogHeader: x,
|
|
58
|
+
dialogHeaderGroup: u,
|
|
59
|
+
calendarGrid: I,
|
|
71
60
|
calendarHeaderCell: Y,
|
|
72
|
-
calendarCell:
|
|
73
|
-
} =
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
calendarCell: B
|
|
62
|
+
} = E({
|
|
63
|
+
isDisabled: t.isDisabled,
|
|
64
|
+
isInteractive: !t.isDisabled && !t.isReadOnly
|
|
65
|
+
});
|
|
66
|
+
return /* @__PURE__ */ a("div", { className: M(), "data-dd-privacy": "mask", children: /* @__PURE__ */ a(
|
|
67
|
+
k,
|
|
76
68
|
{
|
|
77
69
|
...t,
|
|
78
|
-
minValue:
|
|
79
|
-
maxValue:
|
|
80
|
-
value:
|
|
81
|
-
defaultValue:
|
|
70
|
+
minValue: s,
|
|
71
|
+
maxValue: r,
|
|
72
|
+
value: N,
|
|
73
|
+
defaultValue: d,
|
|
82
74
|
onChange: (e) => {
|
|
83
|
-
|
|
75
|
+
G(e), f?.(e);
|
|
84
76
|
},
|
|
85
|
-
focusedValue:
|
|
77
|
+
focusedValue: i,
|
|
86
78
|
onFocusChange: (e) => {
|
|
87
|
-
|
|
79
|
+
o(e), b?.(e);
|
|
88
80
|
},
|
|
89
|
-
children: /* @__PURE__ */
|
|
90
|
-
/* @__PURE__ */
|
|
81
|
+
children: /* @__PURE__ */ n("div", { className: S(), children: [
|
|
82
|
+
/* @__PURE__ */ n("header", { className: x(), children: [
|
|
91
83
|
/* @__PURE__ */ a(F, { className: "uy:sr-only" }),
|
|
92
|
-
/* @__PURE__ */
|
|
84
|
+
/* @__PURE__ */ n(
|
|
93
85
|
"div",
|
|
94
86
|
{
|
|
95
|
-
className:
|
|
87
|
+
className: u({
|
|
96
88
|
className: "uy:pl-100 uy:gap-200"
|
|
97
89
|
}),
|
|
98
90
|
children: [
|
|
99
91
|
/* @__PURE__ */ a(
|
|
100
|
-
|
|
92
|
+
C,
|
|
101
93
|
{
|
|
102
94
|
type: "month",
|
|
103
|
-
items:
|
|
104
|
-
value:
|
|
105
|
-
onChange:
|
|
95
|
+
items: p,
|
|
96
|
+
value: i.month.toString(),
|
|
97
|
+
onChange: H,
|
|
106
98
|
isDisabled: t.isDisabled
|
|
107
99
|
}
|
|
108
100
|
),
|
|
109
101
|
/* @__PURE__ */ a(
|
|
110
|
-
|
|
102
|
+
C,
|
|
111
103
|
{
|
|
112
104
|
type: "year",
|
|
113
|
-
items:
|
|
114
|
-
value:
|
|
115
|
-
onChange:
|
|
105
|
+
items: D,
|
|
106
|
+
value: i.year.toString(),
|
|
107
|
+
onChange: L,
|
|
116
108
|
isDisabled: t.isDisabled
|
|
117
109
|
}
|
|
118
110
|
)
|
|
119
111
|
]
|
|
120
112
|
}
|
|
121
113
|
),
|
|
122
|
-
/* @__PURE__ */
|
|
114
|
+
/* @__PURE__ */ n(
|
|
123
115
|
"div",
|
|
124
116
|
{
|
|
125
|
-
className:
|
|
117
|
+
className: u({
|
|
126
118
|
className: "uy:ml-auto uy:gap-100"
|
|
127
119
|
}),
|
|
128
120
|
children: [
|
|
129
121
|
/* @__PURE__ */ a(
|
|
130
|
-
|
|
122
|
+
g,
|
|
131
123
|
{
|
|
132
124
|
slot: "previous",
|
|
133
125
|
icon: "CaretLeftOutlined",
|
|
134
126
|
color: "neutral",
|
|
135
|
-
label:
|
|
127
|
+
label: m.formatMessage({
|
|
128
|
+
id: "unity:component:common:previous",
|
|
129
|
+
defaultMessage: "Previous"
|
|
130
|
+
}),
|
|
136
131
|
variant: "ghost",
|
|
137
132
|
isDisabled: t.isDisabled
|
|
138
133
|
}
|
|
139
134
|
),
|
|
140
135
|
/* @__PURE__ */ a(
|
|
141
|
-
|
|
136
|
+
g,
|
|
142
137
|
{
|
|
143
138
|
slot: "next",
|
|
144
139
|
icon: "CaretRightOutlined",
|
|
145
140
|
color: "neutral",
|
|
146
|
-
label:
|
|
141
|
+
label: m.formatMessage({
|
|
142
|
+
id: "unity:component:common:next",
|
|
143
|
+
defaultMessage: "Next"
|
|
144
|
+
}),
|
|
147
145
|
variant: "ghost",
|
|
148
146
|
isDisabled: t.isDisabled
|
|
149
147
|
}
|
|
@@ -152,14 +150,14 @@ function z({
|
|
|
152
150
|
}
|
|
153
151
|
)
|
|
154
152
|
] }),
|
|
155
|
-
/* @__PURE__ */
|
|
156
|
-
/* @__PURE__ */ a(
|
|
157
|
-
/* @__PURE__ */ a(
|
|
158
|
-
|
|
153
|
+
/* @__PURE__ */ n(R, { className: I(), weekdayStyle: "short", children: [
|
|
154
|
+
/* @__PURE__ */ a(P, { children: (e) => /* @__PURE__ */ a(W, { className: Y(), children: e }) }),
|
|
155
|
+
/* @__PURE__ */ a(Z, { children: (e) => /* @__PURE__ */ a(
|
|
156
|
+
$,
|
|
159
157
|
{
|
|
160
158
|
date: e,
|
|
161
|
-
"data-today": T(e,
|
|
162
|
-
className:
|
|
159
|
+
"data-today": T(e, h()) ? !0 : void 0,
|
|
160
|
+
className: B()
|
|
163
161
|
}
|
|
164
162
|
) })
|
|
165
163
|
] })
|
|
@@ -167,7 +165,7 @@ function z({
|
|
|
167
165
|
}
|
|
168
166
|
) });
|
|
169
167
|
}
|
|
170
|
-
|
|
168
|
+
J.displayName = "DateCalendar";
|
|
171
169
|
export {
|
|
172
|
-
|
|
170
|
+
J as DateCalendar
|
|
173
171
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base calendar styles shared between DateCalendar and DateRangeCalendar.
|
|
3
|
+
* Use `extend: calendarBase` in component-specific uyTv definitions.
|
|
4
|
+
*/
|
|
5
|
+
export declare const calendarBase: import('tailwind-variants').TVReturnType<{
|
|
6
|
+
isDisabled: {
|
|
7
|
+
true: {
|
|
8
|
+
calendarHeaderCell: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
isInteractive: {
|
|
12
|
+
true: {
|
|
13
|
+
calendarCell: string[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}, {
|
|
17
|
+
base: string;
|
|
18
|
+
calendarWrapper: string;
|
|
19
|
+
dialogHeader: string;
|
|
20
|
+
dialogHeaderGroup: string;
|
|
21
|
+
calendarGrid: string;
|
|
22
|
+
calendarHeaderCell: string;
|
|
23
|
+
calendarCell: string[];
|
|
24
|
+
}, undefined, {
|
|
25
|
+
isDisabled: {
|
|
26
|
+
true: {
|
|
27
|
+
calendarHeaderCell: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
isInteractive: {
|
|
31
|
+
true: {
|
|
32
|
+
calendarCell: string[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}, {
|
|
36
|
+
base: string;
|
|
37
|
+
calendarWrapper: string;
|
|
38
|
+
dialogHeader: string;
|
|
39
|
+
dialogHeaderGroup: string;
|
|
40
|
+
calendarGrid: string;
|
|
41
|
+
calendarHeaderCell: string;
|
|
42
|
+
calendarCell: string[];
|
|
43
|
+
}, import('tailwind-variants').TVReturnType<{
|
|
44
|
+
isDisabled: {
|
|
45
|
+
true: {
|
|
46
|
+
calendarHeaderCell: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
isInteractive: {
|
|
50
|
+
true: {
|
|
51
|
+
calendarCell: string[];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}, {
|
|
55
|
+
base: string;
|
|
56
|
+
calendarWrapper: string;
|
|
57
|
+
dialogHeader: string;
|
|
58
|
+
dialogHeaderGroup: string;
|
|
59
|
+
calendarGrid: string;
|
|
60
|
+
calendarHeaderCell: string;
|
|
61
|
+
calendarCell: string[];
|
|
62
|
+
}, undefined, unknown, unknown, undefined>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { uyTv as a } from "@payfit/unity-themes";
|
|
2
|
+
const t = a({
|
|
3
|
+
slots: {
|
|
4
|
+
base: "",
|
|
5
|
+
calendarWrapper: "uy:flex uy:flex-col uy:gap-100",
|
|
6
|
+
dialogHeader: "uy:flex uy:items-center uy:h-500 uy:w-full",
|
|
7
|
+
dialogHeaderGroup: "uy:flex uy:items-center",
|
|
8
|
+
calendarGrid: "uy:border-separate uy:w-full",
|
|
9
|
+
calendarHeaderCell: "uy:typography-body-small-strong uy:sm:typography-body-strong uy:text-content-neutral-low uy:w-[44px] uy:h-[44px] uy:p-[1px] uy:uppercase",
|
|
10
|
+
calendarCell: [
|
|
11
|
+
// base styles
|
|
12
|
+
"uy:typography-body uy:relative uy:text-content-form-enabled uy:w-[44px] uy:h-[44px] uy:p-[1px] uy:outline-hidden uy:cursor-pointer uy:rounded-circle uy:flex uy:items-center uy:justify-center",
|
|
13
|
+
// cells outside of current month
|
|
14
|
+
"uy:data-[outside-month]:text-content-neutral-disabled uy:data-[outside-month]:cursor-not-allowed uy:data-[disabled]:text-content-neutral-disabled uy:data-[disabled]:cursor-not-allowed uy:data-[unavailable]:text-content-neutral-disabled uy:data-[unavailable]:cursor-not-allowed",
|
|
15
|
+
// "current day" (today) indicator — dot
|
|
16
|
+
"uy:data-[today]:after:content-[''] uy:data-[today]:after:absolute uy:data-[today]:after:bottom-[6px] uy:data-[today]:after:w-[6px] uy:data-[today]:after:h-[6px] uy:data-[today]:after:rounded-circle uy:data-[today]:after:bg-surface-primary-active"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
variants: {
|
|
20
|
+
isDisabled: {
|
|
21
|
+
true: {
|
|
22
|
+
calendarHeaderCell: "uy:text-content-form-disabled"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
isInteractive: {
|
|
26
|
+
true: {
|
|
27
|
+
calendarCell: [
|
|
28
|
+
"uy:hover:bg-surface-neutral-hover uy:active:bg-surface-form-active uy:data-[pressed]:bg-surface-neutral-pressed uy:data-[focus-visible]:outline-2 uy:data-[focus-visible]:outline-solid uy:data-[focus-visible]:outline-utility-focus-ring uy:data-[focus-visible]:outline-offset-2",
|
|
29
|
+
// Disable hover on non-selectable cells
|
|
30
|
+
"uy:data-[disabled]:hover:bg-transparent uy:data-[unavailable]:hover:bg-transparent uy:data-[outside-month]:hover:bg-transparent"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
defaultVariants: {
|
|
36
|
+
isDisabled: !1,
|
|
37
|
+
isInteractive: !0
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
export {
|
|
41
|
+
t as calendarBase
|
|
42
|
+
};
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { CalendarDate } from '@internationalized/date';
|
|
2
2
|
import { ReactElement } from 'react';
|
|
3
3
|
import { DateFieldProps } from 'react-aria-components';
|
|
4
|
+
export declare const dateSegment: import('tailwind-variants').TVReturnType<{
|
|
5
|
+
isPlaceholder: {
|
|
6
|
+
true: string;
|
|
7
|
+
false: string;
|
|
8
|
+
};
|
|
9
|
+
isLiteral: {
|
|
10
|
+
true: string;
|
|
11
|
+
false: string;
|
|
12
|
+
};
|
|
13
|
+
}, undefined, "uy:group uy:box-content uy:rounded-25 uy:px-25 uy:text-end uy:tabular-nums! uy:outline-none uy:typography-body uy:focus:bg-surface-form-active uy:focus:rounded-25 uy:focus:text-content-inverted uy:data-[disabled]:text-content-form-disabled", {
|
|
14
|
+
isPlaceholder: {
|
|
15
|
+
true: string;
|
|
16
|
+
false: string;
|
|
17
|
+
};
|
|
18
|
+
isLiteral: {
|
|
19
|
+
true: string;
|
|
20
|
+
false: string;
|
|
21
|
+
};
|
|
22
|
+
}, undefined, import('tailwind-variants').TVReturnType<{
|
|
23
|
+
isPlaceholder: {
|
|
24
|
+
true: string;
|
|
25
|
+
false: string;
|
|
26
|
+
};
|
|
27
|
+
isLiteral: {
|
|
28
|
+
true: string;
|
|
29
|
+
false: string;
|
|
30
|
+
};
|
|
31
|
+
}, undefined, "uy:group uy:box-content uy:rounded-25 uy:px-25 uy:text-end uy:tabular-nums! uy:outline-none uy:typography-body uy:focus:bg-surface-form-active uy:focus:rounded-25 uy:focus:text-content-inverted uy:data-[disabled]:text-content-form-disabled", unknown, unknown, undefined>>;
|
|
4
32
|
export declare const dateInput: import('tailwind-variants').TVReturnType<{
|
|
5
33
|
isInvalid: {
|
|
6
34
|
true: {
|
|
@@ -14,7 +14,7 @@ const M = i({
|
|
|
14
14
|
false: "uy:text-content-form-enabled"
|
|
15
15
|
},
|
|
16
16
|
isLiteral: {
|
|
17
|
-
true: "uy:text-content-
|
|
17
|
+
true: "uy:text-content-neutral-lowest-enabled",
|
|
18
18
|
false: ""
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -61,13 +61,13 @@ function P({
|
|
|
61
61
|
isDisabled: s,
|
|
62
62
|
onClearButtonPress: d
|
|
63
63
|
}) {
|
|
64
|
-
const t = I(), u = b(x), { dateValue: c } = u, { base:
|
|
64
|
+
const t = I(), u = b(x), { dateValue: c } = u, { base: y, input: m, state: f } = N({
|
|
65
65
|
isInvalid: !!o,
|
|
66
66
|
isReadOnly: !!n,
|
|
67
67
|
isDisabled: !!s
|
|
68
68
|
}), p = c && !r && !n && !s;
|
|
69
|
-
return /* @__PURE__ */ l("div", { className:
|
|
70
|
-
/* @__PURE__ */ e(g, { className:
|
|
69
|
+
return /* @__PURE__ */ l("div", { className: y(), children: [
|
|
70
|
+
/* @__PURE__ */ e(g, { className: m(), children: (a) => /* @__PURE__ */ e(
|
|
71
71
|
v,
|
|
72
72
|
{
|
|
73
73
|
segment: a,
|
|
@@ -120,5 +120,6 @@ function P({
|
|
|
120
120
|
P.displayName = "DateInput";
|
|
121
121
|
export {
|
|
122
122
|
P as DateInput,
|
|
123
|
-
N as dateInput
|
|
123
|
+
N as dateInput,
|
|
124
|
+
M as dateSegment
|
|
124
125
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DateValue } from '@internationalized/date';
|
|
2
|
+
import { RangeCalendarProps as AriaRangeCalendarProps } from 'react-aria-components';
|
|
3
|
+
type PropsFromAriaRangeCalendar<TDate extends DateValue> = AriaRangeCalendarProps<TDate>;
|
|
4
|
+
export type DateRangeCalendarProps<TDate extends DateValue> = PropsFromAriaRangeCalendar<TDate>;
|
|
5
|
+
/**
|
|
6
|
+
* The `DateRangeCalendar` component displays a calendar grid and allows users to select a date range (start and end dates).
|
|
7
|
+
* @param {DateRangeCalendarProps} props - The props for the `DateRangeCalendar` component
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { DateRangeCalendar } from '@payfit/unity-components'
|
|
11
|
+
* import { CalendarDate } from '@internationalized/date'
|
|
12
|
+
*
|
|
13
|
+
* const [range, setRange] = useState({ start: new CalendarDate(2024, 1, 1), end: new CalendarDate(2024, 1, 15) })
|
|
14
|
+
* <DateRangeCalendar value={range} onChange={setRange} />
|
|
15
|
+
* ```
|
|
16
|
+
* @see {@link DateRangeCalendarProps} for all available props
|
|
17
|
+
*/
|
|
18
|
+
declare function DateRangeCalendar<TDate extends DateValue>({ value, defaultValue, minValue, maxValue, onChange, onFocusChange, ...props }: DateRangeCalendarProps<TDate>): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
declare namespace DateRangeCalendar {
|
|
20
|
+
var displayName: string;
|
|
21
|
+
}
|
|
22
|
+
export { DateRangeCalendar };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { jsx as t, jsxs as d } from "react/jsx-runtime";
|
|
2
|
+
import { useState as L } from "react";
|
|
3
|
+
import { today as M, getLocalTimeZone as h, isToday as R } from "@internationalized/date";
|
|
4
|
+
import { uyTv as S } from "@payfit/unity-themes";
|
|
5
|
+
import { RangeCalendar as Y, Heading as B, CalendarGrid as O, CalendarGridHeader as T, CalendarHeaderCell as j, CalendarGridBody as k, CalendarCell as F } from "react-aria-components";
|
|
6
|
+
import { useIntl as P } from "react-intl";
|
|
7
|
+
import { calendarBase as W } from "../date-calendar/DateCalendar.variants.js";
|
|
8
|
+
import { useMonthsList as Z } from "../date-calendar/hooks/useMonthsList.js";
|
|
9
|
+
import { useYearsList as $ } from "../date-calendar/hooks/useYearsList.js";
|
|
10
|
+
import { DateSegmentSelect as m } from "../date-calendar/parts/DateSegmentSelect.js";
|
|
11
|
+
import { IconButton as b } from "../icon-button/IconButton.js";
|
|
12
|
+
const q = S({
|
|
13
|
+
extend: W,
|
|
14
|
+
slots: {
|
|
15
|
+
calendarGrid: [
|
|
16
|
+
"uy:border-spacing-y-25 uy:border-spacing-x-0",
|
|
17
|
+
// All <td> with selected cells need relative positioning for pseudo-elements
|
|
18
|
+
"uy:[&_td:has(>[data-selected])]:relative",
|
|
19
|
+
// Middle cells: full background on the <td>
|
|
20
|
+
"uy:[&_td:has(>[data-selected])]:bg-surface-primary-lowest",
|
|
21
|
+
// Start td: no bg, use :before for right-half band
|
|
22
|
+
"uy:[&_td:has(>[data-selection-start])]:bg-transparent",
|
|
23
|
+
"uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:content-[''] uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:absolute uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:top-0 uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:right-0 uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:w-1/2 uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:h-full uy:[&_td:has(>[data-selection-start]:not([data-selection-end]))]:before:bg-surface-primary-lowest",
|
|
24
|
+
// End td: no bg, use :before for left-half band
|
|
25
|
+
"uy:[&_td:has(>[data-selection-end])]:bg-transparent",
|
|
26
|
+
"uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:content-[''] uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:absolute uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:top-0 uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:left-0 uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:w-1/2 uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:h-full uy:[&_td:has(>[data-selection-end]:not([data-selection-start]))]:before:bg-surface-primary-lowest",
|
|
27
|
+
// Single day range — no band at all
|
|
28
|
+
"uy:[&_td:has(>[data-selection-start][data-selection-end])]:bg-transparent"
|
|
29
|
+
],
|
|
30
|
+
calendarHeaderCell: "uy:text-center",
|
|
31
|
+
calendarCell: [
|
|
32
|
+
// selected cells (range middle) — bg is handled by the <td>, text stays default
|
|
33
|
+
"uy:data-[selected]:rounded-none",
|
|
34
|
+
// selection start — blue circle
|
|
35
|
+
"uy:data-[selection-start]:bg-surface-form-active uy:data-[selection-start]:text-content-inverted uy:data-[selection-start]:rounded-circle",
|
|
36
|
+
// selection end — blue circle
|
|
37
|
+
"uy:data-[selection-end]:bg-surface-form-active uy:data-[selection-end]:text-content-inverted uy:data-[selection-end]:rounded-circle",
|
|
38
|
+
// today dot turns white when on start/end cells
|
|
39
|
+
"uy:data-[today]:data-[selection-start]:after:bg-content-inverted uy:data-[today]:data-[selection-end]:after:bg-content-inverted"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
variants: {
|
|
43
|
+
isDisabled: {
|
|
44
|
+
true: {
|
|
45
|
+
calendarGrid: "uy:[&_td]:bg-transparent uy:[&_td]:before:hidden",
|
|
46
|
+
calendarCell: "uy:data-[selected]:bg-transparent uy:data-[selection-start]:bg-transparent uy:data-[selection-start]:text-content-neutral-disabled uy:data-[selection-end]:bg-transparent uy:data-[selection-end]:text-content-neutral-disabled uy:cursor-not-allowed"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
isInteractive: {
|
|
50
|
+
true: {
|
|
51
|
+
calendarCell: [
|
|
52
|
+
// selected middle cells (not start/end): hover shows a circle with primary-lowest-hover
|
|
53
|
+
"uy:data-[selected]:not-data-[selection-start]:not-data-[selection-end]:hover:bg-surface-primary-lowest-hover uy:data-[selected]:not-data-[selection-start]:not-data-[selection-end]:hover:rounded-circle"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
function z({
|
|
60
|
+
value: i,
|
|
61
|
+
defaultValue: c,
|
|
62
|
+
minValue: n,
|
|
63
|
+
maxValue: s,
|
|
64
|
+
onChange: f,
|
|
65
|
+
onFocusChange: g,
|
|
66
|
+
...a
|
|
67
|
+
}) {
|
|
68
|
+
const u = P(), p = M(h()), v = Z(), C = $({
|
|
69
|
+
startYear: n?.year,
|
|
70
|
+
endYear: s?.year
|
|
71
|
+
}), [r, o] = L(() => {
|
|
72
|
+
const e = i?.start ?? c?.start ?? p;
|
|
73
|
+
return n && e.compare(n) < 0 ? n : s && e.compare(s) > 0 ? s : e;
|
|
74
|
+
}), _ = (e) => {
|
|
75
|
+
o(
|
|
76
|
+
(l) => l.set({ month: parseInt(e, 10) })
|
|
77
|
+
);
|
|
78
|
+
}, D = (e) => {
|
|
79
|
+
o(
|
|
80
|
+
(l) => l.set({ year: parseInt(e, 10) })
|
|
81
|
+
);
|
|
82
|
+
}, {
|
|
83
|
+
base: N,
|
|
84
|
+
calendarWrapper: x,
|
|
85
|
+
dialogHeader: w,
|
|
86
|
+
dialogHeaderGroup: y,
|
|
87
|
+
calendarGrid: G,
|
|
88
|
+
calendarHeaderCell: H,
|
|
89
|
+
calendarCell: I
|
|
90
|
+
} = q({
|
|
91
|
+
isDisabled: a.isDisabled,
|
|
92
|
+
isInteractive: !a.isDisabled && !a.isReadOnly
|
|
93
|
+
});
|
|
94
|
+
return /* @__PURE__ */ t("div", { className: N(), "data-dd-privacy": "mask", children: /* @__PURE__ */ t(
|
|
95
|
+
Y,
|
|
96
|
+
{
|
|
97
|
+
...a,
|
|
98
|
+
minValue: n,
|
|
99
|
+
maxValue: s,
|
|
100
|
+
value: i,
|
|
101
|
+
defaultValue: c,
|
|
102
|
+
onChange: f,
|
|
103
|
+
focusedValue: r,
|
|
104
|
+
onFocusChange: (e) => {
|
|
105
|
+
o(e), g?.(e);
|
|
106
|
+
},
|
|
107
|
+
children: /* @__PURE__ */ d("div", { className: x(), children: [
|
|
108
|
+
/* @__PURE__ */ d("header", { className: w(), children: [
|
|
109
|
+
/* @__PURE__ */ t(B, { className: "uy:sr-only" }),
|
|
110
|
+
/* @__PURE__ */ d(
|
|
111
|
+
"div",
|
|
112
|
+
{
|
|
113
|
+
className: y({
|
|
114
|
+
className: "uy:pl-100 uy:gap-200"
|
|
115
|
+
}),
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ t(
|
|
118
|
+
m,
|
|
119
|
+
{
|
|
120
|
+
type: "month",
|
|
121
|
+
items: v,
|
|
122
|
+
value: r.month.toString(),
|
|
123
|
+
onChange: _,
|
|
124
|
+
isDisabled: a.isDisabled
|
|
125
|
+
}
|
|
126
|
+
),
|
|
127
|
+
/* @__PURE__ */ t(
|
|
128
|
+
m,
|
|
129
|
+
{
|
|
130
|
+
type: "year",
|
|
131
|
+
items: C,
|
|
132
|
+
value: r.year.toString(),
|
|
133
|
+
onChange: D,
|
|
134
|
+
isDisabled: a.isDisabled
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ d(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
className: y({
|
|
144
|
+
className: "uy:ml-auto uy:gap-100"
|
|
145
|
+
}),
|
|
146
|
+
children: [
|
|
147
|
+
/* @__PURE__ */ t(
|
|
148
|
+
b,
|
|
149
|
+
{
|
|
150
|
+
slot: "previous",
|
|
151
|
+
icon: "CaretLeftOutlined",
|
|
152
|
+
color: "neutral",
|
|
153
|
+
label: u.formatMessage({
|
|
154
|
+
id: "unity:component:common:previous",
|
|
155
|
+
defaultMessage: "Previous"
|
|
156
|
+
}),
|
|
157
|
+
variant: "ghost",
|
|
158
|
+
isDisabled: a.isDisabled
|
|
159
|
+
}
|
|
160
|
+
),
|
|
161
|
+
/* @__PURE__ */ t(
|
|
162
|
+
b,
|
|
163
|
+
{
|
|
164
|
+
slot: "next",
|
|
165
|
+
icon: "CaretRightOutlined",
|
|
166
|
+
color: "neutral",
|
|
167
|
+
label: u.formatMessage({
|
|
168
|
+
id: "unity:component:common:next",
|
|
169
|
+
defaultMessage: "Next"
|
|
170
|
+
}),
|
|
171
|
+
variant: "ghost",
|
|
172
|
+
isDisabled: a.isDisabled
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
] }),
|
|
179
|
+
/* @__PURE__ */ d(O, { className: G(), weekdayStyle: "short", children: [
|
|
180
|
+
/* @__PURE__ */ t(T, { children: (e) => /* @__PURE__ */ t(j, { className: H(), children: e }) }),
|
|
181
|
+
/* @__PURE__ */ t(k, { children: (e) => /* @__PURE__ */ t(
|
|
182
|
+
F,
|
|
183
|
+
{
|
|
184
|
+
date: e,
|
|
185
|
+
"data-today": R(e, h()) ? !0 : void 0,
|
|
186
|
+
className: I()
|
|
187
|
+
}
|
|
188
|
+
) })
|
|
189
|
+
] })
|
|
190
|
+
] })
|
|
191
|
+
}
|
|
192
|
+
) });
|
|
193
|
+
}
|
|
194
|
+
z.displayName = "DateRangeCalendar";
|
|
195
|
+
export {
|
|
196
|
+
z as DateRangeCalendar
|
|
197
|
+
};
|