@monolith-forensics/monolith-ui 1.8.1-dev.3 → 1.8.1

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 (171) hide show
  1. package/dist/Button/Button.js +58 -9
  2. package/dist/Calendar/Calendar.d.ts +2 -7
  3. package/dist/Calendar/Calendar.js +49 -226
  4. package/dist/Calendar/CalendarStyles.d.ts +2 -6
  5. package/dist/Calendar/CalendarStyles.js +33 -153
  6. package/dist/Calendar/calendarHelpers.d.ts +2 -6
  7. package/dist/Calendar/calendarHelpers.js +5 -13
  8. package/dist/Charts/BarChart/BarChart.js +28 -14
  9. package/dist/Charts/BarChart/BarChart.styled.d.ts +7 -2
  10. package/dist/Charts/BarChart/BarChart.styled.js +5 -1
  11. package/dist/Charts/BarChart/BarChart.types.d.ts +13 -5
  12. package/dist/Charts/ChartUtils/chartSizing.d.ts +20 -0
  13. package/dist/Charts/ChartUtils/chartSizing.js +83 -0
  14. package/dist/Charts/ChartUtils/index.d.ts +1 -0
  15. package/dist/Charts/ChartUtils/index.js +1 -0
  16. package/dist/Charts/HeatMap/HeatMap.js +28 -7
  17. package/dist/Charts/HeatMap/HeatMap.styled.d.ts +6 -2
  18. package/dist/Charts/HeatMap/HeatMap.styled.js +3 -0
  19. package/dist/Charts/HeatMap/HeatMap.types.d.ts +7 -1
  20. package/dist/Charts/LineChart/LineChart.js +34 -15
  21. package/dist/Charts/LineChart/LineChart.styled.d.ts +7 -2
  22. package/dist/Charts/LineChart/LineChart.styled.js +5 -1
  23. package/dist/Charts/LineChart/LineChart.types.d.ts +13 -5
  24. package/dist/Charts/PieChart/PieChart.js +48 -33
  25. package/dist/Charts/PieChart/PieChart.styled.d.ts +7 -2
  26. package/dist/Charts/PieChart/PieChart.styled.js +6 -1
  27. package/dist/Charts/PieChart/PieChart.types.d.ts +7 -3
  28. package/dist/CheckBox/CheckBox.js +19 -36
  29. package/dist/DateInput/DateInput.js +143 -198
  30. package/dist/DropDownMenu/DropDownMenu.js +15 -25
  31. package/dist/DropDownMenu/components/MenuComponent.js +2 -8
  32. package/dist/DropDownMenu/components/MenuItem.d.ts +0 -2
  33. package/dist/DropDownMenu/components/MenuItem.js +21 -25
  34. package/dist/DropDownMenu/components/MenuItemList.d.ts +0 -3
  35. package/dist/DropDownMenu/components/MenuItemList.js +86 -192
  36. package/dist/DropDownMenu/components/StyledContent.js +2 -1
  37. package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
  38. package/dist/DropDownMenu/types.d.ts +0 -3
  39. package/dist/FieldLabel/FieldLabel.js +12 -4
  40. package/dist/FileInputField/FileInputField.js +23 -4
  41. package/dist/FileViewer/viewers/ImageViewer.js +18 -75
  42. package/dist/FormSection/FormSection.js +25 -5
  43. package/dist/IconButton/IconButton.js +16 -2
  44. package/dist/Input/Input.js +56 -7
  45. package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +4 -1
  46. package/dist/Pill/Pill.js +79 -8
  47. package/dist/Popover/Popover.context.d.ts +1 -2
  48. package/dist/Popover/Popover.js +2 -5
  49. package/dist/Popover/Popover.styles.d.ts +6 -1
  50. package/dist/Popover/Popover.styles.js +28 -11
  51. package/dist/Popover/Popover.transitions.d.ts +2 -4
  52. package/dist/Popover/Popover.transitions.js +49 -23
  53. package/dist/Popover/PopoverDropdown.js +8 -6
  54. package/dist/Popover/PopoverTarget.js +3 -6
  55. package/dist/QueryFilter/DefaultOperators.d.ts +76 -1
  56. package/dist/QueryFilter/DefaultOperators.js +21 -1
  57. package/dist/QueryFilter/QueryFilter.d.ts +1 -1
  58. package/dist/QueryFilter/QueryFilter.js +303 -3
  59. package/dist/QueryFilter/index.d.ts +2 -3
  60. package/dist/QueryFilter/index.js +2 -3
  61. package/dist/QueryFilter/types.d.ts +52 -1
  62. package/dist/QueryFilter/types.js +1 -1
  63. package/dist/QueryFilter/useQueryFilter.d.ts +1 -1
  64. package/dist/QueryFilter/useQueryFilter.js +19 -23
  65. package/dist/RichTextEditor/Components/CodeBlockBaseButton.d.ts +18 -0
  66. package/dist/RichTextEditor/Components/CodeBlockBaseButton.js +6 -0
  67. package/dist/RichTextEditor/Components/CodeBlockCopyButton.d.ts +9 -0
  68. package/dist/RichTextEditor/Components/CodeBlockCopyButton.js +42 -0
  69. package/dist/RichTextEditor/Components/CodeBlockFormatButton.d.ts +10 -0
  70. package/dist/RichTextEditor/Components/CodeBlockFormatButton.js +60 -0
  71. package/dist/RichTextEditor/Components/CodeBlockLanguageSelect.d.ts +9 -0
  72. package/dist/RichTextEditor/Components/CodeBlockLanguageSelect.js +30 -0
  73. package/dist/RichTextEditor/Components/CodeBlockNodeView.d.ts +3 -0
  74. package/dist/RichTextEditor/Components/CodeBlockNodeView.js +28 -0
  75. package/dist/RichTextEditor/Components/CodeBlockWrapButton.d.ts +10 -0
  76. package/dist/RichTextEditor/Components/CodeBlockWrapButton.js +17 -0
  77. package/dist/RichTextEditor/Components/LinkEditor.d.ts +8 -0
  78. package/dist/RichTextEditor/Components/LinkEditor.js +94 -0
  79. package/dist/RichTextEditor/Components/TableTools/TableCornerMenu.d.ts +2 -0
  80. package/dist/RichTextEditor/Components/TableTools/TableCornerMenu.js +19 -0
  81. package/dist/RichTextEditor/Components/TableTools/TableInsertControls.d.ts +2 -0
  82. package/dist/RichTextEditor/Components/TableTools/TableInsertControls.js +24 -0
  83. package/dist/RichTextEditor/Components/TableTools/TableRails.d.ts +2 -0
  84. package/dist/RichTextEditor/Components/TableTools/TableRails.js +180 -0
  85. package/dist/RichTextEditor/Components/TableTools/TableToolMenu.d.ts +5 -0
  86. package/dist/RichTextEditor/Components/TableTools/TableToolMenu.js +6 -0
  87. package/dist/RichTextEditor/Components/TableTools/TableTools.actions.d.ts +5 -0
  88. package/dist/RichTextEditor/Components/TableTools/TableTools.actions.js +183 -0
  89. package/dist/RichTextEditor/Components/TableTools/TableTools.commands.d.ts +16 -0
  90. package/dist/RichTextEditor/Components/TableTools/TableTools.commands.js +217 -0
  91. package/dist/RichTextEditor/Components/TableTools/TableTools.constants.d.ts +8 -0
  92. package/dist/RichTextEditor/Components/TableTools/TableTools.constants.js +11 -0
  93. package/dist/RichTextEditor/Components/TableTools/TableTools.d.ts +3 -0
  94. package/dist/RichTextEditor/Components/TableTools/TableTools.geometry.d.ts +23 -0
  95. package/dist/RichTextEditor/Components/TableTools/TableTools.geometry.js +75 -0
  96. package/dist/RichTextEditor/Components/TableTools/TableTools.js +3 -0
  97. package/dist/RichTextEditor/Components/TableTools/TableTools.selectors.d.ts +16 -0
  98. package/dist/RichTextEditor/Components/TableTools/TableTools.selectors.js +53 -0
  99. package/dist/RichTextEditor/Components/TableTools/TableTools.styled.d.ts +40 -0
  100. package/dist/RichTextEditor/Components/TableTools/TableTools.styled.js +167 -0
  101. package/dist/RichTextEditor/Components/TableTools/TableTools.types.d.ts +76 -0
  102. package/dist/RichTextEditor/Components/TableTools/TableTools.types.js +1 -0
  103. package/dist/RichTextEditor/Components/TableTools/TableTools.utils.d.ts +4 -0
  104. package/dist/RichTextEditor/Components/TableTools/TableTools.utils.js +4 -0
  105. package/dist/RichTextEditor/Components/TableTools/TableToolsPopover.d.ts +2 -0
  106. package/dist/RichTextEditor/Components/TableTools/TableToolsPopover.js +12 -0
  107. package/dist/RichTextEditor/Components/TableTools/index.d.ts +3 -0
  108. package/dist/RichTextEditor/Components/TableTools/index.js +2 -0
  109. package/dist/RichTextEditor/Enums/HighlightColors.d.ts +9 -0
  110. package/dist/RichTextEditor/Enums/HighlightColors.js +10 -0
  111. package/dist/RichTextEditor/Extensions/getTiptapExtensions.js +15 -5
  112. package/dist/RichTextEditor/Plugins/ImageActionsPlugin.js +4 -7
  113. package/dist/RichTextEditor/Plugins/UploadImagesPlugin.d.ts +0 -15
  114. package/dist/RichTextEditor/Plugins/UploadImagesPlugin.js +51 -115
  115. package/dist/RichTextEditor/Plugins/index.d.ts +0 -1
  116. package/dist/RichTextEditor/Plugins/index.js +0 -1
  117. package/dist/RichTextEditor/RichTextEditor.d.ts +2 -3
  118. package/dist/RichTextEditor/RichTextEditor.js +35 -302
  119. package/dist/RichTextEditor/Utils/codeBlockUtils.d.ts +20 -0
  120. package/dist/RichTextEditor/Utils/codeBlockUtils.js +137 -0
  121. package/dist/RichTextEditor/Utils/codeUtils.d.ts +3 -0
  122. package/dist/RichTextEditor/Utils/codeUtils.js +12 -0
  123. package/dist/RichTextEditor/Utils/linkUtils.d.ts +19 -0
  124. package/dist/RichTextEditor/Utils/linkUtils.js +57 -0
  125. package/dist/RichTextEditor/Utils/tableUtils.d.ts +1 -0
  126. package/dist/RichTextEditor/Utils/tableUtils.js +1 -0
  127. package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
  128. package/dist/SegmentedControl/SegmentedControl.utils.js +30 -3
  129. package/dist/SelectBox/SelectBox.js +5 -5
  130. package/dist/SelectBox/select-box.styled-components.d.ts +1 -4
  131. package/dist/SelectBox/select-box.styled-components.js +48 -11
  132. package/dist/SelectBox/types.d.ts +0 -1
  133. package/dist/Switch/Switch.d.ts +2 -2
  134. package/dist/Switch/Switch.js +83 -18
  135. package/dist/Table/ColumnResizer.d.ts +9 -6
  136. package/dist/Table/ColumnResizer.js +10 -30
  137. package/dist/Table/StateStorage.d.ts +0 -4
  138. package/dist/Table/StateStorage.js +0 -13
  139. package/dist/Table/Table.js +12 -160
  140. package/dist/Table/TableComponents.d.ts +0 -10
  141. package/dist/Table/TableComponents.js +10 -71
  142. package/dist/Table/TableDefaults.d.ts +0 -7
  143. package/dist/Table/TableDefaults.js +0 -7
  144. package/dist/Table/TableHeader.js +16 -31
  145. package/dist/Table/TableMenu/TableMenu.js +1 -1
  146. package/dist/Table/TableProvider.js +75 -354
  147. package/dist/Table/TableRow.js +16 -28
  148. package/dist/Table/Utils/index.d.ts +1 -0
  149. package/dist/Table/Utils/index.js +1 -0
  150. package/dist/Table/types.d.ts +19 -70
  151. package/dist/TagBox/TagBox.d.ts +1 -1
  152. package/dist/TagBox/TagBox.js +80 -22
  153. package/dist/TagBox/types.d.ts +0 -1
  154. package/dist/TextArea/TextArea.js +23 -9
  155. package/dist/TextInput/TextInput.js +6 -12
  156. package/dist/Utilities/parseTimestamp.js +6 -11
  157. package/dist/core/ArrowButton.d.ts +0 -2
  158. package/dist/core/ArrowButton.js +3 -7
  159. package/dist/core/ClearButton.d.ts +0 -2
  160. package/dist/core/ClearButton.js +3 -7
  161. package/dist/core/controlSizes.js +9 -9
  162. package/dist/core/index.d.ts +0 -1
  163. package/dist/core/index.js +0 -1
  164. package/dist/index.d.ts +0 -3
  165. package/dist/index.js +0 -2
  166. package/dist/theme/variants.js +8 -2
  167. package/package.json +18 -26
  168. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +0 -41
  169. package/dist/DateTimeRangePicker/DateTimeRangePicker.js +0 -363
  170. package/dist/DateTimeRangePicker/index.d.ts +0 -2
  171. package/dist/DateTimeRangePicker/index.js +0 -2
