@monolith-forensics/monolith-ui 1.1.29 → 1.1.31
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.
- package/dist/Button/Button.js +327 -0
- package/dist/Button/index.js +1 -0
- package/dist/Calendar/Calendar.js +204 -0
- package/dist/Calendar/CalendarStyles.js +164 -0
- package/dist/Calendar/calendarHelpers.js +169 -0
- package/dist/Calendar/index.js +1 -0
- package/dist/CheckBox/CheckBox.js +41 -0
- package/dist/CheckBox/index.js +1 -0
- package/dist/DateInput/DateInput.js +504 -0
- package/dist/DateInput/index.js +1 -0
- package/dist/DropDownMenu/DropDownMenu.js +208 -0
- package/dist/DropDownMenu/index.js +1 -0
- package/dist/Error/Error.js +33 -0
- package/dist/Error/index.js +1 -0
- package/dist/FieldLabel/FieldLabel.js +90 -0
- package/dist/FieldLabel/index.js +1 -0
- package/dist/FileInputField/FileInputField.js +112 -0
- package/dist/FileInputField/index.js +1 -0
- package/dist/Flyout/Flyout.js +106 -0
- package/dist/Flyout/FlyoutHeader.js +7 -0
- package/dist/Flyout/FlyoutTitle.js +8 -0
- package/dist/Flyout/index.js +3 -0
- package/dist/FormSection/FormSection.js +46 -0
- package/dist/FormSection/index.js +1 -0
- package/dist/Grid/Grid.js +13 -0
- package/dist/Grid/index.js +1 -0
- package/dist/IconButton/IconButton.js +25 -0
- package/dist/IconButton/index.js +1 -0
- package/dist/Input/Input.js +144 -0
- package/dist/Input/index.js +1 -0
- package/dist/Modal/Modal.js +105 -0
- package/dist/Modal/index.js +1 -0
- package/dist/MonolithUIProvider/GlobalStyle.js +51 -0
- package/dist/MonolithUIProvider/MonolithUIProvider.js +23 -0
- package/dist/MonolithUIProvider/index.js +3 -0
- package/dist/MonolithUIProvider/useMonolithUITheme.js +10 -0
- package/dist/Pill/Pill.js +147 -0
- package/dist/Pill/index.js +1 -0
- package/dist/SelectBox/SelectBox.js +471 -0
- package/dist/SelectBox/index.js +1 -0
- package/dist/Switch/Switch.js +129 -0
- package/dist/Switch/index.js +1 -0
- package/dist/Table/Table.js +707 -0
- package/dist/Table/index.js +2 -0
- package/dist/TagBox/TagBox.js +585 -0
- package/dist/TagBox/TagBoxStyles.js +107 -0
- package/dist/TagBox/index.js +1 -0
- package/dist/TextArea/TextArea.js +76 -0
- package/dist/TextArea/index.js +1 -0
- package/dist/TextAreaInput/TextAreaInput.js +9 -0
- package/dist/TextAreaInput/index.js +1 -0
- package/dist/TextInput/TextInput.js +26 -0
- package/dist/TextInput/index.js +1 -0
- package/dist/Tooltip/Tooltip.js +25 -0
- package/dist/Tooltip/index.js +1 -0
- package/dist/core/ArrowButton.js +43 -0
- package/dist/core/ClearButton.js +43 -0
- package/dist/core/StyledContent.js +42 -0
- package/dist/core/StyledFloatContainer.js +5 -0
- package/dist/core/Types/Size.js +1 -0
- package/dist/core/Types/Variant.js +1 -0
- package/dist/core/index.js +4 -0
- package/dist/index.js +26 -0
- package/dist/theme/index.js +9 -0
- package/dist/theme/typography.js +57 -0
- package/dist/theme/variants.js +270 -0
- package/package.json +1 -1
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef } from "react";
|
|
14
|
+
import styled from "styled-components";
|
|
15
|
+
import { Loader2Icon } from "lucide-react";
|
|
16
|
+
const colors = {
|
|
17
|
+
gray: "#888888",
|
|
18
|
+
red: "#e03131",
|
|
19
|
+
pink: "#c2255c",
|
|
20
|
+
grape: "#9c36b5",
|
|
21
|
+
violet: "#6741d9",
|
|
22
|
+
indigo: "#3b5bdb",
|
|
23
|
+
cyan: "#0c8599",
|
|
24
|
+
teal: "#099268",
|
|
25
|
+
green: "#2f9e44",
|
|
26
|
+
lime: "#66a80f",
|
|
27
|
+
yellow: "#f08c00",
|
|
28
|
+
orange: "#e8590c",
|
|
29
|
+
};
|
|
30
|
+
const StyledButton = styled.button `
|
|
31
|
+
user-select: none;
|
|
32
|
+
display: flex;
|
|
33
|
+
outline: none;
|
|
34
|
+
white-space: nowrap;
|
|
35
|
+
|
|
36
|
+
width: ${({ fullWidth }) => (fullWidth ? "100%" : "fit-content")};
|
|
37
|
+
height: ${({ theme, size }) => {
|
|
38
|
+
switch (size) {
|
|
39
|
+
case "xxs":
|
|
40
|
+
return `24px`;
|
|
41
|
+
case "xs":
|
|
42
|
+
return `28px`;
|
|
43
|
+
case "sm":
|
|
44
|
+
return `34px`;
|
|
45
|
+
case "md":
|
|
46
|
+
return `40px`;
|
|
47
|
+
case "lg":
|
|
48
|
+
return `48px`;
|
|
49
|
+
case "xl":
|
|
50
|
+
return `58px`;
|
|
51
|
+
default:
|
|
52
|
+
return `34px`;
|
|
53
|
+
}
|
|
54
|
+
}};
|
|
55
|
+
|
|
56
|
+
font-weight: 525;
|
|
57
|
+
letter-spacing: 0.75px;
|
|
58
|
+
font-size: ${({ theme, size }) => {
|
|
59
|
+
switch (size) {
|
|
60
|
+
case "xxs":
|
|
61
|
+
return `11px`;
|
|
62
|
+
case "xs":
|
|
63
|
+
return `12px`;
|
|
64
|
+
case "sm":
|
|
65
|
+
return `14px`;
|
|
66
|
+
case "md":
|
|
67
|
+
return `16px`;
|
|
68
|
+
case "lg":
|
|
69
|
+
return `18px`;
|
|
70
|
+
case "xl":
|
|
71
|
+
return `20px`;
|
|
72
|
+
default:
|
|
73
|
+
return `14px`;
|
|
74
|
+
}
|
|
75
|
+
}};
|
|
76
|
+
|
|
77
|
+
padding: ${({ theme, size, variant }) => {
|
|
78
|
+
if (variant === "text")
|
|
79
|
+
return `0px 0px`;
|
|
80
|
+
switch (size) {
|
|
81
|
+
case "xxs":
|
|
82
|
+
return `0px 8px`;
|
|
83
|
+
case "xs":
|
|
84
|
+
return `0px 12px`;
|
|
85
|
+
case "sm":
|
|
86
|
+
return `0px 16px`;
|
|
87
|
+
case "md":
|
|
88
|
+
return `0px 20px`;
|
|
89
|
+
case "lg":
|
|
90
|
+
return `0px 24px`;
|
|
91
|
+
case "xl":
|
|
92
|
+
return `0px 30px`;
|
|
93
|
+
default:
|
|
94
|
+
return `0px 16px`;
|
|
95
|
+
}
|
|
96
|
+
}};
|
|
97
|
+
|
|
98
|
+
color: ${({ theme, variant, color }) => {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
if (variant === "default")
|
|
101
|
+
return theme.palette.text.primary;
|
|
102
|
+
if (variant === "contained")
|
|
103
|
+
return "white";
|
|
104
|
+
if (variant === "filled")
|
|
105
|
+
return "white";
|
|
106
|
+
switch (color) {
|
|
107
|
+
case "primary":
|
|
108
|
+
return theme.palette.primary.main;
|
|
109
|
+
case undefined:
|
|
110
|
+
return theme.palette.text.primary;
|
|
111
|
+
default:
|
|
112
|
+
return color
|
|
113
|
+
? ((_b = (_a = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _a === void 0 ? void 0 : _a[color]) === null || _b === void 0 ? void 0 : _b.main) ||
|
|
114
|
+
colors[color] ||
|
|
115
|
+
theme.palette.text.primary
|
|
116
|
+
: theme.palette.text.primary;
|
|
117
|
+
}
|
|
118
|
+
}};
|
|
119
|
+
|
|
120
|
+
background-color: ${({ theme, variant, color }) => {
|
|
121
|
+
var _a, _b, _c, _d, _e, _f;
|
|
122
|
+
if (variant === "default")
|
|
123
|
+
return "transparent";
|
|
124
|
+
switch (variant) {
|
|
125
|
+
case "contained":
|
|
126
|
+
return color
|
|
127
|
+
? ((_b = (_a = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _a === void 0 ? void 0 : _a[color]) === null || _b === void 0 ? void 0 : _b.main) ||
|
|
128
|
+
colors[color] ||
|
|
129
|
+
theme.palette.background.secondary
|
|
130
|
+
: theme.palette.background.secondary;
|
|
131
|
+
case "filled":
|
|
132
|
+
return color
|
|
133
|
+
? ((_d = (_c = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _c === void 0 ? void 0 : _c[color]) === null || _d === void 0 ? void 0 : _d.main) ||
|
|
134
|
+
colors[color] ||
|
|
135
|
+
theme.palette.background.secondary
|
|
136
|
+
: theme.palette.background.secondary;
|
|
137
|
+
case "light":
|
|
138
|
+
return ((color
|
|
139
|
+
? ((_f = (_e = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _e === void 0 ? void 0 : _e[color]) === null || _f === void 0 ? void 0 : _f.main) ||
|
|
140
|
+
colors[color] ||
|
|
141
|
+
theme.palette.background.secondary
|
|
142
|
+
: theme.palette.background.secondary) + "30");
|
|
143
|
+
case "outlined":
|
|
144
|
+
return "transparent";
|
|
145
|
+
case "text":
|
|
146
|
+
return "transparent";
|
|
147
|
+
default:
|
|
148
|
+
return "transparent";
|
|
149
|
+
}
|
|
150
|
+
}};
|
|
151
|
+
|
|
152
|
+
border-radius: 4px;
|
|
153
|
+
border: 1px solid
|
|
154
|
+
${({ theme, variant, color }) => {
|
|
155
|
+
var _a, _b, _c, _d;
|
|
156
|
+
switch (variant) {
|
|
157
|
+
case "contained":
|
|
158
|
+
return "transparent";
|
|
159
|
+
case "filled":
|
|
160
|
+
return "transparent";
|
|
161
|
+
case "light":
|
|
162
|
+
return "transparent";
|
|
163
|
+
case "outlined":
|
|
164
|
+
return color
|
|
165
|
+
? ((_b = (_a = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _a === void 0 ? void 0 : _a[color]) === null || _b === void 0 ? void 0 : _b.main) ||
|
|
166
|
+
colors[color] ||
|
|
167
|
+
theme.palette.divider
|
|
168
|
+
: theme.palette.divider;
|
|
169
|
+
case "text":
|
|
170
|
+
return "transparent";
|
|
171
|
+
case "subtle":
|
|
172
|
+
return "transparent";
|
|
173
|
+
default:
|
|
174
|
+
return color
|
|
175
|
+
? ((_d = (_c = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _c === void 0 ? void 0 : _c[color]) === null || _d === void 0 ? void 0 : _d.main) ||
|
|
176
|
+
colors[color] ||
|
|
177
|
+
theme.palette.divider
|
|
178
|
+
: theme.palette.divider;
|
|
179
|
+
}
|
|
180
|
+
}};
|
|
181
|
+
|
|
182
|
+
cursor: pointer;
|
|
183
|
+
|
|
184
|
+
transition: background-color 0.2s, border 0.2s;
|
|
185
|
+
|
|
186
|
+
.inner-span {
|
|
187
|
+
display: flex;
|
|
188
|
+
align-items: center;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.button-label {
|
|
192
|
+
display: flex;
|
|
193
|
+
align-items: center;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
[data-position="left"] {
|
|
197
|
+
margin-inline-end: 6px;
|
|
198
|
+
display: flex;
|
|
199
|
+
align-items: center;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
[data-position="right"] {
|
|
203
|
+
margin-inline-start: 6px;
|
|
204
|
+
display: flex;
|
|
205
|
+
align-items: center;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&:hover {
|
|
209
|
+
background-color: ${({ theme, variant, color }) => {
|
|
210
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
211
|
+
if (variant === "default")
|
|
212
|
+
return "transparent";
|
|
213
|
+
switch (variant) {
|
|
214
|
+
case "contained":
|
|
215
|
+
return ((color
|
|
216
|
+
? ((_b = (_a = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _a === void 0 ? void 0 : _a[color]) === null || _b === void 0 ? void 0 : _b.main) ||
|
|
217
|
+
colors[color] ||
|
|
218
|
+
theme.palette.background.secondary
|
|
219
|
+
: theme.palette.background.secondary) + "90");
|
|
220
|
+
case "filled":
|
|
221
|
+
return ((color
|
|
222
|
+
? ((_d = (_c = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _c === void 0 ? void 0 : _c[color]) === null || _d === void 0 ? void 0 : _d.main) ||
|
|
223
|
+
colors[color] ||
|
|
224
|
+
theme.palette.background.secondary
|
|
225
|
+
: theme.palette.background.secondary) + "90");
|
|
226
|
+
case "light":
|
|
227
|
+
return ((color
|
|
228
|
+
? ((_f = (_e = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _e === void 0 ? void 0 : _e[color]) === null || _f === void 0 ? void 0 : _f.main) ||
|
|
229
|
+
colors[color] ||
|
|
230
|
+
theme.palette.background.secondary
|
|
231
|
+
: theme.palette.background.secondary) + "70");
|
|
232
|
+
case "outlined":
|
|
233
|
+
return theme.palette.action.hover;
|
|
234
|
+
case "text":
|
|
235
|
+
return "transparent";
|
|
236
|
+
case "subtle":
|
|
237
|
+
return color
|
|
238
|
+
? (((_h = (_g = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _g === void 0 ? void 0 : _g[color]) === null || _h === void 0 ? void 0 : _h.main) ||
|
|
239
|
+
colors[color]) + "30" ||
|
|
240
|
+
theme.palette.action.hover
|
|
241
|
+
: theme.palette.action.hover;
|
|
242
|
+
default:
|
|
243
|
+
return theme.palette.action.hover;
|
|
244
|
+
}
|
|
245
|
+
}};
|
|
246
|
+
|
|
247
|
+
border: 1px solid
|
|
248
|
+
${({ theme, variant, color }) => {
|
|
249
|
+
var _a, _b;
|
|
250
|
+
switch (variant) {
|
|
251
|
+
case "contained":
|
|
252
|
+
return "transparent";
|
|
253
|
+
case "filled":
|
|
254
|
+
return "transparent";
|
|
255
|
+
case "light":
|
|
256
|
+
return "transparent";
|
|
257
|
+
case "outlined":
|
|
258
|
+
return color
|
|
259
|
+
? colors[color] || theme.palette.divider
|
|
260
|
+
: theme.palette.divider;
|
|
261
|
+
case "text":
|
|
262
|
+
return "transparent";
|
|
263
|
+
case "subtle":
|
|
264
|
+
return "transparent";
|
|
265
|
+
default:
|
|
266
|
+
return color
|
|
267
|
+
? ((_b = (_a = theme === null || theme === void 0 ? void 0 : theme.palette) === null || _a === void 0 ? void 0 : _a[color]) === null || _b === void 0 ? void 0 : _b.main) ||
|
|
268
|
+
colors[color] ||
|
|
269
|
+
theme.palette.divider
|
|
270
|
+
: theme.palette.divider;
|
|
271
|
+
}
|
|
272
|
+
}};
|
|
273
|
+
opacity: ${({ variant }) => (variant === "text" ? 0.8 : 1)};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};
|
|
277
|
+
pointer-events: ${({ disabled }) => (disabled ? "none" : "auto")};
|
|
278
|
+
|
|
279
|
+
&:focus {
|
|
280
|
+
text-decoration: underline;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
&:active {
|
|
284
|
+
// simulate physical button press
|
|
285
|
+
translate: 0px 1px;
|
|
286
|
+
text-decoration: none;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// disabled styles
|
|
290
|
+
${({ disabled }) => disabled &&
|
|
291
|
+
`
|
|
292
|
+
cursor: not-allowed;
|
|
293
|
+
opacity: 0.5;
|
|
294
|
+
pointer-events: none;
|
|
295
|
+
`}
|
|
296
|
+
`;
|
|
297
|
+
const StyledAnchor = styled.a `
|
|
298
|
+
text-decoration: none;
|
|
299
|
+
height: 100%;
|
|
300
|
+
|
|
301
|
+
&:hover {
|
|
302
|
+
text-decoration: none !important;
|
|
303
|
+
}
|
|
304
|
+
`;
|
|
305
|
+
const StyledLoader = styled.span `
|
|
306
|
+
svg {
|
|
307
|
+
width: 16px;
|
|
308
|
+
height: 16px;
|
|
309
|
+
color: ${({ theme, color }) => color
|
|
310
|
+
? theme.palette[color] || colors[color]
|
|
311
|
+
: theme.palette.primary};
|
|
312
|
+
|
|
313
|
+
animation: spin 0.75s linear infinite;
|
|
314
|
+
|
|
315
|
+
@keyframes spin {
|
|
316
|
+
100% {
|
|
317
|
+
transform: rotate(360deg);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
`;
|
|
322
|
+
const Button = forwardRef((props, ref) => {
|
|
323
|
+
const { children, loading = false, leftSection = null, rightSection = null, href = null, download = null } = props, other = __rest(props, ["children", "loading", "leftSection", "rightSection", "href", "download"]);
|
|
324
|
+
const buttonContent = (_jsx("span", { className: "inner-span", style: { height: "100%" }, children: loading ? (_jsx(StyledLoader, { children: _jsx(Loader2Icon, {}) })) : (_jsxs(_Fragment, { children: [leftSection && _jsx("span", { "data-position": "left", children: leftSection }), _jsx("span", { className: "button-label", children: children }), rightSection && _jsx("span", { "data-position": "right", children: rightSection })] })) }));
|
|
325
|
+
return (_jsx(StyledButton, Object.assign({ ref: ref }, other, { children: href ? (_jsx(StyledAnchor, { href: href, download: download, children: buttonContent })) : (buttonContent) })));
|
|
326
|
+
});
|
|
327
|
+
export default Button;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Button";
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useState } from "react";
|
|
3
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
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";
|
|
6
|
+
import moment from "moment";
|
|
7
|
+
const checkValidRange = (value, min, max) => {
|
|
8
|
+
if (min && moment(value).startOf("day").isBefore(moment(min).startOf("day")))
|
|
9
|
+
return false;
|
|
10
|
+
if (max && moment(value).startOf("day").isAfter(moment(max).startOf("day")))
|
|
11
|
+
return false;
|
|
12
|
+
return true;
|
|
13
|
+
};
|
|
14
|
+
const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hourFormat = "24", includeTime = true, clearable = true, min, max, }) => {
|
|
15
|
+
const [dateState, setDateState] = useState({
|
|
16
|
+
current: defaultValue,
|
|
17
|
+
month: defaultValue.getMonth() + 1,
|
|
18
|
+
year: defaultValue.getFullYear(),
|
|
19
|
+
hours: 0,
|
|
20
|
+
minutes: 0,
|
|
21
|
+
});
|
|
22
|
+
const [today, setToday] = useState(new Date());
|
|
23
|
+
let pressureTimer;
|
|
24
|
+
let pressureTimeout;
|
|
25
|
+
let dayTimeout;
|
|
26
|
+
const addDateToState = (date) => {
|
|
27
|
+
const isDateObject = isDate(date);
|
|
28
|
+
const _date = isDateObject ? date : new Date();
|
|
29
|
+
setDateState({
|
|
30
|
+
current: isDateObject ? date : null,
|
|
31
|
+
month: +_date.getMonth() + 1,
|
|
32
|
+
year: _date.getFullYear(),
|
|
33
|
+
hours: _date.getHours(),
|
|
34
|
+
minutes: _date.getMinutes(),
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const getCalendarDates = () => {
|
|
38
|
+
const { current, month, year } = dateState;
|
|
39
|
+
const calendarMonth = month || +((current === null || current === void 0 ? void 0 : current.getMonth()) || 0) + 1;
|
|
40
|
+
const calendarYear = year || (current === null || current === void 0 ? void 0 : current.getFullYear());
|
|
41
|
+
return calendar(calendarMonth, calendarYear);
|
|
42
|
+
};
|
|
43
|
+
//new start
|
|
44
|
+
const renderMonthAndYear = () => {
|
|
45
|
+
const { month, year } = dateState;
|
|
46
|
+
// Resolve the month name from the CALENDAR_MONTHS object map
|
|
47
|
+
const monthname = Object.keys(CALENDAR_MONTHS)[Math.max(0, Math.min(month - 1, 11))];
|
|
48
|
+
return (_jsxs(CalendarHeader, { children: [_jsx(ChevronLeftIcon, { onMouseDown: handlePrevious, onMouseUp: clearPressureTimer }), _jsxs(CalendarMonth, { children: [monthname, " ", year] }), _jsx(ChevronRightIcon, { onMouseDown: handleNext, onMouseUp: clearPressureTimer })] }));
|
|
49
|
+
};
|
|
50
|
+
// Render the label for day of the week
|
|
51
|
+
// This method is used as a map callback as seen in render()
|
|
52
|
+
const renderDayLabel = (day, index) => {
|
|
53
|
+
// Resolve the day of the week label from the WEEK_DAYS object map
|
|
54
|
+
const daylabel = WEEK_DAYS[day];
|
|
55
|
+
return (_jsx(CalendarDay, { index: index, children: daylabel }, daylabel));
|
|
56
|
+
};
|
|
57
|
+
// Render a calendar date as returned from the calendar builder function
|
|
58
|
+
// This method is used as a map callback as seen in render()
|
|
59
|
+
const renderCalendarDate = (date, index) => {
|
|
60
|
+
const { current, month, year } = dateState;
|
|
61
|
+
const _date = new Date(date.join("-"));
|
|
62
|
+
// Check if calendar date is same day as today
|
|
63
|
+
const isToday = isSameDay(_date, today);
|
|
64
|
+
// Check if calendar date is same day as currently selected date
|
|
65
|
+
const isCurrent = current && isSameDay(_date, current);
|
|
66
|
+
// Check if calendar date is in the same month as the state month and year
|
|
67
|
+
const inMonth = month && year && isSameMonth(_date, new Date([year, month, 1].join("-")));
|
|
68
|
+
// The click handler
|
|
69
|
+
const props = {
|
|
70
|
+
"data-disabled": !checkValidRange(getDateISO(_date), min || null, max || null),
|
|
71
|
+
index,
|
|
72
|
+
key: getDateISO(_date),
|
|
73
|
+
onClick: gotoDate(_date),
|
|
74
|
+
title: _date.toDateString(),
|
|
75
|
+
inMonth,
|
|
76
|
+
};
|
|
77
|
+
// Conditionally render a styled date component
|
|
78
|
+
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() })));
|
|
79
|
+
};
|
|
80
|
+
const renderHours = () => {
|
|
81
|
+
const { hours } = dateState;
|
|
82
|
+
const hoursArray = hourFormat === "24" ? HOURS24 : HOURS12;
|
|
83
|
+
return hoursArray.map((hour, index) => {
|
|
84
|
+
const HourComponent = hour.value === hours ? TimeItemActive : TimeItem;
|
|
85
|
+
return (_jsx(HourComponent, {
|
|
86
|
+
// value={hour.value}
|
|
87
|
+
onClick: (e) => {
|
|
88
|
+
const newTime = moment(dateState.current)
|
|
89
|
+
.hours(hour.value)
|
|
90
|
+
.toDate();
|
|
91
|
+
setDateState(Object.assign(Object.assign({}, dateState), { hours: hour.value, current: newTime }));
|
|
92
|
+
onChange(newTime);
|
|
93
|
+
}, children: hour.label }, hour.value));
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
const renderMinutes = () => {
|
|
97
|
+
const { minutes } = dateState;
|
|
98
|
+
return MINUTES.map((minute) => {
|
|
99
|
+
const MinuteComponent = minute === minutes ? TimeItemActive : TimeItem;
|
|
100
|
+
return (_jsx(MinuteComponent, {
|
|
101
|
+
// value={minute}
|
|
102
|
+
onClick: (e) => {
|
|
103
|
+
const newTime = moment(dateState.current)
|
|
104
|
+
.minutes(Number(minute))
|
|
105
|
+
.toDate();
|
|
106
|
+
setDateState(Object.assign(Object.assign({}, dateState), { minutes: Number(minute), current: newTime }));
|
|
107
|
+
onChange(newTime);
|
|
108
|
+
}, children: minute }, minute));
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
// new 2
|
|
112
|
+
const gotoDate = (date) => (evt) => {
|
|
113
|
+
evt && evt.preventDefault();
|
|
114
|
+
const { current } = dateState;
|
|
115
|
+
// Set Hours and Minutes
|
|
116
|
+
const newTime = moment(date)
|
|
117
|
+
.hours(includeTime ? dateState.hours : 0)
|
|
118
|
+
.minutes(includeTime ? dateState.minutes : 0)
|
|
119
|
+
.toDate();
|
|
120
|
+
!(current && isSameDay(newTime, current)) && addDateToState(newTime);
|
|
121
|
+
onChange(newTime);
|
|
122
|
+
};
|
|
123
|
+
const gotoPreviousMonth = () => {
|
|
124
|
+
const { month, year } = dateState;
|
|
125
|
+
const previousMonth = getPreviousMonth(month, year);
|
|
126
|
+
setDateState({
|
|
127
|
+
month: previousMonth.month,
|
|
128
|
+
year: previousMonth.year,
|
|
129
|
+
current: dateState.current,
|
|
130
|
+
hours: dateState.hours,
|
|
131
|
+
minutes: dateState.minutes,
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const gotoNextMonth = () => {
|
|
135
|
+
const { month, year } = dateState;
|
|
136
|
+
const nextMonth = getNextMonth(month, year);
|
|
137
|
+
setDateState({
|
|
138
|
+
month: nextMonth.month,
|
|
139
|
+
year: nextMonth.year,
|
|
140
|
+
current: dateState.current,
|
|
141
|
+
hours: dateState.hours,
|
|
142
|
+
minutes: dateState.minutes,
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const gotoPreviousYear = () => {
|
|
146
|
+
const { year } = dateState;
|
|
147
|
+
setDateState({
|
|
148
|
+
month: dateState.month,
|
|
149
|
+
year: year - 1,
|
|
150
|
+
current: dateState.current,
|
|
151
|
+
hours: dateState.hours,
|
|
152
|
+
minutes: dateState.minutes,
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const gotoNextYear = () => {
|
|
156
|
+
const { year } = dateState;
|
|
157
|
+
setDateState({
|
|
158
|
+
month: dateState.month,
|
|
159
|
+
year: year + 1,
|
|
160
|
+
current: dateState.current,
|
|
161
|
+
hours: dateState.hours,
|
|
162
|
+
minutes: dateState.minutes,
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
const clearPressureTimer = () => {
|
|
166
|
+
pressureTimer && clearInterval(pressureTimer);
|
|
167
|
+
pressureTimeout && clearTimeout(pressureTimeout);
|
|
168
|
+
};
|
|
169
|
+
const handlePrevious = (evt) => {
|
|
170
|
+
evt && evt.preventDefault();
|
|
171
|
+
const fn = evt.shiftKey ? gotoPreviousYear : gotoPreviousMonth;
|
|
172
|
+
fn();
|
|
173
|
+
};
|
|
174
|
+
const handleNext = (evt) => {
|
|
175
|
+
evt && evt.preventDefault();
|
|
176
|
+
const fn = evt.shiftKey ? gotoNextYear : gotoNextMonth;
|
|
177
|
+
fn();
|
|
178
|
+
};
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
if (value) {
|
|
181
|
+
addDateToState(value);
|
|
182
|
+
}
|
|
183
|
+
}, [value]);
|
|
184
|
+
// lifecycle methods
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
const now = new Date().valueOf();
|
|
187
|
+
const tomorrow = new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000;
|
|
188
|
+
const ms = tomorrow - now;
|
|
189
|
+
dayTimeout = setTimeout(() => {
|
|
190
|
+
setToday(new Date());
|
|
191
|
+
clearDayTimeout();
|
|
192
|
+
}, ms);
|
|
193
|
+
return () => {
|
|
194
|
+
clearPressureTimer();
|
|
195
|
+
clearDayTimeout();
|
|
196
|
+
};
|
|
197
|
+
}, []);
|
|
198
|
+
const clearDayTimeout = () => {
|
|
199
|
+
dayTimeout && clearTimeout(dayTimeout);
|
|
200
|
+
};
|
|
201
|
+
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() })] })] }))] }));
|
|
202
|
+
};
|
|
203
|
+
Calendar.displayName = "Calendar";
|
|
204
|
+
export default Calendar;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
export const MainContainer = styled.div `
|
|
3
|
+
display: flex;
|
|
4
|
+
`;
|
|
5
|
+
export const CalendarContainer = styled.div `
|
|
6
|
+
font-size: 5px;
|
|
7
|
+
width: 250px;
|
|
8
|
+
border-radius: 4px;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
`;
|
|
11
|
+
export const CalendarHeader = styled.div `
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
`;
|
|
16
|
+
export const CalendarGrid = styled.div `
|
|
17
|
+
display: grid;
|
|
18
|
+
grid-template: repeat(7, auto) / repeat(7, auto);
|
|
19
|
+
`;
|
|
20
|
+
export const CalendarMonth = styled.div `
|
|
21
|
+
font-weight: 500;
|
|
22
|
+
font-size: 12px;
|
|
23
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
24
|
+
text-align: center;
|
|
25
|
+
padding: 0.5em 0.25em;
|
|
26
|
+
word-spacing: 5px;
|
|
27
|
+
user-select: none;
|
|
28
|
+
`;
|
|
29
|
+
export const CalendarCell = styled.div `
|
|
30
|
+
text-align: center;
|
|
31
|
+
align-self: center;
|
|
32
|
+
letter-spacing: 0.1rem;
|
|
33
|
+
padding: 7px;
|
|
34
|
+
user-select: none;
|
|
35
|
+
border-radius: 5px;
|
|
36
|
+
border: 1px solid transparent;
|
|
37
|
+
grid-column: ${({ index = 0 }) => (index % 7) + 1} / span 1;
|
|
38
|
+
`;
|
|
39
|
+
export const CalendarDay = styled(CalendarCell) `
|
|
40
|
+
font-weight: bold;
|
|
41
|
+
font-size: 10px;
|
|
42
|
+
border-radius: 0px;
|
|
43
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
44
|
+
`;
|
|
45
|
+
export const CalendarDate = styled(CalendarCell) `
|
|
46
|
+
font-weight: ${(props) => (props.inMonth ? 500 : 300)};
|
|
47
|
+
font-size: 10px;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
|
|
50
|
+
color: ${({ inMonth, theme }) => inMonth ? theme.palette.text.primary : theme.palette.text.secondary};
|
|
51
|
+
grid-row: ${({ index }) => Math.floor((index || 0) / 7) + 2} / span 1;
|
|
52
|
+
transition: all 0.2s ease-out;
|
|
53
|
+
border-radius: 5px;
|
|
54
|
+
:hover {
|
|
55
|
+
background: ${({ theme }) => theme.palette.action.hover};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&[data-disabled="true"] {
|
|
59
|
+
pointer-events: none;
|
|
60
|
+
color: ${({ theme }) => theme.palette.text.disabled};
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
export const HighlightedCalendarDate = styled(CalendarDate) `
|
|
64
|
+
color: white !important;
|
|
65
|
+
background: ${(props) => props.theme.palette.primary.main} !important;
|
|
66
|
+
border: 1px solid ${(props) => props.theme.palette.primary.main} !important;
|
|
67
|
+
position: relative;
|
|
68
|
+
::before {
|
|
69
|
+
content: "";
|
|
70
|
+
position: absolute;
|
|
71
|
+
top: -1px;
|
|
72
|
+
left: -1px;
|
|
73
|
+
width: calc(100% + 2px);
|
|
74
|
+
height: calc(100% + 2px);
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
export const TodayCalendarDate = styled(HighlightedCalendarDate) `
|
|
78
|
+
color: ${(props) => props.theme.palette.text.primary} !important;
|
|
79
|
+
background: transparent !important;
|
|
80
|
+
::after {
|
|
81
|
+
content: "";
|
|
82
|
+
position: absolute;
|
|
83
|
+
right: 0;
|
|
84
|
+
bottom: 0;
|
|
85
|
+
border-bottom: 0.75em solid #06c;
|
|
86
|
+
border-left: 0.75em solid transparent;
|
|
87
|
+
border-top: 0.75em solid transparent;
|
|
88
|
+
}
|
|
89
|
+
:hover {
|
|
90
|
+
color: ${(props) => props.theme.palette.text.primary} !important;
|
|
91
|
+
background: ${(props) => props.theme.palette.action.hover} !important;
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
export const TimeContainer = styled.div `
|
|
95
|
+
font-size: 12px;
|
|
96
|
+
width: 150px;
|
|
97
|
+
height: 100%;
|
|
98
|
+
border: 1px solid ${(props) => props.theme.palette.divider};
|
|
99
|
+
border-left: none;
|
|
100
|
+
border-radius: 4px;
|
|
101
|
+
overflow: hidden;
|
|
102
|
+
`;
|
|
103
|
+
export const TimePickerContainer = styled.div `
|
|
104
|
+
display: flex;
|
|
105
|
+
height: 100%;
|
|
106
|
+
`;
|
|
107
|
+
export const TimeHeader = styled.div `
|
|
108
|
+
font-weight: 500;
|
|
109
|
+
font-size: 12px;
|
|
110
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
111
|
+
border-bottom: 1px solid ${(props) => props.theme.palette.divider};
|
|
112
|
+
text-align: center;
|
|
113
|
+
padding: 5px;
|
|
114
|
+
line-height: 2.3;
|
|
115
|
+
height: 40px;
|
|
116
|
+
user-select: none;
|
|
117
|
+
`;
|
|
118
|
+
export const TimeHourSelect = styled.div `
|
|
119
|
+
border-right: 1px solid ${(props) => props.theme.palette.divider};
|
|
120
|
+
width: 50%;
|
|
121
|
+
height: 250px;
|
|
122
|
+
overflow-y: auto;
|
|
123
|
+
`;
|
|
124
|
+
export const TimeMinuteSelect = styled.div `
|
|
125
|
+
width: 50%;
|
|
126
|
+
height: 250px;
|
|
127
|
+
overflow-y: auto;
|
|
128
|
+
`;
|
|
129
|
+
export const TimeItem = styled.div `
|
|
130
|
+
font-weight: 500;
|
|
131
|
+
font-size: 10px;
|
|
132
|
+
color: ${(props) => props.theme.palette.text.primary};
|
|
133
|
+
text-align: center;
|
|
134
|
+
padding: 5px;
|
|
135
|
+
user-select: none;
|
|
136
|
+
cursor: pointer;
|
|
137
|
+
transition: all 0.2s ease-out;
|
|
138
|
+
:hover {
|
|
139
|
+
background: ${(props) => props.theme.palette.action.hover};
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
export const TimeItemActive = styled(TimeItem) `
|
|
143
|
+
background: ${(props) => props.theme.palette.primary.main};
|
|
144
|
+
color: white;
|
|
145
|
+
&:hover {
|
|
146
|
+
background: ${(props) => props.theme.palette.primary.main};
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
export const NoValueButton = styled.button `
|
|
150
|
+
font-weight: normal;
|
|
151
|
+
font-size: 12px;
|
|
152
|
+
color: ${(props) => props.theme.palette.text.secondary};
|
|
153
|
+
text-align: center;
|
|
154
|
+
padding: 5px;
|
|
155
|
+
user-select: none;
|
|
156
|
+
cursor: pointer;
|
|
157
|
+
transition: all 0.2s ease-out;
|
|
158
|
+
border: none;
|
|
159
|
+
border-radius: 5px;
|
|
160
|
+
background: transparent;
|
|
161
|
+
:hover {
|
|
162
|
+
background: ${(props) => props.theme.palette.action.hover};
|
|
163
|
+
}
|
|
164
|
+
`;
|