@monolith-forensics/monolith-ui 1.0.12 → 1.1.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 (143) hide show
  1. package/dist/Button/Button.d.ts +19 -0
  2. package/dist/Button/Button.js +332 -0
  3. package/dist/Button/index.d.ts +2 -0
  4. package/dist/Button/index.js +8 -0
  5. package/dist/Calendar/Calendar.d.ts +15 -0
  6. package/dist/Calendar/Calendar.js +232 -0
  7. package/dist/Calendar/CalendarStyles.d.ts +36 -0
  8. package/{src/components → dist}/Calendar/CalendarStyles.js +32 -52
  9. package/dist/Calendar/calendarHelpers.d.ts +53 -0
  10. package/dist/Calendar/calendarHelpers.js +181 -0
  11. package/dist/Calendar/index.d.ts +1 -0
  12. package/dist/Calendar/index.js +8 -0
  13. package/dist/CheckBox/CheckBox.d.ts +11 -0
  14. package/dist/CheckBox/CheckBox.js +34 -0
  15. package/dist/CheckBox/index.d.ts +1 -0
  16. package/dist/CheckBox/index.js +8 -0
  17. package/dist/DateInput/DateInput.d.ts +24 -0
  18. package/dist/DateInput/DateInput.js +511 -0
  19. package/dist/DateInput/index.d.ts +1 -0
  20. package/dist/DateInput/index.js +8 -0
  21. package/dist/DropDownMenu/DropDownMenu.d.ts +36 -0
  22. package/dist/DropDownMenu/DropDownMenu.js +212 -0
  23. package/dist/DropDownMenu/index.d.ts +1 -0
  24. package/dist/DropDownMenu/index.js +8 -0
  25. package/dist/Error/Error.d.ts +4 -0
  26. package/dist/Error/Error.js +38 -0
  27. package/dist/Error/index.d.ts +1 -0
  28. package/dist/Error/index.js +8 -0
  29. package/dist/FieldLabel/FieldLabel.d.ts +19 -0
  30. package/dist/FieldLabel/FieldLabel.js +119 -0
  31. package/dist/FieldLabel/index.js +8 -0
  32. package/dist/FileInputField/FileInputField.d.ts +18 -0
  33. package/dist/FileInputField/FileInputField.js +116 -0
  34. package/dist/FileInputField/index.d.ts +1 -0
  35. package/dist/FileInputField/index.js +8 -0
  36. package/dist/Flyout/Flyout.d.ts +10 -0
  37. package/dist/Flyout/Flyout.js +111 -0
  38. package/dist/Flyout/FlyoutHeader.d.ts +5 -0
  39. package/dist/Flyout/FlyoutHeader.js +12 -0
  40. package/dist/Flyout/FlyoutTitle.d.ts +2 -0
  41. package/dist/Flyout/FlyoutTitle.js +13 -0
  42. package/dist/Flyout/index.d.ts +3 -0
  43. package/dist/Flyout/index.js +12 -0
  44. package/dist/FormSection/FormSection.d.ts +9 -0
  45. package/dist/FormSection/FormSection.js +51 -0
  46. package/dist/FormSection/index.d.ts +1 -0
  47. package/dist/FormSection/index.js +8 -0
  48. package/dist/Grid/Grid.d.ts +6 -0
  49. package/dist/Grid/Grid.js +15 -0
  50. package/dist/Grid/index.d.ts +1 -0
  51. package/dist/Grid/index.js +8 -0
  52. package/dist/IconButton/IconButton.d.ts +5 -0
  53. package/dist/IconButton/IconButton.js +30 -0
  54. package/dist/IconButton/index.d.ts +1 -0
  55. package/dist/IconButton/index.js +8 -0
  56. package/dist/Input/Input.d.ts +21 -0
  57. package/dist/Input/Input.js +148 -0
  58. package/dist/Input/index.js +8 -0
  59. package/dist/Modal/Modal.d.ts +14 -0
  60. package/dist/Modal/Modal.js +134 -0
  61. package/dist/Modal/index.d.ts +1 -0
  62. package/dist/Modal/index.js +8 -0
  63. package/dist/Pill/Pill.d.ts +11 -0
  64. package/dist/Pill/Pill.js +146 -0
  65. package/dist/Pill/index.js +8 -0
  66. package/dist/SelectBox/SelectBox.d.ts +45 -0
  67. package/dist/SelectBox/SelectBox.js +469 -0
  68. package/dist/SelectBox/index.d.ts +1 -0
  69. package/dist/SelectBox/index.js +8 -0
  70. package/dist/Switch/Switch.d.ts +18 -0
  71. package/dist/Switch/Switch.js +157 -0
  72. package/dist/Switch/index.d.ts +1 -0
  73. package/dist/Switch/index.js +8 -0
  74. package/dist/TagBox/TagBox.d.ts +38 -0
  75. package/dist/TagBox/TagBox.js +440 -0
  76. package/dist/TagBox/TagBoxStyles.d.ts +11 -0
  77. package/dist/TagBox/TagBoxStyles.js +113 -0
  78. package/dist/TagBox/index.d.ts +1 -0
  79. package/dist/TagBox/index.js +8 -0
  80. package/dist/TextArea/TextArea.d.ts +16 -0
  81. package/dist/TextArea/TextArea.js +80 -0
  82. package/dist/TextArea/index.js +8 -0
  83. package/dist/TextAreaInput/TextAreaInput.d.ts +12 -0
  84. package/dist/TextAreaInput/TextAreaInput.js +23 -0
  85. package/dist/TextAreaInput/index.js +8 -0
  86. package/dist/TextInput/TextInput.d.ts +12 -0
  87. package/dist/TextInput/TextInput.js +30 -0
  88. package/dist/TextInput/index.js +8 -0
  89. package/dist/Tooltip/Tooltip.d.ts +12 -0
  90. package/dist/Tooltip/Tooltip.js +53 -0
  91. package/dist/Tooltip/index.d.ts +1 -0
  92. package/dist/Tooltip/index.js +8 -0
  93. package/dist/core/ArrowButton.d.ts +6 -0
  94. package/dist/core/ArrowButton.js +48 -0
  95. package/dist/core/ClearButton.d.ts +6 -0
  96. package/dist/core/ClearButton.js +48 -0
  97. package/dist/core/StyledContent.d.ts +7 -0
  98. package/dist/core/StyledContent.js +46 -0
  99. package/dist/core/StyledFloatContainer.d.ts +2 -0
  100. package/dist/core/StyledFloatContainer.js +10 -0
  101. package/dist/core/Types/Size.d.ts +2 -0
  102. package/dist/core/Types/Size.js +2 -0
  103. package/dist/core/Types/Variant.d.ts +2 -0
  104. package/dist/core/Types/Variant.js +2 -0
  105. package/dist/core/index.d.ts +6 -0
  106. package/dist/core/index.js +14 -0
  107. package/dist/index.d.ts +22 -0
  108. package/dist/index.js +51 -0
  109. package/package.json +15 -20
  110. package/.gitattributes +0 -2
  111. package/rollup.config.js +0 -10
  112. package/src/components/ArrowButton/ArrowButton.tsx +0 -54
  113. package/src/components/ArrowButton/index.tsx +0 -1
  114. package/src/components/Button/Button.tsx +0 -278
  115. package/src/components/Button/index.ts +0 -1
  116. package/src/components/Calendar/Calendar.js +0 -365
  117. package/src/components/Calendar/calendarHelpers.js +0 -194
  118. package/src/components/DateInput/DateInput.js +0 -583
  119. package/src/components/FieldLabel/FieldLabel.tsx +0 -152
  120. package/src/components/FileInputField/FileInputField.js +0 -171
  121. package/src/components/Input/Input.tsx +0 -141
  122. package/src/components/Pill/Pill.tsx +0 -144
  123. package/src/components/SelectBox/SelectBox.js +0 -543
  124. package/src/components/TagBox/TagBox.js +0 -563
  125. package/src/components/TextArea/TextArea.tsx +0 -70
  126. package/src/components/TextAreaInput/TextAreaInput.tsx +0 -48
  127. package/src/components/TextInput/TextInput.tsx +0 -50
  128. package/src/components/core/index.js +0 -16
  129. package/src/components/index.ts +0 -7
  130. package/src/components/theme/breakpoints.js +0 -11
  131. package/src/components/theme/components.js +0 -140
  132. package/src/components/theme/index.js +0 -77
  133. package/src/components/theme/shadows.js +0 -33
  134. package/src/components/theme/typography.js +0 -58
  135. package/src/components/theme/variants.js +0 -235
  136. package/src/index.ts +0 -1
  137. package/tsconfig.json +0 -109
  138. /package/{src/components/FieldLabel/index.ts → dist/FieldLabel/index.d.ts} +0 -0
  139. /package/{src/components/Input/index.tsx → dist/Input/index.d.ts} +0 -0
  140. /package/{src/components/Pill/index.ts → dist/Pill/index.d.ts} +0 -0
  141. /package/{src/components/TextArea/index.ts → dist/TextArea/index.d.ts} +0 -0
  142. /package/{src/components/TextAreaInput/index.ts → dist/TextAreaInput/index.d.ts} +0 -0
  143. /package/{src/components/TextInput/index.tsx → dist/TextInput/index.d.ts} +0 -0