@@ -13,7 +13,6 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
13
13
  import { forwardRef } from "react";
14
14
  import styled from "styled-components";
15
15
  import { Loader2Icon } from "lucide-react";
16
- import { getControlSizeTokens } from "../core";
17
16
  const colors = {
18
17
  gray: "#888888",
19
18
  lightGray: "#f0f0f0",
@@ -36,14 +35,63 @@ const StyledButton = styled.button `
36
35
  white-space: nowrap;
37
36
 
38
37
  width: ${({ fullWidth }) => (fullWidth ? "100%" : "fit-content")};
39
- height: ${({ size }) => `${getControlSizeTokens(size).height}px`};
38
+ height: ${({ theme, size }) => {
39
+ switch (size) {
40
+ case "xxs":
41
+ return `24px`;
42
+ case "xs":
43
+ return `28px`;
44
+ case "sm":
45
+ return `34px`;
46
+ case "md":
47
+ return `40px`;
48
+ case "lg":
49
+ return `48px`;
50
+ case "xl":
51
+ return `58px`;
52
+ default:
53
+ return `34px`;
54
+ }
55
+ }};
40
56
 
41
- font-size: ${({ size }) => `${getControlSizeTokens(size).fontSize}px`};
57
+ font-size: ${({ theme, size }) => {
58
+ switch (size) {
59
+ case "xxs":
60
+ return `11px`;
61
+ case "xs":
62
+ return `12px`;
63
+ case "sm":
64
+ return `14px`;
65
+ case "md":
66
+ return `16px`;
67
+ case "lg":
68
+ return `18px`;
69
+ case "xl":
70
+ return `20px`;
71
+ default:
72
+ return `14px`;
73
+ }
74
+ }};
42
75
 
43
76
  padding: ${({ theme, size, variant }) => {
44
77
  if (variant === "text")
45
78
  return `0px 0px`;
46
- return `0px ${getControlSizeTokens(size).buttonPaddingX}px`;
79
+ switch (size) {
80
+ case "xxs":
81
+ return `0px 8px`;
82
+ case "xs":
83
+ return `0px 12px`;
84
+ case "sm":
85
+ return `0px 16px`;
86
+ case "md":
87
+ return `0px 20px`;
88
+ case "lg":
89
+ return `0px 24px`;
90
+ case "xl":
91
+ return `0px 30px`;
92
+ default:
93
+ return `0px 16px`;
94
+ }
47
95
  }};
48
96
 
49
97
  color: ${({ theme, variant, color }) => {
@@ -127,7 +175,6 @@ const StyledButton = styled.button `
127
175
  display: flex;
128
176
  align-items: center;
129
177
  justify-content: center;
130
- gap: ${({ size }) => `${getControlSizeTokens(size).iconGap}px`};
131
178
  }
