@salt-ds/lab 1.0.0-alpha.55 → 1.0.0-alpha.57

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 (188) hide show
  1. package/CHANGELOG.md +167 -0
  2. package/css/salt-lab.css +44 -7
  3. package/dist-cjs/calendar/Calendar.js +12 -12
  4. package/dist-cjs/calendar/Calendar.js.map +1 -1
  5. package/dist-cjs/calendar/CalendarGrid.css.js +6 -0
  6. package/dist-cjs/calendar/CalendarGrid.css.js.map +1 -0
  7. package/dist-cjs/calendar/CalendarGrid.js +107 -0
  8. package/dist-cjs/calendar/CalendarGrid.js.map +1 -0
  9. package/dist-cjs/calendar/CalendarNavigation.js +219 -201
  10. package/dist-cjs/calendar/CalendarNavigation.js.map +1 -1
  11. package/dist-cjs/calendar/CalendarWeekHeader.js +10 -4
  12. package/dist-cjs/calendar/CalendarWeekHeader.js.map +1 -1
  13. package/dist-cjs/calendar/internal/CalendarContext.js +6 -2
  14. package/dist-cjs/calendar/internal/CalendarContext.js.map +1 -1
  15. package/dist-cjs/calendar/internal/CalendarDay.js +6 -9
  16. package/dist-cjs/calendar/internal/CalendarDay.js.map +1 -1
  17. package/dist-cjs/calendar/internal/CalendarMonth.css.js +1 -1
  18. package/dist-cjs/calendar/internal/CalendarMonth.js +47 -54
  19. package/dist-cjs/calendar/internal/CalendarMonth.js.map +1 -1
  20. package/dist-cjs/calendar/internal/useFocusManagement.js +18 -18
  21. package/dist-cjs/calendar/internal/useFocusManagement.js.map +1 -1
  22. package/dist-cjs/calendar/internal/utils.js +33 -48
  23. package/dist-cjs/calendar/internal/utils.js.map +1 -1
  24. package/dist-cjs/calendar/useCalendar.js +46 -38
  25. package/dist-cjs/calendar/useCalendar.js.map +1 -1
  26. package/dist-cjs/calendar/useCalendarDay.js +15 -21
  27. package/dist-cjs/calendar/useCalendarDay.js.map +1 -1
  28. package/dist-cjs/calendar/useCalendarSelection.js +44 -35
  29. package/dist-cjs/calendar/useCalendarSelection.js.map +1 -1
  30. package/dist-cjs/date-input/DateInput.css.js +1 -1
  31. package/dist-cjs/date-input/DateInputRange.js +102 -107
  32. package/dist-cjs/date-input/DateInputRange.js.map +1 -1
  33. package/dist-cjs/date-input/DateInputSingle.js +39 -51
  34. package/dist-cjs/date-input/DateInputSingle.js.map +1 -1
  35. package/dist-cjs/date-picker/DatePicker.js +15 -13
  36. package/dist-cjs/date-picker/DatePicker.js.map +1 -1
  37. package/dist-cjs/date-picker/DatePickerActions.js +3 -8
  38. package/dist-cjs/date-picker/DatePickerActions.js.map +1 -1
  39. package/dist-cjs/date-picker/DatePickerContext.js +6 -2
  40. package/dist-cjs/date-picker/DatePickerContext.js.map +1 -1
  41. package/dist-cjs/date-picker/DatePickerOverlay.js +1 -0
  42. package/dist-cjs/date-picker/DatePickerOverlay.js.map +1 -1
  43. package/dist-cjs/date-picker/DatePickerOverlayProvider.js +21 -8
  44. package/dist-cjs/date-picker/DatePickerOverlayProvider.js.map +1 -1
  45. package/dist-cjs/date-picker/DatePickerRangeInput.js +77 -28
  46. package/dist-cjs/date-picker/DatePickerRangeInput.js.map +1 -1
  47. package/dist-cjs/date-picker/DatePickerRangePanel.js +45 -40
  48. package/dist-cjs/date-picker/DatePickerRangePanel.js.map +1 -1
  49. package/dist-cjs/date-picker/DatePickerSingleInput.js +123 -84
  50. package/dist-cjs/date-picker/DatePickerSingleInput.js.map +1 -1
  51. package/dist-cjs/date-picker/DatePickerSinglePanel.js +17 -20
  52. package/dist-cjs/date-picker/DatePickerSinglePanel.js.map +1 -1
  53. package/dist-cjs/date-picker/DatePickerTrigger.js +32 -0
  54. package/dist-cjs/date-picker/DatePickerTrigger.js.map +1 -0
  55. package/dist-cjs/date-picker/useDatePicker.js +60 -110
  56. package/dist-cjs/date-picker/useDatePicker.js.map +1 -1
  57. package/dist-cjs/dropdown/DropdownButton.js.map +1 -1
  58. package/dist-cjs/index.js +19 -20
  59. package/dist-cjs/index.js.map +1 -1
  60. package/dist-cjs/localization-provider/LocalizationProvider.js +48 -0
  61. package/dist-cjs/localization-provider/LocalizationProvider.js.map +1 -0
  62. package/dist-cjs/overlay/OverlayHeader.css.js +6 -0
  63. package/dist-cjs/overlay/OverlayHeader.css.js.map +1 -0
  64. package/dist-cjs/overlay/OverlayHeader.js +35 -0
  65. package/dist-cjs/overlay/OverlayHeader.js.map +1 -0
  66. package/dist-cjs/system-status/SystemStatus.css.js +1 -1
  67. package/dist-cjs/tabs-next/TabListNext.css.js +1 -1
  68. package/dist-cjs/tabs-next/TabListNext.js +4 -0
  69. package/dist-cjs/tabs-next/TabListNext.js.map +1 -1
  70. package/dist-es/calendar/Calendar.js +12 -12
  71. package/dist-es/calendar/Calendar.js.map +1 -1
  72. package/dist-es/calendar/CalendarGrid.css.js +4 -0
  73. package/dist-es/calendar/CalendarGrid.css.js.map +1 -0
  74. package/dist-es/calendar/CalendarGrid.js +105 -0
  75. package/dist-es/calendar/CalendarGrid.js.map +1 -0
  76. package/dist-es/calendar/CalendarNavigation.js +220 -202
  77. package/dist-es/calendar/CalendarNavigation.js.map +1 -1
  78. package/dist-es/calendar/CalendarWeekHeader.js +11 -5
  79. package/dist-es/calendar/CalendarWeekHeader.js.map +1 -1
  80. package/dist-es/calendar/internal/CalendarContext.js +6 -2
  81. package/dist-es/calendar/internal/CalendarContext.js.map +1 -1
  82. package/dist-es/calendar/internal/CalendarDay.js +6 -9
  83. package/dist-es/calendar/internal/CalendarDay.js.map +1 -1
  84. package/dist-es/calendar/internal/CalendarMonth.css.js +1 -1
  85. package/dist-es/calendar/internal/CalendarMonth.js +48 -55
  86. package/dist-es/calendar/internal/CalendarMonth.js.map +1 -1
  87. package/dist-es/calendar/internal/useFocusManagement.js +15 -15
  88. package/dist-es/calendar/internal/useFocusManagement.js.map +1 -1
  89. package/dist-es/calendar/internal/utils.js +32 -45
  90. package/dist-es/calendar/internal/utils.js.map +1 -1
  91. package/dist-es/calendar/useCalendar.js +40 -32
  92. package/dist-es/calendar/useCalendar.js.map +1 -1
  93. package/dist-es/calendar/useCalendarDay.js +11 -17
  94. package/dist-es/calendar/useCalendarDay.js.map +1 -1
  95. package/dist-es/calendar/useCalendarSelection.js +40 -29
  96. package/dist-es/calendar/useCalendarSelection.js.map +1 -1
  97. package/dist-es/date-input/DateInput.css.js +1 -1
  98. package/dist-es/date-input/DateInputRange.js +101 -107
  99. package/dist-es/date-input/DateInputRange.js.map +1 -1
  100. package/dist-es/date-input/DateInputSingle.js +39 -51
  101. package/dist-es/date-input/DateInputSingle.js.map +1 -1
  102. package/dist-es/date-picker/DatePicker.js +15 -13
  103. package/dist-es/date-picker/DatePicker.js.map +1 -1
  104. package/dist-es/date-picker/DatePickerActions.js +3 -8
  105. package/dist-es/date-picker/DatePickerActions.js.map +1 -1
  106. package/dist-es/date-picker/DatePickerContext.js +6 -2
  107. package/dist-es/date-picker/DatePickerContext.js.map +1 -1
  108. package/dist-es/date-picker/DatePickerOverlay.js +1 -0
  109. package/dist-es/date-picker/DatePickerOverlay.js.map +1 -1
  110. package/dist-es/date-picker/DatePickerOverlayProvider.js +21 -8
  111. package/dist-es/date-picker/DatePickerOverlayProvider.js.map +1 -1
  112. package/dist-es/date-picker/DatePickerRangeInput.js +78 -30
  113. package/dist-es/date-picker/DatePickerRangeInput.js.map +1 -1
  114. package/dist-es/date-picker/DatePickerRangePanel.js +44 -39
  115. package/dist-es/date-picker/DatePickerRangePanel.js.map +1 -1
  116. package/dist-es/date-picker/DatePickerSingleInput.js +124 -85
  117. package/dist-es/date-picker/DatePickerSingleInput.js.map +1 -1
  118. package/dist-es/date-picker/DatePickerSinglePanel.js +17 -20
  119. package/dist-es/date-picker/DatePickerSinglePanel.js.map +1 -1
  120. package/dist-es/date-picker/DatePickerTrigger.js +30 -0
  121. package/dist-es/date-picker/DatePickerTrigger.js.map +1 -0
  122. package/dist-es/date-picker/useDatePicker.js +61 -111
  123. package/dist-es/date-picker/useDatePicker.js.map +1 -1
  124. package/dist-es/dropdown/DropdownButton.js.map +1 -1
  125. package/dist-es/index.js +8 -7
  126. package/dist-es/index.js.map +1 -1
  127. package/dist-es/localization-provider/LocalizationProvider.js +44 -0
  128. package/dist-es/localization-provider/LocalizationProvider.js.map +1 -0
  129. package/dist-es/overlay/OverlayHeader.css.js +4 -0
  130. package/dist-es/overlay/OverlayHeader.css.js.map +1 -0
  131. package/dist-es/overlay/OverlayHeader.js +33 -0
  132. package/dist-es/overlay/OverlayHeader.js.map +1 -0
  133. package/dist-es/system-status/SystemStatus.css.js +1 -1
  134. package/dist-es/tabs-next/TabListNext.css.js +1 -1
  135. package/dist-es/tabs-next/TabListNext.js +5 -1
  136. package/dist-es/tabs-next/TabListNext.js.map +1 -1
  137. package/dist-types/calendar/Calendar.d.ts +11 -6
  138. package/dist-types/calendar/CalendarGrid.d.ts +13 -0
  139. package/dist-types/calendar/CalendarNavigation.d.ts +9 -11
  140. package/dist-types/calendar/CalendarWeekHeader.d.ts +4 -3
  141. package/dist-types/calendar/index.d.ts +1 -2
  142. package/dist-types/calendar/internal/CalendarContext.d.ts +5 -6
  143. package/dist-types/calendar/internal/CalendarDay.d.ts +6 -8
  144. package/dist-types/calendar/internal/CalendarMonth.d.ts +5 -6
  145. package/dist-types/calendar/internal/useFocusManagement.d.ts +3 -4
  146. package/dist-types/calendar/internal/utils.d.ts +7 -11
  147. package/dist-types/calendar/useCalendar.d.ts +207 -55
  148. package/dist-types/calendar/useCalendarDay.d.ts +5 -7
  149. package/dist-types/calendar/useCalendarSelection.d.ts +92 -58
  150. package/dist-types/date-input/DateInputRange.d.ts +38 -56
  151. package/dist-types/date-input/DateInputSingle.d.ts +32 -49
  152. package/dist-types/date-input/index.d.ts +0 -1
  153. package/dist-types/date-picker/DatePicker.d.ts +23 -5
  154. package/dist-types/date-picker/DatePickerActions.d.ts +13 -12
  155. package/dist-types/date-picker/DatePickerContext.d.ts +42 -59
  156. package/dist-types/date-picker/DatePickerOverlayProvider.d.ts +10 -0
  157. package/dist-types/date-picker/DatePickerRangeInput.d.ts +13 -3
  158. package/dist-types/date-picker/DatePickerRangePanel.d.ts +17 -17
  159. package/dist-types/date-picker/DatePickerSingleInput.d.ts +12 -3
  160. package/dist-types/date-picker/DatePickerSinglePanel.d.ts +11 -11
  161. package/dist-types/date-picker/DatePickerTrigger.d.ts +9 -0
  162. package/dist-types/date-picker/index.d.ts +3 -2
  163. package/dist-types/date-picker/useDatePicker.d.ts +52 -59
  164. package/dist-types/index.d.ts +2 -0
  165. package/dist-types/localization-provider/LocalizationProvider.d.ts +62 -0
  166. package/dist-types/localization-provider/index.d.ts +1 -0
  167. package/dist-types/overlay/OverlayHeader.d.ts +20 -0
  168. package/dist-types/overlay/index.d.ts +1 -0
  169. package/package.json +11 -3
  170. package/dist-cjs/calendar/CalendarDateGrid.css.js +0 -6
  171. package/dist-cjs/calendar/CalendarDateGrid.css.js.map +0 -1
  172. package/dist-cjs/calendar/CalendarDateGrid.js +0 -105
  173. package/dist-cjs/calendar/CalendarDateGrid.js.map +0 -1
  174. package/dist-cjs/calendar/formatDate.js +0 -51
  175. package/dist-cjs/calendar/formatDate.js.map +0 -1
  176. package/dist-cjs/date-input/utils.js +0 -63
  177. package/dist-cjs/date-input/utils.js.map +0 -1
  178. package/dist-es/calendar/CalendarDateGrid.css.js +0 -4
  179. package/dist-es/calendar/CalendarDateGrid.css.js.map +0 -1
  180. package/dist-es/calendar/CalendarDateGrid.js +0 -103
  181. package/dist-es/calendar/CalendarDateGrid.js.map +0 -1
  182. package/dist-es/calendar/formatDate.js +0 -48
  183. package/dist-es/calendar/formatDate.js.map +0 -1
  184. package/dist-es/date-input/utils.js +0 -57
  185. package/dist-es/date-input/utils.js.map +0 -1
  186. package/dist-types/calendar/CalendarDateGrid.d.ts +0 -10
  187. package/dist-types/calendar/formatDate.d.ts +0 -14
  188. package/dist-types/date-input/utils.d.ts +0 -43
