@opengovsg/oui 0.0.0-snapshot-20250320092809 → 0.0.0-snapshot-20250326085831
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/cjs/button/button.cjs +1 -1
- package/dist/cjs/calendar/agnostic-calendar-state-context.cjs +13 -0
- package/dist/cjs/calendar/calendar-bottom-content.cjs +51 -0
- package/dist/cjs/calendar/calendar-grid-header.cjs +28 -0
- package/dist/cjs/calendar/calendar-header.cjs +74 -0
- package/dist/cjs/calendar/calendar-month-day-selector.cjs +86 -0
- package/dist/cjs/calendar/calendar-style-context.cjs +0 -25
- package/dist/cjs/calendar/calendar.cjs +143 -4
- package/dist/cjs/calendar/hooks/index.cjs +11 -0
- package/dist/cjs/calendar/hooks/use-calendar-i18n.cjs +33 -0
- package/dist/cjs/calendar/hooks/use-calendar-selectors.cjs +41 -0
- package/dist/cjs/calendar/index.cjs +1 -1
- package/dist/cjs/combo-box/combo-box.cjs +1 -1
- package/dist/cjs/index.cjs +9 -5
- package/dist/cjs/range-calendar/index.cjs +10 -0
- package/dist/cjs/range-calendar/range-calendar.cjs +188 -0
- package/dist/cjs/select/select.cjs +1 -1
- package/dist/cjs/tag-field/tag-field.cjs +2 -2
- package/dist/cjs/text-area-field/text-area-field.cjs +1 -1
- package/dist/cjs/text-field/text-field.cjs +1 -1
- package/dist/esm/button/button.js +1 -1
- package/dist/esm/calendar/agnostic-calendar-state-context.js +10 -0
- package/dist/esm/calendar/calendar-bottom-content.js +49 -0
- package/dist/esm/calendar/calendar-grid-header.js +26 -0
- package/dist/esm/calendar/calendar-header.js +72 -0
- package/dist/esm/calendar/calendar-month-day-selector.js +84 -0
- package/dist/esm/calendar/calendar-style-context.js +1 -25
- package/dist/esm/calendar/calendar.js +147 -9
- package/dist/esm/calendar/hooks/index.js +3 -0
- package/dist/esm/calendar/hooks/use-calendar-i18n.js +30 -0
- package/dist/esm/calendar/hooks/use-calendar-selectors.js +39 -0
- package/dist/esm/calendar/index.js +2 -2
- package/dist/esm/combo-box/combo-box.js +1 -1
- package/dist/esm/index.js +5 -4
- package/dist/esm/range-calendar/index.js +2 -0
- package/dist/esm/range-calendar/range-calendar.js +184 -0
- package/dist/esm/select/select.js +1 -1
- package/dist/esm/tag-field/tag-field.js +2 -2
- package/dist/esm/text-area-field/text-area-field.js +1 -1
- package/dist/esm/text-field/text-field.js +1 -1
- package/dist/types/calendar/agnostic-calendar-state-context.d.ts +3 -0
- package/dist/types/calendar/agnostic-calendar-state-context.d.ts.map +1 -0
- package/dist/types/calendar/calendar-bottom-content.d.ts +4 -0
- package/dist/types/calendar/calendar-bottom-content.d.ts.map +1 -0
- package/dist/types/calendar/calendar-grid-header.d.ts +2 -0
- package/dist/types/calendar/calendar-grid-header.d.ts.map +1 -0
- package/dist/types/calendar/calendar-header.d.ts +6 -0
- package/dist/types/calendar/calendar-header.d.ts.map +1 -0
- package/dist/types/calendar/calendar-month-day-selector.d.ts +2 -0
- package/dist/types/calendar/calendar-month-day-selector.d.ts.map +1 -0
- package/dist/types/calendar/calendar-style-context.d.ts +10 -1030
- package/dist/types/calendar/calendar-style-context.d.ts.map +1 -1
- package/dist/types/calendar/calendar.d.ts +5 -2
- package/dist/types/calendar/calendar.d.ts.map +1 -1
- package/dist/types/calendar/hooks/index.d.ts +3 -0
- package/dist/types/calendar/hooks/index.d.ts.map +1 -0
- package/dist/types/calendar/hooks/use-calendar-i18n.d.ts +4 -0
- package/dist/types/calendar/hooks/use-calendar-i18n.d.ts.map +1 -0
- package/dist/types/calendar/hooks/use-calendar-selectors.d.ts +13 -0
- package/dist/types/calendar/hooks/use-calendar-selectors.d.ts.map +1 -0
- package/dist/types/calendar/types.d.ts +5 -4
- package/dist/types/calendar/types.d.ts.map +1 -1
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/range-calendar/index.d.ts +2 -0
- package/dist/types/range-calendar/index.d.ts.map +1 -0
- package/dist/types/range-calendar/range-calendar.d.ts +69 -0
- package/dist/types/range-calendar/range-calendar.d.ts.map +1 -0
- package/dist/types/tag-field/tag-field-tag-list.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/calendar/calendar-base.cjs +0 -347
- package/dist/esm/calendar/calendar-base.js +0 -343
- package/dist/types/calendar/calendar-base.d.ts +0 -14
- package/dist/types/calendar/calendar-base.d.ts.map +0 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var date = require('@internationalized/date');
|
|
8
|
+
var reactAriaComponents = require('react-aria-components');
|
|
9
|
+
var useDeepCompare = require('use-deep-compare');
|
|
10
|
+
var ouiTheme = require('@opengovsg/oui-theme');
|
|
11
|
+
var agnosticCalendarStateContext = require('../calendar/agnostic-calendar-state-context.cjs');
|
|
12
|
+
var calendarBottomContent = require('../calendar/calendar-bottom-content.cjs');
|
|
13
|
+
var calendarGridHeader = require('../calendar/calendar-grid-header.cjs');
|
|
14
|
+
var calendarHeader = require('../calendar/calendar-header.cjs');
|
|
15
|
+
var utils = require('../system/utils.cjs');
|
|
16
|
+
var calendarStyleContext = require('../calendar/calendar-style-context.cjs');
|
|
17
|
+
|
|
18
|
+
const RangeCalendar = react.forwardRef(function RangeCalendar2(originalProps, ref) {
|
|
19
|
+
const [props, variantProps] = utils.mapPropsVariants(
|
|
20
|
+
originalProps,
|
|
21
|
+
ouiTheme.calendarStyles.variantKeys
|
|
22
|
+
);
|
|
23
|
+
const {
|
|
24
|
+
className,
|
|
25
|
+
classNames,
|
|
26
|
+
weekdayStyle = "narrow",
|
|
27
|
+
minValue = new date.CalendarDate(1900, 0, 1),
|
|
28
|
+
maxValue = new date.CalendarDate(2100, 12, 31),
|
|
29
|
+
bottomContent,
|
|
30
|
+
showTodayButton = true,
|
|
31
|
+
errorMessage,
|
|
32
|
+
...restProps
|
|
33
|
+
} = props;
|
|
34
|
+
const slots = useDeepCompare.useDeepCompareMemo(
|
|
35
|
+
() => ouiTheme.calendarStyles({ ...variantProps, isRange: true }),
|
|
36
|
+
[variantProps]
|
|
37
|
+
);
|
|
38
|
+
const context = react.useMemo(
|
|
39
|
+
() => ({
|
|
40
|
+
slots,
|
|
41
|
+
classNames,
|
|
42
|
+
className,
|
|
43
|
+
size: variantProps.size ?? ouiTheme.calendarStyles.defaultVariants.size
|
|
44
|
+
}),
|
|
45
|
+
[className, classNames, slots, variantProps.size]
|
|
46
|
+
);
|
|
47
|
+
const numberOfVisibleMonths = props.visibleDuration?.months ?? 1;
|
|
48
|
+
const dateToHighlight = react.useMemo(() => {
|
|
49
|
+
if (props.defaultFocusedValue !== void 0) {
|
|
50
|
+
return props.defaultFocusedValue;
|
|
51
|
+
}
|
|
52
|
+
return date.today(date.getLocalTimeZone());
|
|
53
|
+
}, [props.defaultFocusedValue]);
|
|
54
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
55
|
+
reactAriaComponents.RangeCalendar,
|
|
56
|
+
{
|
|
57
|
+
...restProps,
|
|
58
|
+
ref,
|
|
59
|
+
minValue,
|
|
60
|
+
maxValue,
|
|
61
|
+
className: ouiTheme.composeRenderProps(
|
|
62
|
+
className,
|
|
63
|
+
(className2, renderProps) => slots.base({
|
|
64
|
+
className: ouiTheme.cn(classNames?.base, className2),
|
|
65
|
+
...renderProps
|
|
66
|
+
})
|
|
67
|
+
),
|
|
68
|
+
children: [
|
|
69
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactAriaComponents.Provider, { values: [[calendarStyleContext.CalendarStyleContext, context]], children: /* @__PURE__ */ jsxRuntime.jsxs(RangeCalendarStateWrapper, { children: [
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
className: slots.gridWrapper({
|
|
74
|
+
className: classNames?.gridWrapper
|
|
75
|
+
}),
|
|
76
|
+
children: Array.from({ length: numberOfVisibleMonths }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
77
|
+
"div",
|
|
78
|
+
{
|
|
79
|
+
className: slots.calendar({ className: classNames?.calendar }),
|
|
80
|
+
children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsx(calendarHeader.CalendarHeader, { offsetMonths: index }),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
83
|
+
reactAriaComponents.CalendarGrid,
|
|
84
|
+
{
|
|
85
|
+
className: slots.grid({ className: classNames?.grid }),
|
|
86
|
+
weekdayStyle,
|
|
87
|
+
offset: { months: index },
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx(calendarGridHeader.CalendarGridHeader, {}),
|
|
90
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
reactAriaComponents.CalendarGridBody,
|
|
92
|
+
{
|
|
93
|
+
className: slots.gridBody({
|
|
94
|
+
className: classNames?.gridBody
|
|
95
|
+
}),
|
|
96
|
+
children: (date) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
97
|
+
RangeCalendarCell,
|
|
98
|
+
{
|
|
99
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
100
|
+
dateToHighlight,
|
|
101
|
+
date,
|
|
102
|
+
isMultipleMonths: numberOfVisibleMonths >= 2
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
index
|
|
113
|
+
))
|
|
114
|
+
}
|
|
115
|
+
),
|
|
116
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
117
|
+
calendarBottomContent.CalendarBottomContent,
|
|
118
|
+
{
|
|
119
|
+
bottomContent,
|
|
120
|
+
showTodayButton
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
] }) }),
|
|
124
|
+
errorMessage && /* @__PURE__ */ jsxRuntime.jsx(
|
|
125
|
+
reactAriaComponents.Text,
|
|
126
|
+
{
|
|
127
|
+
className: slots.errorMessage({
|
|
128
|
+
className: classNames?.errorMessage
|
|
129
|
+
}),
|
|
130
|
+
slot: "errorMessage",
|
|
131
|
+
children: errorMessage
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
const RangeCalendarStateWrapper = ({
|
|
139
|
+
children
|
|
140
|
+
}) => {
|
|
141
|
+
const state = react.useContext(reactAriaComponents.RangeCalendarStateContext);
|
|
142
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactAriaComponents.Provider, { values: [[agnosticCalendarStateContext.AgnosticCalendarStateContext, state]], children });
|
|
143
|
+
};
|
|
144
|
+
const RangeCalendarCell = ({
|
|
145
|
+
date: date$1,
|
|
146
|
+
isMultipleMonths,
|
|
147
|
+
dateToHighlight,
|
|
148
|
+
firstDayOfWeek
|
|
149
|
+
}) => {
|
|
150
|
+
const { classNames, slots } = calendarStyleContext.useCalendarStyleContext();
|
|
151
|
+
const state = react.useContext(agnosticCalendarStateContext.AgnosticCalendarStateContext);
|
|
152
|
+
const { locale } = reactAriaComponents.useLocale();
|
|
153
|
+
const dataAttributes = react.useMemo(() => {
|
|
154
|
+
const isDateHighlighted = dateToHighlight ? date$1.compare(dateToHighlight) === 0 : false;
|
|
155
|
+
const isSelected = state.isSelected(date$1);
|
|
156
|
+
const isDisabled = state.isCellDisabled(date$1);
|
|
157
|
+
const isInvalid = state.isInvalid(date$1);
|
|
158
|
+
const isFirstSelectedAfterDisabled = !isDisabled && !isInvalid && state.isCellUnavailable(date$1.subtract({ days: 1 }));
|
|
159
|
+
const isLastSelectedBeforeDisabled = !isDisabled && !isInvalid && state.isCellUnavailable(date$1.add({ days: 1 }));
|
|
160
|
+
const dayOfWeek = date.getDayOfWeek(date$1, locale, firstDayOfWeek);
|
|
161
|
+
const isRangeStart = isSelected && (isFirstSelectedAfterDisabled || dayOfWeek === 0 || date$1.day === 1);
|
|
162
|
+
const isRangeEnd = isSelected && (isLastSelectedBeforeDisabled || dayOfWeek === 6 || date$1.day === date$1.calendar.getDaysInMonth(date$1));
|
|
163
|
+
return {
|
|
164
|
+
"data-highlighted": ouiTheme.dataAttr(isDateHighlighted),
|
|
165
|
+
"data-range-end": ouiTheme.dataAttr(isRangeEnd),
|
|
166
|
+
"data-range-start": ouiTheme.dataAttr(isRangeStart)
|
|
167
|
+
};
|
|
168
|
+
}, [date$1, dateToHighlight, firstDayOfWeek, locale, state]);
|
|
169
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
170
|
+
reactAriaComponents.CalendarCell,
|
|
171
|
+
{
|
|
172
|
+
className: ouiTheme.composeRenderProps(
|
|
173
|
+
classNames?.cell,
|
|
174
|
+
(className, renderProps) => slots.cell({
|
|
175
|
+
className,
|
|
176
|
+
isMultipleMonths,
|
|
177
|
+
...renderProps
|
|
178
|
+
})
|
|
179
|
+
),
|
|
180
|
+
...dataAttributes,
|
|
181
|
+
date: date$1
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
exports.RangeCalendar = RangeCalendar;
|
|
187
|
+
exports.RangeCalendarCell = RangeCalendarCell;
|
|
188
|
+
exports.RangeCalendarStateWrapper = RangeCalendarStateWrapper;
|
|
@@ -6,9 +6,9 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var reactAriaComponents = require('react-aria-components');
|
|
8
8
|
var ouiTheme = require('@opengovsg/oui-theme');
|
|
9
|
+
var field = require('../field/field.cjs');
|
|
9
10
|
var utils = require('../system/utils.cjs');
|
|
10
11
|
var selectVariantContext = require('./select-variant-context.cjs');
|
|
11
|
-
var field = require('../field/field.cjs');
|
|
12
12
|
var chevronDown = require('../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-down.cjs');
|
|
13
13
|
var button = require('../button/button.cjs');
|
|
14
14
|
|
|
@@ -6,14 +6,14 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var reactAriaComponents = require('react-aria-components');
|
|
8
8
|
var ouiTheme = require('@opengovsg/oui-theme');
|
|
9
|
+
var field = require('../field/field.cjs');
|
|
10
|
+
var input = require('../input/input.cjs');
|
|
9
11
|
var tagFieldItem = require('./tag-field-item.cjs');
|
|
10
12
|
var tagFieldList = require('./tag-field-list.cjs');
|
|
11
13
|
var tagFieldRoot = require('./tag-field-root.cjs');
|
|
12
14
|
var tagFieldTagList = require('./tag-field-tag-list.cjs');
|
|
13
15
|
var tagFieldTrigger = require('./tag-field-trigger.cjs');
|
|
14
16
|
var chevronDown = require('../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-down.cjs');
|
|
15
|
-
var field = require('../field/field.cjs');
|
|
16
|
-
var input = require('../input/input.cjs');
|
|
17
17
|
|
|
18
18
|
function TagField({
|
|
19
19
|
classNames,
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var reactAriaComponents = require('react-aria-components');
|
|
7
7
|
var ouiTheme = require('@opengovsg/oui-theme');
|
|
8
|
-
var textArea = require('../text-area/text-area.cjs');
|
|
9
8
|
var field = require('../field/field.cjs');
|
|
9
|
+
var textArea = require('../text-area/text-area.cjs');
|
|
10
10
|
|
|
11
11
|
function TextAreaField({
|
|
12
12
|
label,
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var reactAriaComponents = require('react-aria-components');
|
|
7
7
|
var ouiTheme = require('@opengovsg/oui-theme');
|
|
8
|
-
var input = require('../input/input.cjs');
|
|
9
8
|
var field = require('../field/field.cjs');
|
|
9
|
+
var input = require('../input/input.cjs');
|
|
10
10
|
|
|
11
11
|
function TextField({
|
|
12
12
|
label,
|
|
@@ -5,9 +5,9 @@ import { forwardRef, useMemo } from 'react';
|
|
|
5
5
|
import { chain } from '@react-aria/utils';
|
|
6
6
|
import { Button as Button$1, composeRenderProps } from 'react-aria-components';
|
|
7
7
|
import { buttonStyles } from '@opengovsg/oui-theme';
|
|
8
|
+
import { Ripple } from '../ripple/ripple.js';
|
|
8
9
|
import { useRipple } from '../ripple/use-ripple.js';
|
|
9
10
|
import { Spinner } from '../spinner/spinner.js';
|
|
10
|
-
import { Ripple } from '../ripple/ripple.js';
|
|
11
11
|
|
|
12
12
|
const Button = forwardRef(
|
|
13
13
|
({
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { createContext } from '../system/react-utils/context.js';
|
|
4
|
+
|
|
5
|
+
const [AgnosticCalendarStateContext, useAgnosticCalendarStateContext] = createContext({
|
|
6
|
+
name: "AgnosticCalendarStateContext",
|
|
7
|
+
strict: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export { AgnosticCalendarStateContext, useAgnosticCalendarStateContext };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useContext } from 'react';
|
|
5
|
+
import { today, getLocalTimeZone } from '@internationalized/date';
|
|
6
|
+
import { Button } from '../button/button.js';
|
|
7
|
+
import { AgnosticCalendarStateContext } from './agnostic-calendar-state-context.js';
|
|
8
|
+
import { useCalendarStyleContext } from './calendar-style-context.js';
|
|
9
|
+
import { useCalendarI18n } from './hooks/use-calendar-i18n.js';
|
|
10
|
+
|
|
11
|
+
const CalendarBottomContent = ({
|
|
12
|
+
bottomContent,
|
|
13
|
+
showTodayButton
|
|
14
|
+
}) => {
|
|
15
|
+
const state = useContext(AgnosticCalendarStateContext);
|
|
16
|
+
const { slots, classNames, size } = useCalendarStyleContext();
|
|
17
|
+
const formatMessage = useCalendarI18n();
|
|
18
|
+
if (bottomContent) {
|
|
19
|
+
return bottomContent;
|
|
20
|
+
}
|
|
21
|
+
if (!showTodayButton) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
"div",
|
|
26
|
+
{
|
|
27
|
+
className: slots.bottomContentWrapper({
|
|
28
|
+
className: classNames?.bottomContentWrapper
|
|
29
|
+
}),
|
|
30
|
+
children: /* @__PURE__ */ jsx(
|
|
31
|
+
Button,
|
|
32
|
+
{
|
|
33
|
+
isDisabled: state.isDisabled,
|
|
34
|
+
variant: "clear",
|
|
35
|
+
color: "sub",
|
|
36
|
+
size,
|
|
37
|
+
slot: null,
|
|
38
|
+
className: slots.todayButton({ className: classNames?.todayButton }),
|
|
39
|
+
onPress: () => {
|
|
40
|
+
state.setFocusedDate(today(getLocalTimeZone()));
|
|
41
|
+
},
|
|
42
|
+
children: formatMessage("today")
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { CalendarBottomContent };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { CalendarGridHeader as CalendarGridHeader$1, CalendarHeaderCell } from 'react-aria-components';
|
|
5
|
+
import { useCalendarStyleContext } from './calendar-style-context.js';
|
|
6
|
+
|
|
7
|
+
function CalendarGridHeader() {
|
|
8
|
+
const { slots, classNames } = useCalendarStyleContext();
|
|
9
|
+
return /* @__PURE__ */ jsx(
|
|
10
|
+
CalendarGridHeader$1,
|
|
11
|
+
{
|
|
12
|
+
className: slots.gridHeader({ className: classNames?.gridHeader }),
|
|
13
|
+
children: (day) => /* @__PURE__ */ jsx(
|
|
14
|
+
CalendarHeaderCell,
|
|
15
|
+
{
|
|
16
|
+
className: slots.gridHeaderCell({
|
|
17
|
+
className: classNames?.gridHeaderCell
|
|
18
|
+
}),
|
|
19
|
+
children: day
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { CalendarGridHeader };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useContext } from 'react';
|
|
5
|
+
import { useLocale, Group, Heading } from 'react-aria-components';
|
|
6
|
+
import { Button } from '../button/button.js';
|
|
7
|
+
import { AgnosticCalendarStateContext } from './agnostic-calendar-state-context.js';
|
|
8
|
+
import { CalendarMonthDaySelector } from './calendar-month-day-selector.js';
|
|
9
|
+
import { useCalendarStyleContext } from './calendar-style-context.js';
|
|
10
|
+
import { useLocalizedMonthYear } from './utils.js';
|
|
11
|
+
import ChevronRight from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-right.js';
|
|
12
|
+
import ChevronLeft from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-left.js';
|
|
13
|
+
|
|
14
|
+
function CalendarHeader({ offsetMonths = 0 }) {
|
|
15
|
+
const { direction } = useLocale();
|
|
16
|
+
const { slots, classNames, size } = useCalendarStyleContext();
|
|
17
|
+
const state = useContext(AgnosticCalendarStateContext);
|
|
18
|
+
const monthYearTitle = useLocalizedMonthYear(
|
|
19
|
+
state.visibleRange.start.add({ months: offsetMonths }),
|
|
20
|
+
state.timeZone
|
|
21
|
+
);
|
|
22
|
+
if (offsetMonths === 0) {
|
|
23
|
+
return /* @__PURE__ */ jsxs("div", { className: slots.header({ className: classNames?.header }), children: [
|
|
24
|
+
/* @__PURE__ */ jsx(CalendarMonthDaySelector, {}),
|
|
25
|
+
/* @__PURE__ */ jsxs(
|
|
26
|
+
Group,
|
|
27
|
+
{
|
|
28
|
+
className: slots.buttonGroup({ className: classNames?.buttonGroup }),
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ jsx(
|
|
31
|
+
Button,
|
|
32
|
+
{
|
|
33
|
+
size,
|
|
34
|
+
isIconOnly: true,
|
|
35
|
+
variant: "clear",
|
|
36
|
+
color: "sub",
|
|
37
|
+
slot: "previous",
|
|
38
|
+
className: slots.prevButton({ className: classNames?.prevButton }),
|
|
39
|
+
children: direction === "rtl" ? /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true })
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
/* @__PURE__ */ jsx(
|
|
43
|
+
Button,
|
|
44
|
+
{
|
|
45
|
+
size,
|
|
46
|
+
variant: "clear",
|
|
47
|
+
color: "sub",
|
|
48
|
+
isIconOnly: true,
|
|
49
|
+
slot: "next",
|
|
50
|
+
className: slots.nextButton({
|
|
51
|
+
className: classNames?.nextButton
|
|
52
|
+
}),
|
|
53
|
+
children: direction === "rtl" ? /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true }) : /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true })
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
] });
|
|
60
|
+
}
|
|
61
|
+
return /* @__PURE__ */ jsx(
|
|
62
|
+
Heading,
|
|
63
|
+
{
|
|
64
|
+
className: slots.header({ className: classNames?.header }),
|
|
65
|
+
"aria-hidden": true,
|
|
66
|
+
level: 2,
|
|
67
|
+
children: monthYearTitle
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { CalendarHeader };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useContext } from 'react';
|
|
5
|
+
import { CalendarDate } from '@internationalized/date';
|
|
6
|
+
import { Group } from 'react-aria-components';
|
|
7
|
+
import { Select } from '../select/select.js';
|
|
8
|
+
import { SelectItem } from '../select/select-item.js';
|
|
9
|
+
import { AgnosticCalendarStateContext } from './agnostic-calendar-state-context.js';
|
|
10
|
+
import { useCalendarStyleContext } from './calendar-style-context.js';
|
|
11
|
+
import { useCalendarSelectors } from './hooks/use-calendar-selectors.js';
|
|
12
|
+
import { useCalendarI18n } from './hooks/use-calendar-i18n.js';
|
|
13
|
+
|
|
14
|
+
const CalendarMonthDaySelector = () => {
|
|
15
|
+
const { slots, size, classNames } = useCalendarStyleContext();
|
|
16
|
+
const state = useContext(AgnosticCalendarStateContext);
|
|
17
|
+
const { months, years, datePartOrder } = useCalendarSelectors(state);
|
|
18
|
+
const formatMessage = useCalendarI18n();
|
|
19
|
+
return /* @__PURE__ */ jsx(Group, { className: slots.selectors({ className: classNames?.selectors }), children: datePartOrder.map((part) => {
|
|
20
|
+
if (part === "month") {
|
|
21
|
+
return /* @__PURE__ */ jsx(
|
|
22
|
+
Select,
|
|
23
|
+
{
|
|
24
|
+
isDisabled: state.isDisabled,
|
|
25
|
+
size,
|
|
26
|
+
items: months,
|
|
27
|
+
variant: "clear",
|
|
28
|
+
classNames: {
|
|
29
|
+
trigger: slots.monthSelector({
|
|
30
|
+
className: classNames?.monthSelector
|
|
31
|
+
}),
|
|
32
|
+
list: slots.monthList({ className: classNames?.monthList }),
|
|
33
|
+
selectedText: slots.selectorText({
|
|
34
|
+
className: classNames?.selectorText
|
|
35
|
+
}),
|
|
36
|
+
popover: "min-w-[12ch]"
|
|
37
|
+
},
|
|
38
|
+
selectedKey: state.visibleRange.start.month,
|
|
39
|
+
"aria-label": formatMessage("selectMonth"),
|
|
40
|
+
onSelectionChange: (month) => {
|
|
41
|
+
state.setFocusedDate(
|
|
42
|
+
new CalendarDate(state.focusedDate.year, Number(month), 1)
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
children: (month) => /* @__PURE__ */ jsx(SelectItem, { children: month.textValue })
|
|
46
|
+
},
|
|
47
|
+
part
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return /* @__PURE__ */ jsx(
|
|
51
|
+
Select,
|
|
52
|
+
{
|
|
53
|
+
isDisabled: state.isDisabled,
|
|
54
|
+
size,
|
|
55
|
+
variant: "clear",
|
|
56
|
+
items: years,
|
|
57
|
+
classNames: {
|
|
58
|
+
trigger: slots.yearSelector({
|
|
59
|
+
className: classNames?.yearSelector
|
|
60
|
+
}),
|
|
61
|
+
list: slots.yearList({ className: classNames?.yearList }),
|
|
62
|
+
selectedText: slots.selectorText({
|
|
63
|
+
className: classNames?.selectorText
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
selectedKey: state.visibleRange.start.year,
|
|
67
|
+
"aria-label": formatMessage("selectYear"),
|
|
68
|
+
onSelectionChange: (year) => {
|
|
69
|
+
state.setFocusedDate(
|
|
70
|
+
new CalendarDate(
|
|
71
|
+
Number(year),
|
|
72
|
+
state.focusedDate.month,
|
|
73
|
+
state.focusedDate.day
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
children: (year) => /* @__PURE__ */ jsx(SelectItem, { children: year.textValue })
|
|
78
|
+
},
|
|
79
|
+
part
|
|
80
|
+
);
|
|
81
|
+
}) });
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { CalendarMonthDaySelector };
|
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
-
import { useDeepCompareMemo } from 'use-deep-compare';
|
|
4
|
-
import { calendarStyles } from '@opengovsg/oui-theme';
|
|
5
|
-
import { mapPropsVariants } from '../system/utils.js';
|
|
6
3
|
import { createContext } from '../system/react-utils/context.js';
|
|
7
4
|
|
|
8
|
-
function useProvideCalendarStyles(originalProps) {
|
|
9
|
-
const [props, variantProps] = mapPropsVariants(
|
|
10
|
-
originalProps,
|
|
11
|
-
calendarStyles.variantKeys
|
|
12
|
-
);
|
|
13
|
-
const { errorMessage, className, classNames, ...restProps } = props;
|
|
14
|
-
const slots = useDeepCompareMemo(
|
|
15
|
-
() => calendarStyles(variantProps),
|
|
16
|
-
[variantProps]
|
|
17
|
-
);
|
|
18
|
-
return {
|
|
19
|
-
context: {
|
|
20
|
-
slots,
|
|
21
|
-
classNames,
|
|
22
|
-
className,
|
|
23
|
-
size: variantProps.size ?? calendarStyles.defaultVariants.size,
|
|
24
|
-
errorMessage
|
|
25
|
-
},
|
|
26
|
-
calendarProps: { ...restProps, onChange: restProps.onChange }
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
5
|
const [CalendarStyleContext, useCalendarStyleContext] = createContext({
|
|
30
6
|
name: "CalendarStyleContext",
|
|
31
7
|
strict: true
|
|
32
8
|
});
|
|
33
9
|
|
|
34
|
-
export { CalendarStyleContext, useCalendarStyleContext
|
|
10
|
+
export { CalendarStyleContext, useCalendarStyleContext };
|