132
179
 
133
180
  .button-label {
@@ -136,15 +183,17 @@ const StyledButton = styled.button `
136
183
  }
137
184
 
138
185
  [data-position="left"] {
186
+ margin-inline-end: 6px;
139
187
  display: flex;
140
188
  align-items: center;
141
189
  }
142
190
 
143
191
  [data-position="right"] {
192
+ margin-inline-start: 6px;
193
+ padding-inline-start: 6px;
144
194
  margin-left: auto;
145
195
  display: flex;
146
196
  align-items: center;
147
- padding-inline-start: ${({ size }) => `${getControlSizeTokens(size).iconGap}px`};
148
197
  }
149
198
 
150
199
  &:hover {
@@ -215,8 +264,8 @@ const StyledAnchor = styled.a `
215
264
  `;
216
265
  const StyledLoader = styled.span `
217
266
  svg {
218
- width: ${({ size }) => `${getControlSizeTokens(size).iconSize}px`};
219
- height: ${({ size }) => `${getControlSizeTokens(size).iconSize}px`};
267
+ width: 16px;
268
+ height: 16px;
220
269
  color: ${({ theme, color }) => {
221
270
  var _a;
222
271
  return color
@@ -236,6 +285,6 @@ const StyledLoader = styled.span `
236
285
  `;
237
286
  export const Button = forwardRef((props, ref) => {
238
287
  const { children, loading = false, leftSection = null, rightSection = null, href = null, download = null, justify = "center" } = props, other = __rest(props, ["children", "loading", "leftSection", "rightSection", "href", "download", "justify"]);
239
- const buttonContent = (_jsx("div", { className: "inner-span", style: { height: "100%", width: "100%", justifyContent: justify }, children: loading ? (_jsx(StyledLoader, { size: other.size, children: _jsx(Loader2Icon, {}) })) : (_jsxs(_Fragment, { children: [leftSection && _jsx("div", { "data-position": "left", children: leftSection }), _jsx("div", { className: "button-label", children: children }), rightSection && _jsx("div", { "data-position": "right", children: rightSection })] })) }));
288
+ const buttonContent = (_jsx("div", { className: "inner-span", style: { height: "100%", width: "100%", justifyContent: justify }, children: loading ? (_jsx(StyledLoader, { children: _jsx(Loader2Icon, {}) })) : (_jsxs(_Fragment, { children: [leftSection && _jsx("div", { "data-position": "left", children: leftSection }), _jsx("div", { className: "button-label", children: children }), rightSection && _jsx("div", { "data-position": "right", children: rightSection })] })) }));
240
289
  return (_jsx(StyledButton, Object.assign({ ref: ref }, other, { children: href ? (_jsx(StyledAnchor, { href: href, download: download, children: buttonContent })) : (buttonContent) })));
241
290
  });
@@ -1,20 +1,15 @@
1
1
  interface CalendarProps {
2
2
  defaultValue?: Date;
3
3
  value?: Date | null;
4
- onChange?: (date: Date | null, meta?: {
5
- source: "date" | "month" | "year" | "time" | "clear";
6
- }) => void;
4
+ onChange?: (date: Date | null) => void;
7
5
  hourFormat?: "12" | "24";
8
6
  includeTime?: boolean;
9
7
  clearable?: boolean;
10
8
  min?: Date;
11
9
  max?: Date;
12
- timeIntervalMinutes?: number;
13
- minuteStep?: number;
14
- timeZoneLabel?: string;
15
10
  }
16
11
  declare const Calendar: {
17
- ({ defaultValue, value, onChange, hourFormat, includeTime, clearable, min, max, timeIntervalMinutes, minuteStep, timeZoneLabel, }: CalendarProps): import("react/jsx-runtime").JSX.Element;
12
+ ({ defaultValue, value, onChange, hourFormat, includeTime, clearable, min, max, }: CalendarProps): import("react/jsx-runtime").JSX.Element;
18
13
  displayName: string;
19
14
  };
20
15
  export default Calendar;
@@ -1,9 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Fragment, useEffect, useMemo, useRef, useState } from "react";
2
+ import { Fragment, useEffect, useRef, useState } from "react";
3
3
  import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
4
- import { CalendarContainer, CalendarHeader, CalendarHeaderControls, CalendarHeaderSelect, CalendarNavButton, CalendarGrid, CalendarMonth, CalendarDay, CalendarDate, HighlightedCalendarDate, TodayCalendarDate, TimeContainer, MainContainer, TimePickerContainer, TimeHeader, TimeHeaderValue, TimeItem, TimeItemActive, TimeSelectList, TimeZoneBadge, NoValueButton, } from "./CalendarStyles";
5
- import { DropDownMenu } from "../DropDownMenu";
6
- import calendar, { createLocalDate, isDate, isSameDay, isSameMonth, getDateISO, getMonthDays, getNextMonth, getPreviousMonth, WEEK_DAYS, CALENDAR_MONTHS, } from "./calendarHelpers";
4
+ import { CalendarContainer, CalendarHeader, CalendarGrid, CalendarMonth, CalendarDay, CalendarDate, HighlightedCalendarDate, TodayCalendarDate, TimeContainer, MainContainer, TimePickerContainer, TimeHourSelect, TimeHeader, TimeMinuteSelect, TimeItem, TimeItemActive, NoValueButton, } from "./CalendarStyles";
5
+ import calendar, { isDate, isSameDay, isSameMonth, getDateISO, getNextMonth, getPreviousMonth, WEEK_DAYS, CALENDAR_MONTHS, HOURS24, HOURS12, MINUTES, } from "./calendarHelpers";
7
6
  import moment from "moment";
8
7
  const checkValidRange = (value, min, max) => {
9
8
  if (min && moment(value).startOf("day").isBefore(moment(min).startOf("day")))
@@ -21,14 +20,8 @@ const resolveValue = (value) => {
21
20
  minutes: safeValue.getMinutes(),
22
21
  };
23
22
  };
24
- const MONTH_OPTIONS = Object.keys(CALENDAR_MONTHS).map((monthName, index) => ({
25
- label: monthName,
26
- value: index + 1,
27
- }));
28
- const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hourFormat = "24", includeTime = true, clearable = true, min, max, timeIntervalMinutes, minuteStep = 1, timeZoneLabel = "Local", }) => {
23
+ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hourFormat = "24", includeTime = true, clearable = true, min, max, }) => {
29
24
  const isControlled = useRef(value !== undefined);
30
- const activeTimeRef = useRef(null);
31
- const hasScrolledInitialTimeIntoView = useRef(false);
32
25
  const [valueState, setValueState] = useState(defaultValue);
33
26
  const _value = isControlled.current
34
27
  ? value
@@ -40,74 +33,16 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
40
33
  let pressureTimer;
41
34
  let pressureTimeout;
42
35
  let dayTimeout;
43
- const normalizedTimeInterval = Math.max(1, Math.min(1440, timeIntervalMinutes || minuteStep || 1));
44
- const selectedMinutesOfDay = calendarState.hours * 60 + calendarState.minutes;
45
- const timeOptions = useMemo(() => {
46
- const steppedTimes = Array.from({ length: Math.ceil(1440 / normalizedTimeInterval) }, (_, index) => index * normalizedTimeInterval).filter((minutesOfDay) => minutesOfDay < 1440);
47
- if (!steppedTimes.includes(selectedMinutesOfDay)) {
48
- steppedTimes.push(selectedMinutesOfDay);
49
- }
50
- return steppedTimes
51
- .sort((a, b) => a - b)
52
- .map((minutesOfDay) => {
53
- const hours = Math.floor(minutesOfDay / 60);
54
- const minutes = minutesOfDay % 60;
55
- return {
56
- value: minutesOfDay,
57
- hours,
58
- minutes,
59
- label: `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`,
60
- };
61
- });
62
- }, [normalizedTimeInterval, selectedMinutesOfDay]);
63
- useEffect(() => {
64
- var _a;
65
- if (!includeTime || hasScrolledInitialTimeIntoView.current)
66
- return;
67
- (_a = activeTimeRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
68
- block: "center",
69
- inline: "nearest",
70
- });
71
- hasScrolledInitialTimeIntoView.current = true;
72
- }, [includeTime]);
73
- const syncCalendarState = (date) => {
74
- setCalendarState({
75
- month: +date.getMonth() + 1,
76
- year: date.getFullYear(),
77
- hours: date.getHours(),
78
- minutes: date.getMinutes(),
79
- });
80
- };
81
- const commitDate = (date, source = "date") => {
82
- if (date && isDate(date)) {
83
- if (!isControlled.current) {
84
- setValueState(date);
85
- }
86
- syncCalendarState(date);
87
- onChange(date, { source });
88
- return;
89
- }
90
- if (!isControlled.current) {
91
- setValueState(null);
92
- }
93
- onChange(null, { source: "clear" });
94
- };
95
- const getWorkingDate = () => {
96
- if (_value && isDate(_value)) {
97
- return _value;
98
- }
99
- const fallbackDay = Math.min(today.getDate(), getMonthDays(calendarState.month, calendarState.year));
100
- const fallbackDate = createLocalDate(calendarState.year, calendarState.month, fallbackDay);
101
- fallbackDate.setHours(calendarState.hours, calendarState.minutes, 0, 0);
102
- return fallbackDate;
103
- };
104
36
  const addDateToState = (date) => {
105
37
  const isDateObject = isDate(date);
106
38
  const _date = isDateObject ? date : new Date();
107
- if (!isControlled.current) {
108
- setValueState(_date);
109
- }
110
- syncCalendarState(_date);
39
+ setValueState(_date);
40
+ setCalendarState({
41
+ month: +_date.getMonth() + 1,
42
+ year: _date.getFullYear(),
43
+ hours: _date.getHours(),
44
+ minutes: _date.getMinutes(),
45
+ });
111
46
  };