@@ -0,0 +1,62 @@
1
+ import type { DateFrameworkType, SaltDateAdapter } from "@salt-ds/date-adapters";
2
+ export interface LocalizationProviderValue<TDate extends DateFrameworkType> {
3
+ defaultDates: {
4
+ minDate: TDate;
5
+ maxDate: TDate;
6
+ };
7
+ dateAdapter: SaltDateAdapter<TDate>;
8
+ }
9
+ /**
10
+ * Props for the LocalizationProvider component.
11
+ *
12
+ * @template TDate - The type of the date object used in the provider.
13
+ * @template TLocale - The type of the locale, defaulting to string.
14
+ */
15
+ export interface LocalizationProviderProps<TDate extends DateFrameworkType, TLocale = string> {
16
+ /**
17
+ * The child components to be rendered within the provider.
18
+ */
19
+ children?: React.ReactNode;
20
+ /**
21
+ * The instance of the date library being used.
22
+ */
23
+ instance?: any;
24
+ /**
25
+ * The date adapter class, which provides methods for date manipulation and formatting.
26
+ * This should be a constructor for a class implementing the SaltDateAdapter interface.
27
+ */
28
+ DateAdapter: new (...args: any) => SaltDateAdapter<TDate, TLocale>;
29
+ /**
30
+ * The locale to be used for date formatting and manipulation.
31
+ */
32
+ locale?: TLocale;
33
+ /**
34
+ * The minimum date allowed for all date selections.
35
+ * Defaults to January 1, 1900.
36
+ */
37
+ minDate?: TDate;
38
+ /**
39
+ * The maximum date allowed for all date selections.
40
+ * Defaults to December 31, 2099.
41
+ */
42
+ maxDate?: TDate;
43
+ }
44
+ export declare type LocalizationProviderContext<TDate extends DateFrameworkType> = {
45
+ [K in keyof LocalizationProviderValue<TDate>]: LocalizationProviderValue<TDate>[K] | null;
46
+ };
47
+ export declare const LocalizationProviderContext: import("react").Context<LocalizationProviderValue<any> | null>;
48
+ export declare const LocalizationProvider: <TDate extends Date | import("dayjs").Dayjs | import("luxon").DateTime<boolean> | import("moment").Moment, TLocale>(props: LocalizationProviderProps<TDate, TLocale>) => import("react/jsx-runtime").JSX.Element;
49
+ /**
50
+ * Custom hook to access the localization context.
51
+ *
52
+ * This hook provides access to the localization settings and utilities
53
+ * within the `LocalizationProviderContext`. It should be used within a
54
+ * component that is a descendant of `LocalizationProviderContext.Provider`.
55
+ *
56
+ * @template TDate - The type of the date object used in the localization context.
57
+ *
58
+ * @returns The localization provider value, which includes date manipulation and formatting utilities.
59
+ *
60
+ * @throws Will throw an error if the hook is used outside of a `LocalizationProviderContext.Provider`.
61
+ */
62
+ export declare const useLocalization: <TDate extends Date | import("dayjs").Dayjs | import("luxon").DateTime<boolean> | import("moment").Moment>() => LocalizationProviderValue<TDate>;
@@ -0,0 +1 @@
1
+ export * from "./LocalizationProvider";
@@ -0,0 +1,20 @@
1
+ import { type ComponentPropsWithoutRef, type ReactNode } from "react";
2
+ export interface OverlayHeaderProps extends ComponentPropsWithoutRef<"div"> {
3
+ /**
4
+ * Description text is displayed just below the header
5
+ **/
6
+ description?: ReactNode;
7
+ /**
8
+ * Actions to be displayed in header
9
+ */
10
+ actions?: ReactNode;
11
+ /**
12
+ * Header text
13
+ */
14
+ header?: ReactNode;
15
+ /**
16
+ * Preheader text is displayed just above the header
17
+ **/
18
+ preheader?: ReactNode;
19
+ }
20
+ export declare const OverlayHeader: import("react").ForwardRefExoticComponent<OverlayHeaderProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1 @@
1
+ export * from "./OverlayHeader";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salt-ds/lab",
3
- "version": "1.0.0-alpha.55",
3
+ "version": "1.0.0-alpha.57",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,8 @@
12
12
  "sideEffects": false,
