@acusti/date-picker 0.8.1 → 0.10.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.
- package/README.md +1 -1
- package/dist/DatePicker.d.ts +5 -14
- package/dist/DatePicker.js +66 -139
- package/dist/DatePicker.js.flow +21 -21
- package/dist/MonthCalendar.d.ts +1 -11
- package/dist/MonthCalendar.js +85 -214
- package/dist/MonthCalendar.js.flow +11 -11
- package/dist/index.js +1 -1
- package/dist/index.js.flow +4 -4
- package/dist/styles/date-picker.d.ts +2 -3
- package/dist/styles/date-picker.js +1 -1
- package/dist/styles/month-calendar.d.ts +2 -3
- package/dist/styles/month-calendar.js +1 -1
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +8 -6
- package/dist/utils.js.flow +8 -5
- package/dist/utils.test.js +23 -79
- package/dist/utils.test.js.flow +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ support for ranges via a two-up month calendar view.
|
|
|
11
11
|
See the [storybook docs and demo][] to get a feel for what it can do.
|
|
12
12
|
|
|
13
13
|
[storybook docs and demo]:
|
|
14
|
-
https://
|
|
14
|
+
https://uikit.acusti.ca/?path=/docs/uikit-controls-datepicker-datepicker--docs
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
17
17
|
|
package/dist/DatePicker.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ export type Props = {
|
|
|
8
8
|
isTwoUp?: boolean;
|
|
9
9
|
monthLimitFirst?: number;
|
|
10
10
|
monthLimitLast?: number;
|
|
11
|
-
onChange: (payload: {
|
|
11
|
+
onChange: (payload: {
|
|
12
|
+
dateEnd?: null | string;
|
|
13
|
+
dateStart: string;
|
|
14
|
+
}) => void;
|
|
12
15
|
/**
|
|
13
16
|
* Boolean to specify that date picker should initially render with the
|
|
14
17
|
* end date’s month visible. The default behavior is to initially render
|
|
@@ -17,16 +20,4 @@ export type Props = {
|
|
|
17
20
|
showEndInitially?: boolean;
|
|
18
21
|
useMonthAbbreviations?: boolean;
|
|
19
22
|
};
|
|
20
|
-
export default function DatePicker({
|
|
21
|
-
className,
|
|
22
|
-
dateEnd: _dateEnd,
|
|
23
|
-
dateStart: _dateStart,
|
|
24
|
-
initialMonth,
|
|
25
|
-
isRange,
|
|
26
|
-
isTwoUp,
|
|
27
|
-
monthLimitFirst,
|
|
28
|
-
monthLimitLast,
|
|
29
|
-
onChange,
|
|
30
|
-
showEndInitially,
|
|
31
|
-
useMonthAbbreviations,
|
|
32
|
-
}: Props): React.JSX.Element;
|
|
23
|
+
export default function DatePicker({ className, dateEnd: _dateEnd, dateStart: _dateStart, initialMonth, isRange, isTwoUp, monthLimitFirst, monthLimitLast, onChange, showEndInitially, useMonthAbbreviations, }: Props): React.JSX.Element;
|
package/dist/DatePicker.js
CHANGED
|
@@ -4,52 +4,27 @@ import clsx from 'clsx';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import MonthCalendar from './MonthCalendar.js';
|
|
6
6
|
import { ROOT_CLASS_NAME, STYLES } from './styles/date-picker.js';
|
|
7
|
-
import {
|
|
8
|
-
getMonthAbbreviationFromMonth,
|
|
9
|
-
getMonthFromDate,
|
|
10
|
-
getYearFromMonth,
|
|
11
|
-
} from './utils.js';
|
|
7
|
+
import { getMonthAbbreviationFromMonth, getMonthFromDate, getYearFromMonth, } from './utils.js';
|
|
12
8
|
const { Fragment, useCallback, useEffect, useRef, useState } = React;
|
|
13
|
-
const getAbbreviatedMonthTitle = (month) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
monthLimitLast,
|
|
24
|
-
onChange,
|
|
25
|
-
showEndInitially,
|
|
26
|
-
useMonthAbbreviations,
|
|
27
|
-
}) {
|
|
28
|
-
const dateEndFromProps =
|
|
29
|
-
_dateEnd != null && typeof _dateEnd !== 'string'
|
|
30
|
-
? new Date(_dateEnd).toISOString()
|
|
31
|
-
: _dateEnd;
|
|
32
|
-
const dateStartFromProps =
|
|
33
|
-
_dateStart != null && typeof _dateStart !== 'string'
|
|
34
|
-
? new Date(_dateStart).toISOString()
|
|
35
|
-
: _dateStart;
|
|
36
|
-
const [dateEnd, setDateEnd] = useState(
|
|
37
|
-
dateEndFromProps !== null && dateEndFromProps !== void 0
|
|
38
|
-
? dateEndFromProps
|
|
39
|
-
: null,
|
|
40
|
-
);
|
|
41
|
-
const [dateStart, setDateStart] = useState(
|
|
42
|
-
dateStartFromProps !== null && dateStartFromProps !== void 0
|
|
43
|
-
? dateStartFromProps
|
|
44
|
-
: null,
|
|
45
|
-
);
|
|
9
|
+
const getAbbreviatedMonthTitle = (month) => `${getMonthAbbreviationFromMonth(month)} ${getYearFromMonth(month)}`;
|
|
10
|
+
export default function DatePicker({ className, dateEnd: _dateEnd, dateStart: _dateStart, initialMonth, isRange = _dateEnd != null, isTwoUp, monthLimitFirst, monthLimitLast, onChange, showEndInitially, useMonthAbbreviations, }) {
|
|
11
|
+
const dateEndFromProps = _dateEnd != null && typeof _dateEnd !== 'string'
|
|
12
|
+
? new Date(_dateEnd).toISOString()
|
|
13
|
+
: _dateEnd;
|
|
14
|
+
const dateStartFromProps = _dateStart != null && typeof _dateStart !== 'string'
|
|
15
|
+
? new Date(_dateStart).toISOString()
|
|
16
|
+
: _dateStart;
|
|
17
|
+
const [dateEnd, setDateEnd] = useState(dateEndFromProps !== null && dateEndFromProps !== void 0 ? dateEndFromProps : null);
|
|
18
|
+
const [dateStart, setDateStart] = useState(dateStartFromProps !== null && dateStartFromProps !== void 0 ? dateStartFromProps : null);
|
|
46
19
|
const updatingDateEndRef = useRef(false);
|
|
47
20
|
useEffect(() => {
|
|
48
|
-
if (dateEndFromProps == null)
|
|
21
|
+
if (dateEndFromProps == null)
|
|
22
|
+
return;
|
|
49
23
|
setDateEnd(dateEndFromProps);
|
|
50
24
|
}, [dateEndFromProps]);
|
|
51
25
|
useEffect(() => {
|
|
52
|
-
if (dateStartFromProps == null)
|
|
26
|
+
if (dateStartFromProps == null)
|
|
27
|
+
return;
|
|
53
28
|
setDateStart(dateStartFromProps);
|
|
54
29
|
}, [dateStartFromProps]);
|
|
55
30
|
if (initialMonth == null) {
|
|
@@ -57,9 +32,7 @@ export default function DatePicker({
|
|
|
57
32
|
const useDateEnd = dateStart == null || Boolean(showEndInitially && dateEnd);
|
|
58
33
|
// use date from props if set
|
|
59
34
|
const initialDate = useDateEnd ? dateEnd : dateStart;
|
|
60
|
-
initialMonth = getMonthFromDate(
|
|
61
|
-
initialDate == null ? new Date() : new Date(initialDate),
|
|
62
|
-
);
|
|
35
|
+
initialMonth = getMonthFromDate(initialDate == null ? new Date() : new Date(initialDate));
|
|
63
36
|
if (useDateEnd && isTwoUp) {
|
|
64
37
|
initialMonth -= 1;
|
|
65
38
|
}
|
|
@@ -71,111 +44,65 @@ export default function DatePicker({
|
|
|
71
44
|
monthLimitLast -= 1;
|
|
72
45
|
}
|
|
73
46
|
const handleClickLeftArrow = useCallback(() => {
|
|
74
|
-
setMonth((existingMonth) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
: existingMonth,
|
|
78
|
-
);
|
|
47
|
+
setMonth((existingMonth) => monthLimitFirst == null || existingMonth > monthLimitFirst
|
|
48
|
+
? existingMonth - 1
|
|
49
|
+
: existingMonth);
|
|
79
50
|
}, [monthLimitFirst]);
|
|
80
51
|
const handleClickRightArrow = useCallback(() => {
|
|
81
|
-
setMonth((existingMonth) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
: existingMonth,
|
|
85
|
-
);
|
|
52
|
+
setMonth((existingMonth) => monthLimitLast == null || existingMonth < monthLimitLast
|
|
53
|
+
? existingMonth + 1
|
|
54
|
+
: existingMonth);
|
|
86
55
|
}, [monthLimitLast]);
|
|
87
|
-
const handleChange = useCallback(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
) {
|
|
95
|
-
// Ensure that dateEnd is after dateStart; if not, swap them
|
|
96
|
-
if (date < dateStart) {
|
|
97
|
-
setDateStart(date);
|
|
98
|
-
setDateEnd(dateStart);
|
|
99
|
-
onChange({ dateEnd: dateStart, dateStart: date });
|
|
100
|
-
} else {
|
|
101
|
-
setDateEnd(date);
|
|
102
|
-
onChange({ dateEnd: date, dateStart });
|
|
103
|
-
}
|
|
104
|
-
updatingDateEndRef.current = false;
|
|
105
|
-
} else {
|
|
56
|
+
const handleChange = useCallback((date) => {
|
|
57
|
+
// If we last set the dateStart or we have a dateStart but no dateEnd, set dateEnd
|
|
58
|
+
if (isRange &&
|
|
59
|
+
dateStart != null &&
|
|
60
|
+
(updatingDateEndRef.current || dateEnd == null)) {
|
|
61
|
+
// Ensure that dateEnd is after dateStart; if not, swap them
|
|
62
|
+
if (date < dateStart) {
|
|
106
63
|
setDateStart(date);
|
|
107
|
-
setDateEnd(
|
|
108
|
-
|
|
109
|
-
onChange({ dateEnd: null, dateStart: date });
|
|
110
|
-
updatingDateEndRef.current = true;
|
|
111
|
-
} else {
|
|
112
|
-
onChange({ dateStart: date });
|
|
113
|
-
}
|
|
64
|
+
setDateEnd(dateStart);
|
|
65
|
+
onChange({ dateEnd: dateStart, dateStart: date });
|
|
114
66
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
67
|
+
else {
|
|
68
|
+
setDateEnd(date);
|
|
69
|
+
onChange({ dateEnd: date, dateStart });
|
|
70
|
+
}
|
|
71
|
+
updatingDateEndRef.current = false;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
setDateStart(date);
|
|
75
|
+
setDateEnd(null);
|
|
76
|
+
if (isRange) {
|
|
77
|
+
onChange({ dateEnd: null, dateStart: date });
|
|
78
|
+
updatingDateEndRef.current = true;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
onChange({ dateStart: date });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, [dateEnd, dateStart, isRange, onChange]);
|
|
118
85
|
const handleChangeEndPreview = useCallback((date) => {
|
|
119
86
|
setDateEndPreview(date);
|
|
120
87
|
}, []);
|
|
121
|
-
return React.createElement(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
className: clsx(ROOT_CLASS_NAME, className, {
|
|
129
|
-
'two-up': isTwoUp,
|
|
130
|
-
}),
|
|
131
|
-
},
|
|
132
|
-
React.createElement(
|
|
133
|
-
'div',
|
|
134
|
-
{ className: `${ROOT_CLASS_NAME}-range-arrow-wrap` },
|
|
135
|
-
React.createElement('div', {
|
|
136
|
-
className: clsx(`${ROOT_CLASS_NAME}-range-arrow left-arrow`, {
|
|
88
|
+
return (React.createElement(Fragment, null,
|
|
89
|
+
React.createElement(Style, { href: "@acusti/date-picker/DatePicker" }, STYLES),
|
|
90
|
+
React.createElement("div", { className: clsx(ROOT_CLASS_NAME, className, {
|
|
91
|
+
'two-up': isTwoUp,
|
|
92
|
+
}) },
|
|
93
|
+
React.createElement("div", { className: `${ROOT_CLASS_NAME}-range-arrow-wrap` },
|
|
94
|
+
React.createElement("div", { className: clsx(`${ROOT_CLASS_NAME}-range-arrow left-arrow`, {
|
|
137
95
|
disabled: monthLimitFirst != null && month <= monthLimitFirst,
|
|
138
|
-
}),
|
|
139
|
-
|
|
140
|
-
}),
|
|
141
|
-
React.createElement('div', {
|
|
142
|
-
className: clsx(`${ROOT_CLASS_NAME}-range-arrow right-arrow`, {
|
|
96
|
+
}), onClick: handleClickLeftArrow }),
|
|
97
|
+
React.createElement("div", { className: clsx(`${ROOT_CLASS_NAME}-range-arrow right-arrow`, {
|
|
143
98
|
disabled: monthLimitLast != null && month >= monthLimitLast,
|
|
144
|
-
}),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
),
|
|
148
|
-
React.createElement(
|
|
149
|
-
'div',
|
|
150
|
-
{ className: `${ROOT_CLASS_NAME}-month-container` },
|
|
151
|
-
React.createElement(MonthCalendar, {
|
|
152
|
-
dateEnd: dateEnd,
|
|
153
|
-
dateEndPreview: dateEndPreview,
|
|
154
|
-
dateStart: dateStart,
|
|
155
|
-
isRange: isRange,
|
|
156
|
-
month: month,
|
|
157
|
-
onChange: handleChange,
|
|
158
|
-
onChangeEndPreview: handleChangeEndPreview,
|
|
159
|
-
title: useMonthAbbreviations
|
|
99
|
+
}), onClick: handleClickRightArrow })),
|
|
100
|
+
React.createElement("div", { className: `${ROOT_CLASS_NAME}-month-container` },
|
|
101
|
+
React.createElement(MonthCalendar, { dateEnd: dateEnd, dateEndPreview: dateEndPreview, dateStart: dateStart, isRange: isRange, month: month, onChange: handleChange, onChangeEndPreview: handleChangeEndPreview, title: useMonthAbbreviations
|
|
160
102
|
? getAbbreviatedMonthTitle(month)
|
|
161
|
-
: undefined,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
dateEnd: dateEnd,
|
|
166
|
-
dateEndPreview: dateEndPreview,
|
|
167
|
-
dateStart: dateStart,
|
|
168
|
-
isRange: isRange,
|
|
169
|
-
month: month + 1,
|
|
170
|
-
onChange: handleChange,
|
|
171
|
-
onChangeEndPreview: handleChangeEndPreview,
|
|
172
|
-
title: useMonthAbbreviations
|
|
173
|
-
? getAbbreviatedMonthTitle(month + 1)
|
|
174
|
-
: undefined,
|
|
175
|
-
})
|
|
176
|
-
: null,
|
|
177
|
-
),
|
|
178
|
-
),
|
|
179
|
-
);
|
|
103
|
+
: undefined }),
|
|
104
|
+
isTwoUp ? (React.createElement(MonthCalendar, { dateEnd: dateEnd, dateEndPreview: dateEndPreview, dateStart: dateStart, isRange: isRange, month: month + 1, onChange: handleChange, onChangeEndPreview: handleChangeEndPreview, title: useMonthAbbreviations
|
|
105
|
+
? getAbbreviatedMonthTitle(month + 1)
|
|
106
|
+
: undefined })) : null))));
|
|
180
107
|
}
|
|
181
|
-
//# sourceMappingURL=DatePicker.js.map
|
|
108
|
+
//# sourceMappingURL=DatePicker.js.map
|
package/dist/DatePicker.js.flow
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for DatePicker
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import * as React from
|
|
8
|
+
import * as React from "react";
|
|
9
9
|
export type Props = {|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
className?: string,
|
|
11
|
+
dateEnd?: Date | number | string,
|
|
12
|
+
dateStart?: Date | number | string,
|
|
13
|
+
initialMonth?: number,
|
|
14
|
+
isRange?: boolean,
|
|
15
|
+
isTwoUp?: boolean,
|
|
16
|
+
monthLimitFirst?: number,
|
|
17
|
+
monthLimitLast?: number,
|
|
18
|
+
onChange: (payload: {|
|
|
19
|
+
dateEnd?: null | string,
|
|
20
|
+
dateStart: string,
|
|
21
|
+
|}) => void,
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Boolean to specify that date picker should initially render with the
|
|
25
|
+
* end date’s month visible. The default behavior is to initially render
|
|
26
|
+
* with the start date’s month visible.
|
|
27
|
+
*/
|
|
28
|
+
showEndInitially?: boolean,
|
|
29
|
+
useMonthAbbreviations?: boolean,
|
|
30
30
|
|};
|
|
31
31
|
declare export default function DatePicker(x: Props): React.Node;
|
package/dist/MonthCalendar.d.ts
CHANGED
|
@@ -10,14 +10,4 @@ export type Props = {
|
|
|
10
10
|
onChangeEndPreview?: (date: string) => void;
|
|
11
11
|
title?: string;
|
|
12
12
|
};
|
|
13
|
-
export default function MonthCalendar({
|
|
14
|
-
className,
|
|
15
|
-
dateEnd,
|
|
16
|
-
dateEndPreview,
|
|
17
|
-
dateStart,
|
|
18
|
-
isRange,
|
|
19
|
-
month,
|
|
20
|
-
onChange,
|
|
21
|
-
onChangeEndPreview,
|
|
22
|
-
title,
|
|
23
|
-
}: Props): React.JSX.Element;
|
|
13
|
+
export default function MonthCalendar({ className, dateEnd, dateEndPreview, dateStart, isRange, month, onChange, onChangeEndPreview, title, }: Props): React.JSX.Element;
|
package/dist/MonthCalendar.js
CHANGED
|
@@ -2,31 +2,12 @@ import { Style } from '@acusti/styling';
|
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { ROOT_CLASS_NAME, STYLES } from './styles/month-calendar.js';
|
|
5
|
-
import {
|
|
6
|
-
getDateFromMonthAndDay,
|
|
7
|
-
getLastDateFromMonth,
|
|
8
|
-
getMonthFromDate,
|
|
9
|
-
getMonthNameFromMonth,
|
|
10
|
-
getYearFromMonth,
|
|
11
|
-
} from './utils.js';
|
|
5
|
+
import { getDateFromMonthAndDay, getLastDateFromMonth, getMonthFromDate, getMonthNameFromMonth, getYearFromMonth, } from './utils.js';
|
|
12
6
|
const { Fragment, useCallback } = React;
|
|
13
7
|
const DAYS = Array(7).fill(null);
|
|
14
|
-
export default function MonthCalendar({
|
|
15
|
-
className,
|
|
16
|
-
dateEnd,
|
|
17
|
-
dateEndPreview,
|
|
18
|
-
dateStart,
|
|
19
|
-
isRange,
|
|
20
|
-
month,
|
|
21
|
-
onChange,
|
|
22
|
-
onChangeEndPreview,
|
|
23
|
-
title,
|
|
24
|
-
}) {
|
|
8
|
+
export default function MonthCalendar({ className, dateEnd, dateEndPreview, dateStart, isRange, month, onChange, onChangeEndPreview, title, }) {
|
|
25
9
|
const year = getYearFromMonth(month);
|
|
26
|
-
title =
|
|
27
|
-
title !== null && title !== void 0
|
|
28
|
-
? title
|
|
29
|
-
: `${getMonthNameFromMonth(month)} ${year}`;
|
|
10
|
+
title = title !== null && title !== void 0 ? title : `${getMonthNameFromMonth(month)} ${year}`;
|
|
30
11
|
const firstDate = getDateFromMonthAndDay(month, 1);
|
|
31
12
|
const lastDate = getLastDateFromMonth(month);
|
|
32
13
|
const totalDays = lastDate.getDate();
|
|
@@ -37,198 +18,88 @@ export default function MonthCalendar({
|
|
|
37
18
|
dateStart,
|
|
38
19
|
dateEnd,
|
|
39
20
|
dateEndPreview,
|
|
40
|
-
].reduce(
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (date == null || Number.isNaN(date.getTime())) return acc;
|
|
46
|
-
const dateMonth = getMonthFromDate(date);
|
|
47
|
-
if (dateMonth < month) acc[index] = -1;
|
|
48
|
-
else if (dateMonth > month) acc[index] = totalDays + 1;
|
|
49
|
-
else acc[index] = date.getDate();
|
|
50
|
-
if (index === 1) {
|
|
51
|
-
const startDay = acc[index - 1];
|
|
52
|
-
const endDay = acc[index];
|
|
53
|
-
// Ensure that end date is after start date and swap them if not
|
|
54
|
-
if (startDay != null && endDay != null && startDay > endDay) {
|
|
55
|
-
acc[index - 1] = endDay;
|
|
56
|
-
acc[index] = startDay;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
21
|
+
].reduce((acc, date, index) => {
|
|
22
|
+
if (date != null && !(date instanceof Date)) {
|
|
23
|
+
date = new Date(date);
|
|
24
|
+
}
|
|
25
|
+
if (date == null || Number.isNaN(date.getTime()))
|
|
59
26
|
return acc;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (date) onChangeEndPreview(date);
|
|
27
|
+
const dateMonth = getMonthFromDate(date);
|
|
28
|
+
if (dateMonth < month)
|
|
29
|
+
acc[index] = -1;
|
|
30
|
+
else if (dateMonth > month)
|
|
31
|
+
acc[index] = totalDays + 1;
|
|
32
|
+
else
|
|
33
|
+
acc[index] = date.getDate();
|
|
34
|
+
if (index === 1) {
|
|
35
|
+
const startDay = acc[index - 1];
|
|
36
|
+
const endDay = acc[index];
|
|
37
|
+
// Ensure that end date is after start date and swap them if not
|
|
38
|
+
if (startDay != null && endDay != null && startDay > endDay) {
|
|
39
|
+
acc[index - 1] = endDay;
|
|
40
|
+
acc[index] = startDay;
|
|
75
41
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
{ className:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
{ className:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
React.createElement(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
React.createElement(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
'
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
{ className:
|
|
137
|
-
|
|
138
|
-
'span',
|
|
139
|
-
{ className: 'week-day-item-text' },
|
|
140
|
-
'Th',
|
|
141
|
-
),
|
|
142
|
-
),
|
|
143
|
-
React.createElement(
|
|
144
|
-
'div',
|
|
145
|
-
{ className: 'week-day-item' },
|
|
146
|
-
React.createElement(
|
|
147
|
-
'span',
|
|
148
|
-
{ className: 'week-day-item-text' },
|
|
149
|
-
'Fr',
|
|
150
|
-
),
|
|
151
|
-
),
|
|
152
|
-
React.createElement(
|
|
153
|
-
'div',
|
|
154
|
-
{ className: 'week-day-item' },
|
|
155
|
-
React.createElement(
|
|
156
|
-
'span',
|
|
157
|
-
{ className: 'week-day-item-text' },
|
|
158
|
-
'Sa',
|
|
159
|
-
),
|
|
160
|
-
),
|
|
161
|
-
),
|
|
162
|
-
React.createElement(
|
|
163
|
-
'div',
|
|
164
|
-
{ className: `${ROOT_CLASS_NAME}-month-days` },
|
|
165
|
-
Array(Math.floor(daySpaces / 7))
|
|
166
|
-
.fill(null)
|
|
167
|
-
.map((_, weekIndex) =>
|
|
168
|
-
React.createElement(
|
|
169
|
-
'div',
|
|
170
|
-
{
|
|
171
|
-
className: `${ROOT_CLASS_NAME}-month-row`,
|
|
172
|
-
key: `MonthRow-${weekIndex}`,
|
|
173
|
-
},
|
|
174
|
-
DAYS.map((__, dayIndex) => {
|
|
175
|
-
dayIndex += weekIndex * 7;
|
|
176
|
-
const dayNumber = (dayIndex - firstDay) + 1; // prettier-ignore
|
|
177
|
-
const isEmpty = dayNumber < 1 || dayNumber > totalDays;
|
|
178
|
-
const date = isEmpty
|
|
179
|
-
? null
|
|
180
|
-
: getDateFromMonthAndDay(month, dayNumber);
|
|
181
|
-
const isAfterDateRangeStart =
|
|
182
|
-
dateRangeStartDay != null &&
|
|
183
|
-
dayNumber > dateRangeStartDay;
|
|
184
|
-
const isBeforeDateRangeEnd =
|
|
185
|
-
(dateRangeEndDay == null &&
|
|
186
|
-
dateRangeEndPreviewDay != null &&
|
|
187
|
-
dayNumber < dateRangeEndPreviewDay) ||
|
|
188
|
-
(dateRangeEndDay != null &&
|
|
189
|
-
dayNumber < dateRangeEndDay);
|
|
190
|
-
return React.createElement(
|
|
191
|
-
'button',
|
|
192
|
-
{
|
|
193
|
-
className: clsx(
|
|
194
|
-
`${ROOT_CLASS_NAME}-month-day-item`,
|
|
195
|
-
{
|
|
196
|
-
'end-date':
|
|
197
|
-
!isEmpty &&
|
|
198
|
-
dayNumber === dateRangeEndDay,
|
|
199
|
-
'is-empty': isEmpty,
|
|
200
|
-
'is-selected':
|
|
201
|
-
!isEmpty &&
|
|
202
|
-
isAfterDateRangeStart &&
|
|
203
|
-
isBeforeDateRangeEnd,
|
|
204
|
-
'start-date':
|
|
205
|
-
!isEmpty &&
|
|
206
|
-
dayNumber === dateRangeStartDay,
|
|
207
|
-
},
|
|
208
|
-
),
|
|
209
|
-
'data-date':
|
|
210
|
-
date === null || date === void 0
|
|
211
|
-
? void 0
|
|
212
|
-
: date.toISOString(),
|
|
213
|
-
disabled: isEmpty,
|
|
214
|
-
key: `MonthDayItem-${dayNumber}`,
|
|
215
|
-
onClick: handleClickDay,
|
|
216
|
-
onMouseEnter: handleMouseEnterDay,
|
|
217
|
-
type: 'button',
|
|
218
|
-
},
|
|
219
|
-
isEmpty
|
|
220
|
-
? null
|
|
221
|
-
: React.createElement(
|
|
222
|
-
'span',
|
|
223
|
-
{ className: 'month-day-item-text' },
|
|
224
|
-
dayNumber,
|
|
225
|
-
),
|
|
226
|
-
);
|
|
227
|
-
}),
|
|
228
|
-
),
|
|
229
|
-
),
|
|
230
|
-
),
|
|
231
|
-
),
|
|
232
|
-
);
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}, [null, null, null]);
|
|
45
|
+
const handleClickDay = useCallback((event) => {
|
|
46
|
+
const { date } = event.currentTarget.dataset;
|
|
47
|
+
if (date && onChange)
|
|
48
|
+
onChange(date);
|
|
49
|
+
}, [onChange]);
|
|
50
|
+
const handleMouseEnterDay = useCallback((event) => {
|
|
51
|
+
if (isRange && onChangeEndPreview) {
|
|
52
|
+
const { date } = event.currentTarget.dataset;
|
|
53
|
+
if (date)
|
|
54
|
+
onChangeEndPreview(date);
|
|
55
|
+
}
|
|
56
|
+
}, [isRange, onChangeEndPreview]);
|
|
57
|
+
return (React.createElement(Fragment, null,
|
|
58
|
+
React.createElement(Style, { href: "@acusti/date-picker/MonthCalendar" }, STYLES),
|
|
59
|
+
React.createElement("div", { className: clsx(ROOT_CLASS_NAME, className) },
|
|
60
|
+
React.createElement("div", { className: `${ROOT_CLASS_NAME}-month-title` },
|
|
61
|
+
React.createElement("h3", { className: `${ROOT_CLASS_NAME}-month-title-text` }, title)),
|
|
62
|
+
React.createElement("div", { className: `${ROOT_CLASS_NAME}-month-week` },
|
|
63
|
+
React.createElement("div", { className: "week-day-item" },
|
|
64
|
+
React.createElement("span", { className: "week-day-item-text" }, "Su")),
|
|
65
|
+
React.createElement("div", { className: "week-day-item" },
|
|
66
|
+
React.createElement("span", { className: "week-day-item-text" }, "Mo")),
|
|
67
|
+
React.createElement("div", { className: "week-day-item" },
|
|
68
|
+
React.createElement("span", { className: "week-day-item-text" }, "Tu")),
|
|
69
|
+
React.createElement("div", { className: "week-day-item" },
|
|
70
|
+
React.createElement("span", { className: "week-day-item-text" }, "We")),
|
|
71
|
+
React.createElement("div", { className: "week-day-item" },
|
|
72
|
+
React.createElement("span", { className: "week-day-item-text" }, "Th")),
|
|
73
|
+
React.createElement("div", { className: "week-day-item" },
|
|
74
|
+
React.createElement("span", { className: "week-day-item-text" }, "Fr")),
|
|
75
|
+
React.createElement("div", { className: "week-day-item" },
|
|
76
|
+
React.createElement("span", { className: "week-day-item-text" }, "Sa"))),
|
|
77
|
+
React.createElement("div", { className: `${ROOT_CLASS_NAME}-month-days` }, Array(Math.floor(daySpaces / 7))
|
|
78
|
+
.fill(null)
|
|
79
|
+
.map((_, weekIndex) => (React.createElement("div", { className: `${ROOT_CLASS_NAME}-month-row`, key: `MonthRow-${weekIndex}` }, DAYS.map((__, dayIndex) => {
|
|
80
|
+
dayIndex += weekIndex * 7;
|
|
81
|
+
const dayNumber = (dayIndex - firstDay) + 1; // prettier-ignore
|
|
82
|
+
const isEmpty = dayNumber < 1 || dayNumber > totalDays;
|
|
83
|
+
const date = isEmpty
|
|
84
|
+
? null
|
|
85
|
+
: getDateFromMonthAndDay(month, dayNumber);
|
|
86
|
+
const isAfterDateRangeStart = dateRangeStartDay != null &&
|
|
87
|
+
dayNumber > dateRangeStartDay;
|
|
88
|
+
const isBeforeDateRangeEnd = (dateRangeEndDay == null &&
|
|
89
|
+
dateRangeEndPreviewDay != null &&
|
|
90
|
+
dayNumber < dateRangeEndPreviewDay) ||
|
|
91
|
+
(dateRangeEndDay != null &&
|
|
92
|
+
dayNumber < dateRangeEndDay);
|
|
93
|
+
return (React.createElement("button", { className: clsx(`${ROOT_CLASS_NAME}-month-day-item`, {
|
|
94
|
+
'end-date': !isEmpty &&
|
|
95
|
+
dayNumber === dateRangeEndDay,
|
|
96
|
+
'is-empty': isEmpty,
|
|
97
|
+
'is-selected': !isEmpty &&
|
|
98
|
+
isAfterDateRangeStart &&
|
|
99
|
+
isBeforeDateRangeEnd,
|
|
100
|
+
'start-date': !isEmpty &&
|
|
101
|
+
dayNumber === dateRangeStartDay,
|
|
102
|
+
}), "data-date": date === null || date === void 0 ? void 0 : date.toISOString(), disabled: isEmpty, key: `MonthDayItem-${dayNumber}`, onClick: handleClickDay, onMouseEnter: handleMouseEnterDay, type: "button" }, isEmpty ? null : (React.createElement("span", { className: "month-day-item-text" }, dayNumber))));
|
|
103
|
+
}))))))));
|
|
233
104
|
}
|
|
234
|
-
//# sourceMappingURL=MonthCalendar.js.map
|
|
105
|
+
//# sourceMappingURL=MonthCalendar.js.map
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for MonthCalendar
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import * as React from
|
|
8
|
+
import * as React from "react";
|
|
9
9
|
export type Props = {|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
className?: string,
|
|
11
|
+
dateEnd?: Date | null | number | string,
|
|
12
|
+
dateEndPreview?: null | string,
|
|
13
|
+
dateStart?: Date | null | number | string,
|
|
14
|
+
isRange?: boolean,
|
|
15
|
+
month: number,
|
|
16
|
+
onChange?: (date: string) => void,
|
|
17
|
+
onChangeEndPreview?: (date: string) => void,
|
|
18
|
+
title?: string,
|
|
19
19
|
|};
|
|
20
20
|
declare export default function MonthCalendar(x: Props): React.Node;
|
package/dist/index.js
CHANGED
package/dist/index.js.flow
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
declare export { default as DatePicker } from
|
|
9
|
-
declare export { default as MonthCalendar } from
|
|
10
|
-
declare export * from
|
|
8
|
+
declare export { default as DatePicker } from "./DatePicker.js";
|
|
9
|
+
declare export { default as MonthCalendar } from "./MonthCalendar.js";
|
|
10
|
+
declare export * from "./utils.js";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare const ROOT_CLASS_NAME =
|
|
2
|
-
export declare const STYLES =
|
|
3
|
-
'\n.uktdatepicker {\n display: flex;\n box-sizing: border-box;\n padding: 40px 60px 60px;\n flex: 1 1 auto;\n position: relative;\n max-width: 450px;\n}\n\n.uktdatepicker.two-up {\n max-width: 820px;\n}\n\n.uktdatepicker-range-arrow-wrap {\n position: absolute;\n top: 30px;\n left: 0px;\n display: flex;\n justify-content: space-between;\n height: 0px;\n width: 100%;\n padding: 0px 60px;\n box-sizing: border-box;\n}\n\n.uktdatepicker-range-arrow {\n width: 35px;\n height: 35px;\n text-align: center;\n cursor: pointer;\n}\n\n.uktdatepicker-range-arrow.disabled {\n color: #ccc;\n cursor: default;\n}\n\n.uktdatepicker-range-arrow:active {\n transform: translateY(1px);\n}\n\n.uktdatepicker-range-arrow.left-arrow:after,\n.uktdatepicker-range-arrow.right-arrow:after {\n content: "\u2039";\n font-size: 24px;\n line-height: 35px;\n font-weight: bold;\n}\n\n.uktdatepicker-range-arrow.right-arrow:after {\n content: "\u203A";\n}\n\n.uktdatepicker-month-container {\n display: flex;\n flex: 1 1 auto;\n justify-content: space-between;\n}\n';
|
|
1
|
+
export declare const ROOT_CLASS_NAME = "uktdatepicker";
|
|
2
|
+
export declare const STYLES = "\n.uktdatepicker {\n display: flex;\n box-sizing: border-box;\n padding: 40px 60px 60px;\n flex: 1 1 auto;\n position: relative;\n max-width: 450px;\n}\n\n.uktdatepicker.two-up {\n max-width: 820px;\n}\n\n.uktdatepicker-range-arrow-wrap {\n position: absolute;\n top: 30px;\n left: 0px;\n display: flex;\n justify-content: space-between;\n height: 0px;\n width: 100%;\n padding: 0px 60px;\n box-sizing: border-box;\n}\n\n.uktdatepicker-range-arrow {\n width: 35px;\n height: 35px;\n text-align: center;\n cursor: pointer;\n}\n\n.uktdatepicker-range-arrow.disabled {\n color: #ccc;\n cursor: default;\n}\n\n.uktdatepicker-range-arrow:active {\n transform: translateY(1px);\n}\n\n.uktdatepicker-range-arrow.left-arrow:after,\n.uktdatepicker-range-arrow.right-arrow:after {\n content: \"\u2039\";\n font-size: 24px;\n line-height: 35px;\n font-weight: bold;\n}\n\n.uktdatepicker-range-arrow.right-arrow:after {\n content: \"\u203A\";\n}\n\n.uktdatepicker-month-container {\n display: flex;\n flex: 1 1 auto;\n justify-content: space-between;\n}\n";
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export declare const ROOT_CLASS_NAME =
|
|
2
|
-
export declare const STYLES =
|
|
3
|
-
'\n.uktmonthcalendar {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n box-sizing: border-box;\n max-width: 325px;\n}\n\n.uktmonthcalendar-month-title {\n display: flex;\n align-items: center;\n justify-content: center;\n flex: 0 0 auto;\n box-sizing: border-box;\n padding-bottom: 25px;\n}\n\nh3.uktmonthcalendar-month-title-text {\n font-size: 18px;\n line-height: 23px;\n font-weight: 600;\n color: #000;\n margin: 0px;\n text-align: center;\n}\n\n.uktmonthcalendar-month-week {\n flex: 0 0 auto;\n display: grid;\n grid-column-gap: 0px;\n grid-template-columns: repeat(auto-fit, minmax(46px, 1fr));\n grid-auto-flow: dense;\n box-sizing: border-box;\n padding-bottom: 12px;\n}\n\n.uktmonthcalendar-month-week .week-day-item {\n flex: 1 1 auto;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.uktmonthcalendar-month-week span.week-day-item-text {\n text-align: center;\n font-size: 13px;\n line-height: 21px;\n margin: 0px;\n color: #9a9a9a;\n}\n\n.uktmonthcalendar-month-days {\n flex: 1 1 auto;\n display: flex;\n flex-direction: column;\n}\n\n.uktmonthcalendar-month-row {\n flex: 1 1 auto;\n display: grid;\n grid-column-gap: 0px;\n grid-template-columns: repeat(auto-fit, minmax(46px, 1fr));\n grid-auto-flow: dense;\n margin-bottom: 1px;\n}\n\n.uktmonthcalendar-month-day-item {\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n height: 46px;\n width: 46px;\n cursor: pointer;\n border: none;\n background-color: transparent;\n}\n\n.uktmonthcalendar-month-day-item:disabled {\n cursor: auto;\n}\n\n.uktmonthcalendar-month-day-item.is-selected {\n background-color: #f8f8f8;\n}\n\n.uktmonthcalendar-month-day-item.start-date {\n background-color: #f8f8f8;\n border-top-left-radius: 50%;\n border-bottom-left-radius: 50%;\n}\n\n.uktmonthcalendar-month-day-item.start-date:after {\n background-color: #000;\n opacity: 1;\n visibility: visible;\n}\n.uktmonthcalendar-month-day-item.start-date span.month-day-item-text {\n color: #fff;\n}\n\n.uktmonthcalendar-month-day-item.end-date {\n background-color: #f8f8f8;\n border-top-right-radius: 50%;\n border-bottom-right-radius: 50%;\n}\n\n.uktmonthcalendar-month-day-item.end-date:after {\n background-color: #000;\n opacity: 1;\n visibility: visible;\n}\n.uktmonthcalendar-month-day-item.end-date span.month-day-item-text {\n color: #fff;\n}\n\n.uktmonthcalendar-month-day-item:hover:after {\n opacity: 1;\n visibility: visible;\n}\n\n.uktmonthcalendar-month-day-item:after {\n content: "";\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n pointer-events: none;\n border-radius: 50%;\n border: 1px solid #000;\n width: 43px;\n height: 43px;\n transition: opacity 0.25s ease-in-out;\n opacity: 0;\n visibility: hidden;\n}\n\n.uktmonthcalendar-month-day-item.is-empty:after {\n content: none;\n}\n\n.uktmonthcalendar-month-day-item span.month-day-item-text {\n text-align: center;\n font-size: 13px;\n line-height: 21px;\n margin: 0px;\n color: #000;\n position: relative;\n z-index: 1;\n}\n';
|
|
1
|
+
export declare const ROOT_CLASS_NAME = "uktmonthcalendar";
|
|
2
|
+
export declare const STYLES = "\n.uktmonthcalendar {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n box-sizing: border-box;\n max-width: 325px;\n}\n\n.uktmonthcalendar-month-title {\n display: flex;\n align-items: center;\n justify-content: center;\n flex: 0 0 auto;\n box-sizing: border-box;\n padding-bottom: 25px;\n}\n\nh3.uktmonthcalendar-month-title-text {\n font-size: 18px;\n line-height: 23px;\n font-weight: 600;\n color: #000;\n margin: 0px;\n text-align: center;\n}\n\n.uktmonthcalendar-month-week {\n flex: 0 0 auto;\n display: grid;\n grid-column-gap: 0px;\n grid-template-columns: repeat(auto-fit, minmax(46px, 1fr));\n grid-auto-flow: dense;\n box-sizing: border-box;\n padding-bottom: 12px;\n}\n\n.uktmonthcalendar-month-week .week-day-item {\n flex: 1 1 auto;\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n.uktmonthcalendar-month-week span.week-day-item-text {\n text-align: center;\n font-size: 13px;\n line-height: 21px;\n margin: 0px;\n color: #9a9a9a;\n}\n\n.uktmonthcalendar-month-days {\n flex: 1 1 auto;\n display: flex;\n flex-direction: column;\n}\n\n.uktmonthcalendar-month-row {\n flex: 1 1 auto;\n display: grid;\n grid-column-gap: 0px;\n grid-template-columns: repeat(auto-fit, minmax(46px, 1fr));\n grid-auto-flow: dense;\n margin-bottom: 1px;\n}\n\n.uktmonthcalendar-month-day-item {\n display: flex;\n justify-content: center;\n align-items: center;\n position: relative;\n height: 46px;\n width: 46px;\n cursor: pointer;\n border: none;\n background-color: transparent;\n}\n\n.uktmonthcalendar-month-day-item:disabled {\n cursor: auto;\n}\n\n.uktmonthcalendar-month-day-item.is-selected {\n background-color: #f8f8f8;\n}\n\n.uktmonthcalendar-month-day-item.start-date {\n background-color: #f8f8f8;\n border-top-left-radius: 50%;\n border-bottom-left-radius: 50%;\n}\n\n.uktmonthcalendar-month-day-item.start-date:after {\n background-color: #000;\n opacity: 1;\n visibility: visible;\n}\n.uktmonthcalendar-month-day-item.start-date span.month-day-item-text {\n color: #fff;\n}\n\n.uktmonthcalendar-month-day-item.end-date {\n background-color: #f8f8f8;\n border-top-right-radius: 50%;\n border-bottom-right-radius: 50%;\n}\n\n.uktmonthcalendar-month-day-item.end-date:after {\n background-color: #000;\n opacity: 1;\n visibility: visible;\n}\n.uktmonthcalendar-month-day-item.end-date span.month-day-item-text {\n color: #fff;\n}\n\n.uktmonthcalendar-month-day-item:hover:after {\n opacity: 1;\n visibility: visible;\n}\n\n.uktmonthcalendar-month-day-item:after {\n content: \"\";\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n pointer-events: none;\n border-radius: 50%;\n border: 1px solid #000;\n width: 43px;\n height: 43px;\n transition: opacity 0.25s ease-in-out;\n opacity: 0;\n visibility: hidden;\n}\n\n.uktmonthcalendar-month-day-item.is-empty:after {\n content: none;\n}\n\n.uktmonthcalendar-month-day-item span.month-day-item-text {\n text-align: center;\n font-size: 13px;\n line-height: 21px;\n margin: 0px;\n color: #000;\n position: relative;\n z-index: 1;\n}\n";
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,9 +2,5 @@ export declare const getMonthFromDate: (date: Date, asUTC?: boolean) => number;
|
|
|
2
2
|
export declare const getYearFromMonth: (month: number) => number;
|
|
3
3
|
export declare const getMonthNameFromMonth: (month: number) => string;
|
|
4
4
|
export declare const getMonthAbbreviationFromMonth: (month: number) => string;
|
|
5
|
-
export declare const getDateFromMonthAndDay: (
|
|
6
|
-
month: number,
|
|
7
|
-
day: number,
|
|
8
|
-
asUTC?: boolean,
|
|
9
|
-
) => Date;
|
|
5
|
+
export declare const getDateFromMonthAndDay: (month: number, day: number, asUTC?: boolean) => Date;
|
|
10
6
|
export declare const getLastDateFromMonth: (month: number, asUTC?: boolean) => Date;
|
package/dist/utils.js
CHANGED
|
@@ -15,8 +15,7 @@ const MONTH_NAMES = [
|
|
|
15
15
|
'November',
|
|
16
16
|
'December',
|
|
17
17
|
];
|
|
18
|
-
const getYearFromDate = (date, asUTC) =>
|
|
19
|
-
(asUTC ? date.getUTCFullYear() : date.getFullYear()) - START_YEAR;
|
|
18
|
+
const getYearFromDate = (date, asUTC) => (asUTC ? date.getUTCFullYear() : date.getFullYear()) - START_YEAR;
|
|
20
19
|
export const getMonthFromDate = (date, asUTC) => {
|
|
21
20
|
const yearAsMonths = getYearFromDate(date, asUTC) * 12;
|
|
22
21
|
return yearAsMonths + (asUTC ? date.getUTCMonth() : date.getMonth());
|
|
@@ -24,13 +23,16 @@ export const getMonthFromDate = (date, asUTC) => {
|
|
|
24
23
|
export const getYearFromMonth = (month) => Math.floor(month / 12) + START_YEAR;
|
|
25
24
|
export const getMonthNameFromMonth = (month) => {
|
|
26
25
|
let index = month % 12;
|
|
27
|
-
if (Number.isNaN(index))
|
|
28
|
-
|
|
26
|
+
if (Number.isNaN(index))
|
|
27
|
+
return '';
|
|
28
|
+
if (index < 0)
|
|
29
|
+
index = 12 + index;
|
|
29
30
|
return MONTH_NAMES[index];
|
|
30
31
|
};
|
|
31
32
|
export const getMonthAbbreviationFromMonth = (month) => {
|
|
32
33
|
const monthName = getMonthNameFromMonth(month);
|
|
33
|
-
if (monthName === 'September')
|
|
34
|
+
if (monthName === 'September')
|
|
35
|
+
return 'Sept';
|
|
34
36
|
return monthName.substring(0, 3);
|
|
35
37
|
};
|
|
36
38
|
export const getDateFromMonthAndDay = (month, day, asUTC) => {
|
|
@@ -44,4 +46,4 @@ export const getLastDateFromMonth = (month, asUTC) => {
|
|
|
44
46
|
// day 0 of the next month is the last day of the current month
|
|
45
47
|
return getDateFromMonthAndDay(month + 1, 0, asUTC);
|
|
46
48
|
};
|
|
47
|
-
//# sourceMappingURL=utils.js.map
|
|
49
|
+
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.flow
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for utils
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -10,8 +10,11 @@ declare export var getYearFromMonth: (month: number) => number;
|
|
|
10
10
|
declare export var getMonthNameFromMonth: (month: number) => string;
|
|
11
11
|
declare export var getMonthAbbreviationFromMonth: (month: number) => string;
|
|
12
12
|
declare export var getDateFromMonthAndDay: (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
month: number,
|
|
14
|
+
day: number,
|
|
15
|
+
asUTC?: boolean
|
|
16
|
+
) => Date;
|
|
17
|
+
declare export var getLastDateFromMonth: (
|
|
18
|
+
month: number,
|
|
19
|
+
asUTC?: boolean
|
|
16
20
|
) => Date;
|
|
17
|
-
declare export var getLastDateFromMonth: (month: number, asUTC?: boolean) => Date;
|
package/dist/utils.test.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
getDateFromMonthAndDay,
|
|
4
|
-
getLastDateFromMonth,
|
|
5
|
-
getMonthFromDate,
|
|
6
|
-
getMonthNameFromMonth,
|
|
7
|
-
getYearFromMonth,
|
|
8
|
-
} from './utils.js';
|
|
2
|
+
import { getDateFromMonthAndDay, getLastDateFromMonth, getMonthFromDate, getMonthNameFromMonth, getYearFromMonth, } from './utils.js';
|
|
9
3
|
const INVALID_DATE = new Date('');
|
|
10
4
|
describe('@acusti/date-picker', () => {
|
|
11
5
|
describe('utils', () => {
|
|
@@ -23,9 +17,7 @@ describe('@acusti/date-picker', () => {
|
|
|
23
17
|
expect(getMonthFromDate(date, true)).toBe(0);
|
|
24
18
|
// if test is run in a timezone behind UTC, ommitting asUTC returns -1
|
|
25
19
|
// if not, the month should be the same with or without asUTC flag
|
|
26
|
-
expect(getMonthFromDate(date)).toBe(
|
|
27
|
-
date.getTimezoneOffset() >= 60 ? -1 : 0,
|
|
28
|
-
);
|
|
20
|
+
expect(getMonthFromDate(date)).toBe(date.getTimezoneOffset() >= 60 ? -1 : 0);
|
|
29
21
|
});
|
|
30
22
|
it('returns NaN for an Invalid Date', () => {
|
|
31
23
|
expect(getMonthFromDate(INVALID_DATE)).toBe(NaN);
|
|
@@ -33,20 +25,12 @@ describe('@acusti/date-picker', () => {
|
|
|
33
25
|
});
|
|
34
26
|
describe('getYearFromMonth', () => {
|
|
35
27
|
it('returns the correct year for a post-unix epoch date', () => {
|
|
36
|
-
expect(getYearFromMonth(getMonthFromDate(new Date(1970, 0, 1)))).toBe(
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
expect(getYearFromMonth(getMonthFromDate(new Date(2048, 4, 31)))).toBe(
|
|
40
|
-
2048,
|
|
41
|
-
);
|
|
28
|
+
expect(getYearFromMonth(getMonthFromDate(new Date(1970, 0, 1)))).toBe(1970);
|
|
29
|
+
expect(getYearFromMonth(getMonthFromDate(new Date(2048, 4, 31)))).toBe(2048);
|
|
42
30
|
});
|
|
43
31
|
it('returns the correct year digit for a pre-unix epoch date', () => {
|
|
44
|
-
expect(getYearFromMonth(getMonthFromDate(new Date(1970, 0, 0)))).toBe(
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
expect(getYearFromMonth(getMonthFromDate(new Date(100, 11, 31)))).toBe(
|
|
48
|
-
100,
|
|
49
|
-
);
|
|
32
|
+
expect(getYearFromMonth(getMonthFromDate(new Date(1970, 0, 0)))).toBe(1969);
|
|
33
|
+
expect(getYearFromMonth(getMonthFromDate(new Date(100, 11, 31)))).toBe(100);
|
|
50
34
|
});
|
|
51
35
|
it('returns NaN for an Invalid Date', () => {
|
|
52
36
|
expect(getYearFromMonth(getMonthFromDate(INVALID_DATE))).toBe(NaN);
|
|
@@ -54,14 +38,10 @@ describe('@acusti/date-picker', () => {
|
|
|
54
38
|
});
|
|
55
39
|
describe('getMonthNameFromMonth', () => {
|
|
56
40
|
it('returns the correct month name for a post-unix epoch month', () => {
|
|
57
|
-
expect(
|
|
58
|
-
getMonthNameFromMonth(getMonthFromDate(new Date(2023, 5, 19))),
|
|
59
|
-
).toBe('June');
|
|
41
|
+
expect(getMonthNameFromMonth(getMonthFromDate(new Date(2023, 5, 19)))).toBe('June');
|
|
60
42
|
});
|
|
61
43
|
it('returns the correct month name for a pre-unix epoch month', () => {
|
|
62
|
-
expect(
|
|
63
|
-
getMonthNameFromMonth(getMonthFromDate(new Date(1865, 5, 2))),
|
|
64
|
-
).toBe('June');
|
|
44
|
+
expect(getMonthNameFromMonth(getMonthFromDate(new Date(1865, 5, 2)))).toBe('June');
|
|
65
45
|
});
|
|
66
46
|
it('returns an empty string if given NaN (e.g. if dealing with an Invalid Date)', () => {
|
|
67
47
|
expect(getMonthNameFromMonth(getMonthFromDate(INVALID_DATE))).toBe('');
|
|
@@ -69,76 +49,40 @@ describe('@acusti/date-picker', () => {
|
|
|
69
49
|
});
|
|
70
50
|
describe('getDateFromMonthAndDay', () => {
|
|
71
51
|
it('returns the date of the specified day for a post-unix epoch month', () => {
|
|
72
|
-
expect(
|
|
73
|
-
|
|
74
|
-
).toEqual(new Date(
|
|
75
|
-
expect(
|
|
76
|
-
getDateFromMonthAndDay(getMonthFromDate(new Date(1999, 11, 1)), 31),
|
|
77
|
-
).toEqual(new Date(1999, 11, 31));
|
|
78
|
-
expect(
|
|
79
|
-
getDateFromMonthAndDay(getMonthFromDate(new Date(2000, 0, 0)), 31),
|
|
80
|
-
).toEqual(new Date(1999, 11, 31));
|
|
52
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(2008, 2, 13)), 1)).toEqual(new Date(2008, 2, 1));
|
|
53
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(1999, 11, 1)), 31)).toEqual(new Date(1999, 11, 31));
|
|
54
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(2000, 0, 0)), 31)).toEqual(new Date(1999, 11, 31));
|
|
81
55
|
});
|
|
82
56
|
it('returns the correct date for a pre-unix epoch month', () => {
|
|
83
|
-
expect(
|
|
84
|
-
|
|
85
|
-
).toEqual(new Date(1865, 5, 30));
|
|
86
|
-
expect(
|
|
87
|
-
getDateFromMonthAndDay(getMonthFromDate(new Date(101, 0, 0)), 1),
|
|
88
|
-
).toEqual(new Date(100, 11, 1));
|
|
57
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(1865, 5, 2)), 30)).toEqual(new Date(1865, 5, 30));
|
|
58
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(101, 0, 0)), 1)).toEqual(new Date(100, 11, 1));
|
|
89
59
|
});
|
|
90
60
|
it('returns date for start of day as UTC time if asUTC is true', () => {
|
|
91
|
-
expect(
|
|
92
|
-
|
|
93
|
-
getMonthFromDate(new Date(1865, 5, 2)),
|
|
94
|
-
30,
|
|
95
|
-
true,
|
|
96
|
-
),
|
|
97
|
-
).toEqual(new Date(Date.UTC(1865, 5, 30)));
|
|
98
|
-
expect(
|
|
99
|
-
getDateFromMonthAndDay(
|
|
100
|
-
getMonthFromDate(new Date(101, 0, 0)),
|
|
101
|
-
1,
|
|
102
|
-
true,
|
|
103
|
-
),
|
|
104
|
-
).toEqual(new Date(Date.UTC(100, 11, 1)));
|
|
61
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(1865, 5, 2)), 30, true)).toEqual(new Date(Date.UTC(1865, 5, 30)));
|
|
62
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(new Date(101, 0, 0)), 1, true)).toEqual(new Date(Date.UTC(100, 11, 1)));
|
|
105
63
|
});
|
|
106
64
|
it('returns an invalid date if given NaN (e.g. if dealing with an Invalid Date)', () => {
|
|
107
|
-
expect(getDateFromMonthAndDay(getMonthFromDate(INVALID_DATE), 1)).toEqual(
|
|
108
|
-
INVALID_DATE,
|
|
109
|
-
);
|
|
65
|
+
expect(getDateFromMonthAndDay(getMonthFromDate(INVALID_DATE), 1)).toEqual(INVALID_DATE);
|
|
110
66
|
});
|
|
111
67
|
});
|
|
112
68
|
describe('getLastDateFromMonth', () => {
|
|
113
69
|
it('returns the date of the last day for a post-unix epoch month', () => {
|
|
114
|
-
expect(
|
|
115
|
-
getLastDateFromMonth(getMonthFromDate(new Date(2008, 2, 13))),
|
|
116
|
-
).toEqual(new Date(2008, 2, 31));
|
|
70
|
+
expect(getLastDateFromMonth(getMonthFromDate(new Date(2008, 2, 13)))).toEqual(new Date(2008, 2, 31));
|
|
117
71
|
// february in a leap year
|
|
118
|
-
expect(
|
|
119
|
-
getLastDateFromMonth(getMonthFromDate(new Date(2024, 1, 23))),
|
|
120
|
-
).toEqual(new Date(2024, 1, 29));
|
|
72
|
+
expect(getLastDateFromMonth(getMonthFromDate(new Date(2024, 1, 23)))).toEqual(new Date(2024, 1, 29));
|
|
121
73
|
// february in a non-leap year
|
|
122
|
-
expect(
|
|
123
|
-
getLastDateFromMonth(getMonthFromDate(new Date(1985, 1, 1))),
|
|
124
|
-
).toEqual(new Date(1985, 1, 28));
|
|
74
|
+
expect(getLastDateFromMonth(getMonthFromDate(new Date(1985, 1, 1)))).toEqual(new Date(1985, 1, 28));
|
|
125
75
|
});
|
|
126
76
|
it('returns the correct date for a pre-unix epoch month', () => {
|
|
127
|
-
expect(
|
|
128
|
-
getLastDateFromMonth(getMonthFromDate(new Date(1865, 5, 2))),
|
|
129
|
-
).toEqual(new Date(1865, 5, 30));
|
|
77
|
+
expect(getLastDateFromMonth(getMonthFromDate(new Date(1865, 5, 2)))).toEqual(new Date(1865, 5, 30));
|
|
130
78
|
});
|
|
131
79
|
it('returns date for start of day as UTC time if asUTC is true', () => {
|
|
132
|
-
expect(
|
|
133
|
-
getLastDateFromMonth(getMonthFromDate(new Date(1865, 5, 2)), true),
|
|
134
|
-
).toEqual(new Date(Date.UTC(1865, 5, 30)));
|
|
80
|
+
expect(getLastDateFromMonth(getMonthFromDate(new Date(1865, 5, 2)), true)).toEqual(new Date(Date.UTC(1865, 5, 30)));
|
|
135
81
|
});
|
|
136
82
|
it('returns an invalid date if given NaN (e.g. if dealing with an Invalid Date)', () => {
|
|
137
|
-
expect(getLastDateFromMonth(getMonthFromDate(INVALID_DATE))).toEqual(
|
|
138
|
-
INVALID_DATE,
|
|
139
|
-
);
|
|
83
|
+
expect(getLastDateFromMonth(getMonthFromDate(INVALID_DATE))).toEqual(INVALID_DATE);
|
|
140
84
|
});
|
|
141
85
|
});
|
|
142
86
|
});
|
|
143
87
|
});
|
|
144
|
-
//# sourceMappingURL=utils.test.js.map
|
|
88
|
+
//# sourceMappingURL=utils.test.js.map
|
package/dist/utils.test.js.flow
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acusti/date-picker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"homepage": "https://github.com/acusti/uikit/tree/main/packages/date-picker#readme",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@testing-library/dom": "^10.4.0",
|
|
46
|
-
"@testing-library/react": "^16.
|
|
47
|
-
"@testing-library/user-event": "^14.
|
|
48
|
-
"@types/react": "^19.
|
|
49
|
-
"happy-dom": "^
|
|
46
|
+
"@testing-library/react": "^16.3.0",
|
|
47
|
+
"@testing-library/user-event": "^14.6.1",
|
|
48
|
+
"@types/react": "^19.1.1",
|
|
49
|
+
"happy-dom": "^17.4.4",
|
|
50
50
|
"react": "^19.0.0",
|
|
51
51
|
"react-dom": "^19.0.0",
|
|
52
|
-
"typescript": "5.
|
|
53
|
-
"vitest": "^
|
|
52
|
+
"typescript": "5.8.3",
|
|
53
|
+
"vitest": "^3.1.1"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@acusti/styling": "^1.0
|
|
56
|
+
"@acusti/styling": "^0.7.2 || ^1.1.0",
|
|
57
57
|
"clsx": "^2"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|