@opengovsg/oui 0.0.0-snapshot-20250320092749 → 0.0.0-snapshot-20250326084237

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.
Files changed (63) hide show
  1. package/dist/cjs/calendar/agnostic-calendar-state-context.cjs +13 -0
  2. package/dist/cjs/calendar/calendar-bottom-content.cjs +51 -0
  3. package/dist/cjs/calendar/calendar-grid-header.cjs +28 -0
  4. package/dist/cjs/calendar/calendar-header.cjs +74 -0
  5. package/dist/cjs/calendar/calendar-month-day-selector.cjs +86 -0
  6. package/dist/cjs/calendar/calendar-style-context.cjs +0 -25
  7. package/dist/cjs/calendar/calendar.cjs +143 -4
  8. package/dist/cjs/calendar/hooks/index.cjs +11 -0
  9. package/dist/cjs/calendar/hooks/use-calendar-i18n.cjs +33 -0
  10. package/dist/cjs/calendar/hooks/use-calendar-selectors.cjs +41 -0
  11. package/dist/cjs/calendar/index.cjs +1 -1
  12. package/dist/cjs/index.cjs +9 -5
  13. package/dist/cjs/range-calendar/index.cjs +10 -0
  14. package/dist/cjs/range-calendar/range-calendar.cjs +188 -0
  15. package/dist/esm/calendar/agnostic-calendar-state-context.js +10 -0
  16. package/dist/esm/calendar/calendar-bottom-content.js +49 -0
  17. package/dist/esm/calendar/calendar-grid-header.js +26 -0
  18. package/dist/esm/calendar/calendar-header.js +72 -0
  19. package/dist/esm/calendar/calendar-month-day-selector.js +84 -0
  20. package/dist/esm/calendar/calendar-style-context.js +1 -25
  21. package/dist/esm/calendar/calendar.js +147 -9
  22. package/dist/esm/calendar/hooks/index.js +3 -0
  23. package/dist/esm/calendar/hooks/use-calendar-i18n.js +30 -0
  24. package/dist/esm/calendar/hooks/use-calendar-selectors.js +39 -0
  25. package/dist/esm/calendar/index.js +2 -2
  26. package/dist/esm/index.js +5 -4
  27. package/dist/esm/range-calendar/index.js +2 -0
  28. package/dist/esm/range-calendar/range-calendar.js +184 -0
  29. package/dist/types/calendar/agnostic-calendar-state-context.d.ts +3 -0
  30. package/dist/types/calendar/agnostic-calendar-state-context.d.ts.map +1 -0
  31. package/dist/types/calendar/calendar-bottom-content.d.ts +4 -0
  32. package/dist/types/calendar/calendar-bottom-content.d.ts.map +1 -0
  33. package/dist/types/calendar/calendar-grid-header.d.ts +2 -0
  34. package/dist/types/calendar/calendar-grid-header.d.ts.map +1 -0
  35. package/dist/types/calendar/calendar-header.d.ts +6 -0
  36. package/dist/types/calendar/calendar-header.d.ts.map +1 -0
  37. package/dist/types/calendar/calendar-month-day-selector.d.ts +2 -0
  38. package/dist/types/calendar/calendar-month-day-selector.d.ts.map +1 -0
  39. package/dist/types/calendar/calendar-style-context.d.ts +10 -1030
  40. package/dist/types/calendar/calendar-style-context.d.ts.map +1 -1
  41. package/dist/types/calendar/calendar.d.ts +5 -2
  42. package/dist/types/calendar/calendar.d.ts.map +1 -1
  43. package/dist/types/calendar/hooks/index.d.ts +3 -0
  44. package/dist/types/calendar/hooks/index.d.ts.map +1 -0
  45. package/dist/types/calendar/hooks/use-calendar-i18n.d.ts +4 -0
  46. package/dist/types/calendar/hooks/use-calendar-i18n.d.ts.map +1 -0
  47. package/dist/types/calendar/hooks/use-calendar-selectors.d.ts +13 -0
  48. package/dist/types/calendar/hooks/use-calendar-selectors.d.ts.map +1 -0
  49. package/dist/types/calendar/types.d.ts +5 -4
  50. package/dist/types/calendar/types.d.ts.map +1 -1
  51. package/dist/types/index.d.mts +1 -0
  52. package/dist/types/index.d.ts +1 -0
  53. package/dist/types/index.d.ts.map +1 -1
  54. package/dist/types/range-calendar/index.d.ts +2 -0
  55. package/dist/types/range-calendar/index.d.ts.map +1 -0
  56. package/dist/types/range-calendar/range-calendar.d.ts +69 -0
  57. package/dist/types/range-calendar/range-calendar.d.ts.map +1 -0
  58. package/dist/types/tag-field/tag-field-tag-list.d.ts.map +1 -1
  59. package/package.json +4 -4
  60. package/dist/cjs/calendar/calendar-base.cjs +0 -347
  61. package/dist/esm/calendar/calendar-base.js +0 -343
  62. package/dist/types/calendar/calendar-base.d.ts +0 -14
  63. 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;
