@opengovsg/oui 0.0.0-snapshot-20250320092809 → 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
@@ -1,343 +0,0 @@
1
- "use strict";
2
- "use client";
3
- import { jsxs, jsx } from 'react/jsx-runtime';
4
- import { useMemo, useContext } from 'react';
5
- import { today, getLocalTimeZone, CalendarDate } from '@internationalized/date';
6
- import { useMessageFormatter, useDateFormatter } from 'react-aria';
7
- import { Calendar, composeRenderProps, CalendarGrid, CalendarGridBody, CalendarCell, useLocale, CalendarStateContext, Group, Heading, CalendarGridHeader as CalendarGridHeader$1, CalendarHeaderCell } from 'react-aria-components';
8
- import { cn } from '@opengovsg/oui-theme';
9
- import { Button } from '../button/button.js';
10
- import { useCalendarStyleContext } from './calendar-style-context.js';
11
- import { useLocalizedMonthYear, useGenerateLocalizedMonths, useGenerateLocalizedYears } from './utils.js';
12
- 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';
13
- 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';
14
- import { Select } from '../select/select.js';
15
- import { SelectItem } from '../select/select-item.js';
16
-
17
- const useCalendarSelectors = (state) => {
18
- const yearRange = useMemo(() => {
19
- const start = state.minValue.year ?? 1900;
20
- const end = state.maxValue.year ?? 2100;
21
- return { start, end };
22
- }, [state.maxValue, state.minValue]);
23
- const dateFormatter = useDateFormatter(state);
24
- const datePartOrder = useMemo(() => {
25
- const parts = dateFormatter.formatToParts(
26
- state.visibleRange.start.toDate(state.timeZone)
27
- );
28
- const filteredParts = parts.filter(
29
- (part) => ["year", "month"].includes(part.type)
30
- );
31
- const filteredPartNames = filteredParts.map((part) => part.type);
32
- return filteredPartNames;
33
- }, [dateFormatter, state.timeZone, state.visibleRange.start]);
34
- const months = useGenerateLocalizedMonths(state.timeZone);
35
- const years = useGenerateLocalizedYears(
36
- yearRange.start,
37
- yearRange.end,
38
- state.timeZone
39
- );
40
- return useMemo(() => {
41
- return {
42
- months,
43
- years,
44
- datePartOrder
45
- };
46
- }, [datePartOrder, months, years]);
47
- };
48
- const i18nStrings = {
49
- "en-SG": {
50
- selectMonth: "Select month",
51
- selectYear: "Select year",
52
- today: "Today"
53
- },
54
- "zh-SG": {
55
- selectMonth: "\u9009\u62E9\u6708\u4EFD",
56
- selectYear: "\u9009\u62E9\u5E74\u4EFD",
57
- today: "\u4ECA\u5929"
58
- },
59
- "ms-SG": {
60
- selectMonth: "Pilih bulan",
61
- selectYear: "Pilih tahun",
62
- today: "Hari ini"
63
- },
64
- "ta-SG": {
65
- 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",
66
- selectYear: "\u0B86\u0BA3\u0BCD\u0B9F\u0BC8 \u0BA4\u0BC7\u0BB0\u0BCD\u0BA8\u0BCD\u0BA4\u0BC6\u0B9F\u0BC1\u0B95\u0BCD\u0B95\u0BB5\u0BC1\u0BAE\u0BCD",
67
- today: "\u0B87\u0BA9\u0BCD\u0BB1\u0BC1"
68
- }
69
- };
70
- const CalendarBottomContent = ({
71
- bottomContent,
72
- showTodayButton
73
- }) => {
74
- const state = useContext(CalendarStateContext);
75
- const { slots, classNames, size } = useCalendarStyleContext();
76
- const formatMessage = useMessageFormatter(i18nStrings);
77
- if (bottomContent) {
78
- return bottomContent;
79
- }
80
- if (!showTodayButton) {
81
- return null;
82
- }
83
- return /* @__PURE__ */ jsx(
84
- "div",
85
- {
86
- className: slots.bottomContentWrapper({
87
- className: classNames?.bottomContentWrapper
88
- }),
89
- children: /* @__PURE__ */ jsx(
90
- Button,
91
- {
92
- isDisabled: state.isDisabled,
93
- variant: "clear",
94
- color: "sub",
95
- size,
96
- slot: null,
97
- className: slots.todayButton({ className: classNames?.todayButton }),
98
- onPress: () => {
99
- state.setFocusedDate(today(getLocalTimeZone()));
100
- },
101
- children: formatMessage("today")
102
- }
103
- )
104
- }
105
- );
106
- };
107
- function CalendarBase({
108
- weekdayStyle = "narrow",
109
- calendarRef,
110
- minValue = new CalendarDate(1900, 0, 1),
111
- maxValue = new CalendarDate(2100, 12, 31),
112
- bottomContent,
113
- showTodayButton = true,
114
- ...props
115
- }) {
116
- const { slots, className, classNames } = useCalendarStyleContext();
117
- const numberOfVisibleMonths = props.visibleDuration?.months ?? 1;
118
- const dateToHighlight = useMemo(() => {
119
- return props.defaultFocusedValue ?? today(getLocalTimeZone());
120
- }, [props.defaultFocusedValue]);
121
- return /* @__PURE__ */ jsxs(
122
- Calendar,
123
- {
124
- pageBehavior: "single",
125
- ...props,
126
- ref: calendarRef,
127
- minValue,
128
- maxValue,
129
- className: composeRenderProps(
130
- className,
131
- (className2, renderProps) => slots.base({
132
- className: cn(classNames?.base, className2),
133
- ...renderProps
134
- })
135
- ),
136
- children: [
137
- /* @__PURE__ */ jsx(
138
- "div",
139
- {
140
- className: slots.gridWrapper({
141
- className: classNames?.gridWrapper
142
- }),
143
- children: Array.from({ length: numberOfVisibleMonths }).map((_, index) => /* @__PURE__ */ jsxs(
144
- "div",
145
- {
146
- className: slots.calendar({ className: classNames?.calendar }),
147
- children: [
148
- /* @__PURE__ */ jsx(CalendarHeader, { offsetMonths: index }),
149
- /* @__PURE__ */ jsxs(
150
- CalendarGrid,
151
- {
152
- className: slots.grid({ className: classNames?.grid }),
153
- weekdayStyle,
154
- offset: { months: index },
155
- children: [
156
- /* @__PURE__ */ jsx(CalendarGridHeader, {}),
157
- /* @__PURE__ */ jsx(
158
- CalendarGridBody,
159
- {
160
- className: slots.gridBody({ className: classNames?.gridBody }),
161
- children: (date) => /* @__PURE__ */ jsx(
162
- CalendarCell,
163
- {
164
- className: composeRenderProps(
165
- classNames?.cell,
166
- (className2, renderProps) => slots.cell({
167
- className: className2,
168
- isMultipleMonths: numberOfVisibleMonths >= 2,
169
- isDateHighlighted: date.compare(dateToHighlight) === 0,
170
- ...renderProps
171
- })
172
- ),
173
- date
174
- }
175
- )
176
- }
177
- )
178
- ]
179
- }
180
- )
181
- ]
182
- },
183
- index
184
- ))
185
- }
186
- ),
187
- /* @__PURE__ */ jsx(
188
- CalendarBottomContent,
189
- {
190
- bottomContent,
191
- showTodayButton
192
- }
193
- )
194
- ]
195
- }
196
- );
197
- }
198
- const CalendarMonthDaySelector = () => {
199
- const { slots, size, classNames } = useCalendarStyleContext();
200
- const state = useContext(CalendarStateContext);
201
- const { months, years, datePartOrder } = useCalendarSelectors(state);
202
- const formatMessage = useMessageFormatter(i18nStrings);
203
- return /* @__PURE__ */ jsx(Group, { className: slots.selectors({ className: classNames?.selectors }), children: datePartOrder.map((part) => {
204
- if (part === "month") {
205
- return /* @__PURE__ */ jsx(
206
- Select,
207
- {
208
- isDisabled: state.isDisabled,
209
- size,
210
- items: months,
211
- variant: "clear",
212
- classNames: {
213
- trigger: slots.monthSelector({
214
- className: classNames?.monthSelector
215
- }),
216
- list: slots.monthList({ className: classNames?.monthList }),
217
- selectedText: slots.selectorText({
218
- className: classNames?.selectorText
219
- }),
220
- popover: "min-w-[12ch]"
221
- },
222
- selectedKey: state.visibleRange.start.month,
223
- "aria-label": formatMessage("selectMonth"),
224
- onSelectionChange: (month) => {
225
- state.setFocusedDate(
226
- new CalendarDate(state.focusedDate.year, Number(month), 1)
227
- );
228
- },
229
- children: (month) => /* @__PURE__ */ jsx(SelectItem, { children: month.textValue })
230
- },
231
- part
232
- );
233
- }
234
- return /* @__PURE__ */ jsx(
235
- Select,
236
- {
237
- isDisabled: state.isDisabled,
238
- size,
239
- variant: "clear",
240
- items: years,
241
- classNames: {
242
- trigger: slots.yearSelector({
243
- className: classNames?.yearSelector
244
- }),
245
- list: slots.yearList({ className: classNames?.yearList }),
246
- selectedText: slots.selectorText({
247
- className: classNames?.selectorText
248
- })
249
- },
250
- selectedKey: state.visibleRange.start.year,
251
- "aria-label": formatMessage("selectYear"),
252
- onSelectionChange: (year) => {
253
- state.setFocusedDate(
254
- new CalendarDate(
255
- Number(year),
256
- state.focusedDate.month,
257
- state.focusedDate.day
258
- )
259
- );
260
- },
261
- children: (year) => /* @__PURE__ */ jsx(SelectItem, { children: year.textValue })
262
- },
263
- part
264
- );
265
- }) });
266
- };
267
- function CalendarHeader({ offsetMonths = 0 }) {
268
- const { direction } = useLocale();
269
- const { slots, classNames, size } = useCalendarStyleContext();
270
- const state = useContext(CalendarStateContext);
271
- const monthYearTitle = useLocalizedMonthYear(
272
- state.visibleRange.start.add({ months: offsetMonths }),
273
- state.timeZone
274
- );
275
- if (offsetMonths === 0) {
276
- return /* @__PURE__ */ jsxs("div", { className: slots.header({ className: classNames?.header }), children: [
277
- /* @__PURE__ */ jsx(CalendarMonthDaySelector, {}),
278
- /* @__PURE__ */ jsxs(
279
- Group,
280
- {
281
- className: slots.buttonGroup({ className: classNames?.buttonGroup }),
282
- children: [
283
- /* @__PURE__ */ jsx(
284
- Button,
285
- {
286
- size,
287
- isIconOnly: true,
288
- variant: "clear",
289
- color: "sub",
290
- slot: "previous",
291
- className: slots.prevButton({ className: classNames?.prevButton }),
292
- children: direction === "rtl" ? /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true }) : /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true })
293
- }
294
- ),
295
- /* @__PURE__ */ jsx(
296
- Button,
297
- {
298
- size,
299
- variant: "clear",
300
- color: "sub",
301
- isIconOnly: true,
302
- slot: "next",
303
- className: slots.nextButton({
304
- className: classNames?.nextButton
305
- }),
306
- children: direction === "rtl" ? /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": true }) : /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": true })
307
- }
308
- )
309
- ]
310
- }
311
- )
312
- ] });
313
- }
314
- return /* @__PURE__ */ jsx(
315
- Heading,
316
- {
317
- className: slots.header({ className: classNames?.header }),
318
- "aria-hidden": true,
319
- level: 2,
320
- children: monthYearTitle
321
- }
322
- );
323
- }
324
- function CalendarGridHeader() {
325
- const { slots, classNames } = useCalendarStyleContext();
326
- return /* @__PURE__ */ jsx(
327
- CalendarGridHeader$1,
328
- {
329
- className: slots.gridHeader({ className: classNames?.gridHeader }),
330
- children: (day) => /* @__PURE__ */ jsx(
331
- CalendarHeaderCell,
332
- {
333
- className: slots.gridHeaderCell({
334
- className: classNames?.gridHeaderCell
335
- }),
336
- children: day
337
- }
338
- )
339
- }
340
- );
341
- }
342
-
343
- export { CalendarBase, CalendarGridHeader, CalendarHeader };
@@ -1,14 +0,0 @@
1
- import type { ForwardedRef } from "react";
2
- import type { DateValue } from "react-aria-components";
3
- import type { CalendarProps } from "./types";
4
- export interface CalendarBaseProps<T extends DateValue> extends CalendarProps<T> {
5
- calendarRef: ForwardedRef<HTMLDivElement>;
6
- }
7
- export declare function CalendarBase<T extends DateValue>({ weekdayStyle, calendarRef, minValue, maxValue, bottomContent, showTodayButton, ...props }: CalendarBaseProps<T>): import("react/jsx-runtime").JSX.Element;
8
- interface CalendarHeaderProps {
9
- offsetMonths?: number;
10
- }
11
- export declare function CalendarHeader({ offsetMonths }: CalendarHeaderProps): import("react/jsx-runtime").JSX.Element;
12
- export declare function CalendarGridHeader(): import("react/jsx-runtime").JSX.Element;
13
- export {};
14
- //# sourceMappingURL=calendar-base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calendar-base.d.ts","sourceRoot":"","sources":["../../../src/calendar/calendar-base.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAEzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAsBtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AA6C5C,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,SAAS,CACpD,SAAQ,aAAa,CAAC,CAAC,CAAC;IACxB,WAAW,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;CAC1C;AAgED,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAAE,EAChD,YAAuB,EACvB,WAAW,EACX,QAAuC,EACvC,QAAyC,EACzC,aAAa,EACb,eAAsB,EACtB,GAAG,KAAK,EACT,EAAE,iBAAiB,CAAC,CAAC,CAAC,2CAsEtB;AA+ED,UAAU,mBAAmB;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,wBAAgB,cAAc,CAAC,EAAE,YAAgB,EAAE,EAAE,mBAAmB,2CA8DvE;AAED,wBAAgB,kBAAkB,4CAiBjC"}