Skip to content

Commit db4ebb8

Browse files
author
신용준
committed
release 1.4.0
1 parent 67666cd commit db4ebb8

File tree

6 files changed

+59
-24
lines changed

6 files changed

+59
-24
lines changed

package/CHANGE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.4.0
2+
3+
### What's New?
4+
5+
- remove ExtraController
6+
- New Props = isMultipleCalendar
7+
18
## 1.3.0
29

310
### What's New?

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shinyongjun/react-datepicker",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"main": "./dist/cjs/index.js",
55
"module": "./dist/esm/index.js",
66
"source": "./src/index.tsx",

package/src/assets/ReactDatepicker.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
}
3636
.react-datepicker__datepicker-container {
3737
position: absolute;
38-
width: 252px;
3938
top: 50px;
4039
left: 0;
4140
z-index: 1000;
@@ -85,19 +84,25 @@
8584
.react-datepicker__controller-next {
8685
background-image: url(./next.svg);
8786
}
87+
.react-datepicker__datepicker {
88+
display: flex;
89+
}
8890
.react-datepicker__century-view,
8991
.react-datepicker__decade-view,
9092
.react-datepicker__year-view {
9193
display: grid;
9294
grid-template-columns: repeat(3, 1fr);
95+
width: 252px;
9396
}
9497
.react-datepicker__month-view {
9598
display: grid;
9699
grid-template-columns: repeat(7, 1fr);
100+
width: 252px;
97101
}
98102
.react-datepicker__datepicker-button {
99103
border: none;
100104
background-color: transparent;
105+
flex-basis: 100%;
101106
height: 36px;
102107
cursor: pointer;
103108
}

package/src/components/Controller.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client';
22

33
import * as React from 'react';
4-
import { useMemo } from 'react';
54
import { NAME_SPACE } from '../constants/core';
65
import {
76
setCenturyPage,
@@ -19,6 +18,7 @@ interface IProps {
1918
setViewType: (value: TviewType) => void;
2019
viewDate: string;
2120
labelFormat: string;
21+
isMultipleCalendar: boolean;
2222
setViewDateByType: (
2323
value: string | number,
2424
type: 'year' | 'month' | 'date'
@@ -30,8 +30,17 @@ function Controller({
3030
viewType,
3131
labelFormat,
3232
setViewType,
33+
isMultipleCalendar,
3334
setViewDateByType,
3435
}: IProps) {
36+
const setMonthLabel = (date: string, addMonth = 0) => {
37+
const monthPage = setMonthPage(date);
38+
const year = Math.ceil((monthPage + addMonth) / 12);
39+
const month = addLeadingZero((monthPage + addMonth) % 12 || 12);
40+
41+
return formatLabel(`${year}-${month}`, labelFormat);
42+
};
43+
3544
const setLabel = (date: string, type: TviewType): string => {
3645
if (type === 'century') {
3746
const centuryPage = setCenturyPage(date);
@@ -53,20 +62,11 @@ function Controller({
5362
return `${yearPage}`;
5463
}
5564
if (type === 'month') {
56-
const monthPage = setMonthPage(date);
57-
const year = Math.ceil(monthPage / 12);
58-
const month = addLeadingZero(monthPage % 12 || 12);
59-
60-
return formatLabel(`${year}-${month}`, labelFormat);
65+
return setMonthLabel(date);
6166
}
6267
return '';
6368
};
6469

65-
const label = useMemo(
66-
() => setLabel(viewDate, viewType),
67-
[viewDate, viewType]
68-
);
69-
7070
const handleLabelClick = () => {
7171
if (viewType === 'decade') {
7272
setViewType('century');
@@ -111,14 +111,14 @@ function Controller({
111111

112112
return (
113113
<div className={`${NAME_SPACE}__controller`}>
114-
{viewType !== 'century' && (
114+
{/* {viewType !== 'century' && (
115115
<button
116116
className={`${NAME_SPACE}__controller-arrow ${NAME_SPACE}__controller-extra-prev`}
117117
onClick={() => handleControl('extraPrev')}
118118
>
119119
Extra Previous
120120
</button>
121-
)}
121+
)} */}
122122
<button
123123
className={`${NAME_SPACE}__controller-arrow ${NAME_SPACE}__controller-prev`}
124124
onClick={() => handleControl('prev')}
@@ -131,22 +131,31 @@ function Controller({
131131
onClick={handleLabelClick}
132132
disabled={viewType === 'century'}
133133
>
134-
{label}
134+
{setLabel(viewDate, viewType)}
135135
</button>
136+
{isMultipleCalendar && viewType === 'month' && (
137+
<button
138+
type="button"
139+
className={`${NAME_SPACE}__label`}
140+
onClick={handleLabelClick}
141+
>
142+
{setMonthLabel(viewDate, 1)}
143+
</button>
144+
)}
136145
<button
137146
className={`${NAME_SPACE}__controller-arrow ${NAME_SPACE}__controller-next`}
138147
onClick={() => handleControl('next')}
139148
>
140149
Next
141150
</button>
142-
{viewType !== 'century' && (
151+
{/* {viewType !== 'century' && (
143152
<button
144153
className={`${NAME_SPACE}__controller-arrow ${NAME_SPACE}__controller-extra-next`}
145154
onClick={() => handleControl('extraNext')}
146155
>
147156
Extra Next
148157
</button>
149-
)}
158+
)} */}
150159
</div>
151160
);
152161
}

package/src/components/Datepicker.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import useOutsideClick from '../hooks/useOutsideClick';
2222
interface Iprops {
2323
initValue?: Date | null;
2424
isClearButton?: boolean;
25+
isMultipleCalendar?: boolean;
2526
valueFormat?: string;
2627
labelFormat?: string;
2728
onChange?: (activeDate: Date | null) => void;
@@ -30,6 +31,7 @@ interface Iprops {
3031
function Datepicker({
3132
initValue = null,
3233
isClearButton = false,
34+
isMultipleCalendar = false,
3335
valueFormat = 'YYYY-MM-DD',
3436
labelFormat = 'YYYY / MM',
3537
onChange,
@@ -128,16 +130,27 @@ function Datepicker({
128130
setViewType={setViewType}
129131
viewDate={viewDate}
130132
labelFormat={labelFormat}
133+
isMultipleCalendar={isMultipleCalendar}
131134
setViewDateByType={setViewDateByType}
132135
/>
133136
<div className={`${NAME_SPACE}__datepicker`}>
134137
{viewType === 'month' && (
135-
<ViewMonth
136-
value={value}
137-
valueFormat={valueFormat}
138-
monthPage={monthPage}
139-
setValue={setValue}
140-
/>
138+
<>
139+
<ViewMonth
140+
value={value}
141+
valueFormat={valueFormat}
142+
monthPage={monthPage}
143+
setValue={setValue}
144+
/>
145+
{isMultipleCalendar && (
146+
<ViewMonth
147+
value={value}
148+
valueFormat={valueFormat}
149+
monthPage={monthPage + 1}
150+
setValue={setValue}
151+
/>
152+
)}
153+
</>
141154
)}
142155
{viewType === 'year' && (
143156
<ViewYear

test/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function App() {
1414
}}
1515
/>
1616
<Datepicker />
17+
<Datepicker isMultipleCalendar />
1718
<Datepicker isClearButton />
1819
<Datepicker valueFormat="MM/DD/YYYY" />
1920
<Datepicker labelFormat="YYYY년 MM월" />

0 commit comments

Comments
 (0)