@@ -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 { AgnosticCalendarStateContext } from './agnostic-calendar-state-context.js';
8
+ import { useCalendarStyleContext } from './calendar-style-context.js';
9
+ import { useCalendarSelectors } from './hooks/use-calendar-selectors.js';
10
+ import { Select } from '../select/select.js';
11
+ import { SelectItem } from '../select/select-item.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, useProvideCalendarStyles };
10
+ export { CalendarStyleContext, useCalendarStyleContext };
@@ -1,14 +1,152 @@
1
1
  "use strict";
2
2
  "use client";
3
- import { jsx } from 'react/jsx-runtime';
4
- import { Provider } from 'react-aria-components';
5
- import { forwardRef } from '../system/utils.js';
6
- import { CalendarBase } from './calendar-base.js';
7
- import { useProvideCalendarStyles, CalendarStyleContext } from './calendar-style-context.js';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+ import { useMemo, useContext } from 'react';
5
+ import { CalendarDate, today, getLocalTimeZone } from '@internationalized/date';
6
+ import { Calendar as Calendar$1, composeRenderProps, Provider, CalendarGrid, CalendarGridBody, CalendarCell, Text, CalendarStateContext } from 'react-aria-components';
7
+ import { useDeepCompareMemo } from 'use-deep-compare';
8
+ import { calendarStyles, dataAttr, cn } from '@opengovsg/oui-theme';
9
+ import { forwardRef, mapPropsVariants } from '../system/utils.js';
10
+ import { AgnosticCalendarStateContext } from './agnostic-calendar-state-context.js';
11
+ import { CalendarBottomContent } from './calendar-bottom-content.js';
12
+ import { CalendarGridHeader } from './calendar-grid-header.js';
13
+ import { CalendarHeader } from './calendar-header.js';
14
+ import { CalendarStyleContext } from './calendar-style-context.js';
8
15
 