112
47
  const getCalendarDates = () => {
113
48
  const { month, year } = calendarState;
@@ -115,179 +50,71 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
115
50
  const calendarYear = year || (_value === null || _value === void 0 ? void 0 : _value.getFullYear()) || new Date().getFullYear();
116
51
  return calendar(calendarMonth, calendarYear);
117
52
  };
118
- const setCalendarView = (nextMonth, nextYear) => {
119
- setCalendarState((prev) => (Object.assign(Object.assign({}, prev), { month: nextMonth, year: nextYear })));
120
- };
121
- const commitMonthOrYearSelection = (nextMonth, nextYear, source) => {
122
- const workingDate = getWorkingDate();
123
- const clampedDay = Math.min(workingDate.getDate(), getMonthDays(nextMonth, nextYear));
124
- const nextDate = createLocalDate(nextYear, nextMonth, clampedDay);
125
- nextDate.setHours(workingDate.getHours(), workingDate.getMinutes(), 0, 0);
126
- commitDate(nextDate, source);
127
- };
128
- const getYearOptions = () => {
129
- var _a, _b;
130
- const currentYear = calendarState.year;
131
- const minYear = (_a = min === null || min === void 0 ? void 0 : min.getFullYear()) !== null && _a !== void 0 ? _a : currentYear - 50;
132
- const maxYear = (_b = max === null || max === void 0 ? void 0 : max.getFullYear()) !== null && _b !== void 0 ? _b : currentYear + 50;
133
- return Array.from({ length: maxYear - minYear + 1 }, (_, index) => {
134
- const optionYear = minYear + index;
135
- return {
136
- label: `${optionYear}`,
137
- value: optionYear,
138
- };
139
- });
140
- };
53
+ //new start
141
54
  const renderMonthAndYear = () => {
142
55
  const { month, year } = calendarState;
143
- const monthName = Object.keys(CALENDAR_MONTHS)[Math.max(0, Math.min(month - 1, 11))];
144
- const yearOptions = getYearOptions();
145
- const selectedMonthOption = MONTH_OPTIONS.find((option) => option.value === month);
146
- const selectedYearOption = yearOptions.find((option) => option.value === year);
147
- return (_jsxs(CalendarHeader, { children: [_jsx(CalendarNavButton, { type: "button", onClick: handlePrevious, onMouseUp: clearPressureTimer, "aria-label": "Go to previous month", title: "Previous month. Hold Shift to jump by year.", children: _jsx(ChevronLeftIcon, { "aria-hidden": "true" }) }), _jsxs(CalendarHeaderControls, { children: [_jsx(CalendarHeaderSelect, { children: _jsx(DropDownMenu, { data: MONTH_OPTIONS, value: selectedMonthOption ? [selectedMonthOption] : [], variant: "outlined", size: "xs", arrow: true, onItemSelect: (item) => commitMonthOrYearSelection(Number(item.value), year, "month"), dropDownProps: {
148
- style: { maxHeight: 260, width: 125 },
149
- }, buttonProps: {
150
- title: "Select month",
151
- size: "xxs",
152
- style: { minWidth: 95 },
153
- }, children: _jsx(CalendarMonth, { children: monthName }) }) }), _jsx(CalendarHeaderSelect, { children: _jsx(DropDownMenu, { data: yearOptions, value: selectedYearOption ? [selectedYearOption] : [], variant: "outlined", size: "xs", arrow: true, searchable: true, onItemSelect: (item) => commitMonthOrYearSelection(month, Number(item.value), "year"), dropDownProps: {
154
- style: { width: 120, maxHeight: 260 },
155
- }, buttonProps: {
156
- title: "Select year",
157
- size: "xxs",
158
- style: { minWidth: 50 },
159
- }, children: _jsx(CalendarMonth, { children: year }) }) })] }), _jsx(CalendarNavButton, { type: "button", onClick: handleNext, onMouseUp: clearPressureTimer, "aria-label": "Go to next month", title: "Next month. Hold Shift to jump by year.", children: _jsx(ChevronRightIcon, { "aria-hidden": "true" }) })] }));
160
- };
161
- const handleActionKeyDown = (action) => (evt) => {
162
- if (evt.key === "Enter" || evt.key === " ") {
163
- evt.preventDefault();
164
- action();
165
- }
56
+ // Resolve the month name from the CALENDAR_MONTHS object map
57
+ const monthname = Object.keys(CALENDAR_MONTHS)[Math.max(0, Math.min(month - 1, 11))];
58
+ return (_jsxs(CalendarHeader, { children: [_jsx(ChevronLeftIcon, { onMouseDown: handlePrevious, onMouseUp: clearPressureTimer }), _jsxs(CalendarMonth, { children: [monthname, " ", year] }), _jsx(ChevronRightIcon, { onMouseDown: handleNext, onMouseUp: clearPressureTimer })] }));
166
59
  };
