@jk-core/components 1.1.10 → 1.1.11
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 +73 -73
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +99 -99
- package/src/Calendar/Calendar.module.scss +213 -213
- package/src/Calendar/RangeCalendar.tsx +125 -125
- package/src/Calendar/ScrollCalendar.module.scss +214 -214
- package/src/Calendar/ScrollCalendar.tsx +124 -124
- package/src/Calendar/SingleCalendar.tsx +121 -121
- package/src/Calendar/components/DateLabel/DateLabel.module.scss +89 -89
- package/src/Calendar/components/DateLabel/index.tsx +91 -91
- package/src/Calendar/components/DayTile/DayTile.module.scss +117 -117
- package/src/Calendar/components/DayTile/index.tsx +108 -108
- package/src/Calendar/components/MonthTile/MonthTile.module.scss +59 -59
- package/src/Calendar/components/MonthTile/index.tsx +50 -50
- package/src/Calendar/components/ViewSelector/ViewSelector.module.scss +48 -48
- package/src/Calendar/components/ViewSelector/index.tsx +49 -49
- package/src/Calendar/components/YearTile/YearTile.module.scss +85 -85
- package/src/Calendar/components/YearTile/index.tsx +65 -65
- package/src/Calendar/hooks/useCalendarNav.ts +83 -83
- package/src/Calendar/hooks/useDateSelect.ts +54 -54
- package/src/Calendar/index.scss +189 -189
- package/src/Calendar/index.tsx +66 -66
- package/src/Calendar/type.ts +3 -3
- package/src/Calendar/utils/getWeeksInMonth.ts +45 -45
- package/src/Calendar/utils/isInRange.ts +8 -8
- package/src/Calendar/utils/isSameDay.ts +21 -21
- package/src/assets/arrow.svg +11 -11
- package/src/assets/close.svg +15 -15
- package/src/assets/drop-arrow.svg +3 -3
- package/src/common/Accordion/Accordion.module.scss +53 -53
- package/src/common/Accordion/arrow-down.svg +3 -3
- package/src/common/Accordion/arrow-up.svg +3 -3
- package/src/common/Accordion/index.tsx +54 -54
- package/src/common/Breadcrumbs/Breadcrumbs.module.scss +46 -46
- package/src/common/Breadcrumbs/home.svg +5 -5
- package/src/common/Breadcrumbs/index.tsx +82 -82
- package/src/common/Button/Button.module.scss +127 -127
- package/src/common/Button/index.tsx +60 -60
- package/src/common/Card/Card.module.scss +28 -28
- package/src/common/Card/index.tsx +19 -19
- package/src/common/Divider/Divider.module.scss +101 -101
- package/src/common/Divider/index.tsx +24 -24
- package/src/common/DropDown/DropDown.module.scss +135 -135
- package/src/common/DropDown/List.tsx +156 -156
- package/src/common/DropDown/arrow-down.svg +3 -3
- package/src/common/DropDown/index.tsx +103 -103
- package/src/common/DropDown/search.svg +4 -4
- package/src/common/Pagination/Pagination.module.scss +210 -210
- package/src/common/Pagination/arrow-left.svg +11 -11
- package/src/common/Pagination/arrow-right.svg +11 -11
- package/src/common/Pagination/index.tsx +156 -156
- package/src/common/SegmentButton/SegmentButton.module.scss +45 -45
- package/src/common/SegmentButton/index.tsx +79 -79
- package/src/common/Skeleton/Skeleton.module.scss +80 -80
- package/src/common/Skeleton/index.tsx +47 -47
- package/src/common/SwitchButton/SwitchButton.module.scss +65 -65
- package/src/common/SwitchButton/index.tsx +56 -56
- package/src/common/Table/Table.module.scss +70 -70
- package/src/common/Table/index.tsx +128 -128
- package/src/index.scss +1 -1
- package/src/index.tsx +21 -21
- package/src/styles/color.scss +346 -94
- package/src/styles/font-face.scss +18 -18
- package/src/styles/font.scss +49 -49
- package/src/styles/mediaQuery.scss +22 -22
- package/src/styles/scrollbar.scss +71 -71
- package/src/svg.d.ts +6 -6
- package/src/utils/styles/mediaQuery.scss +22 -22
- package/src/utils/ts/allowDecimal.ts +4 -4
- package/src/utils/ts/autoHypen.ts +33 -33
- package/src/utils/ts/calculateMax.ts +24 -24
- package/src/utils/ts/checkIsMobilePlatform.ts +15 -15
- package/src/utils/ts/formatFileSize.ts +16 -16
- package/src/utils/ts/formatMoney.ts +16 -16
- package/src/utils/ts/gradientRatio.ts +61 -61
- package/src/utils/ts/kiloToMega.ts +30 -30
- package/src/utils/ts/maskingPhone.ts +8 -8
- package/src/utils/ts/toQueryString.ts +7 -7
- package/src/utils/ts/valueAsNumber.ts +15 -15
- package/src/vite-env.d.ts +2 -2
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { cn } from '@jk-core/utils';
|
|
3
|
-
import { CalendarView } from '@/Calendar/type';
|
|
4
|
-
import styles from './YearTile.module.scss';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
selectedDate?: Date;
|
|
8
|
-
onClick: (year: number) => void;
|
|
9
|
-
tileContent?: (date: Date, view:CalendarView) => React.ReactNode;
|
|
10
|
-
max: Date;
|
|
11
|
-
min: Date;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default function YearTile({
|
|
15
|
-
selectedDate, onClick,
|
|
16
|
-
tileContent = () => false,
|
|
17
|
-
max, min,
|
|
18
|
-
}: Props) {
|
|
19
|
-
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
20
|
-
const selectedRef = useRef<HTMLButtonElement>(null);
|
|
21
|
-
const YEARS = Array.from(
|
|
22
|
-
{ length: max.getFullYear() - min.getFullYear() + 1 },
|
|
23
|
-
(_, i) => min.getFullYear() + i,
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const selectedElement = selectedRef.current;
|
|
28
|
-
const wrapperElement = wrapperRef.current;
|
|
29
|
-
if (!selectedElement || !wrapperElement) return;
|
|
30
|
-
|
|
31
|
-
const { clientHeight } = wrapperElement;
|
|
32
|
-
const { offsetTop, clientHeight: selectedHeight } = selectedElement;
|
|
33
|
-
|
|
34
|
-
wrapperElement.scrollTo({
|
|
35
|
-
top: offsetTop - clientHeight / 2 + selectedHeight,
|
|
36
|
-
});
|
|
37
|
-
}, []);
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div className={styles['year-tile']} ref={wrapperRef}>
|
|
41
|
-
<div className={styles['year-tile__blank']} />
|
|
42
|
-
{YEARS.map((year) => (
|
|
43
|
-
<button
|
|
44
|
-
className={cn({
|
|
45
|
-
[styles['year-tile__year']]: true,
|
|
46
|
-
[styles['year-tile__year--selected']]: !!selectedDate && selectedDate.getFullYear() === year,
|
|
47
|
-
[styles['year-tile__year--border']]: !!tileContent(new Date(year, 1, 1), 'year'),
|
|
48
|
-
})}
|
|
49
|
-
key={year}
|
|
50
|
-
type="button"
|
|
51
|
-
ref={!!selectedDate && selectedDate.getFullYear() === year ? selectedRef : null}
|
|
52
|
-
onClick={() => onClick(year)}
|
|
53
|
-
>
|
|
54
|
-
<span className={styles['yearTile__year--year']}>{year}</span>
|
|
55
|
-
{tileContent(new Date(year, 1, 1), 'year') && (
|
|
56
|
-
<div className={styles['yearTile__year--tile']}>
|
|
57
|
-
{tileContent(new Date(year, 1, 1), 'year')}
|
|
58
|
-
</div>
|
|
59
|
-
)}
|
|
60
|
-
</button>
|
|
61
|
-
))}
|
|
62
|
-
<div className={styles['year-tile__blank']} />
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { cn } from '@jk-core/utils';
|
|
3
|
+
import { CalendarView } from '@/Calendar/type';
|
|
4
|
+
import styles from './YearTile.module.scss';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
selectedDate?: Date;
|
|
8
|
+
onClick: (year: number) => void;
|
|
9
|
+
tileContent?: (date: Date, view:CalendarView) => React.ReactNode;
|
|
10
|
+
max: Date;
|
|
11
|
+
min: Date;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function YearTile({
|
|
15
|
+
selectedDate, onClick,
|
|
16
|
+
tileContent = () => false,
|
|
17
|
+
max, min,
|
|
18
|
+
}: Props) {
|
|
19
|
+
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
20
|
+
const selectedRef = useRef<HTMLButtonElement>(null);
|
|
21
|
+
const YEARS = Array.from(
|
|
22
|
+
{ length: max.getFullYear() - min.getFullYear() + 1 },
|
|
23
|
+
(_, i) => min.getFullYear() + i,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const selectedElement = selectedRef.current;
|
|
28
|
+
const wrapperElement = wrapperRef.current;
|
|
29
|
+
if (!selectedElement || !wrapperElement) return;
|
|
30
|
+
|
|
31
|
+
const { clientHeight } = wrapperElement;
|
|
32
|
+
const { offsetTop, clientHeight: selectedHeight } = selectedElement;
|
|
33
|
+
|
|
34
|
+
wrapperElement.scrollTo({
|
|
35
|
+
top: offsetTop - clientHeight / 2 + selectedHeight,
|
|
36
|
+
});
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className={styles['year-tile']} ref={wrapperRef}>
|
|
41
|
+
<div className={styles['year-tile__blank']} />
|
|
42
|
+
{YEARS.map((year) => (
|
|
43
|
+
<button
|
|
44
|
+
className={cn({
|
|
45
|
+
[styles['year-tile__year']]: true,
|
|
46
|
+
[styles['year-tile__year--selected']]: !!selectedDate && selectedDate.getFullYear() === year,
|
|
47
|
+
[styles['year-tile__year--border']]: !!tileContent(new Date(year, 1, 1), 'year'),
|
|
48
|
+
})}
|
|
49
|
+
key={year}
|
|
50
|
+
type="button"
|
|
51
|
+
ref={!!selectedDate && selectedDate.getFullYear() === year ? selectedRef : null}
|
|
52
|
+
onClick={() => onClick(year)}
|
|
53
|
+
>
|
|
54
|
+
<span className={styles['yearTile__year--year']}>{year}</span>
|
|
55
|
+
{tileContent(new Date(year, 1, 1), 'year') && (
|
|
56
|
+
<div className={styles['yearTile__year--tile']}>
|
|
57
|
+
{tileContent(new Date(year, 1, 1), 'year')}
|
|
58
|
+
</div>
|
|
59
|
+
)}
|
|
60
|
+
</button>
|
|
61
|
+
))}
|
|
62
|
+
<div className={styles['year-tile__blank']} />
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { CalendarView } from '../type';
|
|
2
|
-
|
|
3
|
-
interface Props {
|
|
4
|
-
method: CalendarView;
|
|
5
|
-
selectMode: CalendarView;
|
|
6
|
-
viewDate: Date;
|
|
7
|
-
setDate:(date: Date) => void;
|
|
8
|
-
min: Date;
|
|
9
|
-
max: Date;
|
|
10
|
-
}
|
|
11
|
-
const useCalendarNav = ({
|
|
12
|
-
method, selectMode, viewDate, setDate, min, max,
|
|
13
|
-
}:Props) => {
|
|
14
|
-
const disabled = (direction: 'prev' | 'next') => {
|
|
15
|
-
if (selectMode === 'year' || method !== selectMode) return true;
|
|
16
|
-
|
|
17
|
-
if (method === 'day') {
|
|
18
|
-
if (direction === 'prev') {
|
|
19
|
-
const prevMonth = new Date(viewDate.getFullYear(), viewDate.getMonth() - 1, 1);
|
|
20
|
-
const isPrevMonthBeforeMin = prevMonth.getFullYear() < min.getFullYear()
|
|
21
|
-
|| (prevMonth.getFullYear() === min.getFullYear()
|
|
22
|
-
&& prevMonth.getMonth() < min.getMonth());
|
|
23
|
-
return isPrevMonthBeforeMin;
|
|
24
|
-
}
|
|
25
|
-
const nextMonth = new Date(viewDate.getFullYear(), viewDate.getMonth() + 1, 1);
|
|
26
|
-
return nextMonth > max;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (method === 'month') {
|
|
30
|
-
if (direction === 'prev') {
|
|
31
|
-
const prevYear = new Date(viewDate.getFullYear() - 1, viewDate.getMonth(), 1);
|
|
32
|
-
return prevYear < min;
|
|
33
|
-
}
|
|
34
|
-
const nextYear = new Date(viewDate.getFullYear() + 1, viewDate.getMonth(), 1);
|
|
35
|
-
return nextYear > max;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (method === 'year') {
|
|
39
|
-
if (direction === 'prev') {
|
|
40
|
-
const prevDecade = new Date(viewDate.getFullYear() - 10, viewDate.getMonth(), 1);
|
|
41
|
-
return prevDecade < min;
|
|
42
|
-
}
|
|
43
|
-
const nextDecade = new Date(viewDate.getFullYear() + 10, viewDate.getMonth(), 1);
|
|
44
|
-
return nextDecade > max;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return false;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const onArrowClick = (direction: 'prev' | 'next') => {
|
|
51
|
-
const offset = direction === 'prev' ? -1 : 1;
|
|
52
|
-
const minDate = new Date(2000, 0, 1);
|
|
53
|
-
const maxDate = new Date(2099, 11, 31);
|
|
54
|
-
|
|
55
|
-
if (method === 'day') {
|
|
56
|
-
const newDate = new Date(viewDate.getFullYear(), viewDate.getMonth() + offset, 1);
|
|
57
|
-
|
|
58
|
-
if (newDate >= minDate && newDate <= maxDate) {
|
|
59
|
-
setDate(newDate);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (method === 'month') {
|
|
64
|
-
const newDate = new Date(viewDate.getFullYear() + offset, viewDate.getMonth(), 1);
|
|
65
|
-
|
|
66
|
-
if (newDate >= minDate && newDate <= maxDate) {
|
|
67
|
-
setDate(newDate);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (method === 'year') {
|
|
72
|
-
const newDate = new Date(viewDate.getFullYear() + offset * 10, viewDate.getMonth(), 1);
|
|
73
|
-
|
|
74
|
-
if (newDate >= minDate && newDate <= maxDate) {
|
|
75
|
-
setDate(newDate);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return { disabled, onArrowClick };
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export default useCalendarNav;
|
|
1
|
+
import { CalendarView } from '../type';
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
method: CalendarView;
|
|
5
|
+
selectMode: CalendarView;
|
|
6
|
+
viewDate: Date;
|
|
7
|
+
setDate:(date: Date) => void;
|
|
8
|
+
min: Date;
|
|
9
|
+
max: Date;
|
|
10
|
+
}
|
|
11
|
+
const useCalendarNav = ({
|
|
12
|
+
method, selectMode, viewDate, setDate, min, max,
|
|
13
|
+
}:Props) => {
|
|
14
|
+
const disabled = (direction: 'prev' | 'next') => {
|
|
15
|
+
if (selectMode === 'year' || method !== selectMode) return true;
|
|
16
|
+
|
|
17
|
+
if (method === 'day') {
|
|
18
|
+
if (direction === 'prev') {
|
|
19
|
+
const prevMonth = new Date(viewDate.getFullYear(), viewDate.getMonth() - 1, 1);
|
|
20
|
+
const isPrevMonthBeforeMin = prevMonth.getFullYear() < min.getFullYear()
|
|
21
|
+
|| (prevMonth.getFullYear() === min.getFullYear()
|
|
22
|
+
&& prevMonth.getMonth() < min.getMonth());
|
|
23
|
+
return isPrevMonthBeforeMin;
|
|
24
|
+
}
|
|
25
|
+
const nextMonth = new Date(viewDate.getFullYear(), viewDate.getMonth() + 1, 1);
|
|
26
|
+
return nextMonth > max;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (method === 'month') {
|
|
30
|
+
if (direction === 'prev') {
|
|
31
|
+
const prevYear = new Date(viewDate.getFullYear() - 1, viewDate.getMonth(), 1);
|
|
32
|
+
return prevYear < min;
|
|
33
|
+
}
|
|
34
|
+
const nextYear = new Date(viewDate.getFullYear() + 1, viewDate.getMonth(), 1);
|
|
35
|
+
return nextYear > max;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (method === 'year') {
|
|
39
|
+
if (direction === 'prev') {
|
|
40
|
+
const prevDecade = new Date(viewDate.getFullYear() - 10, viewDate.getMonth(), 1);
|
|
41
|
+
return prevDecade < min;
|
|
42
|
+
}
|
|
43
|
+
const nextDecade = new Date(viewDate.getFullYear() + 10, viewDate.getMonth(), 1);
|
|
44
|
+
return nextDecade > max;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const onArrowClick = (direction: 'prev' | 'next') => {
|
|
51
|
+
const offset = direction === 'prev' ? -1 : 1;
|
|
52
|
+
const minDate = new Date(2000, 0, 1);
|
|
53
|
+
const maxDate = new Date(2099, 11, 31);
|
|
54
|
+
|
|
55
|
+
if (method === 'day') {
|
|
56
|
+
const newDate = new Date(viewDate.getFullYear(), viewDate.getMonth() + offset, 1);
|
|
57
|
+
|
|
58
|
+
if (newDate >= minDate && newDate <= maxDate) {
|
|
59
|
+
setDate(newDate);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (method === 'month') {
|
|
64
|
+
const newDate = new Date(viewDate.getFullYear() + offset, viewDate.getMonth(), 1);
|
|
65
|
+
|
|
66
|
+
if (newDate >= minDate && newDate <= maxDate) {
|
|
67
|
+
setDate(newDate);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (method === 'year') {
|
|
72
|
+
const newDate = new Date(viewDate.getFullYear() + offset * 10, viewDate.getMonth(), 1);
|
|
73
|
+
|
|
74
|
+
if (newDate >= minDate && newDate <= maxDate) {
|
|
75
|
+
setDate(newDate);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return { disabled, onArrowClick };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default useCalendarNav;
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { CalendarView } from '../type';
|
|
2
|
-
|
|
3
|
-
interface UseDateSelectProps {
|
|
4
|
-
viewDate: Date;
|
|
5
|
-
setViewDate: (date: Date) => void;
|
|
6
|
-
method: CalendarView;
|
|
7
|
-
setSelectMode:(mode:CalendarView) => void;
|
|
8
|
-
onChange: (date: Date) => void;
|
|
9
|
-
setView:(view:CalendarView)=>void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const useDateSelect = ({
|
|
13
|
-
viewDate, setViewDate, onChange, setSelectMode, method, setView,
|
|
14
|
-
}: UseDateSelectProps) => {
|
|
15
|
-
const min = new Date(2000, 0, 1);
|
|
16
|
-
const max = new Date(2099, 11, 31);
|
|
17
|
-
|
|
18
|
-
const onDayClick = (day: Date) => {
|
|
19
|
-
if (day < min || day > max) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
setViewDate(day);
|
|
24
|
-
setView('day');
|
|
25
|
-
onChange(day);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const onMonthClick = (month:number) => {
|
|
29
|
-
const newDate = new Date(viewDate.getFullYear(), month, 1);
|
|
30
|
-
|
|
31
|
-
setViewDate(newDate);
|
|
32
|
-
|
|
33
|
-
if (method !== 'month') setSelectMode(method);
|
|
34
|
-
if (method === 'month') {
|
|
35
|
-
setView('month');
|
|
36
|
-
onChange(newDate);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const onYearClick = (year:number) => {
|
|
41
|
-
const newDate = new Date(year, 0, 1);
|
|
42
|
-
|
|
43
|
-
setViewDate(newDate);
|
|
44
|
-
if (method !== 'year') setSelectMode(method);
|
|
45
|
-
if (method === 'year') {
|
|
46
|
-
setView('year');
|
|
47
|
-
onChange(newDate);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return { onDayClick, onMonthClick, onYearClick };
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export default useDateSelect;
|
|
1
|
+
import { CalendarView } from '../type';
|
|
2
|
+
|
|
3
|
+
interface UseDateSelectProps {
|
|
4
|
+
viewDate: Date;
|
|
5
|
+
setViewDate: (date: Date) => void;
|
|
6
|
+
method: CalendarView;
|
|
7
|
+
setSelectMode:(mode:CalendarView) => void;
|
|
8
|
+
onChange: (date: Date) => void;
|
|
9
|
+
setView:(view:CalendarView)=>void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const useDateSelect = ({
|
|
13
|
+
viewDate, setViewDate, onChange, setSelectMode, method, setView,
|
|
14
|
+
}: UseDateSelectProps) => {
|
|
15
|
+
const min = new Date(2000, 0, 1);
|
|
16
|
+
const max = new Date(2099, 11, 31);
|
|
17
|
+
|
|
18
|
+
const onDayClick = (day: Date) => {
|
|
19
|
+
if (day < min || day > max) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setViewDate(day);
|
|
24
|
+
setView('day');
|
|
25
|
+
onChange(day);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const onMonthClick = (month:number) => {
|
|
29
|
+
const newDate = new Date(viewDate.getFullYear(), month, 1);
|
|
30
|
+
|
|
31
|
+
setViewDate(newDate);
|
|
32
|
+
|
|
33
|
+
if (method !== 'month') setSelectMode(method);
|
|
34
|
+
if (method === 'month') {
|
|
35
|
+
setView('month');
|
|
36
|
+
onChange(newDate);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const onYearClick = (year:number) => {
|
|
41
|
+
const newDate = new Date(year, 0, 1);
|
|
42
|
+
|
|
43
|
+
setViewDate(newDate);
|
|
44
|
+
if (method !== 'year') setSelectMode(method);
|
|
45
|
+
if (method === 'year') {
|
|
46
|
+
setView('year');
|
|
47
|
+
onChange(newDate);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return { onDayClick, onMonthClick, onYearClick };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default useDateSelect;
|