Skip to content

Commit 0f19e08

Browse files
authored
Merge pull request #139 from imaginer-dev/127--ui--calendarmain
127 UI calendarmain
2 parents 1edb361 + 24eeb56 commit 0f19e08

File tree

4 files changed

+210
-1
lines changed

4 files changed

+210
-1
lines changed

โ€Žpackage.jsonโ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"prepare": "husky"
1616
},
1717
"dependencies": {
18+
"@fullcalendar/core": "^6.1.11",
19+
"@fullcalendar/daygrid": "^6.1.11",
20+
"@fullcalendar/interaction": "^6.1.11",
21+
"@fullcalendar/react": "^6.1.11",
1822
"@lukemorales/query-key-factory": "^1.3.4",
1923
"@supabase/supabase-js": "^2.42.7",
2024
"@tanstack/react-query": "^5.29.0",

โ€Žpnpm-lock.yamlโ€Ž

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€Žsrc/App.tsxโ€Ž

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
1+
import { Calendar } from './components/common/Calendar.tsx';
2+
13
function App() {
24
return (
35
<div>
4-
<h1>๋ฉ”์ธ ํŽ˜์ด์ง€</h1>
6+
<header className="relative z-10">
7+
<div className="drawer">
8+
<input id="my-drawer-3" type="checkbox" className="drawer-toggle" />
9+
<div className="drawer-content flex flex-col">
10+
{/* Navbar */}
11+
<div className="navbar w-full">
12+
<div className="flex-none lg:hidden">
13+
<label htmlFor="my-drawer-3" aria-label="open sidebar" className="btn btn-square btn-ghost">
14+
<svg
15+
xmlns="http://www.w3.org/2000/svg"
16+
fill="none"
17+
viewBox="0 0 24 24"
18+
className="inline-block h-6 w-6 stroke-current"
19+
>
20+
<path
21+
strokeLinecap="round"
22+
strokeLinejoin="round"
23+
strokeWidth="2"
24+
d="M4 6h16M4 12h16M4 18h16"
25+
></path>
26+
</svg>
27+
</label>
28+
</div>
29+
<div className="flex-1">
30+
<h1 className="base-200 min-w-40 p-2 text-center">๊ฐœ์ธ ์ผ์ • ์บ˜๋ฆฐ๋”</h1>
31+
</div>
32+
</div>
33+
</div>
34+
<div className="drawer-side">
35+
<label htmlFor="my-drawer-3" aria-label="close sidebar" className="drawer-overlay"></label>
36+
<ul className="menu min-h-full w-80 bg-base-200 p-4">
37+
{/* Sidebar content here */}
38+
<li>
39+
<a>๊ทธ๋ฃน ์ผ์ • ์บ˜๋ฆฐ๋” 1</a>
40+
</li>
41+
<li>
42+
<a>๊ทธ๋ฃน ์ผ์ • ์บ˜๋ฆฐ๋” 2</a>
43+
</li>
44+
</ul>
45+
</div>
46+
</div>
47+
</header>
48+
<main className="z-1 relative flex-grow">
49+
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
50+
<div className="rounded bg-white p-6 px-4 sm:px-0">
51+
<Calendar />
52+
</div>
53+
</div>
54+
</main>
555
</div>
656
);
757
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import FullCalendar from '@fullcalendar/react';
2+
import dayGridPlugin from '@fullcalendar/daygrid';
3+
import interactionPlugin from '@fullcalendar/interaction';
4+
import { useRef, useState, useEffect } from 'react';
5+
6+
const events = [
7+
{ title: 'Meeting', start: new Date() },
8+
{ title: 'Meeting', start: '2024-05-08' },
9+
{ title: 'Meeting', start: '2024-05-08' },
10+
{ title: 'Meeting', start: '2024-05-08' },
11+
];
12+
13+
export function Calendar() {
14+
const [calendarHeight, setCalendarHeight] = useState<string | number>('auto');
15+
const calendarRef = useRef<FullCalendar | null>(null);
16+
const handlePrev = () => {
17+
const calendarApi = calendarRef?.current?.getApi();
18+
if (calendarApi) {
19+
calendarApi.prev();
20+
} else {
21+
console.error('Calendar API is not available.');
22+
}
23+
};
24+
25+
const handleNext = () => {
26+
const calendarApi = calendarRef?.current?.getApi();
27+
if (calendarApi) {
28+
calendarApi.next();
29+
} else {
30+
console.error('Calendar API is not available.');
31+
}
32+
};
33+
34+
useEffect(() => {
35+
const updateSize = () => {
36+
const isMobile = window.innerWidth < 768;
37+
setCalendarHeight(isMobile ? 500 : 'auto');
38+
};
39+
40+
window.addEventListener('resize', updateSize);
41+
updateSize();
42+
43+
return () => window.removeEventListener('resize', updateSize);
44+
}, []);
45+
46+
return (
47+
<div>
48+
<FullCalendar
49+
ref={calendarRef}
50+
plugins={[dayGridPlugin, interactionPlugin]}
51+
initialView="dayGridMonth"
52+
events={events}
53+
dayMaxEvents={2} //Max๊ฐœ์ˆ˜๊นŒ์ง€๋ณด์ด๊ณ  ๋‚˜๋จธ์ง€๋Š” more
54+
navLinks={true} // ๋‚ ์งœ/์ฃผ ์ด๋ฆ„์„ ํด๋ฆญํ•˜์—ฌ ๋ทฐ๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
55+
editable={true} // ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
56+
eventContent={renderEventContent}
57+
contentHeight={calendarHeight}
58+
titleFormat={{
59+
year: 'numeric',
60+
month: '2-digit',
61+
meridiem: false,
62+
}}
63+
dayHeaderFormat={{
64+
weekday: 'short',
65+
}}
66+
headerToolbar={{
67+
left: 'prevButton',
68+
center: 'title',
69+
right: 'nextButton',
70+
}}
71+
customButtons={{
72+
prevButton: {
73+
icon: 'chevron-left',
74+
click: handlePrev,
75+
},
76+
nextButton: {
77+
icon: 'chevron-right',
78+
click: handleNext,
79+
},
80+
}}
81+
/>
82+
</div>
83+
);
84+
}
85+
86+
interface EventInfo {
87+
timeText: string;
88+
event: {
89+
title: string;
90+
};
91+
}
92+
93+
function renderEventContent(eventInfo: EventInfo) {
94+
return (
95+
<>
96+
<b>{eventInfo.timeText}</b>
97+
<i>{eventInfo.event.title}</i>
98+
</>
99+
);
100+
}

0 commit comments

Comments
ย (0)