@monolith-forensics/monolith-ui 1.0.10 → 1.1.0

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 (189) hide show
  1. package/Button/Button.tsx +382 -0
  2. package/Button/index.ts +2 -0
  3. package/{src/components/Calendar/Calendar.js → Calendar/Calendar.tsx} +104 -93
  4. package/{src/components/Calendar/CalendarStyles.js → Calendar/CalendarStyles.tsx} +26 -36
  5. package/{src/components/Calendar/calendarHelpers.js → Calendar/calendarHelpers.ts} +10 -8
  6. package/Calendar/index.ts +1 -0
  7. package/CheckBox/CheckBox.tsx +61 -0
  8. package/CheckBox/index.ts +1 -0
  9. package/{src/components/DateInput/DateInput.js → DateInput/DateInput.tsx} +227 -93
  10. package/DateInput/index.ts +1 -0
  11. package/DropDownMenu/DropDownMenu.tsx +402 -0
  12. package/DropDownMenu/index.ts +1 -0
  13. package/Error/Error.tsx +51 -0
  14. package/Error/index.ts +1 -0
  15. package/{src/components/FieldLabel → FieldLabel}/FieldLabel.tsx +25 -22
  16. package/{src/components/FileInputField/FileInputField.js → FileInputField/FileInputField.tsx} +23 -15
  17. package/FileInputField/index.ts +1 -0
  18. package/Flyout/Flyout.tsx +172 -0
  19. package/Flyout/FlyoutHeader.tsx +14 -0
  20. package/Flyout/FlyoutTitle.tsx +10 -0
  21. package/Flyout/index.ts +3 -0
  22. package/FormSection/FormSection.tsx +71 -0
  23. package/FormSection/index.ts +1 -0
  24. package/Grid/Grid.tsx +18 -0
  25. package/Grid/index.ts +1 -0
  26. package/IconButton/IconButton.tsx +27 -0
  27. package/IconButton/index.ts +1 -0
  28. package/{src/components/Input → Input}/Input.tsx +57 -34
  29. package/Modal/Modal.tsx +172 -0
  30. package/Modal/index.ts +1 -0
  31. package/{src/components/Pill → Pill}/Pill.tsx +41 -11
  32. package/SelectBox/SelectBox.tsx +745 -0
  33. package/SelectBox/index.ts +1 -0
  34. package/Switch/Switch.tsx +204 -0
  35. package/Switch/index.ts +1 -0
  36. package/TagBox/TagBox.tsx +694 -0
  37. package/TagBox/TagBoxStyles.tsx +116 -0
  38. package/TagBox/index.ts +1 -0
  39. package/{src/components/TextArea → TextArea}/TextArea.tsx +35 -13
  40. package/{src/components/TextAreaInput → TextAreaInput}/TextAreaInput.tsx +11 -13
  41. package/{src/components/TextInput → TextInput}/TextInput.tsx +11 -13
  42. package/Tooltip/Tooltip.tsx +68 -0
  43. package/Tooltip/index.ts +1 -0
  44. package/{src/components/ArrowButton → core}/ArrowButton.tsx +17 -20
  45. package/core/ClearButton.tsx +51 -0
  46. package/core/StyledContent.tsx +50 -0
  47. package/core/StyledFloatContainer.tsx +7 -0
  48. package/core/Types/Size.ts +3 -0
  49. package/core/Types/Variant.ts +10 -0
  50. package/core/index.ts +6 -0
  51. package/dist/Button/Button.d.ts +19 -0
  52. package/dist/Button/Button.js +332 -0
  53. package/dist/Button/index.d.ts +2 -0
  54. package/dist/Button/index.js +8 -0
  55. package/dist/Calendar/Calendar.d.ts +15 -0
  56. package/dist/Calendar/Calendar.js +232 -0
  57. package/dist/Calendar/CalendarStyles.d.ts +36 -0
  58. package/dist/Calendar/CalendarStyles.js +170 -0
  59. package/dist/Calendar/calendarHelpers.d.ts +53 -0
  60. package/dist/Calendar/calendarHelpers.js +181 -0
  61. package/dist/Calendar/index.d.ts +1 -0
  62. package/dist/Calendar/index.js +8 -0
  63. package/dist/CheckBox/CheckBox.d.ts +11 -0
  64. package/dist/CheckBox/CheckBox.js +34 -0
  65. package/dist/CheckBox/index.d.ts +1 -0
  66. package/dist/CheckBox/index.js +8 -0
  67. package/dist/DateInput/DateInput.d.ts +24 -0
  68. package/dist/DateInput/DateInput.js +511 -0
  69. package/dist/DateInput/index.d.ts +1 -0
  70. package/dist/DateInput/index.js +8 -0
  71. package/dist/DropDownMenu/DropDownMenu.d.ts +36 -0
  72. package/dist/DropDownMenu/DropDownMenu.js +212 -0
  73. package/dist/DropDownMenu/index.d.ts +1 -0
  74. package/dist/DropDownMenu/index.js +8 -0
  75. package/dist/Error/Error.d.ts +4 -0
  76. package/dist/Error/Error.js +38 -0
  77. package/dist/Error/index.d.ts +1 -0
  78. package/dist/Error/index.js +8 -0
  79. package/dist/FieldLabel/FieldLabel.d.ts +19 -0
  80. package/dist/FieldLabel/FieldLabel.js +119 -0
  81. package/dist/FieldLabel/index.d.ts +1 -0
  82. package/dist/FieldLabel/index.js +8 -0
  83. package/dist/FileInputField/FileInputField.d.ts +18 -0
  84. package/dist/FileInputField/FileInputField.js +116 -0
  85. package/dist/FileInputField/index.d.ts +1 -0
  86. package/dist/FileInputField/index.js +8 -0
  87. package/dist/Flyout/Flyout.d.ts +10 -0
  88. package/dist/Flyout/Flyout.js +111 -0
  89. package/dist/Flyout/FlyoutHeader.d.ts +5 -0
  90. package/dist/Flyout/FlyoutHeader.js +12 -0
  91. package/dist/Flyout/FlyoutTitle.d.ts +2 -0
  92. package/dist/Flyout/FlyoutTitle.js +13 -0
  93. package/dist/Flyout/index.d.ts +3 -0
  94. package/dist/Flyout/index.js +12 -0
  95. package/dist/FormSection/FormSection.d.ts +9 -0
  96. package/dist/FormSection/FormSection.js +51 -0
  97. package/dist/FormSection/index.d.ts +1 -0
  98. package/dist/FormSection/index.js +8 -0
  99. package/dist/Grid/Grid.d.ts +6 -0
  100. package/dist/Grid/Grid.js +15 -0
  101. package/dist/Grid/index.d.ts +1 -0
  102. package/dist/Grid/index.js +8 -0
  103. package/dist/IconButton/IconButton.d.ts +5 -0
  104. package/dist/IconButton/IconButton.js +30 -0
  105. package/dist/IconButton/index.d.ts +1 -0
  106. package/dist/IconButton/index.js +8 -0
  107. package/dist/Input/Input.d.ts +21 -0
  108. package/dist/Input/Input.js +148 -0
  109. package/dist/Input/index.d.ts +1 -0
  110. package/dist/Input/index.js +8 -0
  111. package/dist/Modal/Modal.d.ts +14 -0
  112. package/dist/Modal/Modal.js +134 -0
  113. package/dist/Modal/index.d.ts +1 -0
  114. package/dist/Modal/index.js +8 -0
  115. package/dist/Pill/Pill.d.ts +11 -0
  116. package/dist/Pill/Pill.js +146 -0
  117. package/dist/Pill/index.d.ts +1 -0
  118. package/dist/Pill/index.js +8 -0
  119. package/dist/SelectBox/SelectBox.d.ts +45 -0
  120. package/dist/SelectBox/SelectBox.js +469 -0
  121. package/dist/SelectBox/index.d.ts +1 -0
  122. package/dist/SelectBox/index.js +8 -0
  123. package/dist/Switch/Switch.d.ts +18 -0
  124. package/dist/Switch/Switch.js +157 -0
  125. package/dist/Switch/index.d.ts +1 -0
  126. package/dist/Switch/index.js +8 -0
  127. package/dist/TagBox/TagBox.d.ts +38 -0
  128. package/dist/TagBox/TagBox.js +440 -0
  129. package/dist/TagBox/TagBoxStyles.d.ts +11 -0
  130. package/dist/TagBox/TagBoxStyles.js +113 -0
  131. package/dist/TagBox/index.d.ts +1 -0
  132. package/dist/TagBox/index.js +8 -0
  133. package/dist/TextArea/TextArea.d.ts +16 -0
  134. package/dist/TextArea/TextArea.js +80 -0
  135. package/dist/TextArea/index.d.ts +1 -0
  136. package/dist/TextArea/index.js +8 -0
  137. package/dist/TextAreaInput/TextAreaInput.d.ts +12 -0
  138. package/dist/TextAreaInput/TextAreaInput.js +23 -0
  139. package/dist/TextAreaInput/index.d.ts +1 -0
  140. package/dist/TextAreaInput/index.js +8 -0
  141. package/dist/TextInput/TextInput.d.ts +12 -0
  142. package/dist/TextInput/TextInput.js +30 -0
  143. package/dist/TextInput/index.d.ts +1 -0
  144. package/dist/TextInput/index.js +8 -0
  145. package/dist/Tooltip/Tooltip.d.ts +12 -0
  146. package/dist/Tooltip/Tooltip.js +53 -0
  147. package/dist/Tooltip/index.d.ts +1 -0
  148. package/dist/Tooltip/index.js +8 -0
  149. package/dist/core/ArrowButton.d.ts +6 -0
  150. package/dist/core/ArrowButton.js +48 -0
  151. package/dist/core/ClearButton.d.ts +6 -0
  152. package/dist/core/ClearButton.js +48 -0
  153. package/dist/core/StyledContent.d.ts +7 -0
  154. package/dist/core/StyledContent.js +46 -0
  155. package/dist/core/StyledFloatContainer.d.ts +2 -0
  156. package/dist/core/StyledFloatContainer.js +10 -0
  157. package/dist/core/Types/Size.d.ts +2 -0
  158. package/dist/core/Types/Size.js +2 -0
  159. package/dist/core/Types/Variant.d.ts +2 -0
  160. package/dist/core/Types/Variant.js +2 -0
  161. package/dist/core/index.d.ts +6 -0
  162. package/dist/core/index.js +14 -0
  163. package/dist/index.d.ts +22 -0
  164. package/dist/index.js +51 -0
  165. package/index.ts +22 -0
  166. package/package.json +12 -21
  167. package/{src/components/theme → theme}/components.js +0 -2
  168. package/{src/components/theme → theme}/index.js +0 -1
  169. package/{src/components/theme → theme}/variants.js +0 -1
  170. package/tsconfig.json +11 -11
  171. package/.gitattributes +0 -2
  172. package/rollup.config.js +0 -10
  173. package/src/components/ArrowButton/index.tsx +0 -1
  174. package/src/components/Button/Button.tsx +0 -278
  175. package/src/components/Button/index.ts +0 -1
  176. package/src/components/SelectBox/SelectBox.js +0 -543
  177. package/src/components/TagBox/TagBox.js +0 -563
  178. package/src/components/index.ts +0 -7
  179. package/src/index.ts +0 -1
  180. /package/{src/components/FieldLabel → FieldLabel}/index.ts +0 -0
  181. /package/{src/components/Input/index.tsx → Input/index.ts} +0 -0
  182. /package/{src/components/Pill → Pill}/index.ts +0 -0
  183. /package/{src/components/TextArea → TextArea}/index.ts +0 -0
  184. /package/{src/components/TextAreaInput → TextAreaInput}/index.ts +0 -0
  185. /package/{src/components/TextInput/index.tsx → TextInput/index.ts} +0 -0
  186. /package/{src/components/core/index.js → core/MonolithThemeProvider.js} +0 -0
  187. /package/{src/components/theme → theme}/breakpoints.js +0 -0
  188. /package/{src/components/theme → theme}/shadows.js +0 -0
  189. /package/{src/components/theme → theme}/typography.js +0 -0
