Event Calendar - 편집
이벤트 생성, 편집 상호작용, 읽기 전용 동작을 구성해 봐요.
본문
이벤트 생성 (Event creation)
eventCreation prop을 사용해서 이벤트 생성 동작을 커스터마이징할 수 있어요.
이벤트 생성 비활성화하기
eventCreation={false}를 전달해서 이벤트 생성을 비활성화하세요.
<EventCalendar eventCreation={false} />
커스텀 기본 지속 시간
eventCreation.duration에 커스텀 값을 전달해서 새로 만든 이벤트의 기본 지속 시간을 바꿀 수 있어요.
<EventCalendar eventCreation={{ duration: 60 }} />
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventCalendar } from '@mui/x-scheduler/event-calendar';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/personal-agenda';
export default function EventCreationDuration() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '650px', width: '100%' }}>
<EventCalendar
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreferences={{ isSidePanelOpen: false }}
eventCreation={{ duration: 60 }}
/>
</div>
);
}
더블 클릭으로 이벤트 생성하기
eventCreation.interaction을 "double-click"으로 설정하면 클릭 대신 셀을 더블 클릭했을 때 생성 폼이 열려요.
<EventCalendar eventCreation={{ interaction: 'double-click' }} />
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventCalendar } from '@mui/x-scheduler/event-calendar';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/personal-agenda';
export default function EventCreationInteraction() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '650px', width: '100%' }}>
<EventCalendar
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreferences={{ isSidePanelOpen: false }}
eventCreation={{ interaction: 'double-click' }}
/>
</div>
);
}
이벤트 다이얼로그 (Event dialog)
이벤트를 클릭하거나 새로 만들면 이벤트 다이얼로그가 열려요.
다이얼로그에는 두 개의 탭이 있어요.
- 일반(General): 제목, 시작/종료 날짜와 시간, 종일(all-day) 토글, 리소스와 색상 셀렉터, 설명.
- 반복(Recurrence): 빈도, 간격, 요일, 종료 조건.
Premium 패키지(
@mui/x-scheduler-premium)에서만 사용할 수 있어요.
아래 데모에서 아무 이벤트나 클릭하면 다이얼로그가 열려요. 거기서 이벤트 세부 정보를 편집하거나 삭제할 수 있어요.
import * as React from 'react';
import { SchedulerEvent, SchedulerResource } from '@mui/x-scheduler/models';
import { EventCalendarPremium } from '@mui/x-scheduler-premium/event-calendar-premium';
const defaultVisibleDate = new Date('2025-07-01T00:00:00');
const initialEvents: SchedulerEvent[] = [
{
id: 'team-sync',
title: 'Team Sync',
start: '2025-07-01T09:00:00',
end: '2025-07-01T10:00:00',
resource: 'work',
rrule: { freq: 'WEEKLY', interval: 1, byDay: ['TU', 'TH'] },
},
{
id: 'lunch',
title: 'Lunch with Sarah',
start: '2025-07-02T12:00:00',
end: '2025-07-02T13:00:00',
resource: 'personal',
},
{
id: 'birthday',
title: "Alice's Birthday",
start: '2025-07-03T00:00:00',
end: '2025-07-04T00:00:00',
resource: 'personal',
allDay: true,
readOnly: true,
},
];
const resources: SchedulerResource[] = [
{ id: 'work', title: 'Work', eventColor: 'purple' },
{ id: 'personal', title: 'Personal', eventColor: 'teal' },
];
export default function EventDialog() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '600px', width: '100%' }}>
<EventCalendarPremium
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreferences={{ isSidePanelOpen: false }}
defaultView="month"
/>
</div>
);
}
:::info
이 데모는 반복(Recurrence) 탭을 보여 주기 위해 EventCalendarPremium을 사용해요.
다른 모든 다이얼로그 기능(제목·날짜·리소스·색상·설명 편집, 이벤트 삭제)은 표준 EventCalendar 컴포넌트에서도 사용할 수 있어요.
:::
:::info
readOnly: true인 이벤트(또는 읽기 전용 리소스에 속한 이벤트)는 보기 전용(view-only) 모드로 다이얼로그를 열어요.
:::
일반(General) 탭은 eventDialogGeneralTab 슬롯을 통해 내장 및 커스텀 섹션으로 다시 구성할 수 있어요—이벤트 다이얼로그 컴포넌트 페이지를 참고하세요.
다이얼로그를 나만의 UI로 교체하기
onEventEditingStart 콜백을 사용해서 내장 다이얼로그가 열리기 직전에 편집을 가로챌 수 있어요.
이 콜백은 모든 진입점(포인터, 키보드, 터치, 이벤트 생성)에 대해 호출돼요.
사용자가 새 이벤트를 만들 때는 eventDetails.reason이 "creation"이고, 발생(occurrence)이 읽기 전용(이벤트, 그 리소스, 또는 readOnly prop을 통해)이며 다이얼로그가 보기 전용 모드로 열릴 때는 "view", 그 외에는 "edit"이에요.
eventDetails.occurrence는 그 reason으로 타입이 정해지므로, reason에 따라 좁히면 "edit"와 "view"에서는 저장된 발생 필드를, "creation"에서는 초안(draft)을 얻을 수 있어요.
eventDetails.anchor는 취소 후에도 DOM에 남아 있어 직접 만든 팝오버를 고정할 준비가 된 엘리먼트예요. eventDetails.trigger는 정확히 활성화된 엘리먼트를 식별하지만, 일부 흐름은 취소된 활성화 직후에 그것을 마운트 해제하므로(arm된 툴바의 Edit 버튼, "+N more" 팝오버 안의 항목, 생성 플레이스홀더) 그것에 대고 위치를 정하지 마세요.
eventDetails.cancel()을 호출하면 내장 다이얼로그를 열지 않고 대신 나만의 편집 UI를 열 수 있어요.
<EventCalendar
onEventEditingStart={(occurrence, eventDetails) => {
if (eventDetails.reason === 'view') {
// Read-only activation: keep the built-in view-only dialog.
// Cancel here only if you render your own read-only UI instead.
return;
}
eventDetails.cancel();
if (eventDetails.reason === 'creation') {
// Creation drafts have a synthetic `id` — use the proposed dates instead.
openYourCreationUI(eventDetails.occurrence.displayTimezone);
} else {
openYourEditingUI(eventDetails.occurrence.id);
}
}}
/>
아래 데모에서는 이벤트를 클릭해도, 빈 셀을 클릭해도 내장 다이얼로그 대신 커스텀 다이얼로그가 열려요.
import * as React from 'react';
import {
SchedulerEvent,
SchedulerResource,
SchedulerRenderableEventOccurrence,
} from '@mui/x-scheduler/models';
import { EventCalendar } from '@mui/x-scheduler/event-calendar';
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import TextField from '@mui/material/TextField';
const defaultVisibleDate = new Date('2025-07-01T00:00:00');
const initialEvents: SchedulerEvent[] = [
{
id: 'team-sync',
title: 'Team Sync',
start: '2025-07-01T09:00:00',
end: '2025-07-01T10:00:00',
resource: 'work',
},
{
id: 'lunch',
title: 'Lunch with Sarah',
start: '2025-07-02T12:00:00',
end: '2025-07-02T13:00:00',
resource: 'personal',
},
];
const resources: SchedulerResource[] = [
{ id: 'work', title: 'Work', eventColor: 'purple' },
{ id: 'personal', title: 'Personal', eventColor: 'teal' },
];
interface EditedEvent {
occurrence: SchedulerRenderableEventOccurrence;
isNew: boolean;
}
export default function CustomEditingUI() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
const [editedEvent, setEditedEvent] = React.useState<EditedEvent | null>(null);
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
if (editedEvent == null) {
return;
}
const { occurrence, isNew } = editedEvent;
const title =
(new FormData(event.currentTarget).get('title') as string) || '(No title)';
if (isNew) {
setEvents([
...events,
{
id: `custom-${Date.now()}`,
title,
start: new Date(occurrence.displayTimezone.start.timestamp).toISOString(),
end: new Date(occurrence.displayTimezone.end.timestamp).toISOString(),
allDay: occurrence.allDay,
},
]);
} else {
setEvents(
events.map((item) =>
item.id === occurrence.id ? { ...item, title } : item,
),
);
}
setEditedEvent(null);
};
return (
<div style={{ height: '600px', width: '100%' }}>
<EventCalendar
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreferences={{ isSidePanelOpen: false }}
onEventEditingStart={(_occurrence, eventDetails) => {
if (eventDetails.reason === 'view') {
return;
}
eventDetails.cancel();
setEditedEvent({
occurrence: eventDetails.occurrence,
isNew: eventDetails.reason === 'creation',
});
}}
/>
<Dialog
open={editedEvent != null}
onClose={() => setEditedEvent(null)}
fullWidth
maxWidth="xs"
>
<form onSubmit={handleSubmit}>
<DialogTitle>
{editedEvent?.isNew ? 'New event' : 'Edit event'}
</DialogTitle>
<DialogContent>
<TextField
autoFocus
fullWidth
name="title"
label="Title"
margin="dense"
defaultValue={
editedEvent?.isNew ? '' : (editedEvent?.occurrence.title ?? '')
}
/>
</DialogContent>
<DialogActions>
<Button onClick={() => setEditedEvent(null)}>Cancel</Button>
<Button type="submit" variant="contained">
Save
</Button>
</DialogActions>
</form>
</Dialog>
</div>
);
}
:::warning
onEventEditingStart를 취소하면 내장 다이얼로그(그리고 그 모바일 서랍 변형)가 교체돼요. 이제 편집 폼, 반복 이벤트 범위 선택("this event", "this and following events", "all events"), 변경 사항 저장(예: 제어되는 events 상태 업데이트)은 전부 나의 UI가 담당해요.
그 외 모든 것은 내장 동작을 유지해요. 드래그 앤 드롭, 크기 조절, 그것들이 트리거하는 반복 범위 다이얼로그, 그리고 터치 기기에서 편집·삭제·크기 조절 기능을 갖춘 이벤트 툴바 등이요—거기서는 다이얼로그가 열리기 직전에 사용자가 툴바의 Edit 동작을 탭할 때 이 콜백이 호출돼요. :::
읽기 전용 (Read-only)
readOnly prop을 사용해서 모든 편집 상호작용(이벤트 생성, 드래그 앤 드롭, 크기 조절, 팝오버 편집)을 비활성화하세요.
<EventCalendar readOnly />
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventCalendar } from '@mui/x-scheduler/event-calendar';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/personal-agenda';
export default function ReadOnly() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '650px', width: '100%' }}>
<EventCalendar
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreferences={{ isSidePanelOpen: false }}
readOnly
/>
</div>
);
}
일부 이벤트에만 설정하기
이벤트별
이벤트 모델의 readOnly 속성을 사용해서 이벤트를 읽기 전용으로 표시하세요.
const event = {
// ...other properties
readOnly: true,
};
리소스별
리소스 모델의 areEventsReadOnly 속성을 사용해서 리소스의 모든 이벤트를 읽기 전용으로 표시하세요.
const resource = {
// ...other properties
areEventsReadOnly: true,
};
우선순위 순서
읽기 전용 동작의 우선순위 순서는 다음과 같아요.
- 이벤트에 할당된
readOnly속성
<EventCalendar events={[{ id: '1', title: 'Event 1', readOnly: true }]} />
- 이벤트의 리소스에 할당된
areEventsReadOnly속성
<EventCalendar
resources={[
{
id: '1',
title: 'Resource 1',
areEventsReadOnly: true,
},
]}
/>
:::info 리소스에 속성이 정의되어 있지 않으면, 그 속성이 정의된 가장 가까운 조상 리소스가 우선해요. :::
- Event Calendar에 할당된
readOnlyprop
<EventCalendar readOnly />
예를 들어 아래 코드에서는 "event-3"을 제외한 모든 work 이벤트가 읽기 전용이에요.
function App() {
const resources = [
{ id: 'work', title: 'Work', areEventsReadOnly: true },
{ id: 'personal', title: 'Personal' },
];
const events = [
{ id: 'event-1', resource: 'work' },
{ id: 'event-2', resource: 'personal' },
{ id: 'event-3', resource: 'work', readOnly: false },
];
return <EventCalendar resources={resources} events={events} />;
}
이벤트 복사 및 붙여넣기 🚧
:::warning 이 기능은 아직 사용할 수 없지만 계획되어 있어요—이 GitHub 이슈에 👍를 눌러 우선순위를 높이는 데 도움을 줄 수 있어요. 특히 다뤄야 할 사용 사례가 있거나 현재 솔루션에서 특정 불편함을 겪고 있다면, 거기에 담긴 요구 사항을 설명하는 댓글을 남겨 주세요. :::
이 기능이 생기면 사용자는 캘린더 안에서 이벤트를 복사하고 붙여넣을 수 있게 될 거예요.
실행 취소 및 다시 실행 🚧
:::warning 이 기능은 아직 사용할 수 없지만 계획되어 있어요—이 GitHub 이슈에 👍를 눌러 우선순위를 높이는 데 도움을 줄 수 있어요. 특히 다뤄야 할 사용 사례가 있거나 현재 솔루션에서 특정 불편함을 겪고 있다면, 거기에 담긴 요구 사항을 설명하는 댓글을 남겨 주세요. :::
이 기능이 생기면 사용자는 이벤트에 가한 변경을 실행 취소하고 다시 실행할 수 있게 될 거예요.
더 알아보기
더 자세한 내용은 MUI X Scheduler 문서를 참고하세요.