9
- const Calendar = forwardRef(function Calendar2(props, ref) {
10
- const { calendarProps, context } = useProvideCalendarStyles(props);
11
- return /* @__PURE__ */ jsx(Provider, { values: [[CalendarStyleContext, context]], children: /* @__PURE__ */ jsx(CalendarBase, { calendarRef: ref, ...calendarProps }) });
16
+ const Calendar = forwardRef(function Calendar2(originalProps, ref) {
17
+ const [props, variantProps] = mapPropsVariants(
18
+ originalProps,
19
+ calendarStyles.variantKeys
20
+ );
21
+ const {
22
+ className,
23
+ classNames,
24
+ weekdayStyle = "narrow",
25
+ minValue = new CalendarDate(1900, 0, 1),
26
+ maxValue = new CalendarDate(2100, 12, 31),
27
+ bottomContent,
28
+ showTodayButton = true,
29
+ errorMessage,
30
+ ...restProps
31
+ } = props;
32
+ const slots = useDeepCompareMemo(
33
+ () => calendarStyles(variantProps),
34
+ [variantProps]
35
+ );
36
+ const context = useMemo(
37
+ () => ({
38
+ slots,
39
+ classNames,
40
+ className,
41
+ size: variantProps.size ?? calendarStyles.defaultVariants.size
42
+ }),
43
+ [className, classNames, slots, variantProps.size]
44
+ );
45
+ const numberOfVisibleMonths = props.visibleDuration?.months ?? 1;
46
+ const dateToHighlight = useMemo(() => {
47
+ if (props.defaultFocusedValue !== void 0) {
48
+ return props.defaultFocusedValue;
49
+ }
50
+ return today(getLocalTimeZone());
51
+ }, [props.defaultFocusedValue]);
52
+ return /* @__PURE__ */ jsxs(
53
+ Calendar$1,
54
+ {
55
+ pageBehavior: "single",
56
+ ...restProps,
57
+ ref,
58
+ minValue,
59
+ maxValue,
60
+ className: composeRenderProps(
61
+ className,
62
+ (className2, renderProps) => slots.base({
63
+ className: cn(classNames?.base, className2),
64
+ ...renderProps
65
+ })
66
+ ),
67
+ children: [
68
+ /* @__PURE__ */ jsx(CalendarStateWrapper, { children: /* @__PURE__ */ jsxs(Provider, { values: [[CalendarStyleContext, context]], children: [
69
+ /* @__PURE__ */ jsx(
70
+ "div",
71
+ {
72
+ className: slots.gridWrapper({
73
+ className: classNames?.gridWrapper
74
+ }),
75
+ children: Array.from({ length: numberOfVisibleMonths }).map((_, index) => /* @__PURE__ */ jsxs(
76
+ "div",
77
+ {
78
+ className: slots.calendar({ className: classNames?.calendar }),
79
+ children: [
80
+ /* @__PURE__ */ jsx(CalendarHeader, { offsetMonths: index }),
81
+ /* @__PURE__ */ jsxs(
82
+ CalendarGrid,
83
+ {
84
+ className: slots.grid({ className: classNames?.grid }),
85
+ weekdayStyle,
86
+ offset: { months: index },
87
+ children: [
88
+ /* @__PURE__ */ jsx(CalendarGridHeader, {}),
89
+ /* @__PURE__ */ jsx(
90
+ CalendarGridBody,
91
+ {
92
+ className: slots.gridBody({
93
+ className: classNames?.gridBody
94
+ }),
95
+ children: (date) => /* @__PURE__ */ jsx(
96
+ CalendarCell,
97
+ {
98
+ className: composeRenderProps(
99
+ classNames?.cell,
100
+ (className2, renderProps) => slots.cell({
101
+ className: className2,
102
+ isMultipleMonths: numberOfVisibleMonths >= 2,
103
+ ...renderProps
104
+ })
105
+ ),
106
+ "data-highlighted": dataAttr(
107
+ dateToHighlight ? date.compare(dateToHighlight) === 0 : false
108
+ ),
109
+ date
110
+ }
111
+ )
112
+ }
113
+ )
114
+ ]
115
+ }
116
+ )
117
+ ]
118
+ },
119
+ index
120
+ ))
121
+ }
122
+ ),
123
+ /* @__PURE__ */ jsx(
124
+ CalendarBottomContent,
125
+ {
126
+ bottomContent,
127
+ showTodayButton
128
+ }
129
+ )
130
+ ] }) }),
131
+ errorMessage && /* @__PURE__ */ jsx(
132
+ Text,
133
+ {
134
+ className: slots.errorMessage({
135
+ className: classNames?.errorMessage
136
+ }),
137
+ slot: "errorMessage",
138
+ children: errorMessage
139
+ }
140
+ )
141
+ ]
142
+ }
143
+ );
12
144
  });
145
+ const CalendarStateWrapper = ({
146
+ children
147
+ }) => {
148
+ const state = useContext(CalendarStateContext);
149
+ return /* @__PURE__ */ jsx(Provider, { values: [[AgnosticCalendarStateContext, state]], children });
150
+ };
13
151
 
14
- export { Calendar };
152
+ export { Calendar, CalendarStateWrapper };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ export { i18nStrings, useCalendarI18n } from './use-calendar-i18n.js';
3
+ export { useCalendarSelectors } from './use-calendar-selectors.js';
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ import { useMessageFormatter } from 'react-aria';
3
+
4
+ const i18nStrings = {
5
+ "en-SG": {
6
+ selectMonth: "Select month",
7
+ selectYear: "Select year",
8
+ today: "Today"
9
+ },
10
+ "zh-SG": {
11
+ selectMonth: "\u9009\u62E9\u6708\u4EFD",
12
+ selectYear: "\u9009\u62E9\u5E74\u4EFD",
13
+ today: "\u4ECA\u5929"
14
+ },
15
+ "ms-SG": {
16
+ selectMonth: "Pilih bulan",
17
+ selectYear: "Pilih tahun",
18
+ today: "Hari ini"
19
+ },
20
+ "ta-SG": {
21
+ selectMonth: "\u0BAE\u0BBE\u0BA4\u0BA4\u0BCD\u0BA4\u0BC8 \u0BA4\u0BC7\u0BB0\u0BCD\u0BA8\u0BCD\u0BA4\u0BC6\u0B9F\u0BC1\u0B95\u0BCD\u0B95\u0BB5\u0BC1\u0BAE\u0BCD",
22
+ selectYear: "\u0B86\u0BA3\u0BCD\u0B9F\u0BC8 \u0BA4\u0BC7\u0BB0\u0BCD\u0BA8\u0BCD\u0BA4\u0BC6\u0B9F\u0BC1\u0B95\u0BCD\u0B95\u0BB5\u0BC1\u0BAE\u0BCD",
23
+ today: "\u0B87\u0BA9\u0BCD\u0BB1\u0BC1"
24
+ }
25
+ };
26
+ const useCalendarI18n = () => {
27
+ return useMessageFormatter(i18nStrings);
28
+ };
29
+
30
+ export { i18nStrings, useCalendarI18n };