@@ -1,7 +1,5 @@
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";
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
5
3
  import {
6
4
  CalendarContainer,
7
5
  CalendarHeader,
@@ -33,29 +31,62 @@ import calendar, {
33
31
  HOURS24,
34
32
  HOURS12,
35
33
  MINUTES,
34
+ WeekDay,
36
35
  } from "./calendarHelpers";
37
36
  import moment from "moment";
38
37
 
39
- export default function Calendar({
40
- date = new Date(),
41
- onDateChanged = () => {},
38
+ const checkValidRange = (
39
+ value: string | null,
40
+ min: Date | null,
41
+ max: Date | null
42
+ ) => {
43
+ if (min && moment(value).startOf("day").isBefore(moment(min).startOf("day")))
44
+ return false;
45
+ if (max && moment(value).startOf("day").isAfter(moment(max).startOf("day")))
46
+ return false;
47
+ return true;
48
+ };
49
+
50
+ interface CalendarProps {
51
+ defaultValue?: Date;
52
+ value?: Date | null;
53
+ onChange?: (date: Date | null) => void;
54
+ hourFormat?: "12" | "24";
55
+ includeTime?: boolean;
56
+ clearable?: boolean;
57
+ min?: Date;
58
+ max?: Date;
59
+ }
60
+
61
+ const Calendar = ({
62
+ defaultValue = new Date(),
63
+ value,
64
+ onChange = () => {},
42
65
  hourFormat = "24",
43
66
  includeTime = true,
44
67
  clearable = true,
45
68
  min,
46
69
  max,
47
- }) {
48
- const [dateState, setDateState] = useState({
49
- current: new Date(),
50
- month: 0,
51
- year: 0,
70
+ }: CalendarProps) => {
71
+ const [dateState, setDateState] = useState<{
72
+ current: Date | null;
73
+ month: number;
74
+ year: number;
75
+ hours: number;
76
+ minutes: number;
77
+ }>({
78
+ current: defaultValue,
79
+ month: defaultValue.getMonth() + 1,
80
+ year: defaultValue.getFullYear(),
52
81
  hours: 0,
53
82
  minutes: 0,
54
83
  });
55
84
  const [today, setToday] = useState(new Date());
56
- let pressureTimer, pressureTimeout, dayTimeout;
85
+ let pressureTimer: ReturnType<typeof setInterval>;
86
+ let pressureTimeout: ReturnType<typeof setTimeout>;
87
+ let dayTimeout: ReturnType<typeof setTimeout>;
57
88
 
58
- const addDateToState = (date) => {
89
+ const addDateToState = (date: Date) => {
59
90
  const isDateObject = isDate(date);
60
91
  const _date = isDateObject ? date : new Date();
61
92
  setDateState({
@@ -69,22 +100,11 @@ export default function Calendar({
69
100
 
70
101
  const getCalendarDates = () => {
71
102
  const { current, month, year } = dateState;
72
- const calendarMonth = month || +current?.getMonth() + 1;
103
+ const calendarMonth = month || +(current?.getMonth() || 0) + 1;
73
104
  const calendarYear = year || current?.getFullYear();
74
105
  return calendar(calendarMonth, calendarYear);
75
106
  };
76
107
 
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
108
  //new start
89
109
 
90
110
  const renderMonthAndYear = () => {
@@ -95,30 +115,27 @@ export default function Calendar({
95
115
  Object.keys(CALENDAR_MONTHS)[Math.max(0, Math.min(month - 1, 11))];
96
116
  return (
97
117
  <CalendarHeader>
98
- <ArrowLeftIcon
118
+ <ChevronLeftIcon
99
119
  onMouseDown={handlePrevious}
100
120
  onMouseUp={clearPressureTimer}
101
- title="Previous Month"
121
+ // title="Previous Month"
102
122
  />
103
-
104
123
  <CalendarMonth>
105
124
  {monthname} {year}
106
125
  </CalendarMonth>
107
-
108
- <ArrowRightIcon
126
+ <ChevronRightIcon
109
127
  onMouseDown={handleNext}
110
128
  onMouseUp={clearPressureTimer}
111
- title="Next Month"
129
+ // title="Next Month"
112
130
  />
113
131
  </CalendarHeader>
114
132
  );
115
133
  };
116
134
  // Render the label for day of the week
117
135
  // This method is used as a map callback as seen in render()
118
- const renderDayLabel = (day, index) => {
136
+ const renderDayLabel = (day: string, index?: number) => {
119
137
  // Resolve the day of the week label from the WEEK_DAYS object map
120
- const daylabel = WEEK_DAYS[day];
121
-
138
+ const daylabel = WEEK_DAYS[day as WeekDay];
122
139
  return (
123
140
  <CalendarDay key={daylabel} index={index}>
124
141
  {daylabel}
@@ -127,7 +144,7 @@ export default function Calendar({
127
144
  };
128
145
  // Render a calendar date as returned from the calendar builder function
129
146
  // This method is used as a map callback as seen in render()
130
- const renderCalendarDate = (date, index) => {
147
+ const renderCalendarDate = (date: (string | number)[], index: number) => {
131
148
  const { current, month, year } = dateState;
132
149
  const _date = new Date(date.join("-"));
133
150
  // Check if calendar date is same day as today
@@ -140,22 +157,28 @@ export default function Calendar({
140
157
  const inMonth =
141
158
  month && year && isSameMonth(_date, new Date([year, month, 1].join("-")));
142
159
  // The click handler
143
- const onClick = gotoDate(_date);
144
- const props = { index, inMonth, onClick, title: _date.toDateString() };
160
+ const props = {
161
+ "data-disabled": !checkValidRange(
162
+ getDateISO(_date),
163
+ min || null,
164
+ max || null
165
+ ),
166
+ index,
167
+ key: getDateISO(_date),
168
+ onClick: gotoDate(_date),
169
+ title: _date.toDateString(),
170
+ inMonth,
171
+ };
145
172
  // 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
- >
173
+
174
+ return isCurrent ? (
175
+ <HighlightedCalendarDate {...props}>
157
176
  {_date.getDate()}
158
- </DateComponent>
177
+ </HighlightedCalendarDate>
178
+ ) : isToday ? (
179
+ <TodayCalendarDate {...props}>{_date.getDate()}</TodayCalendarDate>
180
+ ) : (
181
+ <CalendarDate {...props}>{_date.getDate()}</CalendarDate>
159
182
  );
160
183
  };
161
184
 
@@ -163,27 +186,23 @@ export default function Calendar({
163
186
  const { hours } = dateState;
164
187
  const hoursArray = hourFormat === "24" ? HOURS24 : HOURS12;
165
188
  return hoursArray.map((hour, index) => {
166
- const HourComponent =
167
- parseInt(hour.value) === hours ? TimeItemActive : TimeItem;
189
+ const HourComponent = hour.value === hours ? TimeItemActive : TimeItem;
168
190
  return (
169
191
  <HourComponent
170
192
  key={hour.value}
171
- value={hour.value}
193
+ // value={hour.value}
172
194
  onClick={(e) => {
173
195
  const newTime = moment(dateState.current)
174
196
  .hours(hour.value)
175
197
  .toDate();
176
198
  setDateState({
177
199
  ...dateState,
178
- hours: parseInt(hour.value),
200
+ hours: hour.value,
179
201
  current: newTime,
180
202
  });
181
- onDateChanged(newTime);
203
+ onChange(newTime);
182
204
  }}
183
205
  >
184
- {/* {`${hour.label}${
185
- hourFormat === "24" ? "" : index < 11 ? " AM" : " PM"
186
- }`} */}
187
206
  {hour.label}
188
207
  </HourComponent>
189
208
  );
@@ -193,20 +212,21 @@ export default function Calendar({
193
212
  const renderMinutes = () => {
194
213
  const { minutes } = dateState;
195
214
  return MINUTES.map((minute) => {
196
- const MinuteComponent =
197
- parseInt(minute) === minutes ? TimeItemActive : TimeItem;
215
+ const MinuteComponent = minute === minutes ? TimeItemActive : TimeItem;
198
216
  return (
199
217
  <MinuteComponent
200
218
  key={minute}
201
- value={minute}
219
+ // value={minute}
202
220
  onClick={(e) => {
203
- const newTime = moment(dateState.current).minutes(minute).toDate();
221
+ const newTime = moment(dateState.current)
222
+ .minutes(Number(minute))
223
+ .toDate();
204
224
  setDateState({
205
225
  ...dateState,
206
- minutes: parseInt(minute),
226
+ minutes: Number(minute),
207
227
  current: newTime,
208
228
  });
209
- onDateChanged(newTime);
229
+ onChange(newTime);
210
230
  }}
211
231
  >
212
232
  {minute}
@@ -215,8 +235,17 @@ export default function Calendar({
215
235
  });
216
236
  };
217
237
 
238
+ type GotoDate = (
239
+ date: Date
240
+ ) => (
241
+ evt:
242
+ | React.MouseEvent<HTMLElement, MouseEvent>
243
+ | React.FormEvent<HTMLFormElement>
244
+ | undefined
245
+ ) => void;
246
+
218
247
  // new 2
219
- const gotoDate = (date) => (evt) => {
248
+ const gotoDate: GotoDate = (date) => (evt) => {
220
249
  evt && evt.preventDefault();
221
250
  const { current } = dateState;
222
251
 
@@ -227,12 +256,11 @@ export default function Calendar({
227
256
  .toDate();
228
257
 
229
258
  !(current && isSameDay(newTime, current)) && addDateToState(newTime);
230
- onDateChanged(newTime);
259
+ onChange(newTime);
231
260
  };
232
261
 
233
262
  const gotoPreviousMonth = () => {
234
263
  const { month, year } = dateState;
235
- // this.setState(getPreviousMonth(month, year));
236
264
  const previousMonth = getPreviousMonth(month, year);
237
265
  setDateState({
238
266
  month: previousMonth.month,
@@ -245,7 +273,6 @@ export default function Calendar({
245
273
 
246
274
  const gotoNextMonth = () => {
247
275
  const { month, year } = dateState;
248
- //this.setState(getNextMonth(month, year));
249
276
  const nextMonth = getNextMonth(month, year);
250
277
  setDateState({
251
278
  month: nextMonth.month,
@@ -275,43 +302,30 @@ export default function Calendar({
275
302
  minutes: dateState.minutes,
276
303
  });
277
304
  };
278
- const handlePressure = (fn) => {
279
- if (typeof fn === "function") {
280
- fn();
281
- pressureTimeout = setTimeout(() => {
282
- pressureTimer = setInterval(fn, 100);
283
- }, 500);
284
- }
285
- };
286
305
  const clearPressureTimer = () => {
287
306
  pressureTimer && clearInterval(pressureTimer);
288
307
  pressureTimeout && clearTimeout(pressureTimeout);
289
308
  };
290
- const handlePrevious = (evt) => {
309
+ const handlePrevious = (evt: React.MouseEvent) => {
291
310
  evt && evt.preventDefault();
292
311
  const fn = evt.shiftKey ? gotoPreviousYear : gotoPreviousMonth;
293
312
  fn();
294
- // handlePressure(fn);
295
313
  };
296
- const handleNext = (evt) => {
314
+ const handleNext = (evt: React.MouseEvent) => {
297
315
  evt && evt.preventDefault();
298
316
  const fn = evt.shiftKey ? gotoNextYear : gotoNextMonth;
299
317
  fn();
300
- // handlePressure(fn);
301
318
  };
302
319
 
303
320
  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;
321
+ if (value) {
322
+ addDateToState(value);
308
323
  }
309
- addDateToState(date);
310
- }, [date]);
324
+ }, [value]);
311
325
 
312
326
  // lifecycle methods
313
327
  useEffect(() => {
314
- const now = new Date();
328
+ const now = new Date().valueOf();
315
329
  const tomorrow = new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000;
316
330
  const ms = tomorrow - now;
317
331
  dayTimeout = setTimeout(() => {
@@ -338,7 +352,7 @@ export default function Calendar({
338
352
  </CalendarGrid>
339
353
  {clearable && (
340
354
  <div style={{ textAlign: "center", marginTop: 3 }}>
341
- <NoValueButton onClick={() => onDateChanged(null)}>
355
+ <NoValueButton onClick={() => onChange(null)}>
342
356
  Clear Date
343
357
  </NoValueButton>
344
358
  </div>
@@ -355,11 +369,8 @@ export default function Calendar({
355
369
  )}
356
370
  </MainContainer>
357
371
  );
358
- }
372
+ };
359
373
 
360
374
  Calendar.displayName = "Calendar";
361
375
 
362
- Calendar.propTypes = {
363
- date: PropTypes.instanceOf(Date),
364
- onDateChanged: PropTypes.func,
365
- };
376
+ export default Calendar;
@@ -6,7 +6,6 @@ export const MainContainer = styled.div`
6
6
  export const CalendarContainer = styled.div`
7
7
  font-size: 5px;
8
8
  width: 250px;
9
- // border: 1px solid ${(props) => props.theme.palette.divider};
10
9
  border-radius: 4px;
11
10
  overflow: hidden;
12
11
  `;
@@ -28,7 +27,16 @@ export const CalendarMonth = styled.div`
28
27
  word-spacing: 5px;
29
28
  user-select: none;
30
29
  `;
31
- export const CalendarCell = styled.div`
30
+
31
+ interface CalendarCellProps {
32
+ index?: number;
33
+ inMonth?: boolean | 0;
34
+ "data-disabled"?: boolean | 0;
35
+ key: string | null;
36
+ title?: string;
37
+ }
38
+
39
+ export const CalendarCell = styled.div<CalendarCellProps>`
32
40
  text-align: center;
33
41
  align-self: center;
34
42
  letter-spacing: 0.1rem;
@@ -36,53 +44,36 @@ export const CalendarCell = styled.div`
36
44
  user-select: none;
37
45
  border-radius: 5px;
38
46
  border: 1px solid transparent;
39
- grid-column: ${(props) => (props.index % 7) + 1} / span 1;
47
+ grid-column: ${({ index = 0 }) => (index % 7) + 1} / span 1;
40
48
  `;
41
- export const CalendarDay = styled(CalendarCell)`
49
+
50
+ export const CalendarDay = styled(CalendarCell)<CalendarCellProps>`
42
51
  font-weight: bold;
43
52
  font-size: 10px;
44
53
  border-radius: 0px;
45
54
  color: ${(props) => props.theme.palette.text.secondary};
46
- // border-top: 1px solid ${(props) => props.theme.palette.divider};
47
- // border-bottom: 1px solid ${(props) => props.theme.palette.divider};
48
- border-right: ${(props) =>
49
- (props.index % 7) + 1 === 7
50
- ? `none`
51
- : `2px solid ${(props) => props.theme.palette.divider}`};
52
- `;
53
- export const CalendarDate = styled(CalendarCell)`
55
+ `;
56
+
57
+ export const CalendarDate = styled(CalendarCell)<CalendarCellProps>`
54
58
  font-weight: ${(props) => (props.inMonth ? 500 : 300)};
55
59
  font-size: 10px;
56
60
  cursor: pointer;
57
- border-bottom: ${(props) =>
58
- (props.index + 1) / 7 <= 5
59
- ? `1px solid ${(props) => props.theme.palette.divider}`
60
- : `1px solid transparent`};
61
- border-right: ${(props) =>
62
- (props.index % 7) + 1 === 7
63
- ? `1px solid transparent`
64
- : `1px solid ${(props) => props.theme.palette.divider}`};
65
- border-left: 1px solid transparent;
66
- border-top: 1px solid transparent;
67
- color: ${(props) =>
68
- props.inMonth
69
- ? props.theme.palette.text.primary
70
- : props.theme.palette.text.secondary};
71
- grid-row: ${(props) => Math.floor(props.index / 7) + 2} / span 1;
61
+
62
+ color: ${({ inMonth, theme }) =>
63
+ inMonth ? theme.palette.text.primary : theme.palette.text.secondary};
64
+ grid-row: ${({ index }) => Math.floor((index || 0) / 7) + 2} / span 1;
72
65
  transition: all 0.2s ease-out;
73
66
  border-radius: 5px;
74
67
  :hover {
75
- // color: ${(props) => props.theme.palette.primary.main};
76
- background: ${(props) => props.theme.palette.action.hover};
68
+ background: ${({ theme }) => theme.palette.action.hover};
77
69
  }
78
70
 
79
71
  &[data-disabled="true"] {
80
72
  pointer-events: none;
81
- color: ${(props) => props.theme.palette.text.disabled};
73
+ color: ${({ theme }) => theme.palette.text.disabled};
82
74
  }
83
75
  `;
84
- export const HighlightedCalendarDate = styled(CalendarDate)`
85
- // color: ${(props) => props.theme.palette.primary.main} !important;
76
+ export const HighlightedCalendarDate = styled(CalendarDate)<CalendarCellProps>`
86
77
  color: white !important;
87
78
  background: ${(props) => props.theme.palette.primary.main} !important;
88
79
  border: 1px solid ${(props) => props.theme.palette.primary.main} !important;
@@ -94,10 +85,11 @@ export const HighlightedCalendarDate = styled(CalendarDate)`
94
85
  left: -1px;
95
86
  width: calc(100% + 2px);
96
87
  height: calc(100% + 2px);
97
- // border: 2px solid #06c;
98
88
  }
99
89
  `;
100
- export const TodayCalendarDate = styled(HighlightedCalendarDate)`
90
+ export const TodayCalendarDate = styled(
91
+ HighlightedCalendarDate
92
+ )<CalendarCellProps>`
101
93
  color: ${(props) => props.theme.palette.text.primary} !important;
102
94
  background: transparent !important;
103
95
  ::after {
@@ -136,7 +128,6 @@ export const TimeHeader = styled.div`
136
128
  padding: 5px;
137
129
  line-height: 2.3;
138
130
  height: 40px;
139
- // word-spacing: 5px;
140
131
  user-select: none;
141
132
  `;
142
133
  export const TimeHourSelect = styled.div`
@@ -156,7 +147,6 @@ export const TimeItem = styled.div`
156
147
  color: ${(props) => props.theme.palette.text.primary};
157
148
  text-align: center;
158
149
  padding: 5px;
159
- // word-spacing: 5px;
160
150
  user-select: none;
161
151
  cursor: pointer;
162
152
  transition: all 0.2s ease-out;
@@ -11,7 +11,6 @@ export const HOURS24 = [...new Array(24)].map((n, index) => {
11
11
  value: index,
12
12
  label: index < 10 ? `0${index}` : `${index}`,
13
13
  };
14
- // return index < 10 ? `0${index}` : `${index}`;
15
14
  });
16
15
 
17
16
  export const HOURS12 = [
@@ -43,6 +42,8 @@ export const WEEK_DAYS = {
43
42
  Saturday: "Sa",
44
43
  };
45
44
 
45
+ export type WeekDay = keyof typeof WEEK_DAYS;
46
+
46
47
  // Calendar months names and short names
47
48
  export const CALENDAR_MONTHS = {
48
49
  January: "Jan",
@@ -64,7 +65,7 @@ export const CALENDAR_WEEKS = 6;
64
65
 
65
66
  // Pads a string value with leading zeroes(0) until length is reached
66
67
  // For example: zeroPad(5, 2) => "05"
67
- export const zeroPad = (value, length) => {
68
+ export const zeroPad = (value: number, length: number) => {
68
69
  return `${value}`.padStart(length, "0");
69
70
  };
70
71
 
@@ -88,7 +89,7 @@ export const getMonthFirstDay = (month = THIS_MONTH, year = THIS_YEAR) => {
88
89
  };
89
90
 
90
91
  // (bool) Checks if a value is a date - this is just a simple check
91
- export const isDate = (date) => {
92
+ export const isDate = (date: Date) => {
92
93
  const isDate = Object.prototype.toString.call(date) === "[object Date]";
93
94
  const isValidDate = date && !Number.isNaN(date.valueOf());
94
95
 
@@ -96,7 +97,7 @@ export const isDate = (date) => {
96
97
  };
97
98
 
98
99
  // (bool) Checks if two date values are of the same month and year
99
- export const isSameMonth = (date, basedate = new Date()) => {
100
+ export const isSameMonth = (date: Date, basedate = new Date()) => {
100
101
  if (!(isDate(date) && isDate(basedate))) return false;
101
102
  const basedateMonth = +basedate.getMonth() + 1;
102
103
  const basedateYear = basedate.getFullYear();
@@ -105,7 +106,7 @@ export const isSameMonth = (date, basedate = new Date()) => {
105
106
  return +basedateMonth === +dateMonth && +basedateYear === +dateYear;
106
107
  };
107
108
  // (bool) Checks if two date values are the same day
108
- export const isSameDay = (date, basedate = new Date()) => {
109
+ export const isSameDay = (date: Date, basedate = new Date()) => {
109
110
  if (!(isDate(date) && isDate(basedate))) return false;
110
111
  const basedateDate = basedate.getDate();
111
112
  const basedateMonth = +basedate.getMonth() + 1;
@@ -121,7 +122,7 @@ export const isSameDay = (date, basedate = new Date()) => {
121
122
  };
122
123
  // (string) Formats the given date as YYYY-MM-DD
123
124
  // Months and Days are zero padded
124
- export const getDateISO = (date = new Date()) => {
125
+ export const getDateISO = (date: Date) => {
125
126
  if (!isDate(date)) return null;
126
127
  return [
127
128
  date.getFullYear(),
@@ -132,7 +133,8 @@ export const getDateISO = (date = new Date()) => {
132
133
  // ({month, year}) Gets the month and year before the given month and year
133
134
  // For example: getPreviousMonth(1, 2000) => {month: 12, year: 1999}
134
135
  // while: getPreviousMonth(12, 2000) => {month: 11, year: 2000}
135
- export const getPreviousMonth = (month, year) => {
136
+
137
+ export const getPreviousMonth = (month: number, year: number) => {
136
138
  const prevMonth = month > 1 ? month - 1 : 12;
137
139
  const prevMonthYear = month > 1 ? year : year - 1;
138
140
  return { month: prevMonth, year: prevMonthYear };
@@ -140,7 +142,7 @@ export const getPreviousMonth = (month, year) => {
140
142
  // ({month, year}) Gets the month and year after the given month and year
141
143
  // For example: getNextMonth(1, 2000) => {month: 2, year: 2000}
142
144
  // while: getNextMonth(12, 2000) => {month: 1, year: 2001}
143
- export const getNextMonth = (month, year) => {
145
+ export const getNextMonth = (month: number, year: number) => {
144
146
  const nextMonth = month < 12 ? month + 1 : 1;
145
147
  const nextMonthYear = month < 12 ? year : year + 1;
146
148
  return { month: nextMonth, year: nextMonthYear };
@@ -0,0 +1 @@
1
+ export { default } from "./Calendar";
@@ -0,0 +1,61 @@
1
+ import styled from "styled-components";
2
+ import { useState, useEffect, CSSProperties, MouseEvent } from "react";
3
+ import CheckBoxOutlineBlankOutlinedIcon from "@mui/icons-material/CheckBoxOutlineBlankOutlined";
4
+ import IndeterminateCheckBoxIcon from "@mui/icons-material/IndeterminateCheckBox";
5
+ import CheckBoxIcon from "@mui/icons-material/CheckBox";
6
+
7
+ interface CheckBoxProps {
8
+ className?: string;
9
+ defaultValue?: boolean;
10
+ value?: boolean;
11
+ partialCheck?: boolean;
12
+ onChange?: (value: boolean) => void;
13
+ style?: CSSProperties;
14
+ }
15
+
16
+ const CheckBox = styled(
17
+ ({
18
+ className,
19
+ defaultValue = false,
20
+ value = false,
21
+ partialCheck = false,
22
+ onChange = () => {},
23
+ }: CheckBoxProps) => {
24
+ const [checkedState, setCheckedState] = useState(defaultValue);
25
+
26
+ const handleChange = (e: MouseEvent) => {
27
+ e.stopPropagation();
28
+ setCheckedState(!checkedState);
29
+ onChange(!checkedState);
30
+ };
31
+
32
+ useEffect(() => {
33
+ setCheckedState(value);
34
+ }, [value]);
35
+
36
+ const _checked = value === undefined ? checkedState : value;
37
+
38
+ return (
39
+ <div className={className} onClick={handleChange}>
40
+ {partialCheck === true ? (
41
+ <IndeterminateCheckBoxIcon className="checkbox partial" />
42
+ ) : _checked === true ? (
43
+ <CheckBoxIcon className="checkbox checked" />
44
+ ) : (
45
+ <CheckBoxOutlineBlankOutlinedIcon className="checkbox unchecked" />
46
+ )}
47
+ </div>
48
+ );
49
+ }
50
+ )`
51
+ display: flex;
52
+ align-items: center;
53
+ cursor: pointer;
54
+
55
+ .checkbox {
56
+ color: ${(props) => props.theme.palette.primary.main};
57
+ font-size: 16px;
58
+ }
59
+ `;
60
+
61
+ export default CheckBox;
@@ -0,0 +1 @@
1
+ export { default } from "./CheckBox";