@monolith-forensics/monolith-ui 1.1.30 → 1.1.32
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 +11 -16
- package/dist/Button/index.js +1 -8
- package/dist/Calendar/Calendar.js +38 -66
- package/dist/Calendar/CalendarStyles.js +19 -25
- package/dist/Calendar/calendarHelpers.js +34 -46
- package/dist/Calendar/index.js +1 -8
- package/dist/CheckBox/CheckBox.js +9 -14
- package/dist/CheckBox/index.js +1 -8
- package/dist/DateInput/DateInput.js +46 -51
- package/dist/DateInput/index.js +1 -8
- package/dist/DropDownMenu/DropDownMenu.js +27 -32
- package/dist/DropDownMenu/index.js +1 -8
- package/dist/Error/Error.js +10 -15
- package/dist/Error/index.js +1 -8
- package/dist/FieldLabel/FieldLabel.js +8 -37
- package/dist/FieldLabel/index.js +1 -8
- package/dist/FileInputField/FileInputField.js +11 -16
- package/dist/FileInputField/index.js +1 -8
- package/dist/Flyout/Flyout.js +14 -18
- package/dist/Flyout/FlyoutHeader.js +3 -8
- package/dist/Flyout/FlyoutTitle.js +3 -8
- package/dist/Flyout/index.js +3 -12
- package/dist/FormSection/FormSection.js +8 -13
- package/dist/FormSection/index.js +1 -8
- package/dist/Grid/Grid.js +5 -10
- package/dist/Grid/index.js +1 -8
- package/dist/IconButton/IconButton.js +4 -9
- package/dist/IconButton/index.js +1 -8
- package/dist/Input/Input.js +6 -11
- package/dist/Input/index.js +1 -8
- package/dist/Modal/Modal.js +16 -20
- package/dist/Modal/index.js +1 -8
- package/dist/MonolithUIProvider/GlobalStyle.js +3 -5
- package/dist/MonolithUIProvider/MonolithUIProvider.js +14 -19
- package/dist/MonolithUIProvider/index.js +3 -12
- package/dist/MonolithUIProvider/useMonolithUITheme.js +4 -6
- package/dist/Pill/Pill.js +9 -14
- package/dist/Pill/index.js +1 -8
- package/dist/SelectBox/SelectBox.js +44 -50
- package/dist/SelectBox/index.js +1 -8
- package/dist/Switch/Switch.js +12 -39
- package/dist/Switch/index.js +1 -8
- package/dist/Table/Table.js +70 -78
- package/dist/Table/index.js +2 -10
- package/dist/TagBox/TagBox.js +40 -45
- package/dist/TagBox/TagBoxStyles.js +11 -17
- package/dist/TagBox/index.js +1 -8
- package/dist/TextArea/TextArea.js +4 -9
- package/dist/TextArea/index.js +1 -8
- package/dist/TextAreaInput/TextAreaInput.js +5 -7
- package/dist/TextAreaInput/index.js +1 -8
- package/dist/TextInput/TextInput.js +7 -12
- package/dist/TextInput/index.js +1 -8
- package/dist/Tooltip/Tooltip.js +6 -34
- package/dist/Tooltip/index.js +1 -8
- package/dist/core/ArrowButton.js +8 -13
- package/dist/core/ClearButton.js +8 -13
- package/dist/core/StyledContent.js +3 -8
- package/dist/core/StyledFloatContainer.js +3 -8
- package/dist/core/Types/Size.js +1 -2
- package/dist/core/Types/Variant.js +1 -2
- package/dist/core/index.js +4 -14
- package/dist/index.js +26 -59
- package/dist/theme/index.js +5 -9
- package/dist/theme/typography.js +1 -3
- package/dist/theme/variants.js +8 -14
- package/package.json +1 -1
- package/dist/Button/Button.d.ts +0 -19
- package/dist/Button/index.d.ts +0 -2
- package/dist/Calendar/Calendar.d.ts +0 -15
- package/dist/Calendar/CalendarStyles.d.ts +0 -36
- package/dist/Calendar/calendarHelpers.d.ts +0 -53
- package/dist/Calendar/index.d.ts +0 -1
- package/dist/CheckBox/CheckBox.d.ts +0 -13
- package/dist/CheckBox/index.d.ts +0 -1
- package/dist/DateInput/DateInput.d.ts +0 -24
- package/dist/DateInput/index.d.ts +0 -1
- package/dist/DropDownMenu/DropDownMenu.d.ts +0 -36
- package/dist/DropDownMenu/index.d.ts +0 -1
- package/dist/Error/Error.d.ts +0 -4
- package/dist/Error/index.d.ts +0 -1
- package/dist/FieldLabel/FieldLabel.d.ts +0 -19
- package/dist/FieldLabel/index.d.ts +0 -1
- package/dist/FileInputField/FileInputField.d.ts +0 -19
- package/dist/FileInputField/index.d.ts +0 -1
- package/dist/Flyout/Flyout.d.ts +0 -11
- package/dist/Flyout/FlyoutHeader.d.ts +0 -5
- package/dist/Flyout/FlyoutTitle.d.ts +0 -2
- package/dist/Flyout/index.d.ts +0 -3
- package/dist/FormSection/FormSection.d.ts +0 -9
- package/dist/FormSection/index.d.ts +0 -1
- package/dist/Grid/Grid.d.ts +0 -8
- package/dist/Grid/index.d.ts +0 -1
- package/dist/IconButton/IconButton.d.ts +0 -5
- package/dist/IconButton/index.d.ts +0 -1
- package/dist/Input/Input.d.ts +0 -21
- package/dist/Input/index.d.ts +0 -1
- package/dist/Modal/Modal.d.ts +0 -14
- package/dist/Modal/index.d.ts +0 -1
- package/dist/MonolithUIProvider/GlobalStyle.d.ts +0 -4
- package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +0 -10
- package/dist/MonolithUIProvider/index.d.ts +0 -3
- package/dist/MonolithUIProvider/useMonolithUITheme.d.ts +0 -2
- package/dist/Pill/Pill.d.ts +0 -11
- package/dist/Pill/index.d.ts +0 -1
- package/dist/SelectBox/SelectBox.d.ts +0 -45
- package/dist/SelectBox/index.d.ts +0 -1
- package/dist/Switch/Switch.d.ts +0 -18
- package/dist/Switch/index.d.ts +0 -1
- package/dist/Table/Table.d.ts +0 -91
- package/dist/Table/index.d.ts +0 -2
- package/dist/TagBox/TagBox.d.ts +0 -39
- package/dist/TagBox/TagBoxStyles.d.ts +0 -11
- package/dist/TagBox/index.d.ts +0 -1
- package/dist/TextArea/TextArea.d.ts +0 -16
- package/dist/TextArea/index.d.ts +0 -1
- package/dist/TextAreaInput/TextAreaInput.d.ts +0 -19
- package/dist/TextAreaInput/index.d.ts +0 -1
- package/dist/TextInput/TextInput.d.ts +0 -13
- package/dist/TextInput/index.d.ts +0 -1
- package/dist/Tooltip/Tooltip.d.ts +0 -12
- package/dist/Tooltip/index.d.ts +0 -1
- package/dist/core/ArrowButton.d.ts +0 -6
- package/dist/core/ClearButton.d.ts +0 -6
- package/dist/core/MonolithThemeProvider.d.ts +0 -4
- package/dist/core/MonolithThemeProvider.js +0 -20
- package/dist/core/StyledContent.d.ts +0 -7
- package/dist/core/StyledFloatContainer.d.ts +0 -2
- package/dist/core/Types/Size.d.ts +0 -2
- package/dist/core/Types/Variant.d.ts +0 -2
- package/dist/core/index.d.ts +0 -6
- package/dist/index.d.ts +0 -26
- package/dist/theme/index.d.ts +0 -168
- package/dist/theme/typography.d.ts +0 -45
- package/dist/theme/variants.d.ts +0 -172
package/dist/Button/Button.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
2
|
var t = {};
|
|
4
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -10,14 +9,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
9
|
}
|
|
11
10
|
return t;
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
|
-
const react_1 = require("react");
|
|
19
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
20
|
-
const lucide_react_1 = require("lucide-react");
|
|
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";
|
|
21
16
|
const colors = {
|
|
22
17
|
gray: "#888888",
|
|
23
18
|
red: "#e03131",
|
|
@@ -32,7 +27,7 @@ const colors = {
|
|
|
32
27
|
yellow: "#f08c00",
|
|
33
28
|
orange: "#e8590c",
|
|
34
29
|
};
|
|
35
|
-
const StyledButton =
|
|
30
|
+
const StyledButton = styled.button `
|
|
36
31
|
user-select: none;
|
|
37
32
|
display: flex;
|
|
38
33
|
outline: none;
|
|
@@ -299,7 +294,7 @@ const StyledButton = styled_components_1.default.button `
|
|
|
299
294
|
pointer-events: none;
|
|
300
295
|
`}
|
|
301
296
|
`;
|
|
302
|
-
const StyledAnchor =
|
|
297
|
+
const StyledAnchor = styled.a `
|
|
303
298
|
text-decoration: none;
|
|
304
299
|
height: 100%;
|
|
305
300
|
|
|
@@ -307,7 +302,7 @@ const StyledAnchor = styled_components_1.default.a `
|
|
|
307
302
|
text-decoration: none !important;
|
|
308
303
|
}
|
|
309
304
|
`;
|
|
310
|
-
const StyledLoader =
|
|
305
|
+
const StyledLoader = styled.span `
|
|
311
306
|
svg {
|
|
312
307
|
width: 16px;
|
|
313
308
|
height: 16px;
|
|
@@ -324,9 +319,9 @@ const StyledLoader = styled_components_1.default.span `
|
|
|
324
319
|
}
|
|
325
320
|
}
|
|
326
321
|
`;
|
|
327
|
-
const Button =
|
|
322
|
+
const Button = forwardRef((props, ref) => {
|
|
328
323
|
const { children, loading = false, leftSection = null, rightSection = null, href = null, download = null } = props, other = __rest(props, ["children", "loading", "leftSection", "rightSection", "href", "download"]);
|
|
329
|
-
const buttonContent = ((
|
|
330
|
-
return ((
|
|
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) })));
|
|
331
326
|
});
|
|
332
|
-
|
|
327
|
+
export default Button;
|
package/dist/Button/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var Button_1 = require("./Button");
|
|
8
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Button_1).default; } });
|
|
1
|
+
export { default } from "./Button";
|
|
@@ -1,58 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
-
const react_1 = require("react");
|
|
31
|
-
const lucide_react_1 = require("lucide-react");
|
|
32
|
-
const CalendarStyles_1 = require("./CalendarStyles");
|
|
33
|
-
const calendarHelpers_1 = __importStar(require("./calendarHelpers"));
|
|
34
|
-
const moment_1 = __importDefault(require("moment"));
|
|
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";
|
|
35
7
|
const checkValidRange = (value, min, max) => {
|
|
36
|
-
if (min && (
|
|
8
|
+
if (min && moment(value).startOf("day").isBefore(moment(min).startOf("day")))
|
|
37
9
|
return false;
|
|
38
|
-
if (max && (
|
|
10
|
+
if (max && moment(value).startOf("day").isAfter(moment(max).startOf("day")))
|
|
39
11
|
return false;
|
|
40
12
|
return true;
|
|
41
13
|
};
|
|
42
14
|
const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hourFormat = "24", includeTime = true, clearable = true, min, max, }) => {
|
|
43
|
-
const [dateState, setDateState] =
|
|
15
|
+
const [dateState, setDateState] = useState({
|
|
44
16
|
current: defaultValue,
|
|
45
17
|
month: defaultValue.getMonth() + 1,
|
|
46
18
|
year: defaultValue.getFullYear(),
|
|
47
19
|
hours: 0,
|
|
48
20
|
minutes: 0,
|
|
49
21
|
});
|
|
50
|
-
const [today, setToday] =
|
|
22
|
+
const [today, setToday] = useState(new Date());
|
|
51
23
|
let pressureTimer;
|
|
52
24
|
let pressureTimeout;
|
|
53
25
|
let dayTimeout;
|
|
54
26
|
const addDateToState = (date) => {
|
|
55
|
-
const isDateObject =
|
|
27
|
+
const isDateObject = isDate(date);
|
|
56
28
|
const _date = isDateObject ? date : new Date();
|
|
57
29
|
setDateState({
|
|
58
30
|
current: isDateObject ? date : null,
|
|
@@ -66,21 +38,21 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
66
38
|
const { current, month, year } = dateState;
|
|
67
39
|
const calendarMonth = month || +((current === null || current === void 0 ? void 0 : current.getMonth()) || 0) + 1;
|
|
68
40
|
const calendarYear = year || (current === null || current === void 0 ? void 0 : current.getFullYear());
|
|
69
|
-
return (
|
|
41
|
+
return calendar(calendarMonth, calendarYear);
|
|
70
42
|
};
|
|
71
43
|
//new start
|
|
72
44
|
const renderMonthAndYear = () => {
|
|
73
45
|
const { month, year } = dateState;
|
|
74
46
|
// Resolve the month name from the CALENDAR_MONTHS object map
|
|
75
|
-
const monthname = Object.keys(
|
|
76
|
-
return ((
|
|
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 })] }));
|
|
77
49
|
};
|
|
78
50
|
// Render the label for day of the week
|
|
79
51
|
// This method is used as a map callback as seen in render()
|
|
80
52
|
const renderDayLabel = (day, index) => {
|
|
81
53
|
// Resolve the day of the week label from the WEEK_DAYS object map
|
|
82
|
-
const daylabel =
|
|
83
|
-
return ((
|
|
54
|
+
const daylabel = WEEK_DAYS[day];
|
|
55
|
+
return (_jsx(CalendarDay, { index: index, children: daylabel }, daylabel));
|
|
84
56
|
};
|
|
85
57
|
// Render a calendar date as returned from the calendar builder function
|
|
86
58
|
// This method is used as a map callback as seen in render()
|
|
@@ -88,32 +60,32 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
88
60
|
const { current, month, year } = dateState;
|
|
89
61
|
const _date = new Date(date.join("-"));
|
|
90
62
|
// Check if calendar date is same day as today
|
|
91
|
-
const isToday =
|
|
63
|
+
const isToday = isSameDay(_date, today);
|
|
92
64
|
// Check if calendar date is same day as currently selected date
|
|
93
|
-
const isCurrent = current &&
|
|
65
|
+
const isCurrent = current && isSameDay(_date, current);
|
|
94
66
|
// Check if calendar date is in the same month as the state month and year
|
|
95
|
-
const inMonth = month && year &&
|
|
67
|
+
const inMonth = month && year && isSameMonth(_date, new Date([year, month, 1].join("-")));
|
|
96
68
|
// The click handler
|
|
97
69
|
const props = {
|
|
98
|
-
"data-disabled": !checkValidRange(
|
|
70
|
+
"data-disabled": !checkValidRange(getDateISO(_date), min || null, max || null),
|
|
99
71
|
index,
|
|
100
|
-
key:
|
|
72
|
+
key: getDateISO(_date),
|
|
101
73
|
onClick: gotoDate(_date),
|
|
102
74
|
title: _date.toDateString(),
|
|
103
75
|
inMonth,
|
|
104
76
|
};
|
|
105
77
|
// Conditionally render a styled date component
|
|
106
|
-
return isCurrent ? ((
|
|
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() })));
|
|
107
79
|
};
|
|
108
80
|
const renderHours = () => {
|
|
109
81
|
const { hours } = dateState;
|
|
110
|
-
const hoursArray = hourFormat === "24" ?
|
|
82
|
+
const hoursArray = hourFormat === "24" ? HOURS24 : HOURS12;
|
|
111
83
|
return hoursArray.map((hour, index) => {
|
|
112
|
-
const HourComponent = hour.value === hours ?
|
|
113
|
-
return ((
|
|
84
|
+
const HourComponent = hour.value === hours ? TimeItemActive : TimeItem;
|
|
85
|
+
return (_jsx(HourComponent, {
|
|
114
86
|
// value={hour.value}
|
|
115
87
|
onClick: (e) => {
|
|
116
|
-
const newTime = (
|
|
88
|
+
const newTime = moment(dateState.current)
|
|
117
89
|
.hours(hour.value)
|
|
118
90
|
.toDate();
|
|
119
91
|
setDateState(Object.assign(Object.assign({}, dateState), { hours: hour.value, current: newTime }));
|
|
@@ -123,12 +95,12 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
123
95
|
};
|
|
124
96
|
const renderMinutes = () => {
|
|
125
97
|
const { minutes } = dateState;
|
|
126
|
-
return
|
|
127
|
-
const MinuteComponent = minute === minutes ?
|
|
128
|
-
return ((
|
|
98
|
+
return MINUTES.map((minute) => {
|
|
99
|
+
const MinuteComponent = minute === minutes ? TimeItemActive : TimeItem;
|
|
100
|
+
return (_jsx(MinuteComponent, {
|
|
129
101
|
// value={minute}
|
|
130
102
|
onClick: (e) => {
|
|
131
|
-
const newTime = (
|
|
103
|
+
const newTime = moment(dateState.current)
|
|
132
104
|
.minutes(Number(minute))
|
|
133
105
|
.toDate();
|
|
134
106
|
setDateState(Object.assign(Object.assign({}, dateState), { minutes: Number(minute), current: newTime }));
|
|
@@ -141,16 +113,16 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
141
113
|
evt && evt.preventDefault();
|
|
142
114
|
const { current } = dateState;
|
|
143
115
|
// Set Hours and Minutes
|
|
144
|
-
const newTime = (
|
|
116
|
+
const newTime = moment(date)
|
|
145
117
|
.hours(includeTime ? dateState.hours : 0)
|
|
146
118
|
.minutes(includeTime ? dateState.minutes : 0)
|
|
147
119
|
.toDate();
|
|
148
|
-
!(current &&
|
|
120
|
+
!(current && isSameDay(newTime, current)) && addDateToState(newTime);
|
|
149
121
|
onChange(newTime);
|
|
150
122
|
};
|
|
151
123
|
const gotoPreviousMonth = () => {
|
|
152
124
|
const { month, year } = dateState;
|
|
153
|
-
const previousMonth =
|
|
125
|
+
const previousMonth = getPreviousMonth(month, year);
|
|
154
126
|
setDateState({
|
|
155
127
|
month: previousMonth.month,
|
|
156
128
|
year: previousMonth.year,
|
|
@@ -161,7 +133,7 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
161
133
|
};
|
|
162
134
|
const gotoNextMonth = () => {
|
|
163
135
|
const { month, year } = dateState;
|
|
164
|
-
const nextMonth =
|
|
136
|
+
const nextMonth = getNextMonth(month, year);
|
|
165
137
|
setDateState({
|
|
166
138
|
month: nextMonth.month,
|
|
167
139
|
year: nextMonth.year,
|
|
@@ -204,13 +176,13 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
204
176
|
const fn = evt.shiftKey ? gotoNextYear : gotoNextMonth;
|
|
205
177
|
fn();
|
|
206
178
|
};
|
|
207
|
-
|
|
179
|
+
useEffect(() => {
|
|
208
180
|
if (value) {
|
|
209
181
|
addDateToState(value);
|
|
210
182
|
}
|
|
211
183
|
}, [value]);
|
|
212
184
|
// lifecycle methods
|
|
213
|
-
|
|
185
|
+
useEffect(() => {
|
|
214
186
|
const now = new Date().valueOf();
|
|
215
187
|
const tomorrow = new Date().setHours(0, 0, 0, 0) + 24 * 60 * 60 * 1000;
|
|
216
188
|
const ms = tomorrow - now;
|
|
@@ -226,7 +198,7 @@ const Calendar = ({ defaultValue = new Date(), value, onChange = () => { }, hour
|
|
|
226
198
|
const clearDayTimeout = () => {
|
|
227
199
|
dayTimeout && clearTimeout(dayTimeout);
|
|
228
200
|
};
|
|
229
|
-
return ((
|
|
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() })] })] }))] }));
|
|
230
202
|
};
|
|
231
203
|
Calendar.displayName = "Calendar";
|
|
232
|
-
|
|
204
|
+
export default Calendar;
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NoValueButton = exports.TimeItemActive = exports.TimeItem = exports.TimeMinuteSelect = exports.TimeHourSelect = exports.TimeHeader = exports.TimePickerContainer = exports.TimeContainer = exports.TodayCalendarDate = exports.HighlightedCalendarDate = exports.CalendarDate = exports.CalendarDay = exports.CalendarCell = exports.CalendarMonth = exports.CalendarGrid = exports.CalendarHeader = exports.CalendarContainer = exports.MainContainer = void 0;
|
|
7
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
-
exports.MainContainer = styled_components_1.default.div `
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
export const MainContainer = styled.div `
|
|
9
3
|
display: flex;
|
|
10
4
|
`;
|
|
11
|
-
|
|
5
|
+
export const CalendarContainer = styled.div `
|
|
12
6
|
font-size: 5px;
|
|
13
7
|
width: 250px;
|
|
14
8
|
border-radius: 4px;
|
|
15
9
|
overflow: hidden;
|
|
16
10
|
`;
|
|
17
|
-
|
|
11
|
+
export const CalendarHeader = styled.div `
|
|
18
12
|
display: flex;
|
|
19
13
|
align-items: center;
|
|
20
14
|
justify-content: space-between;
|
|
21
15
|
`;
|
|
22
|
-
|
|
16
|
+
export const CalendarGrid = styled.div `
|
|
23
17
|
display: grid;
|
|
24
18
|
grid-template: repeat(7, auto) / repeat(7, auto);
|
|
25
19
|
`;
|
|
26
|
-
|
|
20
|
+
export const CalendarMonth = styled.div `
|
|
27
21
|
font-weight: 500;
|
|
28
22
|
font-size: 12px;
|
|
29
23
|
color: ${(props) => props.theme.palette.text.primary};
|
|
@@ -32,7 +26,7 @@ exports.CalendarMonth = styled_components_1.default.div `
|
|
|
32
26
|
word-spacing: 5px;
|
|
33
27
|
user-select: none;
|
|
34
28
|
`;
|
|
35
|
-
|
|
29
|
+
export const CalendarCell = styled.div `
|
|
36
30
|
text-align: center;
|
|
37
31
|
align-self: center;
|
|
38
32
|
letter-spacing: 0.1rem;
|
|
@@ -42,13 +36,13 @@ exports.CalendarCell = styled_components_1.default.div `
|
|
|
42
36
|
border: 1px solid transparent;
|
|
43
37
|
grid-column: ${({ index = 0 }) => (index % 7) + 1} / span 1;
|
|
44
38
|
`;
|
|
45
|
-
|
|
39
|
+
export const CalendarDay = styled(CalendarCell) `
|
|
46
40
|
font-weight: bold;
|
|
47
41
|
font-size: 10px;
|
|
48
42
|
border-radius: 0px;
|
|
49
43
|
color: ${(props) => props.theme.palette.text.secondary};
|
|
50
44
|
`;
|
|
51
|
-
|
|
45
|
+
export const CalendarDate = styled(CalendarCell) `
|
|
52
46
|
font-weight: ${(props) => (props.inMonth ? 500 : 300)};
|
|
53
47
|
font-size: 10px;
|
|
54
48
|
cursor: pointer;
|
|
@@ -66,7 +60,7 @@ exports.CalendarDate = (0, styled_components_1.default)(exports.CalendarCell) `
|
|
|
66
60
|
color: ${({ theme }) => theme.palette.text.disabled};
|
|
67
61
|
}
|
|
68
62
|
`;
|
|
69
|
-
|
|
63
|
+
export const HighlightedCalendarDate = styled(CalendarDate) `
|
|
70
64
|
color: white !important;
|
|
71
65
|
background: ${(props) => props.theme.palette.primary.main} !important;
|
|
72
66
|
border: 1px solid ${(props) => props.theme.palette.primary.main} !important;
|
|
@@ -80,7 +74,7 @@ exports.HighlightedCalendarDate = (0, styled_components_1.default)(exports.Calen
|
|
|
80
74
|
height: calc(100% + 2px);
|
|
81
75
|
}
|
|
82
76
|
`;
|
|
83
|
-
|
|
77
|
+
export const TodayCalendarDate = styled(HighlightedCalendarDate) `
|
|
84
78
|
color: ${(props) => props.theme.palette.text.primary} !important;
|
|
85
79
|
background: transparent !important;
|
|
86
80
|
::after {
|
|
@@ -97,7 +91,7 @@ exports.TodayCalendarDate = (0, styled_components_1.default)(exports.Highlighted
|
|
|
97
91
|
background: ${(props) => props.theme.palette.action.hover} !important;
|
|
98
92
|
}
|
|
99
93
|
`;
|
|
100
|
-
|
|
94
|
+
export const TimeContainer = styled.div `
|
|
101
95
|
font-size: 12px;
|
|
102
96
|
width: 150px;
|
|
103
97
|
height: 100%;
|
|
@@ -106,11 +100,11 @@ exports.TimeContainer = styled_components_1.default.div `
|
|
|
106
100
|
border-radius: 4px;
|
|
107
101
|
overflow: hidden;
|
|
108
102
|
`;
|
|
109
|
-
|
|
103
|
+
export const TimePickerContainer = styled.div `
|
|
110
104
|
display: flex;
|
|
111
105
|
height: 100%;
|
|
112
106
|
`;
|
|
113
|
-
|
|
107
|
+
export const TimeHeader = styled.div `
|
|
114
108
|
font-weight: 500;
|
|
115
109
|
font-size: 12px;
|
|
116
110
|
color: ${(props) => props.theme.palette.text.primary};
|
|
@@ -121,18 +115,18 @@ exports.TimeHeader = styled_components_1.default.div `
|
|
|
121
115
|
height: 40px;
|
|
122
116
|
user-select: none;
|
|
123
117
|
`;
|
|
124
|
-
|
|
118
|
+
export const TimeHourSelect = styled.div `
|
|
125
119
|
border-right: 1px solid ${(props) => props.theme.palette.divider};
|
|
126
120
|
width: 50%;
|
|
127
121
|
height: 250px;
|
|
128
122
|
overflow-y: auto;
|
|
129
123
|
`;
|
|
130
|
-
|
|
124
|
+
export const TimeMinuteSelect = styled.div `
|
|
131
125
|
width: 50%;
|
|
132
126
|
height: 250px;
|
|
133
127
|
overflow-y: auto;
|
|
134
128
|
`;
|
|
135
|
-
|
|
129
|
+
export const TimeItem = styled.div `
|
|
136
130
|
font-weight: 500;
|
|
137
131
|
font-size: 10px;
|
|
138
132
|
color: ${(props) => props.theme.palette.text.primary};
|
|
@@ -145,14 +139,14 @@ exports.TimeItem = styled_components_1.default.div `
|
|
|
145
139
|
background: ${(props) => props.theme.palette.action.hover};
|
|
146
140
|
}
|
|
147
141
|
`;
|
|
148
|
-
|
|
142
|
+
export const TimeItemActive = styled(TimeItem) `
|
|
149
143
|
background: ${(props) => props.theme.palette.primary.main};
|
|
150
144
|
color: white;
|
|
151
145
|
&:hover {
|
|
152
146
|
background: ${(props) => props.theme.palette.primary.main};
|
|
153
147
|
}
|
|
154
148
|
`;
|
|
155
|
-
|
|
149
|
+
export const NoValueButton = styled.button `
|
|
156
150
|
font-weight: normal;
|
|
157
151
|
font-size: 12px;
|
|
158
152
|
color: ${(props) => props.theme.palette.text.secondary};
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNextMonth = exports.getPreviousMonth = exports.getDateISO = exports.isSameDay = exports.isSameMonth = exports.isDate = exports.getMonthFirstDay = exports.getMonthDays = exports.zeroPad = exports.CALENDAR_WEEKS = exports.CALENDAR_MONTHS = exports.WEEK_DAYS = exports.MINUTES = exports.HOURS12 = exports.HOURS24 = exports.THIS_MONTH = exports.THIS_YEAR = void 0;
|
|
4
1
|
// (int) The current year
|
|
5
|
-
|
|
2
|
+
export const THIS_YEAR = +new Date().getFullYear();
|
|
6
3
|
// (int) The current month starting from 1 - 12
|
|
7
4
|
// 1 => January, 12 => December
|
|
8
|
-
|
|
5
|
+
export const THIS_MONTH = +new Date().getMonth() + 1;
|
|
9
6
|
// Week days names and shortnames
|
|
10
|
-
|
|
7
|
+
export const HOURS24 = [...new Array(24)].map((n, index) => {
|
|
11
8
|
return {
|
|
12
9
|
value: index,
|
|
13
10
|
label: index < 10 ? `0${index}` : `${index}`,
|
|
14
11
|
};
|
|
15
12
|
});
|
|
16
|
-
|
|
13
|
+
export const HOURS12 = [
|
|
17
14
|
...[...new Array(12)].map((n, index) => {
|
|
18
15
|
return {
|
|
19
16
|
value: index,
|
|
@@ -27,10 +24,10 @@ exports.HOURS12 = [
|
|
|
27
24
|
};
|
|
28
25
|
}),
|
|
29
26
|
];
|
|
30
|
-
|
|
27
|
+
export const MINUTES = new Array(60).fill(0).map((n, index) => {
|
|
31
28
|
return index < 10 ? `0${index}` : index;
|
|
32
29
|
});
|
|
33
|
-
|
|
30
|
+
export const WEEK_DAYS = {
|
|
34
31
|
Sunday: "Su",
|
|
35
32
|
Monday: "Mo",
|
|
36
33
|
Tuesday: "Tu",
|
|
@@ -40,7 +37,7 @@ exports.WEEK_DAYS = {
|
|
|
40
37
|
Saturday: "Sa",
|
|
41
38
|
};
|
|
42
39
|
// Calendar months names and short names
|
|
43
|
-
|
|
40
|
+
export const CALENDAR_MONTHS = {
|
|
44
41
|
January: "Jan",
|
|
45
42
|
February: "Feb",
|
|
46
43
|
March: "Mar",
|
|
@@ -55,15 +52,14 @@ exports.CALENDAR_MONTHS = {
|
|
|
55
52
|
December: "Dec",
|
|
56
53
|
};
|
|
57
54
|
// Weeks displayed on calendar
|
|
58
|
-
|
|
55
|
+
export const CALENDAR_WEEKS = 6;
|
|
59
56
|
// Pads a string value with leading zeroes(0) until length is reached
|
|
60
57
|
// For example: zeroPad(5, 2) => "05"
|
|
61
|
-
const zeroPad = (value, length) => {
|
|
58
|
+
export const zeroPad = (value, length) => {
|
|
62
59
|
return `${value}`.padStart(length, "0");
|
|
63
60
|
};
|
|
64
|
-
exports.zeroPad = zeroPad;
|
|
65
61
|
// (int) Number days in a month for a given year from 28 - 31
|
|
66
|
-
const getMonthDays = (month =
|
|
62
|
+
export const getMonthDays = (month = THIS_MONTH, year = THIS_YEAR) => {
|
|
67
63
|
const months30 = [4, 6, 9, 11];
|
|
68
64
|
const leapYear = year % 4 === 0;
|
|
69
65
|
return month === 2
|
|
@@ -74,23 +70,20 @@ const getMonthDays = (month = exports.THIS_MONTH, year = exports.THIS_YEAR) => {
|
|
|
74
70
|
? 30
|
|
75
71
|
: 31;
|
|
76
72
|
};
|
|
77
|
-
exports.getMonthDays = getMonthDays;
|
|
78
73
|
// (int) First day of the month for a given year from 1 - 7
|
|
79
74
|
// 1 => Sunday, 7 => Saturday
|
|
80
|
-
const getMonthFirstDay = (month =
|
|
81
|
-
return +new Date(`${year}-${
|
|
75
|
+
export const getMonthFirstDay = (month = THIS_MONTH, year = THIS_YEAR) => {
|
|
76
|
+
return +new Date(`${year}-${zeroPad(month, 2)}-01`).getDay() + 1;
|
|
82
77
|
};
|
|
83
|
-
exports.getMonthFirstDay = getMonthFirstDay;
|
|
84
78
|
// (bool) Checks if a value is a date - this is just a simple check
|
|
85
|
-
const isDate = (date) => {
|
|
79
|
+
export const isDate = (date) => {
|
|
86
80
|
const isDate = Object.prototype.toString.call(date) === "[object Date]";
|
|
87
81
|
const isValidDate = date && !Number.isNaN(date.valueOf());
|
|
88
82
|
return isDate && isValidDate;
|
|
89
83
|
};
|
|
90
|
-
exports.isDate = isDate;
|
|
91
84
|
// (bool) Checks if two date values are of the same month and year
|
|
92
|
-
const isSameMonth = (date, basedate = new Date()) => {
|
|
93
|
-
if (!(
|
|
85
|
+
export const isSameMonth = (date, basedate = new Date()) => {
|
|
86
|
+
if (!(isDate(date) && isDate(basedate)))
|
|
94
87
|
return false;
|
|
95
88
|
const basedateMonth = +basedate.getMonth() + 1;
|
|
96
89
|
const basedateYear = basedate.getFullYear();
|
|
@@ -98,10 +91,9 @@ const isSameMonth = (date, basedate = new Date()) => {
|
|
|
98
91
|
const dateYear = date.getFullYear();
|
|
99
92
|
return +basedateMonth === +dateMonth && +basedateYear === +dateYear;
|
|
100
93
|
};
|
|
101
|
-
exports.isSameMonth = isSameMonth;
|
|
102
94
|
// (bool) Checks if two date values are the same day
|
|
103
|
-
const isSameDay = (date, basedate = new Date()) => {
|
|
104
|
-
if (!(
|
|
95
|
+
export const isSameDay = (date, basedate = new Date()) => {
|
|
96
|
+
if (!(isDate(date) && isDate(basedate)))
|
|
105
97
|
return false;
|
|
106
98
|
const basedateDate = basedate.getDate();
|
|
107
99
|
const basedateMonth = +basedate.getMonth() + 1;
|
|
@@ -113,69 +105,65 @@ const isSameDay = (date, basedate = new Date()) => {
|
|
|
113
105
|
+basedateMonth === +dateMonth &&
|
|
114
106
|
+basedateYear === +dateYear);
|
|
115
107
|
};
|
|
116
|
-
exports.isSameDay = isSameDay;
|
|
117
108
|
// (string) Formats the given date as YYYY-MM-DD
|
|
118
109
|
// Months and Days are zero padded
|
|
119
|
-
const getDateISO = (date) => {
|
|
120
|
-
if (!
|
|
110
|
+
export const getDateISO = (date) => {
|
|
111
|
+
if (!isDate(date))
|
|
121
112
|
return null;
|
|
122
113
|
return [
|
|
123
114
|
date.getFullYear(),
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
zeroPad(+date.getMonth() + 1, 2),
|
|
116
|
+
zeroPad(+date.getDate(), 2),
|
|
126
117
|
].join("-");
|
|
127
118
|
};
|
|
128
|
-
exports.getDateISO = getDateISO;
|
|
129
119
|
// ({month, year}) Gets the month and year before the given month and year
|
|
130
120
|
// For example: getPreviousMonth(1, 2000) => {month: 12, year: 1999}
|
|
131
121
|
// while: getPreviousMonth(12, 2000) => {month: 11, year: 2000}
|
|
132
|
-
const getPreviousMonth = (month, year) => {
|
|
122
|
+
export const getPreviousMonth = (month, year) => {
|
|
133
123
|
const prevMonth = month > 1 ? month - 1 : 12;
|
|
134
124
|
const prevMonthYear = month > 1 ? year : year - 1;
|
|
135
125
|
return { month: prevMonth, year: prevMonthYear };
|
|
136
126
|
};
|
|
137
|
-
exports.getPreviousMonth = getPreviousMonth;
|
|
138
127
|
// ({month, year}) Gets the month and year after the given month and year
|
|
139
128
|
// For example: getNextMonth(1, 2000) => {month: 2, year: 2000}
|
|
140
129
|
// while: getNextMonth(12, 2000) => {month: 1, year: 2001}
|
|
141
|
-
const getNextMonth = (month, year) => {
|
|
130
|
+
export const getNextMonth = (month, year) => {
|
|
142
131
|
const nextMonth = month < 12 ? month + 1 : 1;
|
|
143
132
|
const nextMonthYear = month < 12 ? year : year + 1;
|
|
144
133
|
return { month: nextMonth, year: nextMonthYear };
|
|
145
134
|
};
|
|
146
|
-
exports.getNextMonth = getNextMonth;
|
|
147
135
|
// Calendar builder for a month in the specified year
|
|
148
136
|
// Returns an array of the calendar dates.
|
|
149
137
|
// Each calendar date is represented as an array => [YYYY, MM, DD]
|
|
150
|
-
const calendarBuilder = (month =
|
|
138
|
+
const calendarBuilder = (month = THIS_MONTH, year = THIS_YEAR) => {
|
|
151
139
|
// Get number of days in the month and the month's first day
|
|
152
|
-
const monthDays =
|
|
153
|
-
const monthFirstDay =
|
|
140
|
+
const monthDays = getMonthDays(month, year);
|
|
141
|
+
const monthFirstDay = getMonthFirstDay(month, year);
|
|
154
142
|
// Get number of days to be displayed from previous and next months
|
|
155
143
|
// These ensure a total of 42 days (6 weeks) displayed on the calendar
|
|
156
144
|
const daysFromPrevMonth = monthFirstDay - 1;
|
|
157
|
-
const daysFromNextMonth =
|
|
145
|
+
const daysFromNextMonth = CALENDAR_WEEKS * 7 - (daysFromPrevMonth + monthDays);
|
|
158
146
|
// Get the previous and next months and years
|
|
159
|
-
const { month: prevMonth, year: prevMonthYear } =
|
|
160
|
-
const { month: nextMonth, year: nextMonthYear } =
|
|
147
|
+
const { month: prevMonth, year: prevMonthYear } = getPreviousMonth(month, year);
|
|
148
|
+
const { month: nextMonth, year: nextMonthYear } = getNextMonth(month, year);
|
|
161
149
|
// Get number of days in previous month
|
|
162
|
-
const prevMonthDays =
|
|
150
|
+
const prevMonthDays = getMonthDays(prevMonth, prevMonthYear);
|
|
163
151
|
// Builds dates to be displayed from previous month
|
|
164
152
|
const prevMonthDates = [...new Array(daysFromPrevMonth)].map((n, index) => {
|
|
165
153
|
const day = index + 1 + (prevMonthDays - daysFromPrevMonth);
|
|
166
|
-
return [prevMonthYear,
|
|
154
|
+
return [prevMonthYear, zeroPad(prevMonth, 2), zeroPad(day, 2)];
|
|
167
155
|
});
|
|
168
156
|
// Builds dates to be displayed from current month
|
|
169
157
|
const thisMonthDates = [...new Array(monthDays)].map((n, index) => {
|
|
170
158
|
const day = index + 1;
|
|
171
|
-
return [year,
|
|
159
|
+
return [year, zeroPad(month, 2), zeroPad(day, 2)];
|
|
172
160
|
});
|
|
173
161
|
// Builds dates to be displayed from next month
|
|
174
162
|
const nextMonthDates = [...new Array(daysFromNextMonth)].map((n, index) => {
|
|
175
163
|
const day = index + 1;
|
|
176
|
-
return [nextMonthYear,
|
|
164
|
+
return [nextMonthYear, zeroPad(nextMonth, 2), zeroPad(day, 2)];
|
|
177
165
|
});
|
|
178
166
|
// Combines all dates from previous, current and next months
|
|
179
167
|
return [...prevMonthDates, ...thisMonthDates, ...nextMonthDates];
|
|
180
168
|
};
|
|
181
|
-
|
|
169
|
+
export default calendarBuilder;
|
package/dist/Calendar/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var Calendar_1 = require("./Calendar");
|
|
8
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(Calendar_1).default; } });
|
|
1
|
+
export { default } from "./Calendar";
|