13
13
  "dependencies": {
14
14
  "@floating-ui/react": "^0.26.5",
15
- "@internationalized/date": "^3.5.5",
16
- "@salt-ds/core": "^1.37.2",
15
+ "@salt-ds/core": "^1.37.3",
16
+ "@salt-ds/date-adapters": "0.1.0-alpha.1",
17
17
  "@salt-ds/icons": "^1.13.0",
18
18
  "@salt-ds/styles": "0.2.1",
19
19
  "@salt-ds/window": "0.1.1",
@@ -31,6 +31,14 @@
31
31
  "tabbable": "^6.0.0",
32
32
  "tinycolor2": "^1.4.2"
33
33
  },
34
+ "devDependencies": {
35
+ "@types/luxon": "^3.4.2",
36
+ "date-fns": "^3.6.0",
37
+ "dayjs": "^1.11.13",
38
+ "luxon": "^3.5.0",
39
+ "moment": "^2.30.1",
40
+ "moment-timezone": "^0.5.46"
41
+ },
34
42
  "peerDependencies": {
35
43
  "@types/react": ">=16.14.0",
36
44
  "react": ">=16.14.0",
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var css_248z = ".saltCalendarDateGrid-grid {\n display: grid;\n grid-auto-flow: column;\n}\n\n.saltCalendarDateGrid-grid > * {\n position: absolute;\n left: 0;\n width: 100%;\n}\n\n.saltCalendarDateGrid-grid > :nth-child(2) {\n position: relative;\n}\n";
4
-
5
- module.exports = css_248z;
6
- //# sourceMappingURL=CalendarDateGrid.css.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CalendarDateGrid.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -1,105 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var date = require('@internationalized/date');
5
- var core = require('@salt-ds/core');
6
- var react = require('react');
7
- var CalendarContext = require('./internal/CalendarContext.js');
8
- var CalendarMonth = require('./internal/CalendarMonth.js');
9
- var styles = require('@salt-ds/styles');
10
- var window = require('@salt-ds/window');
11
- var CalendarDateGrid$1 = require('./CalendarDateGrid.css.js');
12
- var utils = require('./internal/utils.js');
13
-
14
- function getMonths(month) {
15
- return [month.subtract({ months: 1 }), month, month.add({ months: 1 })];
16
- }
17
- const withBaseName = core.makePrefixer("saltCalendarDateGrid");
18
- const CalendarDateGrid = react.forwardRef(function CalendarDateGrid2(props, ref) {
19
- const {
20
- onFocus,
21
- onBlur,
22
- getCalendarMonthProps = () => void 0,
23
- ...rest
24
- } = props;
25
- const targetWindow = window.useWindow();
26
- styles.useComponentCssInjection({
27
- testId: "salt-calendar-date-grid",
28
- css: CalendarDateGrid$1,
29
- window: targetWindow
30
- });
31
- const {
32
- state: { visibleMonth, locale },
33
- helpers: { setCalendarFocused }
34
- } = CalendarContext.useCalendarContext();
35
- const containerRef = react.useRef(null);
36
- const diffIndex = (a, b) => utils.monthDiff(a, b);
37
- const { current: baseIndex } = react.useRef(visibleMonth);
38
- core.useIsomorphicLayoutEffect(() => {
39
- if (containerRef.current) {
40
- containerRef.current.style.transform = `translate3d(${diffIndex(baseIndex, visibleMonth) * -101}%, 0, 0)`;
41
- }
42
- });
43
- const [months, setMonths] = react.useState(() => getMonths(visibleMonth));
44
- react.useEffect(() => {
45
- setMonths((oldMonths) => {
46
- const newMonths = getMonths(visibleMonth).filter((month) => {
47
- return !oldMonths.find((oldMonth) => date.isSameMonth(oldMonth, month));
48
- });
49
- return oldMonths.concat(newMonths);
50
- });
51
- setMonths(getMonths(visibleMonth));
52
- return void 0;
53
- }, [utils.formatDate(visibleMonth, locale)]);
54
- const handleFocus = react.useCallback(
55
- (event) => {
56
- setCalendarFocused(true);
57
- onFocus == null ? void 0 : onFocus(event);
58
- },
59
- [setCalendarFocused, onFocus]
60
- );
61
- const handleBlur = react.useCallback(
62
- (event) => {
63
- setCalendarFocused(false);
64
- onBlur == null ? void 0 : onBlur(event);
65
- },
66
- [setCalendarFocused, onBlur]
67
- );
68
- return /* @__PURE__ */ jsxRuntime.jsx(
69
- "div",
70
- {
71
- className: withBaseName(),
72
- tabIndex: -1,
73
- style: {
74
- overflowX: "hidden",
75
- position: "relative"
76
- },
77
- ref,
78
- children: /* @__PURE__ */ jsxRuntime.jsx(
79
- "div",
80
- {
81
- className: withBaseName("grid"),
82
- ref: containerRef,
83
- onBlur: handleBlur,
84
- onFocus: handleFocus,
85
- ...rest,
86
- children: months.map((date, index) => /* @__PURE__ */ jsxRuntime.jsx(
87
- "div",
88
- {
89
- className: withBaseName("slide"),
90
- style: {
91
- transform: `translateX(${diffIndex(date, baseIndex) * -101}%)`
92
- },
93
- "aria-hidden": index !== 1 ? "true" : void 0,
94
- children: /* @__PURE__ */ jsxRuntime.jsx(CalendarMonth.CalendarMonth, { ...getCalendarMonthProps(date), date })
95
- },
96
- utils.formatDate(date, locale)
97
- ))
98
- }
99
- )
100
- }
101
- );
102
- });
103
-
104
- exports.CalendarDateGrid = CalendarDateGrid;
105
- //# sourceMappingURL=CalendarDateGrid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CalendarDateGrid.js","sources":["../src/calendar/CalendarDateGrid.tsx"],"sourcesContent":["import { type DateValue, isSameMonth } from \"@internationalized/date\";\nimport { makePrefixer, useIsomorphicLayoutEffect } from \"@salt-ds/core\";\nimport {\n type ComponentPropsWithoutRef,\n type FocusEventHandler,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useCalendarContext } from \"./internal/CalendarContext\";\nimport {\n CalendarMonth,\n type CalendarMonthProps,\n} from \"./internal/CalendarMonth\";\n\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport calendarDateGridCss from \"./CalendarDateGrid.css\";\nimport { formatDate, monthDiff } from \"./internal/utils\";\n\nexport interface CalendarDateGridProps extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * Props getter to pass to each CalendarMonth element\n */\n getCalendarMonthProps?: (date: DateValue) => Omit<CalendarMonthProps, \"date\">;\n}\n\nfunction getMonths(month: DateValue) {\n return [month.subtract({ months: 1 }), month, month.add({ months: 1 })];\n}\n\nconst withBaseName = makePrefixer(\"saltCalendarDateGrid\");\n\nexport const CalendarDateGrid = forwardRef<\n HTMLDivElement,\n CalendarDateGridProps\n>(function CalendarDateGrid(props, ref) {\n const {\n onFocus,\n onBlur,\n getCalendarMonthProps = () => undefined,\n ...rest\n } = props;\n\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-calendar-date-grid\",\n css: calendarDateGridCss,\n window: targetWindow,\n });\n\n const {\n state: { visibleMonth, locale },\n helpers: { setCalendarFocused },\n } = useCalendarContext();\n const containerRef = useRef<HTMLDivElement>(null);\n const diffIndex = (a: DateValue, b: DateValue) => monthDiff(a, b);\n\n const { current: baseIndex } = useRef(visibleMonth);\n\n useIsomorphicLayoutEffect(() => {\n if (containerRef.current) {\n containerRef.current.style.transform = `translate3d(${\n diffIndex(baseIndex, visibleMonth) * -101 // needs to be higher than 100% so the next month doesn't show on the edges\n }%, 0, 0)`;\n }\n });\n\n const [months, setMonths] = useState(() => getMonths(visibleMonth));\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: uses formatData to change visibleMonth into string\n useEffect(() => {\n setMonths((oldMonths) => {\n const newMonths = getMonths(visibleMonth).filter((month) => {\n return !oldMonths.find((oldMonth) => isSameMonth(oldMonth, month));\n });\n\n return oldMonths.concat(newMonths);\n });\n setMonths(getMonths(visibleMonth));\n return undefined;\n }, [formatDate(visibleMonth, locale)]);\n\n const handleFocus: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n setCalendarFocused(true);\n onFocus?.(event);\n },\n [setCalendarFocused, onFocus],\n );\n\n const handleBlur: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n setCalendarFocused(false);\n onBlur?.(event);\n },\n [setCalendarFocused, onBlur],\n );\n\n return (\n <div\n className={withBaseName()}\n tabIndex={-1} // https://bugzilla.mozilla.org/show_bug.cgi?id=1069739\n style={{\n overflowX: \"hidden\",\n position: \"relative\",\n }}\n ref={ref}\n >\n <div\n className={withBaseName(\"grid\")}\n ref={containerRef}\n onBlur={handleBlur}\n onFocus={handleFocus}\n {...rest}\n >\n {months.map((date, index) => (\n <div\n key={formatDate(date, locale)}\n className={withBaseName(\"slide\")}\n style={{\n transform: `translateX(${diffIndex(date, baseIndex) * -101}%)`,\n }}\n aria-hidden={index !== 1 ? \"true\" : undefined}\n >\n <CalendarMonth {...getCalendarMonthProps(date)} date={date} />\n </div>\n ))}\n </div>\n </div>\n );\n});\n"],"names":["makePrefixer","forwardRef","CalendarDateGrid","useWindow","useComponentCssInjection","calendarDateGridCss","useCalendarContext","useRef","monthDiff","useIsomorphicLayoutEffect","useState","useEffect","isSameMonth","formatDate","useCallback","js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AW,EAAA,QAAA;AAAA,QACX,QAAU,EAAA;AAAA,OACZ;AAAA,MACA,GAAA;AAAA,MAEA,QAAA,kBAAAA,cAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAW,aAAa,MAAM,CAAA;AAAA,UAC9B,GAAK,EAAA,YAAA;AAAA,UACL,MAAQ,EAAA,UAAA;AAAA,UACR,OAAS,EAAA,WAAA;AAAA,UACR,GAAG,IAAA;AAAA,UAEH,QAAO,EAAA,MAAA,CAAA,GAAA,CAAI,CAAC,IAAA,EAAM,KACjB,qBAAAA,cAAA;AAAA,YAAC,KAAA;AAAA,YAAA;AAAA,cAEC,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,cAC/B,KAAO,EAAA;AAAA,gBACL,WAAW,CAAc,WAAA,EAAA,SAAA,CAAU,IAAM,EAAA,SAAS,IAAI,CAAI,GAAA,CAAA,EAAA;AAAA,eAC5D;AAAA,cACA,aAAA,EAAa,KAAU,KAAA,CAAA,GAAI,MAAS,GAAA,KAAA,CAAA;AAAA,cAEpC,yCAACC,2BAAe,EAAA,EAAA,GAAG,qBAAsB,CAAA,IAAI,GAAG,IAAY,EAAA;AAAA,aAAA;AAAA,YAPvDH,gBAAA,CAAW,MAAM,MAAM;AAAA,WAS/B;AAAA;AAAA;AACH;AAAA,GACF;AAEJ,CAAC;;;;"}
@@ -1,51 +0,0 @@
1
- 'use strict';
2
-
3
- var date = require('@internationalized/date');
4
-
5
- function getCurrentLocale() {
6
- return navigator.languages[0];
7
- }
8
- const defaultFormatOptions = {
9
- day: "2-digit",
10
- month: "short",
11
- year: "numeric"
12
- };
13
- function formatDate(date$1, locale, options) {
14
- var _a, _b, _c;
15
- if (!date$1) {
16
- return "";
17
- }
18
- const timeLocale = locale || getCurrentLocale();
19
- const timeZone = (options == null ? void 0 : options.timeZone) || date.getLocalTimeZone();
20
- const formatter = new date.DateFormatter(timeLocale, {
21
- ...defaultFormatOptions,
22
- ...options
23
- });
24
- const formattedDate = formatter.formatToParts(date$1.toDate(timeZone));
25
- const isNumericFormat = (options == null ? void 0 : options.month) === "numeric" || defaultFormatOptions.month === "numeric";
26
- const separator = isNumericFormat ? "/" : " ";
27
- const parts = [];
28
- if ((options == null ? void 0 : options.day) !== void 0 || defaultFormatOptions.day !== void 0) {
29
- const day = (_a = formattedDate.find(
30
- (part) => part.type === "day"
31
- )) == null ? void 0 : _a.value;
32
- if (day) parts.push(day);
33
- }
34
- if ((options == null ? void 0 : options.month) !== void 0 || defaultFormatOptions.month !== void 0) {
35
- const month = (_b = formattedDate.find(
36
- (part) => part.type === "month"
37
- )) == null ? void 0 : _b.value;
38
- if (month) parts.push(month);
39
- }
40
- if ((options == null ? void 0 : options.year) !== void 0 || defaultFormatOptions.year !== void 0) {
41
- const year = (_c = formattedDate.find(
42
- (part) => part.type === "year"
43
- )) == null ? void 0 : _c.value;
44
- if (year) parts.push(year);
45
- }
46
- return parts.join(separator);
47
- }
48
-
49
- exports.formatDate = formatDate;
50
- exports.getCurrentLocale = getCurrentLocale;
51
- //# sourceMappingURL=formatDate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatDate.js","sources":["../src/calendar/formatDate.ts"],"sourcesContent":["import {\n DateFormatter,\n type DateValue,\n getLocalTimeZone,\n} from \"@internationalized/date\";\n\n/**\n * Gets the current locale from the browser.\n * @returns The current locale as a string.\n */\nexport function getCurrentLocale() {\n return navigator.languages[0];\n}\n\n/**\n * Default options for date formatting.\n */\nconst defaultFormatOptions: Intl.DateTimeFormatOptions = {\n day: \"2-digit\",\n month: \"short\",\n year: \"numeric\",\n};\n\n/**\n * Formats a date value according to the specified locale and options.\n * @param date - The date value to format.\n * @param locale - The locale to use for formatting. Defaults to the current locale.\n * @param options - Additional options for date formatting.\n * @returns The formatted date as a string.\n */\nexport function formatDate(\n date: DateValue | null,\n locale?: string,\n options?: Intl.DateTimeFormatOptions,\n) {\n if (!date) {\n return \"\";\n }\n const timeLocale = locale || getCurrentLocale();\n const timeZone = options?.timeZone || getLocalTimeZone();\n\n const formatter = new DateFormatter(timeLocale, {\n ...defaultFormatOptions,\n ...options,\n });\n\n const formattedDate = formatter.formatToParts(date.toDate(timeZone));\n\n // Determine the separator based on the provided options\n const isNumericFormat =\n options?.month === \"numeric\" || defaultFormatOptions.month === \"numeric\";\n const separator = isNumericFormat ? \"/\" : \" \";\n\n // Some locales (USA) added commas, so construct the final date ourselves from formatter parts\n const parts = [];\n if (options?.day !== undefined || defaultFormatOptions.day !== undefined) {\n const day = formattedDate.find(\n (part: Intl.DateTimeFormatPart) => part.type === \"day\",\n )?.value;\n if (day) parts.push(day);\n }\n if (\n options?.month !== undefined ||\n defaultFormatOptions.month !== undefined\n ) {\n const month = formattedDate.find(\n (part: Intl.DateTimeFormatPart) => part.type === \"month\",\n )?.value;\n if (month) parts.push(month);\n }\n if (options?.year !== undefined || defaultFormatOptions.year !== undefined) {\n const year = formattedDate.find(\n (part: Intl.DateTimeFormatPart) => part.type === \"year\",\n )?.value;\n if (year) parts.push(year);\n }\n\n return parts.join(separator);\n}\n"],"names":["date","getLocalTimeZone","DateFormatter"],"mappings":";;;;AAUO,SAAS,gBAAmB,GAAA;AACjC,EAAO,OAAA,SAAA,CAAU,UAAU,CAAC,CAAA;AAC9B;AAKA,MAAM,oBAAmD,GAAA;AAAA,EACvD,GAAK,EAAA,SAAA;AAAA,EACL,KAAO,EAAA,OAAA;AAAA,EACP,IAAM,EAAA;AACR,CAAA;AASgB,SAAA,UAAA,CACdA,MACA,EAAA,MAAA,EACA,OACA,EAAA;AAlCF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAmCE,EAAA,IAAI,CAACA,MAAM,EAAA;AACT,IAAO,OAAA,EAAA;AAAA;AAET,EAAM,MAAA,UAAA,GAAa,UAAU,gBAAiB,EAAA;AAC9C,EAAM,MAAA,QAAA,GAAA,CAAW,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,QAAA,KAAYC,qBAA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AAA;AAE7B,EAAA,IAAA,CAAI,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,IAAA,MAAS,KAAa,CAAA,IAAA,oBAAA,CAAqB,SAAS,KAAW,CAAA,EAAA;AAC1E,IAAA,MAAM,QAAO,EAAc,GAAA,aAAA,CAAA,IAAA;AAAA,MACzB,CAAC,IAAkC,KAAA,IAAA,CAAK,IAAS,KAAA;AAAA,UADtC,IAEV,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,KAAA;AACH,IAAI,IAAA,IAAA,EAAY,KAAA,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA;AAG3B,EAAO,OAAA,KAAA,CAAM,KAAK,SAAS,CAAA;AAC7B;;;;;"}
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- var date = require('@internationalized/date');
4
-
5
- function parseCalendarDate(inputDate) {
6
- if (!(inputDate == null ? void 0 : inputDate.length)) {
7
- return { date: null, error: false };
8
- }
9
- const date$1 = new Date(inputDate);
10
- if (Number.isNaN(date$1.getTime())) {
11
- return { date: null, error: "not a valid date" };
12
- }
13
- const year = date$1.getFullYear();
14
- const month = date$1.getMonth() + 1;
15
- const day = date$1.getDate();
16
- try {
17
- const isoDate = new date.CalendarDate(year, month, day);
18
- return { date: isoDate, error: false };
19
- } catch (err) {
20
- return { date: null, error: err.message };
21
- }
22
- }
23
- function parseZonedDateTime(inputDate, timeZone = date.getLocalTimeZone()) {
24
- const parsedDate = parseCalendarDate(inputDate);
25
- if (!parsedDate.date || parsedDate.error) {
26
- return { ...parsedDate, date: null };
27
- }
28
- try {
29
- const zonedDate = date.toZoned(parsedDate.date, timeZone, "compatible");
30
- return { date: zonedDate, error: false };
31
- } catch (err) {
32
- return { date: null, error: err.message };
33
- }
34
- }
35
- const dateSupportsTime = (date$1) => date$1 instanceof date.CalendarDateTime || date$1 instanceof date.ZonedDateTime;
36
- function extractTimeFieldsFromDateRange(selectedDate) {
37
- let startTime;
38
- let endTime;
39
- if (selectedDate) {
40
- if (selectedDate.startDate && dateSupportsTime(selectedDate.startDate)) {
41
- const { hour, minute, second, millisecond } = selectedDate.startDate;
42
- startTime = { hour, minute, second, millisecond };
43
- }
44
- if (selectedDate.endDate && dateSupportsTime(selectedDate.endDate)) {
45
- const { hour, minute, second, millisecond } = selectedDate.endDate;
46
- endTime = { hour, minute, second, millisecond };
47
- }
48
- }
49
- return { startTime, endTime };
50
- }
51
- function extractTimeFieldsFromDate(selectedDate) {
52
- if (selectedDate && dateSupportsTime(selectedDate)) {
53
- const { hour, minute, second, millisecond } = selectedDate;
54
- return { hour, minute, second, millisecond };
55
- }
56
- }
57
-
58
- exports.dateSupportsTime = dateSupportsTime;
59
- exports.extractTimeFieldsFromDate = extractTimeFieldsFromDate;
60
- exports.extractTimeFieldsFromDateRange = extractTimeFieldsFromDateRange;
61
- exports.parseCalendarDate = parseCalendarDate;
62
- exports.parseZonedDateTime = parseZonedDateTime;
63
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sources":["../src/date-input/utils.ts"],"sourcesContent":["import {\n CalendarDate,\n CalendarDateTime,\n type DateValue,\n type TimeFields,\n ZonedDateTime,\n getLocalTimeZone,\n toZoned,\n} from \"@internationalized/date\";\nimport type { DateRangeSelection, SingleDateSelection } from \"../calendar\";\n\nexport type RangeTimeFields = {\n startTime?: TimeFields;\n endTime?: TimeFields;\n};\n\n/**\n * Parses a string into a CalendarDate.\n * @param inputDate - The input date string.\n * @returns An object containing the parsed date and any error encountered.\n */\nexport function parseCalendarDate(inputDate: string): {\n date: DateValue | null;\n error: string | false;\n} {\n if (!inputDate?.length) {\n return { date: null, error: false };\n }\n const date = new Date(inputDate);\n if (Number.isNaN(date.getTime())) {\n return { date: null, error: \"not a valid date\" };\n }\n\n const year = date.getFullYear();\n const month = date.getMonth() + 1;\n const day = date.getDate();\n\n try {\n const isoDate = new CalendarDate(year, month, day);\n return { date: isoDate, error: false };\n } catch (err) {\n return { date: null, error: (err as Error).message };\n }\n}\n\n/**\n * Parses a string into a ZonedDateTime.\n * @param inputDate - The input date string.\n * @param timeZone - The time zone to use for parsing. Defaults to the local time zone.\n * @returns An object containing the parsed date and any error encountered.\n */\nexport function parseZonedDateTime(\n inputDate: string,\n timeZone: string = getLocalTimeZone(),\n): {\n date: DateValue | null;\n error: string | false;\n} {\n const parsedDate = parseCalendarDate(inputDate);\n if (!parsedDate.date || parsedDate.error) {\n return { ...parsedDate, date: null };\n }\n try {\n const zonedDate = toZoned(parsedDate.date, timeZone, \"compatible\");\n return { date: zonedDate, error: false };\n } catch (err) {\n return { date: null, error: (err as Error).message };\n }\n}\n\n/**\n * Checks if a date supports time fields.\n * @param date - The date to check.\n * @returns `true` if the date supports time fields, otherwise `false`.\n */\nexport const dateSupportsTime = (\n date: DateValue,\n): date is CalendarDateTime | ZonedDateTime =>\n date instanceof CalendarDateTime || date instanceof ZonedDateTime;\n\n/**\n * Extracts time fields from a date range selection.\n * @param selectedDate - The selected date range.\n * @returns An object containing the start and end time fields.\n */\nexport function extractTimeFieldsFromDateRange(\n selectedDate: DateRangeSelection | null,\n): RangeTimeFields {\n let startTime: TimeFields | undefined;\n let endTime: TimeFields | undefined;\n if (selectedDate) {\n if (selectedDate.startDate && dateSupportsTime(selectedDate.startDate)) {\n const { hour, minute, second, millisecond } = selectedDate.startDate;\n startTime = { hour, minute, second, millisecond };\n }\n if (selectedDate.endDate && dateSupportsTime(selectedDate.endDate)) {\n const { hour, minute, second, millisecond } = selectedDate.endDate;\n endTime = { hour, minute, second, millisecond };\n }\n }\n return { startTime, endTime };\n}\n\n/**\n * Extracts time fields from a single date selection.\n * @param selectedDate - The selected date.\n * @returns The time fields of the selected date, if available.\n */\nexport function extractTimeFieldsFromDate(\n selectedDate: SingleDateSelection | null,\n): TimeFields | undefined {\n if (selectedDate && dateSupportsTime(selectedDate)) {\n const { hour, minute, second, millisecond } = selectedDate;\n return { hour, minute, second, millisecond };\n }\n}\n"],"names":["date","Calendar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AAQ,EAAA,MAAA,EAAQ,WAAY,EAAA;AAAA;AAE/C;;;;;;;;"}
@@ -1,4 +0,0 @@
1
- var css_248z = ".saltCalendarDateGrid-grid {\n display: grid;\n grid-auto-flow: column;\n}\n\n.saltCalendarDateGrid-grid > * {\n position: absolute;\n left: 0;\n width: 100%;\n}\n\n.saltCalendarDateGrid-grid > :nth-child(2) {\n position: relative;\n}\n";
2
-
3
- export { css_248z as default };
4
- //# sourceMappingURL=CalendarDateGrid.css.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CalendarDateGrid.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,103 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { isSameMonth } from '@internationalized/date';
3
- import { makePrefixer, useIsomorphicLayoutEffect } from '@salt-ds/core';
4
- import { forwardRef, useRef, useState, useEffect, useCallback } from 'react';
5
- import { useCalendarContext } from './internal/CalendarContext.js';
6
- import { CalendarMonth } from './internal/CalendarMonth.js';
7
- import { useComponentCssInjection } from '@salt-ds/styles';
8
- import { useWindow } from '@salt-ds/window';
9
- import css_248z from './CalendarDateGrid.css.js';
10
- import { formatDate, monthDiff } from './internal/utils.js';
11
-
12
- function getMonths(month) {
13
- return [month.subtract({ months: 1 }), month, month.add({ months: 1 })];
14
- }
15
- const withBaseName = makePrefixer("saltCalendarDateGrid");
16
- const CalendarDateGrid = forwardRef(function CalendarDateGrid2(props, ref) {
17
- const {
18
- onFocus,
19
- onBlur,
20
- getCalendarMonthProps = () => void 0,
21
- ...rest
22
- } = props;
23
- const targetWindow = useWindow();
24
- useComponentCssInjection({
25
- testId: "salt-calendar-date-grid",
26
- css: css_248z,
27
- window: targetWindow
28
- });
29
- const {
30
- state: { visibleMonth, locale },
31
- helpers: { setCalendarFocused }
32
- } = useCalendarContext();
33
- const containerRef = useRef(null);
34
- const diffIndex = (a, b) => monthDiff(a, b);
35
- const { current: baseIndex } = useRef(visibleMonth);
36
- useIsomorphicLayoutEffect(() => {
37
- if (containerRef.current) {
38
- containerRef.current.style.transform = `translate3d(${diffIndex(baseIndex, visibleMonth) * -101}%, 0, 0)`;
39
- }
40
- });
41
- const [months, setMonths] = useState(() => getMonths(visibleMonth));
42
- useEffect(() => {
43
- setMonths((oldMonths) => {
44
- const newMonths = getMonths(visibleMonth).filter((month) => {
45
- return !oldMonths.find((oldMonth) => isSameMonth(oldMonth, month));
46
- });
47
- return oldMonths.concat(newMonths);
48
- });
49
- setMonths(getMonths(visibleMonth));
50
- return void 0;
51
- }, [formatDate(visibleMonth, locale)]);
52
- const handleFocus = useCallback(
53
- (event) => {
54
- setCalendarFocused(true);
55
- onFocus == null ? void 0 : onFocus(event);
56
- },
57
- [setCalendarFocused, onFocus]
58
- );
59
- const handleBlur = useCallback(
60
- (event) => {
61
- setCalendarFocused(false);
62
- onBlur == null ? void 0 : onBlur(event);
63
- },
64
- [setCalendarFocused, onBlur]
65
- );
66
- return /* @__PURE__ */ jsx(
67
- "div",
68
- {
69
- className: withBaseName(),
70
- tabIndex: -1,
71
- style: {
72
- overflowX: "hidden",
73
- position: "relative"
74
- },
75
- ref,
76
- children: /* @__PURE__ */ jsx(
77
- "div",
78
- {
79
- className: withBaseName("grid"),
80
- ref: containerRef,
81
- onBlur: handleBlur,
82
- onFocus: handleFocus,
83
- ...rest,
84
- children: months.map((date, index) => /* @__PURE__ */ jsx(
85
- "div",
86
- {
87
- className: withBaseName("slide"),
88
- style: {
89
- transform: `translateX(${diffIndex(date, baseIndex) * -101}%)`
90
- },
91
- "aria-hidden": index !== 1 ? "true" : void 0,
92
- children: /* @__PURE__ */ jsx(CalendarMonth, { ...getCalendarMonthProps(date), date })
93
- },
94
- formatDate(date, locale)
95
- ))
96
- }
97
- )
98
- }
99
- );
100
- });
101
-
102
- export { CalendarDateGrid };
103
- //# sourceMappingURL=CalendarDateGrid.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CalendarDateGrid.js","sources":["../src/calendar/CalendarDateGrid.tsx"],"sourcesContent":["import { type DateValue, isSameMonth } from \"@internationalized/date\";\nimport { makePrefixer, useIsomorphicLayoutEffect } from \"@salt-ds/core\";\nimport {\n type ComponentPropsWithoutRef,\n type FocusEventHandler,\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useCalendarContext } from \"./internal/CalendarContext\";\nimport {\n CalendarMonth,\n type CalendarMonthProps,\n} from \"./internal/CalendarMonth\";\n\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\nimport { useWindow } from \"@salt-ds/window\";\nimport calendarDateGridCss from \"./CalendarDateGrid.css\";\nimport { formatDate, monthDiff } from \"./internal/utils\";\n\nexport interface CalendarDateGridProps extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * Props getter to pass to each CalendarMonth element\n */\n getCalendarMonthProps?: (date: DateValue) => Omit<CalendarMonthProps, \"date\">;\n}\n\nfunction getMonths(month: DateValue) {\n return [month.subtract({ months: 1 }), month, month.add({ months: 1 })];\n}\n\nconst withBaseName = makePrefixer(\"saltCalendarDateGrid\");\n\nexport const CalendarDateGrid = forwardRef<\n HTMLDivElement,\n CalendarDateGridProps\n>(function CalendarDateGrid(props, ref) {\n const {\n onFocus,\n onBlur,\n getCalendarMonthProps = () => undefined,\n ...rest\n } = props;\n\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-calendar-date-grid\",\n css: calendarDateGridCss,\n window: targetWindow,\n });\n\n const {\n state: { visibleMonth, locale },\n helpers: { setCalendarFocused },\n } = useCalendarContext();\n const containerRef = useRef<HTMLDivElement>(null);\n const diffIndex = (a: DateValue, b: DateValue) => monthDiff(a, b);\n\n const { current: baseIndex } = useRef(visibleMonth);\n\n useIsomorphicLayoutEffect(() => {\n if (containerRef.current) {\n containerRef.current.style.transform = `translate3d(${\n diffIndex(baseIndex, visibleMonth) * -101 // needs to be higher than 100% so the next month doesn't show on the edges\n }%, 0, 0)`;\n }\n });\n\n const [months, setMonths] = useState(() => getMonths(visibleMonth));\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: uses formatData to change visibleMonth into string\n useEffect(() => {\n setMonths((oldMonths) => {\n const newMonths = getMonths(visibleMonth).filter((month) => {\n return !oldMonths.find((oldMonth) => isSameMonth(oldMonth, month));\n });\n\n return oldMonths.concat(newMonths);\n });\n setMonths(getMonths(visibleMonth));\n return undefined;\n }, [formatDate(visibleMonth, locale)]);\n\n const handleFocus: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n setCalendarFocused(true);\n onFocus?.(event);\n },\n [setCalendarFocused, onFocus],\n );\n\n const handleBlur: FocusEventHandler<HTMLDivElement> = useCallback(\n (event) => {\n setCalendarFocused(false);\n onBlur?.(event);\n },\n [setCalendarFocused, onBlur],\n );\n\n return (\n <div\n className={withBaseName()}\n tabIndex={-1} // https://bugzilla.mozilla.org/show_bug.cgi?id=1069739\n style={{\n overflowX: \"hidden\",\n position: \"relative\",\n }}\n ref={ref}\n >\n <div\n className={withBaseName(\"grid\")}\n ref={containerRef}\n onBlur={handleBlur}\n onFocus={handleFocus}\n {...rest}\n >\n {months.map((date, index) => (\n <div\n key={formatDate(date, locale)}\n className={withBaseName(\"slide\")}\n style={{\n transform: `translateX(${diffIndex(date, baseIndex) * -101}%)`,\n }}\n aria-hidden={index !== 1 ? \"true\" : undefined}\n >\n <CalendarMonth {...getCalendarMonthProps(date)} date={date} />\n </div>\n ))}\n </div>\n </div>\n );\n});\n"],"names":["CalendarDateGrid","calendarDateGridCss"],"mappings":";;;;;;;;;;;AA6BA,SAAS,UAAU,KAAkB,EAAA;AACnC,EAAA,OAAO,CAAC,KAAA,CAAM,QAAS,CAAA,EAAE,QAAQ,CAAE,EAAC,CAAG,EAAA,KAAA,EAAO,MAAM,GAAI,CAAA,EAAE,MAAQ,EAAA,CAAA,EAAG,CAAC,CAAA;AACxE;AAEA,MAAM,YAAA,GAAe,aAAa,sBAAsB,CAAA;AAEjD,MAAM,gBAAmB,GAAA,UAAA,CAG9B,SAASA,iBAAAA,CAA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GAAA;AAAA,YAAC,KAAA;AAAA,YAAA;AAAA,cAEC,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,cAC/B,KAAO,EAAA;AAAA,gBACL,WAAW,CAAc,WAAA,EAAA,SAAA,CAAU,IAAM,EAAA,SAAS,IAAI,CAAI,GAAA,CAAA,EAAA;AAAA,eAC5D;AAAA,cACA,aAAA,EAAa,KAAU,KAAA,CAAA,GAAI,MAAS,GAAA,KAAA,CAAA;AAAA,cAEpC,8BAAC,aAAe,EAAA,EAAA,GAAG,qBAAsB,CAAA,IAAI,GAAG,IAAY,EAAA;AAAA,aAAA;AAAA,YAPvD,UAAA,CAAW,MAAM,MAAM;AAAA,WAS/B;AAAA;AAAA;AACH;AAAA,GACF;AAEJ,CAAC;;;;"}
@@ -1,48 +0,0 @@
1
- import { getLocalTimeZone, DateFormatter } from '@internationalized/date';
2
-
3
- function getCurrentLocale() {
4
- return navigator.languages[0];
5
- }
6
- const defaultFormatOptions = {
7
- day: "2-digit",
8
- month: "short",
9
- year: "numeric"
10
- };
11
- function formatDate(date, locale, options) {
12
- var _a, _b, _c;
13
- if (!date) {
14
- return "";
15
- }
16
- const timeLocale = locale || getCurrentLocale();
17
- const timeZone = (options == null ? void 0 : options.timeZone) || getLocalTimeZone();
18
- const formatter = new DateFormatter(timeLocale, {
19
- ...defaultFormatOptions,
20
- ...options
21
- });
22
- const formattedDate = formatter.formatToParts(date.toDate(timeZone));
23
- const isNumericFormat = (options == null ? void 0 : options.month) === "numeric" || defaultFormatOptions.month === "numeric";
24
- const separator = isNumericFormat ? "/" : " ";
25
- const parts = [];
26
- if ((options == null ? void 0 : options.day) !== void 0 || defaultFormatOptions.day !== void 0) {
27
- const day = (_a = formattedDate.find(
28
- (part) => part.type === "day"
29
- )) == null ? void 0 : _a.value;
30
- if (day) parts.push(day);
31
- }
32
- if ((options == null ? void 0 : options.month) !== void 0 || defaultFormatOptions.month !== void 0) {
33
- const month = (_b = formattedDate.find(
34
- (part) => part.type === "month"
35
- )) == null ? void 0 : _b.value;
36
- if (month) parts.push(month);
37
- }
38
- if ((options == null ? void 0 : options.year) !== void 0 || defaultFormatOptions.year !== void 0) {
39
- const year = (_c = formattedDate.find(
40
- (part) => part.type === "year"
41
- )) == null ? void 0 : _c.value;
42
- if (year) parts.push(year);
43
- }
44
- return parts.join(separator);
45
- }
46
-
47
- export { formatDate, getCurrentLocale };
48
- //# sourceMappingURL=formatDate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatDate.js","sources":["../src/calendar/formatDate.ts"],"sourcesContent":["import {\n DateFormatter,\n type DateValue,\n getLocalTimeZone,\n} from \"@internationalized/date\";\n\n/**\n * Gets the current locale from the browser.\n * @returns The current locale as a string.\n */\nexport function getCurrentLocale() {\n return navigator.languages[0];\n}\n\n/**\n * Default options for date formatting.\n */\nconst defaultFormatOptions: Intl.DateTimeFormatOptions = {\n day: \"2-digit\",\n month: \"short\",\n year: \"numeric\",\n};\n\n/**\n * Formats a date value according to the specified locale and options.\n * @param date - The date value to format.\n * @param locale - The locale to use for formatting. Defaults to the current locale.\n * @param options - Additional options for date formatting.\n * @returns The formatted date as a string.\n */\nexport function formatDate(\n date: DateValue | null,\n locale?: string,\n options?: Intl.DateTimeFormatOptions,\n) {\n if (!date) {\n return \"\";\n }\n const timeLocale = locale || getCurrentLocale();\n const timeZone = options?.timeZone || getLocalTimeZone();\n\n const formatter = new DateFormatter(timeLocale, {\n ...defaultFormatOptions,\n ...options,\n });\n\n const formattedDate = formatter.formatToParts(date.toDate(timeZone));\n\n // Determine the separator based on the provided options\n const isNumericFormat =\n options?.month === \"numeric\" || defaultFormatOptions.month === \"numeric\";\n const separator = isNumericFormat ? \"/\" : \" \";\n\n // Some locales (USA) added commas, so construct the final date ourselves from formatter parts\n const parts = [];\n if (options?.day !== undefined || defaultFormatOptions.day !== undefined) {\n const day = formattedDate.find(\n (part: Intl.DateTimeFormatPart) => part.type === \"day\",\n )?.value;\n if (day) parts.push(day);\n }\n if (\n options?.month !== undefined ||\n defaultFormatOptions.month !== undefined\n ) {\n const month = formattedDate.find(\n (part: Intl.DateTimeFormatPart) => part.type === \"month\",\n )?.value;\n if (month) parts.push(month);\n }\n if (options?.year !== undefined || defaultFormatOptions.year !== undefined) {\n const year = formattedDate.find(\n (part: Intl.DateTimeFormatPart) => part.type === \"year\",\n )?.value;\n if (year) parts.push(year);\n }\n\n return parts.join(separator);\n}\n"],"names":[],"mappings":";;AAUO,SAAS,gBAAmB,GAAA;AACjC,EAAO,OAAA,SAAA,CAAU,UAAU,CAAC,CAAA;AAC9B;AAKA,MAAM,oBAAmD,GAAA;AAAA,EACvD,GAAK,EAAA,SAAA;AAAA,EACL,KAAO,EAAA,OAAA;AAAA,EACP,IAAM,EAAA;AACR,CAAA;AASgB,SAAA,UAAA,CACd,IACA,EAAA,MAAA,EACA,OACA,EAAA;AAlCF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAmCE,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAO,OAAA,EAAA;AAAA;AAET,EAAM,MAAA,UAAA,GAAa,UAAU,gBAAiB,EAAA;AAC9C,EAAM,MAAA,QAAA,GAAA,CAAW,OAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,QAAA,KAAY,gBAAiB,EAAA;AAEvD,EAAM,MAAA,SAAA,GAAY,IAAI,aAAA,CAAc,UAAY,EAAA;AAAA,IAC9C,GAAG,oBAAA;AAAA,IACH,GAAG;AAAA,GACJ,CAAA;AAED,EAAA,MAAM,gBAAgB,SAAU,CAAA,aAAA,CAAc,IAAK,CAAA,MAAA,CAAO,QAAQ,CAAC,CAAA;AAGnE,EAAA,MAAM,eACJ,GAAA,CAAA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAS,KAAU,MAAA,SAAA,IAAa,qBAAqB,KAAU,KAAA,SAAA;AACjE,EAAM,MAAA,SAAA,GAAY,kBAAkB,GAAM,GAAA,GAAA;AAG1C,E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S,CAAA;AAC7B;;;;"}
@@ -1,57 +0,0 @@
1
- import { CalendarDate, toZoned, getLocalTimeZone, CalendarDateTime, ZonedDateTime } from '@internationalized/date';
2
-
3
- function parseCalendarDate(inputDate) {
4
- if (!(inputDate == null ? void 0 : inputDate.length)) {
5
- return { date: null, error: false };
6
- }
7
- const date = new Date(inputDate);
8
- if (Number.isNaN(date.getTime())) {
9
- return { date: null, error: "not a valid date" };
10
- }
11
- const year = date.getFullYear();
12
- const month = date.getMonth() + 1;
13
- const day = date.getDate();
14
- try {
15
- const isoDate = new CalendarDate(year, month, day);
16
- return { date: isoDate, error: false };
17
- } catch (err) {
18
- return { date: null, error: err.message };
19
- }
20
- }
21
- function parseZonedDateTime(inputDate, timeZone = getLocalTimeZone()) {
22
- const parsedDate = parseCalendarDate(inputDate);
23
- if (!parsedDate.date || parsedDate.error) {
24
- return { ...parsedDate, date: null };
25
- }
26
- try {
27
- const zonedDate = toZoned(parsedDate.date, timeZone, "compatible");
28
- return { date: zonedDate, error: false };
29
- } catch (err) {
30
- return { date: null, error: err.message };
31
- }
32
- }
33
- const dateSupportsTime = (date) => date instanceof CalendarDateTime || date instanceof ZonedDateTime;
34
- function extractTimeFieldsFromDateRange(selectedDate) {
35
- let startTime;
36
- let endTime;
37
- if (selectedDate) {
38
- if (selectedDate.startDate && dateSupportsTime(selectedDate.startDate)) {
39
- const { hour, minute, second, millisecond } = selectedDate.startDate;
40
- startTime = { hour, minute, second, millisecond };
41
- }
42
- if (selectedDate.endDate && dateSupportsTime(selectedDate.endDate)) {
43
- const { hour, minute, second, millisecond } = selectedDate.endDate;
44
- endTime = { hour, minute, second, millisecond };
45
- }
46
- }
47
- return { startTime, endTime };
48
- }
49
- function extractTimeFieldsFromDate(selectedDate) {
50
- if (selectedDate && dateSupportsTime(selectedDate)) {
51
- const { hour, minute, second, millisecond } = selectedDate;
52
- return { hour, minute, second, millisecond };
53
- }
54
- }
55
-
56
- export { dateSupportsTime, extractTimeFieldsFromDate, extractTimeFieldsFromDateRange, parseCalendarDate, parseZonedDateTime };
57
- //# sourceMappingURL=utils.js.map