@@ -1,54 +0,0 @@
1
- import React from "react";
2
- import { ChevronDownIcon } from "lucide-react";
3
- import styled from "styled-components";
4
-
5
- interface ArrowIconProps {
6
- className?: string;
7
- }
8
-
9
- const ArrowIcon: React.FC<ArrowIconProps> = styled(
10
- ({ className, ...props }: ArrowIconProps) => (
11
- <div className={className} {...props}>
12
- <ChevronDownIcon size={16} />
13
- </div>
14
- )
15
- )`
16
- color: ${(props) => props.theme.palette.text.secondary};
17
- transition: transform 0.2s ease-in-out;
18
- transform: rotate(0deg);
19
- will-change: transform;
20
-
21
- display: flex;
22
- flex-direction: column;
23
- align-items: center;
24
- justify-content: center;
25
- `;
26
-
27
- interface ArrowButtonProps {
28
- className?: string;
29
- }
30
-
31
- const ArrowButton: React.FC<ArrowButtonProps> = styled(
32
- ({ className, ...props }: ArrowButtonProps) => (
33
- <button
34
- className={className}
35
- {...props}
36
- tabIndex={-1}
37
- data-default-btn={true}
38
- >
39
- <ArrowIcon />
40
- </button>
41
- )
42
- )`
43
- position: absolute;
44
- right: 0;
45
- height: 100%;
46
- padding-inline: 10px;
47
- background: none;
48
- border: none;
49
- cursor: pointer;
50
- margin: 0;
51
- outline: none;
52
- `;
53
-
54
- export default ArrowButton;
@@ -1 +0,0 @@
1
- export { default } from "./ArrowButton";
@@ -1,278 +0,0 @@
1
- import React from "react";
2
- import { forwardRef } from "react";
3
- import styled from "styled-components";
4
-
5
- const colors = {
6
- gray: "#dee2e6",
7
- red: "#e03131",
8
- pink: "#c2255c",
9
- grape: "#9c36b5",
10
- violet: "#6741d9",
11
- indigo: "#3b5bdb",
12
- cyan: "#0c8599",
13
- teal: "#099268",
14
- green: "#2f9e44",
15
- lime: "#66a80f",
16
- yellow: "#f08c00",
17
- orange: "#e8590c",
18
- };
19
-
20
- interface StyledButtonProps {
21
- variant?:
22
- | "default"
23
- | "contained"
24
- | "filled"
25
- | "light"
26
- | "outlined"
27
- | "text"
28
- | "subtle";
29
- color?: string;
30
- size?: "xxs" | "xs" | "sm" | "md" | "lg" | "xl";
31
- fullWidth?: boolean;
32
- }
33
-
34
- const StyledButton = styled.button<StyledButtonProps>`
35
- width: ${({ fullWidth }) => (fullWidth ? "100%" : "auto")};
36
- height: ${({ size }) => {
37
- switch (size) {
38
- case "xxs":
39
- return `24px`;
40
- case "xs":
41
- return `28px`;
42
- case "sm":
43
- return `34px`;
44
- case "md":
45
- return `40px`;
46
- case "lg":
47
- return `48px`;
48
- case "xl":
49
- return `58px`;
50
- default:
51
- return `34px`;
52
- }
53
- }};
54
-
55
- font-weight: 525;
56
- letter-spacing: 0.75px;
57
- font-size: ${({ 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
- }};
75
-
76
- padding: ${({ size }) => {
77
- switch (size) {
78
- case "xxs":
79
- return `0px 8px`;
80
- case "xs":
81
- return `0px 12px`;
82
- case "sm":
83
- return `0px 16px`;
84
- case "md":
85
- return `0px 20px`;
86
- case "lg":
87
- return `0px 24px`;
88
- case "xl":
89
- return `0px 30px`;
90
- default:
91
- return `0px 16px`;
92
- }
93
- }};
94
-
95
- color: ${({ theme, variant, color }) => {
96
- if (variant === "default") return theme.palette.text.primary;
97
- if (variant === "contained") return "white";
98
- if (variant === "filled") return "white";
99
-
100
- switch (color) {
101
- case "primary":
102
- return theme.palette.primary.main;
103
- case undefined || null:
104
- return theme.palette.text.primary;
105
- default:
106
- return (
107
- theme?.palette?.[color!]?.main ||
108
- colors?.[color!] ||
109
- theme.palette.text.primary
110
- );
111
- }
112
- }};
113
-
114
- background-color: ${({ theme, variant, color }) => {
115
- if (variant === "default") return "transparent";
116
- switch (variant) {
117
- case "contained":
118
- if (!color) return theme.palette.background.secondary;
119
- return (
120
- theme?.palette?.[color]?.main ||
121
- colors?.[color] ||
122
- theme.palette.background.secondary
123
- );
124
- case "filled":
125
- if (!color) return theme.palette.background.secondary;
126
- return (
127
- theme?.palette?.[color]?.main ||
128
- colors?.[color] ||
129
- theme.palette.background.secondary
130
- );
131
- case "light":
132
- if (!color) return theme.palette.background.secondary + "30";
133
- return (
134
- (theme?.palette?.[color]?.main ||
135
- colors?.[color] ||
136
- theme.palette.background.secondary) + "30"
137
- );
138
- case "outlined":
139
- return "transparent";
140
- case "text":
141
- return "transparent";
142
- default:
143
- return "transparent";
144
- }
145
- }};
146
-
147
- border-radius: 4px;
148
- border: 1px solid
149
- ${({ theme, variant, color }) => {
150
- switch (variant) {
151
- case "contained":
152
- return "transparent";
153
- case "filled":
154
- return "transparent";
155
- case "light":
156
- return "transparent";
157
- case "outlined":
158
- if (!color) return theme.palette.divider;
159
- return (
160
- theme?.palette?.[color]?.main ||
161
- colors?.[color] ||
162
- theme.palette.divider
163
- );
164
- case "text":
165
- return "transparent";
166
- case "subtle":
167
- return "transparent";
168
- default:
169
- if (!color) return theme.palette.divider;
170
- return (
171
- theme?.palette?.[color]?.main ||
172
- colors?.[color] ||
173
- theme.palette.divider
174
- );
175
- }
176
- }};
177
-
178
- cursor: pointer;
179
-
180
- transition: background-color 0.2s, border 0.2s;
181
-
182
- &:hover {
183
- background-color: ${({ theme, variant, color }) => {
184
- if (variant === "default") return "transparent";
185
- switch (variant) {
186
- case "contained":
187
- if (!color) return theme.palette.background.secondary + "90";
188
- return (
189
- (theme?.palette?.[color]?.main ||
190
- colors?.[color] ||
191
- theme.palette.background.secondary) + "90"
192
- );
193
- case "filled":
194
- if (!color) return theme.palette.background.secondary + "90";
195
- return (
196
- (theme?.palette?.[color]?.main ||
197
- colors?.[color] ||
198
- theme.palette.background.secondary) + "90"
199
- );
200
- case "light":
201
- if (!color) return theme.palette.background.secondary + "70";
202
- return (
203
- (theme?.palette?.[color]?.main ||
204
- colors?.[color] ||
205
- theme.palette.background.secondary) + "70"
206
- );
207
- case "outlined":
208
- return theme.palette.action.hover;
209
- case "text":
210
- return "transparent";
211
- case "subtle":
212
- if (!color) return theme.palette.action.hover;
213
- return theme?.palette?.[color]?.main || colors?.[color]
214
- ? (theme?.palette?.[color]?.main || colors?.[color]) + "30"
215
- : theme.palette.action.hover;
216
- default:
217
- return theme.palette.action.hover;
218
- }
219
- }};
220
-
221
- border: 1px solid
222
- ${({ theme, variant, color }) => {
223
- switch (variant) {
224
- case "contained":
225
- return "transparent";
226
- case "filled":
227
- return "transparent";
228
- case "light":
229
- return "transparent";
230
- case "outlined":
231
- if (!color) return theme.palette.divider;
232
- return colors?.[color] || theme.palette.divider;
233
- case "text":
234
- return "transparent";
235
- case "subtle":
236
- return "transparent";
237
- default:
238
- if (!color) return theme.palette.divider;
239
- return (
240
- theme?.palette?.[color]?.main ||
241
- colors?.[color] ||
242
- theme.palette.divider
243
- );
244
- }
245
- }};
246
- }
247
- `;
248
-
249
- export interface ButtonProps {
250
- children: React.ReactNode;
251
- variant?:
252
- | "default"
253
- | "contained"
254
- | "filled"
255
- | "light"
256
- | "outlined"
257
- | "text"
258
- | "subtle";
259
- color?: string;
260
- size?: "xxs" | "xs" | "sm" | "md" | "lg" | "xl";
261
- fullWidth?: boolean;
262
- onClick?: () => void;
263
- }
264
-
265
- const Button = forwardRef(
266
- (props: ButtonProps, ref: React.Ref<HTMLButtonElement>) => {
267
- const { children, ...other } = props;
268
- return (
269
- <StyledButton ref={ref} {...other}>
270
- <span style={{ height: "100%" }}>
271
- <span style={{ height: "100%" }}>{children}</span>
272
- </span>
273
- </StyledButton>
274
- );
275
- }
276
- );
277
-
278
- export default Button;
@@ -1 +0,0 @@
1
- export { default } from "./Button";
@@ -1,365 +0,0 @@
1
- import React, { Fragment, useEffect, useState } from "react";
2
- import PropTypes from "prop-types";
3
- import ArrowLeftIcon from "@mui/icons-material/ArrowLeft";
4
- import ArrowRightIcon from "@mui/icons-material/ArrowRight";
5
- import {
6
- CalendarContainer,
7
- CalendarHeader,
8
- CalendarGrid,
9
- CalendarMonth,
10
- CalendarDay,
11
- CalendarDate,
12
- HighlightedCalendarDate,
13
- TodayCalendarDate,
14
- TimeContainer,
15
- MainContainer,
16
- TimePickerContainer,
17
- TimeHourSelect,
18
- TimeHeader,
19
- TimeMinuteSelect,
20
- TimeItem,
21
- TimeItemActive,
22
- NoValueButton,
23
- } from "./CalendarStyles";
24
- import calendar, {
25
- isDate,
26
- isSameDay,
27
- isSameMonth,
28
- getDateISO,
29
- getNextMonth,
30
- getPreviousMonth,
31
- WEEK_DAYS,
32
- CALENDAR_MONTHS,
33
- HOURS24,
34
- HOURS12,
35
- MINUTES,
36
- } from "./calendarHelpers";
37
- import moment from "moment";
38
-
39
- export default function Calendar({
40
- date = new Date(),
41
- onDateChanged = () => {},
42
- hourFormat = "24",
43
- includeTime = true,
44
- clearable = true,
45
- min,
46
- max,
47
- }) {
48
- const [dateState, setDateState] = useState({
49
- current: new Date(),
50
- month: 0,
51
- year: 0,
52
- hours: 0,
53
- minutes: 0,
54
- });
55
- const [today, setToday] = useState(new Date());
56
- let pressureTimer, pressureTimeout, dayTimeout;
57
-
58
- const addDateToState = (date) => {
59
- const isDateObject = isDate(date);
60
- const _date = isDateObject ? date : new Date();
61
- setDateState({
62
- current: isDateObject ? date : null,
63
- month: +_date.getMonth() + 1,
64
- year: _date.getFullYear(),
65
- hours: _date.getHours(),
66
- minutes: _date.getMinutes(),
67
- });
68
- };
69
-
70
- const getCalendarDates = () => {
71
- const { current, month, year } = dateState;
72
- const calendarMonth = month || +current?.getMonth() + 1;
73
- const calendarYear = year || current?.getFullYear();
74
- return calendar(calendarMonth, calendarYear);
75
- };
76
-
77
- const checkValidRange = (value) => {
78
- if (
79
- min &&
80
- moment(value).startOf("day").isBefore(moment(min).startOf("day"))
81
- )
82
- return false;
83
- if (max && moment(value).startOf("day").isAfter(moment(max).startOf("day")))
84
- return false;
85
- return true;
86
- };
87
-
88
- //new start
89
-
90
- const renderMonthAndYear = () => {
91
- const { month, year } = dateState;
92
-
93
- // Resolve the month name from the CALENDAR_MONTHS object map
94
- const monthname =
95
- Object.keys(CALENDAR_MONTHS)[Math.max(0, Math.min(month - 1, 11))];
96
- return (
97
- <CalendarHeader>
98
- <ArrowLeftIcon
99
- onMouseDown={handlePrevious}
100
- onMouseUp={clearPressureTimer}
101
- title="Previous Month"
102
- />
103
-
104
- <CalendarMonth>
105
- {monthname} {year}
106
- </CalendarMonth>
107
-
108
- <ArrowRightIcon
109
- onMouseDown={handleNext}
110
- onMouseUp={clearPressureTimer}
111
- title="Next Month"
112
- />
113
- </CalendarHeader>
114
- );
115
- };
116
- // Render the label for day of the week
117
- // This method is used as a map callback as seen in render()
118
- const renderDayLabel = (day, index) => {
119
- // Resolve the day of the week label from the WEEK_DAYS object map
120
- const daylabel = WEEK_DAYS[day];
121
-
122
- return (
123
- <CalendarDay key={daylabel} index={index}>
124
- {daylabel}
125
- </CalendarDay>
126
- );
127
- };
128
- // Render a calendar date as returned from the calendar builder function
129
- // This method is used as a map callback as seen in render()
130
- const renderCalendarDate = (date, index) => {
131
- const { current, month, year } = dateState;
132
- const _date = new Date(date.join("-"));
133
- // Check if calendar date is same day as today
134
- const isToday = isSameDay(_date, today);
135
-
136
- // Check if calendar date is same day as currently selected date
137
- const isCurrent = current && isSameDay(_date, current);
138
-
139
- // Check if calendar date is in the same month as the state month and year
140
- const inMonth =
141
- month && year && isSameMonth(_date, new Date([year, month, 1].join("-")));
142
- // The click handler
143
- const onClick = gotoDate(_date);
144
- const props = { index, inMonth, onClick, title: _date.toDateString() };
145
- // Conditionally render a styled date component
146
- const DateComponent = isCurrent
147
- ? HighlightedCalendarDate
148
- : isToday
149
- ? TodayCalendarDate
150
- : CalendarDate;
151
- return (
152
- <DateComponent
153
- data-disabled={!checkValidRange(getDateISO(_date))}
154
- key={getDateISO(_date)}
155
- {...props}
156
- >
157
- {_date.getDate()}
158
- </DateComponent>
159
- );
160
- };
161
-
162
- const renderHours = () => {
163
- const { hours } = dateState;
164
- const hoursArray = hourFormat === "24" ? HOURS24 : HOURS12;
165
- return hoursArray.map((hour, index) => {
166
- const HourComponent =
167
- parseInt(hour.value) === hours ? TimeItemActive : TimeItem;
168
- return (
169
- <HourComponent
170
- key={hour.value}
171
- value={hour.value}
172
- onClick={(e) => {
173
- const newTime = moment(dateState.current)
174
- .hours(hour.value)
175
- .toDate();
176
- setDateState({
177
- ...dateState,
178
- hours: parseInt(hour.value),
179
- current: newTime,
180
- });
181
- onDateChanged(newTime);
182
- }}
183
- >
184
- {/* {`${hour.label}${
185
- hourFormat === "24" ? "" : index < 11 ? " AM" : " PM"
186
- }`} */}
187
- {hour.label}
188
- </HourComponent>
189
- );
190
- });
191
- };
192
-
193
- const renderMinutes = () => {
194
- const { minutes } = dateState;
195
- return MINUTES.map((minute) => {
196
- const MinuteComponent =
197
- parseInt(minute) === minutes ? TimeItemActive : TimeItem;
198
- return (
199
- <MinuteComponent
200
- key={minute}
201
- value={minute}
202
- onClick={(e) => {
203
- const newTime = moment(dateState.current).minutes(minute).toDate();
204
- setDateState({
205
- ...dateState,
206
- minutes: parseInt(minute),
207
- current: newTime,
208
- });
209
- onDateChanged(newTime);
210
- }}
211
- >
212
- {minute}
213
- </MinuteComponent>
214
- );
215
- });
216
- };
217
-
218
- // new 2
219
- const gotoDate = (date) => (evt) => {
220
- evt && evt.preventDefault();
221
- const { current } = dateState;
222
-
223
- // Set Hours and Minutes
224
- const newTime = moment(date)
225
- .hours(includeTime ? dateState.hours : 0)
226
- .minutes(includeTime ? dateState.minutes : 0)
227
- .toDate();
228
-
229
- !(current && isSameDay(newTime, current)) && addDateToState(newTime);
230
- onDateChanged(newTime);
231
- };
232
-
233
- const gotoPreviousMonth = () => {
234
- const { month, year } = dateState;
235
- // this.setState(getPreviousMonth(month, year));
236
- const previousMonth = getPreviousMonth(month, year);
237
- setDateState({
238
- month: previousMonth.month,
239
- year: previousMonth.year,
240
- current: dateState.current,
241
- hours: dateState.hours,
242
- minutes: dateState.minutes,
243
- });
244
- };
245
-
246
- const gotoNextMonth = () => {
247
- const { month, year } = dateState;
248
- //this.setState(getNextMonth(month, year));
249
- const nextMonth = getNextMonth(month, year);
250
- setDateState({
251
- month: nextMonth.month,
252
- year: nextMonth.year,
253
- current: dateState.current,
254
- hours: dateState.hours,
255
- minutes: dateState.minutes,
256
- });
257
- };
258
- const gotoPreviousYear = () => {
259
- const { year } = dateState;
260
- setDateState({
261
- month: dateState.month,
262
- year: year - 1,
263
- current: dateState.current,
264
- hours: dateState.hours,
265
- minutes: dateState.minutes,
266
- });
267
- };
268
- const gotoNextYear = () => {
269
- const { year } = dateState;
270
- setDateState({
271
- month: dateState.month,
272
- year: year + 1,
273
- current: dateState.current,
274
- hours: dateState.hours,
275
- minutes: dateState.minutes,
276
- });
277
- };
278
- const handlePressure = (fn) => {
279
- if (typeof fn === "function") {
280
- fn();
281
- pressureTimeout = setTimeout(() => {
282
- pressureTimer = setInterval(fn, 100);
283
- }, 500);
284
- }
285
- };
286
- const clearPressureTimer = () => {
287
- pressureTimer && clearInterval(pressureTimer);
288
- pressureTimeout && clearTimeout(pressureTimeout);
289
- };
290
- const handlePrevious = (evt) => {
291
- evt && evt.preventDefault();
292
- const fn = evt.shiftKey ? gotoPreviousYear : gotoPreviousMonth;
293
- fn();
294
- // handlePressure(fn);
295
- };
296
- const handleNext = (evt) => {
297
- evt && evt.preventDefault();
298
- const fn = evt.shiftKey ? gotoNextYear : gotoNextMonth;
299
- fn();
300
- // handlePressure(fn);
301
- };
302
-
303
- useEffect(() => {
304
- // check that date is greater than the year 1900
305
- // if not, set date to today
306
- if (date?.getFullYear() < 1000) {
307
- return;
308
- }
309
- addDateToState(date);
310
- }, [date]);
311
-
312
- // lifecycle methods
313
- useEffect(() => {
314
- const now = new Date();
315
- const tomorrow = new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000;
316
- const ms = tomorrow - now;
317
- dayTimeout = setTimeout(() => {
318
- setToday(new Date());
319
- clearDayTimeout();
320
- }, ms);
321
- return () => {
322
- clearPressureTimer();
323
- clearDayTimeout();
324
- };
325
- }, []);
326
-
327
- const clearDayTimeout = () => {
328
- dayTimeout && clearTimeout(dayTimeout);
329
- };
330
-
331
- return (
332
- <MainContainer>
333
- <CalendarContainer>
334
- {renderMonthAndYear()}
335
- <CalendarGrid>
336
- <Fragment>{Object.keys(WEEK_DAYS).map(renderDayLabel)}</Fragment>
337
- <Fragment>{getCalendarDates().map(renderCalendarDate)}</Fragment>
338
- </CalendarGrid>
339
- {clearable && (
340
- <div style={{ textAlign: "center", marginTop: 3 }}>
341
- <NoValueButton onClick={() => onDateChanged(null)}>
342
- Clear Date
343
- </NoValueButton>
344
- </div>
345
- )}
346
- </CalendarContainer>
347
- {includeTime && (
348
- <TimeContainer>
349
- <TimeHeader>Select Time</TimeHeader>
350
- <TimePickerContainer>
351
- <TimeHourSelect>{renderHours()}</TimeHourSelect>
352
- <TimeMinuteSelect>{renderMinutes()}</TimeMinuteSelect>
353
- </TimePickerContainer>
354
- </TimeContainer>
355
- )}
356
- </MainContainer>
357
- );
358
- }
359
-
360
- Calendar.displayName = "Calendar";
361
-
362
- Calendar.propTypes = {
363
- date: PropTypes.instanceOf(Date),
364
- onDateChanged: PropTypes.func,
365
- };