167
60
  // Render the label for day of the week
168
61
  // This method is used as a map callback as seen in render()
169
62
  const renderDayLabel = (day, index) => {
170
63
  // Resolve the day of the week label from the WEEK_DAYS object map
171
64
  const daylabel = WEEK_DAYS[day];
172
- return (_jsx(CalendarDay, { index: index, role: "columnheader", children: daylabel }, daylabel));
65
+ return (_jsx(CalendarDay, { index: index, children: daylabel }, daylabel));
173
66
  };
174
67
  // Render a calendar date as returned from the calendar builder function
175
68
  // This method is used as a map callback as seen in render()
176
69
  const renderCalendarDate = (date, index) => {
177
- const [dateYear, dateMonth, dateDay] = date.map(Number);
178
70
  const { month, year } = calendarState;
179
- const _date = createLocalDate(dateYear, dateMonth, dateDay);
71
+ const _date = new Date(date.join("-"));
180
72
  // Check if calendar date is same day as today
181
73
  const isToday = isSameDay(_date, today);
182
74
  // Check if calendar date is same day as currently selected date
183
75
  const isCurrent = _value && isSameDay(_date, _value);
184
76
  // Check if calendar date is in the same month as the state month and year
185
- const inMonth = month && year && isSameMonth(_date, createLocalDate(year, month, 1));
186
- const isDisabled = !checkValidRange(getDateISO(_date), min || null, max || null);
187
- const ariaCurrent = isToday ? "date" : undefined;
188
- const handleDisabledAction = (evt) => {
189
- evt.preventDefault();
190
- evt.stopPropagation();
191
- };
77
+ const inMonth = month && year && isSameMonth(_date, new Date([year, month, 1].join("-")));
192
78
  // The click handler
193
79
  const props = {
194
- "data-disabled": isDisabled,
195
- "aria-current": ariaCurrent,
196
- "aria-disabled": isDisabled,
197
- "aria-label": `${isCurrent ? "Selected" : "Select"} ${_date.toDateString()}`,
198
- "aria-pressed": Boolean(isCurrent),
80
+ "data-disabled": !checkValidRange(getDateISO(_date), min || null, max || null),
199
81
  index,
200
82
  key: getDateISO(_date),
201
- onClick: isDisabled ? handleDisabledAction : gotoDate(_date),
202
- onKeyDown: isDisabled
203
- ? handleDisabledAction
204
- : handleActionKeyDown(() => gotoDate(_date)(undefined)),
205
- role: "button",
206
- tabIndex: isDisabled ? -1 : 0,
83
+ onClick: gotoDate(_date),
207
84
  title: _date.toDateString(),
208
85
  inMonth,
209
86
  };
210
87
  // Conditionally render a styled date component
211
88
  return isCurrent ? (_jsx(HighlightedCalendarDate, Object.assign({}, props, { children: _date.getDate() }))) : isToday ? (_jsx(TodayCalendarDate, Object.assign({}, props, { children: _date.getDate() }))) : (_jsx(CalendarDate, Object.assign({}, props, { children: _date.getDate() })));
212
89
  };
