Skip to content

Commit 5773b34

Browse files
committed
feat: create a hook to use calendar
1 parent a71735a commit 5773b34

25 files changed

Lines changed: 4509 additions & 1700 deletions

packages/react-date-time-picker-component/src/app/App.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/react-date-time-picker-component/src/lib/components/DateTimePicker.tsx

Lines changed: 0 additions & 161 deletions
This file was deleted.

packages/react-date-time-picker-component/src/lib/components/Portal.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/react-date-time-picker-component/src/lib/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

packages/react-date-time-picker-component/package.json renamed to packages/react-use-calendar-component/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "react-date-time-picker-component",
2+
"name": "react-use-calendar-component",
33
"version": "0.0.0",
44
"type": "module",
55
"scripts": {
@@ -19,8 +19,8 @@
1919
"dist"
2020
],
2121
"types": "./dist/types/index.d.ts",
22-
"main": "./dist/react-date-time-picker-component.umd.cjs",
23-
"module": "./dist/react-date-time-picker-component.js",
22+
"main": "./dist/react-use-calendar-component.umd.cjs",
23+
"module": "./dist/react-use-calendar-component.js",
2424
"devDependencies": {
2525
"react": "^18.2.0",
2626
"react-dom": "^18.2.0",

packages/react-date-time-picker-component/src/app/App.css renamed to packages/react-use-calendar-component/src/app/App.css

File renamed without changes.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { useCalendarComponent } from '../lib';
2+
import { getWeekDayList } from '../lib/utils/locale';
3+
4+
const weekDayList = getWeekDayList();
5+
6+
function App() {
7+
const {
8+
displayedYear,
9+
displayedMonth,
10+
addMonth,
11+
addYear,
12+
getDateCellInfos,
13+
setSelectedDate,
14+
} = useCalendarComponent();
15+
16+
const dateCells = getDateCellInfos().map(
17+
({ key, year, month, monthStatus, dayOfMonth, isToday, isSelected }) => {
18+
let className = 'c-day-container';
19+
if (monthStatus !== 'current') className = `${className} disabled`;
20+
if (isToday) className = `${className} highlight`;
21+
if (isSelected) className = `${className} highlight-green`;
22+
23+
return (
24+
<div
25+
key={key}
26+
className={className}
27+
onClick={() => {
28+
setSelectedDate(
29+
{
30+
year,
31+
month,
32+
dayOfMonth,
33+
},
34+
{ shouldChangePanel: true }
35+
);
36+
}}>
37+
<div className='cdc-day'>
38+
<span>{dayOfMonth}</span>
39+
</div>
40+
</div>
41+
);
42+
}
43+
);
44+
45+
return (
46+
<div className='mdp-container'>
47+
<div className='mdpc-head'>
48+
<div className='mdpch-button'>
49+
<div className='mdpchb-inner' onClick={() => addYear(-1)}>
50+
<span className='mdpchbi-left-arrows'></span>
51+
</div>
52+
</div>
53+
<div className='mdpch-button'>
54+
<div className='mdpchb-inner' onClick={() => addMonth(-1)}>
55+
<span className='mdpchbi-left-arrow'></span>
56+
</div>
57+
</div>
58+
<div className='mdpch-container'>
59+
<div className='mdpchc-year'>{displayedYear}</div>
60+
<div className='mdpchc-month'>{displayedMonth + 1}</div>
61+
</div>
62+
<div className='mdpch-button'>
63+
<div className='mdpchb-inner' onClick={() => addMonth(1)}>
64+
<span className='mdpchbi-right-arrow'></span>
65+
</div>
66+
</div>
67+
<div className='mdpch-button' onClick={() => addYear(1)}>
68+
<div className='mdpchb-inner'>
69+
<span className='mdpchbi-right-arrows'></span>
70+
</div>
71+
</div>
72+
</div>
73+
<div className='mdpc-body'>
74+
<div className='c-container'>
75+
<div className='cc-head'>
76+
{weekDayList.map((d, i) => (
77+
<div key={i} className='cch-name'>
78+
{d}
79+
</div>
80+
))}
81+
</div>
82+
<div className='cc-body'>{dateCells}</div>
83+
</div>
84+
</div>
85+
</div>
86+
);
87+
}
88+
89+
export default App;

packages/react-use-calendar-component/src/app/DateCell.tsx

Whitespace-only changes.

0 commit comments

Comments
 (0)