Skip to content

Commit 7a9d0c6

Browse files
author
신용준
committed
2 parents dcde68e + ae86fee commit 7a9d0c6

File tree

10 files changed

+86
-7
lines changed

10 files changed

+86
-7
lines changed

package/CHANGE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 1.8.0
2+
3+
### What's New?
4+
5+
- add props `initStartValue` of `Rangepicker`
6+
- add props `initEndValue` of `Rangepicker`
7+
- add props `onChange` of `Rangepicker`
8+
9+
## 1.7.0
10+
11+
### What's New?
12+
13+
- add props weekdayLabels - An option that allows you to label the day of the week in any format that you want.
14+
115
## 1.6.0
216

317
### What's New?

package/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# React Datepicker
22

3-
![Datepicker](https://github.com/shinyj1991/react-datepicker/raw/main/package/public/readme-1.png)
3+
![Datepicker](https://github.com/shinyj1991/react-datepicker/raw/main/package/public/readme-2.jpg)
44

55
Example - [Link](https://shinyongjun.com/react-datepicker/example)
66

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.7.0",
3+
"version": "1.9.0",
44
"main": "./dist/cjs/index.js",
55
"module": "./dist/esm/index.js",
66
"source": "./src/index.tsx",

package/public/readme-2.jpg

71.2 KB
Loading

package/src/assets/ReactDatepicker.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,19 @@
100100
grid-template-columns: repeat(7, 1fr);
101101
width: 252px;
102102
}
103+
.react-datepicker__weekday {
104+
display: flex;
105+
align-items: center;
106+
justify-content: center;
107+
text-align: center;
108+
flex-basis: 100%;
109+
height: 36px;
110+
color: #000;
111+
}
103112
.react-datepicker__datepicker-button {
113+
display: flex;
114+
align-items: center;
115+
justify-content: center;
104116
border: none;
105117
background-color: transparent;
106118
flex-basis: 100%;

package/src/components/Datepicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface IProps {
2020
valueFormat?: string;
2121
labelFormat?: string;
2222
closesAfterChange?: boolean;
23+
weekdayLabels?: string[];
2324
onChange?: (activeDate: Date | null) => void;
2425
}
2526

@@ -30,6 +31,7 @@ function Datepicker({
3031
valueFormat = 'YYYY-MM-DD',
3132
labelFormat = 'YYYY / MM',
3233
closesAfterChange = true,
34+
weekdayLabels = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
3335
onChange,
3436
}: IProps) {
3537
// 인수가 없을 땐 LOCAL 기준 현재 시간을 반환한다.
@@ -87,13 +89,15 @@ function Datepicker({
8789
value={value}
8890
valueFormat={valueFormat}
8991
monthPage={monthPage}
92+
weekdayLabels={weekdayLabels}
9093
setValue={setValue}
9194
/>
9295
{showsMultipleCalendar && (
9396
<DatepickerMonth
9497
value={value}
9598
valueFormat={valueFormat}
9699
monthPage={monthPage + 1}
100+
weekdayLabels={weekdayLabels}
97101
setValue={setValue}
98102
/>
99103
)}

package/src/components/Rangepicker.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,32 @@ import InputRange from './input/Range';
1515

1616
interface IProps {
1717
// initValue?: Date | null;
18+
initStartValue?: Date | null;
19+
initEndValue?: Date | null;
1820
useClearButton?: boolean;
1921
showsMultipleCalendar?: boolean;
2022
valueFormat?: string;
2123
labelFormat?: string;
2224
closesAfterChange?: boolean;
23-
onChange?: (activeDate: Date | null) => void;
25+
weekdayLabels?: string[];
26+
onChange?: (startDate: Date | null, endDate: Date | null) => void;
2427
}
2528

2629
function Rangepicker({
27-
// initValue = null,
30+
initStartValue = null,
31+
initEndValue = null,
2832
useClearButton = false,
2933
showsMultipleCalendar = false,
3034
valueFormat = 'YYYY-MM-DD',
3135
labelFormat = 'YYYY / MM',
3236
closesAfterChange = true,
37+
weekdayLabels = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
3338
onChange,
3439
}: IProps) {
3540
// 인수가 없을 땐 LOCAL 기준 현재 시간을 반환한다.
3641
const NEW_DATE = new Date();
37-
const [startValue, setStartValue] = useState<Date | null>(null);
38-
const [endValue, setEndValue] = useState<Date | null>(null);
42+
const [startValue, setStartValue] = useState<Date | null>(initStartValue);
43+
const [endValue, setEndValue] = useState<Date | null>(initEndValue);
3944
const [hoverValue, setHoverValue] = useState<Date | null>(null);
4045
const [viewDate, setViewDate] = useState<string>(
4146
formatDate(startValue || NEW_DATE, 'YYYY-MM-DD')
@@ -61,6 +66,12 @@ function Rangepicker({
6166
// eslint-disable-next-line react-hooks/exhaustive-deps
6267
}, [endValue, onChange, setViewDate]);
6368

69+
useEffect(() => {
70+
if (onChange) {
71+
onChange(startValue, endValue);
72+
}
73+
}, [startValue, endValue, onChange]);
74+
6475
return (
6576
<div className={`${NAME_SPACE}__wrapper`}>
6677
<InputRange
@@ -91,6 +102,7 @@ function Rangepicker({
91102
hoverValue={hoverValue}
92103
valueFormat={valueFormat}
93104
monthPage={monthPage}
105+
weekdayLabels={weekdayLabels}
94106
setStartValue={setStartValue}
95107
setEndValue={setEndValue}
96108
setHoverValue={setHoverValue}
@@ -102,6 +114,7 @@ function Rangepicker({
102114
hoverValue={hoverValue}
103115
valueFormat={valueFormat}
104116
monthPage={monthPage + 1}
117+
weekdayLabels={weekdayLabels}
105118
setStartValue={setStartValue}
106119
setEndValue={setEndValue}
107120
setHoverValue={setHoverValue}

package/src/components/datepicker/Month.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ interface Iprops {
88
value: Date | null;
99
valueFormat: string;
1010
monthPage: number;
11+
weekdayLabels: string[];
1112
setValue: (value: Date) => void;
1213
}
1314

14-
function DatepicerMonth({ value, valueFormat, monthPage, setValue }: Iprops) {
15+
function DatepicerMonth({
16+
value,
17+
valueFormat,
18+
monthPage,
19+
weekdayLabels,
20+
setValue,
21+
}: Iprops) {
1522
const year = Math.ceil(monthPage / 12);
1623
const month = monthPage % 12 || 12;
1724
const firstDay = new Date(year, month - 1, 1).getDay(); // 이달 1일의 요일
@@ -46,6 +53,11 @@ function DatepicerMonth({ value, valueFormat, monthPage, setValue }: Iprops) {
4653

4754
return (
4855
<div className={`${NAME_SPACE}__month-view`}>
56+
{weekdayLabels.map((day, index) => (
57+
<div className={`${NAME_SPACE}__weekday`} data-day={index} key={day}>
58+
{day}
59+
</div>
60+
))}
4961
{Array.apply(0, Array(firstDay)).map((x, i) => {
5062
const date = prevLastDate - (firstDay - i - 1);
5163
const thisValue = new Date(-1, monthPage + 22, date);

package/src/components/rangepicker/Month.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface Iprops {
1010
hoverValue: Date | null;
1111
valueFormat: string;
1212
monthPage: number;
13+
weekdayLabels: string[];
1314
setStartValue: (value: Date | null) => void;
1415
setEndValue: (value: Date | null) => void;
1516
setHoverValue: (value: Date | null) => void;
@@ -21,6 +22,7 @@ function RangepicerMonth({
2122
hoverValue,
2223
valueFormat,
2324
monthPage,
25+
weekdayLabels,
2426
setStartValue,
2527
setEndValue,
2628
setHoverValue,
@@ -94,6 +96,11 @@ function RangepicerMonth({
9496

9597
return (
9698
<div className={`${NAME_SPACE}__month-view`}>
99+
{weekdayLabels.map((day, index) => (
100+
<div className={`${NAME_SPACE}__weekday`} data-day={index} key={day}>
101+
{day}
102+
</div>
103+
))}
97104
{Array.apply(0, Array(firstDay)).map((x, i) => {
98105
const date = prevLastDate - (firstDay - i - 1);
99106
const thisValue = new Date(-1, monthPage + 22, date);

test/src/App.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ function App() {
2222
<Rangepicker />
2323
<Rangepicker showsMultipleCalendar />
2424
<Rangepicker closesAfterChange={false} />
25+
<Rangepicker
26+
weekdayLabels={['일', '월', '화', '수', '목', '금', '토']}
27+
showsMultipleCalendar
28+
closesAfterChange={false}
29+
/>
30+
<Rangepicker
31+
weekdayLabels={['일', '월', '화', '수', '목', '금', '토']}
32+
showsMultipleCalendar
33+
closesAfterChange={false}
34+
onChange={(startDate, endDate) => {
35+
console.log(startDate, endDate);
36+
}}
37+
/>
38+
<Rangepicker
39+
initStartValue={new Date(2023, 7, 1)}
40+
initEndValue={new Date(2023, 8, 7)}
41+
/>
2542
</div>
2643
);
2744
}

0 commit comments

Comments
 (0)