213
- const isTimeOptionDisabled = (hours, minutes) => {
214
- const candidate = moment(getWorkingDate())
215
- .hours(hours)
216
- .minutes(minutes)
217
- .seconds(0)
218
- .milliseconds(0);
219
- if (min && candidate.isBefore(moment(min)))
220
- return true;
221
- if (max && candidate.isAfter(moment(max)))
222
- return true;
223
- return false;
224
- };
225
- const renderTimeOptions = () => {
226
- return timeOptions.map((timeOption, index) => {
227
- const isActive = timeOption.value === selectedMinutesOfDay;
228
- const isDisabled = isTimeOptionDisabled(timeOption.hours, timeOption.minutes);
229
- const TimeComponent = isActive ? TimeItemActive : TimeItem;
230
- const commitTime = () => {
231
- if (isDisabled)
232
- return;
233
- const newTime = moment(getWorkingDate())
234
- .hours(timeOption.hours)
235
- .minutes(timeOption.minutes)
236
- .seconds(0)
237
- .milliseconds(0)
238
- .toDate();
239
- commitDate(newTime, "time");
240
- };
241
- return (_jsx(TimeComponent, { ref: isActive ? activeTimeRef : undefined, role: "button", tabIndex: isDisabled ? -1 : 0, "data-disabled": isDisabled, "aria-disabled": isDisabled, "aria-label": `Select ${timeOption.label}`, "aria-pressed": isActive, onClick: commitTime, onKeyDown: handleTimeKeyDown(index, commitTime), children: timeOption.label }, timeOption.value));
90
+ const renderHours = () => {
91
+ const { hours } = calendarState;
92
+ const hoursArray = hourFormat === "24" ? HOURS24 : HOURS12;
93
+ return hoursArray.map((hour, index) => {
94
+ const HourComponent = hour.value === hours ? TimeItemActive : TimeItem;
95
+ return (_jsx(HourComponent, {
96
+ // value={hour.value}
97
+ onClick: (e) => {
98
+ const newTime = moment(_value).hours(hour.value).toDate();
99
+ setCalendarState(Object.assign(Object.assign({}, calendarState), { hours: hour.value }));
100
+ setValueState(newTime);
101
+ onChange === null || onChange === void 0 ? void 0 : onChange(newTime);
102
+ }, children: hour.label }, hour.value));
242
103
  });
243
104
  };
244
- const handleTimeKeyDown = (index, selectCurrent) => (evt) => {
245
- const findEnabledIndex = (nextIndex, direction) => {
246
- let boundedIndex = Math.max(0, Math.min(timeOptions.length - 1, nextIndex));
247
- while (boundedIndex >= 0 &&
248
- boundedIndex < timeOptions.length &&
249
- isTimeOptionDisabled(timeOptions[boundedIndex].hours, timeOptions[boundedIndex].minutes)) {
250
- boundedIndex += direction;
251
- }
252
- if (boundedIndex < 0 || boundedIndex >= timeOptions.length) {
253
- return null;
254
- }
255
- return boundedIndex;
256
- };
257
- const commitOption = (nextIndex, direction) => {
258
- const enabledIndex = findEnabledIndex(nextIndex, direction);
259
- if (enabledIndex === null)
260
- return;
261
- const nextOption = timeOptions[enabledIndex];
262
- const newTime = moment(getWorkingDate())
263
- .hours(nextOption.hours)
264
- .minutes(nextOption.minutes)
265
- .seconds(0)
266
- .milliseconds(0)
267
- .toDate();
268
- commitDate(newTime, "time");
269
- };
270
- if (evt.key === "Enter" || evt.key === " ") {
271
- evt.preventDefault();
272
- selectCurrent();
273
- return;
274
- }
275
- if (evt.key === "ArrowDown") {
276
- evt.preventDefault();
277
- commitOption(index + 1, 1);
278
- }
279
- if (evt.key === "ArrowUp") {
280
- evt.preventDefault();
281
- commitOption(index - 1, -1);
282
- }
283
- if (evt.key === "Home") {
284
- evt.preventDefault();
285
- commitOption(0, 1);
286
- }
287
- if (evt.key === "End") {
288
- evt.preventDefault();
289
- commitOption(timeOptions.length - 1, -1);
290
- }
105
+ const renderMinutes = () => {
106
+ const { minutes } = calendarState;
107
+ return MINUTES.map((minute) => {
108
+ const MinuteComponent = minute === minutes ? TimeItemActive : TimeItem;
109
+ return (_jsx(MinuteComponent, {
110
+ // value={minute}
111
+ onClick: (e) => {
112
+ const newTime = moment(_value).minutes(Number(minute)).toDate();
113
+ setCalendarState(Object.assign(Object.assign({}, calendarState), { minutes: Number(minute) }));
114
+ setValueState(newTime);
115
+ onChange === null || onChange === void 0 ? void 0 : onChange(newTime);
116
+ }, children: minute }, minute));
117
+ });
291
118
  };
292
119
  // new 2
293
120
  const gotoDate = (date) => (evt) => {
@@ -297,12 +124,8 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
297
124
  .hours(includeTime ? calendarState.hours : 0)
298
125
  .minutes(includeTime ? calendarState.minutes : 0)
299
126
  .toDate();
300
- if (!(_value && isSameDay(newTime, _value))) {
301
- commitDate(newTime, "date");
302
- return;
303
- }
304
- syncCalendarState(newTime);
305
- onChange(newTime, { source: "date" });
127
+ !(_value && isSameDay(newTime, _value)) && addDateToState(newTime);
128
+ onChange(newTime);
306
129
  };
307
130
  const gotoPreviousMonth = () => {
308
131
  const { month, year } = calendarState;
@@ -379,7 +202,7 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
379
202
  // const clearDayTimeout = () => {
380
203
  // dayTimeout && clearTimeout(dayTimeout);
381
204
  // };
382
- return (_jsxs(MainContainer, { children: [_jsxs(CalendarContainer, { children: [renderMonthAndYear(), _jsxs(CalendarGrid, { role: "grid", "aria-label": `Calendar view for ${Object.keys(CALENDAR_MONTHS)[calendarState.month - 1]} ${calendarState.year}`, children: [_jsx(Fragment, { children: Object.keys(WEEK_DAYS).map(renderDayLabel) }), _jsx(Fragment, { children: getCalendarDates().map(renderCalendarDate) })] }), clearable && (_jsx("div", { style: { textAlign: "center", marginTop: 3 }, children: _jsx(NoValueButton, { type: "button", onClick: () => commitDate(null, "clear"), "aria-label": "Clear selected date", children: "Clear Date" }) }))] }), includeTime && (_jsxs(TimeContainer, { children: [_jsxs(TimeHeader, { children: [_jsx(TimeHeaderValue, { children: `${String(calendarState.hours).padStart(2, "0")}:${String(calendarState.minutes).padStart(2, "0")}` }), timeZoneLabel && _jsx(TimeZoneBadge, { children: timeZoneLabel })] }), _jsx(TimePickerContainer, { children: _jsx(TimeSelectList, { children: renderTimeOptions() }) })] }))] }));
205
+ return (_jsxs(MainContainer, { children: [_jsxs(CalendarContainer, { children: [renderMonthAndYear(), _jsxs(CalendarGrid, { children: [_jsx(Fragment, { children: Object.keys(WEEK_DAYS).map(renderDayLabel) }), _jsx(Fragment, { children: getCalendarDates().map(renderCalendarDate) })] }), clearable && (_jsx("div", { style: { textAlign: "center", marginTop: 3 }, children: _jsx(NoValueButton, { onClick: () => onChange(null), children: "Clear Date" }) }))] }), includeTime && (_jsxs(TimeContainer, { children: [_jsx(TimeHeader, { children: "Select Time" }), _jsxs(TimePickerContainer, { children: [_jsx(TimeHourSelect, { children: renderHours() }), _jsx(TimeMinuteSelect, { children: renderMinutes() })] })] }))] }));
383
206
  };
384
207
  Calendar.displayName = "Calendar";
385
208
  export default Calendar;
@@ -1,11 +1,8 @@
1
1
  export declare const MainContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
2
2
  export declare const CalendarContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
3
3
  export declare const CalendarHeader: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
4
- export declare const CalendarHeaderControls: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
5
- export declare const CalendarNavButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
6
4
  export declare const CalendarGrid: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
7
5
  export declare const CalendarMonth: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
8
- export declare const CalendarHeaderSelect: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
9
6
  interface CalendarCellProps {
10
7
  index?: number;
11
8
  inMonth?: boolean | 0;
@@ -21,9 +18,8 @@ export declare const TodayCalendarDate: import("styled-components/dist/types").I
21
18
  export declare const TimeContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
22
19
  export declare const TimePickerContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
23
20
  export declare const TimeHeader: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
24
- export declare const TimeHeaderValue: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
25
- export declare const TimeZoneBadge: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
26
- export declare const TimeSelectList: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
21
+ export declare const TimeHourSelect: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
22
+ export declare const TimeMinuteSelect: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
27
23
  export declare const TimeItem: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
28
24
  export declare const TimeItemActive: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>, never>> & string;
29
25
  export declare const NoValueButton: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;