Event Timeline - 편집
Event Timeline - 편집 (Editing)
이벤트 생성, 편집 상호작용, 읽기 전용 동작을 구성합니다.
{{"component": "@mui/internal-core-docs/ComponentLinkHeader", "design": false}}
이벤트 생성
eventCreation prop을 사용하여 이벤트 생성 동작을 커스터마이즈합니다:
이벤트 생성 비활성화
eventCreation={false}를 전달하여 이벤트 생성을 비활성화합니다:
<EventTimelinePremium eventCreation={false} />
사용자 정의 기본 지속 시간
eventCreation.duration에 사용자 정의 값을 전달하여 새로 생성되는 이벤트의 기본 지속 시간을 변경합니다:
<EventTimelinePremium eventCreation={{ duration: 60 }} />
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventTimelinePremium } from '@mui/x-scheduler-premium/event-timeline-premium';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/company-roadmap';
export default function EventCreationDuration() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '500px', width: '100%', overflow: 'auto' }}>
<EventTimelinePremium
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreset="monthAndYear"
eventCreation={{ duration: 60 * 24 * 7 }} // 1 week in minutes
/>
</div>
);
}
더블 클릭으로 이벤트 생성
eventCreation.interaction을 "double-click"으로 설정하여 셀을 클릭하는 대신 더블 클릭할 때 생성 폼을 엽니다:
<EventTimelinePremium eventCreation={{ interaction: 'double-click' }} />
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventTimelinePremium } from '@mui/x-scheduler-premium/event-timeline-premium';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/company-roadmap';
export default function EventCreationInteraction() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '500px', width: '100%', overflow: 'auto' }}>
<EventTimelinePremium
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreset="monthAndYear"
eventCreation={{ interaction: 'double-click' }}
/>
</div>
);
}
이벤트 대화상자
이벤트를 클릭하거나 새 이벤트를 만들면 이벤트 대화상자가 열립니다.
이 대화상자에는 두 개의 탭이 있습니다:
- General: 제목, 시작/종료 날짜와 시간, 종일 토글, 리소스와 색상 선택기, 설명.
- Recurrence: 빈도, 간격, 요일, 종료 조건.
아래 데모에서 아무 이벤트나 클릭하여 대화상자를 엽니다. 거기에서 이벤트 세부 정보를 편집하거나 삭제할 수 있습니다.
General 탭은 eventDialogGeneralTab 슬롯을 통해 내장 및 사용자 정의 섹션으로 재구성할 수 있습니다—Event dialog 컴포넌트 페이지를 참고하세요.
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventTimelinePremium } from '@mui/x-scheduler-premium/event-timeline-premium';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/company-roadmap';
export default function EventDialog() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '500px', width: '100%', overflow: 'auto' }}>
<EventTimelinePremium
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreset="monthAndYear"
/>
</div>
);
}
:::info
readOnly: true인 이벤트(또는 읽기 전용 리소스에 속한 이벤트)는 대화상자를 보기 전용 모드로 엽니다.
:::
대화상자를 자신만의 UI로 교체
onEventEditingStart 콜백을 사용하여 내장 대화상자가 열리기 직전에 편집을 가로챕니다.
이 콜백은 모든 진입점(포인터, 키보드, 터치, 이벤트 생성)에서 발생합니다.
eventDetails.reason은 사용자가 새 이벤트를 만들 때 "creation", 발생(occurrence)이 읽기 전용(이벤트, 그 리소스, 또는 readOnly prop을 통해)일 때와 대화상자가 보기 전용 모드로 열릴 때 "view", 그 외에는 "edit"입니다.
eventDetails.occurrence는 그 reason에 따라 타입이 지정되므로, reason으로 좁히면 "edit"와 "view"에서는 유지된 발생 필드를, "creation"에서는 초안을 얻을 수 있습니다.
eventDetails.anchor는 취소 후에도 DOM에 남아 있어 자신만의 팝오버를 고정할 준비가 된 요소이며, eventDetails.trigger는 정확히 활성화된 요소를 식별하지만 일부 흐름(armed toolbar의 Edit 버튼, 생성 자리 표시자)은 취소된 활성화 직후에 그것을 마운트 해제하므로 위치 기준으로 사용하지 마세요.
eventDetails.cancel()을 호출하여 내장 대화상자를 닫은 상태로 유지하고 대신 자신만의 편집 UI를 엽니다:
<EventTimelinePremium
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,
SchedulerRenderableEventOccurrence,
} from '@mui/x-scheduler/models';
import { EventTimelinePremium } from '@mui/x-scheduler-premium/event-timeline-premium';
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';
import {
initialEvents,
defaultVisibleDate,
resources,
} from '../../datasets/company-roadmap';
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,
resource: occurrence.resource,
},
]);
} else {
setEvents(
events.map((item) =>
item.id === occurrence.id ? { ...item, title } : item,
),
);
}
setEditedEvent(null);
};
return (
<div style={{ height: '500px', width: '100%', overflow: 'auto' }}>
<EventTimelinePremium
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
defaultPreset="monthAndYear"
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를 취소하면 내장 대화상자(및 그 모바일 서랍 변형)가 대체됩니다: 여러분의 UI가 편집 폼, 반복 이벤트 범위 선택("this event", "this and following events", "all events"), 그리고 변경 사항 저장(예: 제어되는 events 상태를 업데이트)을 책임집니다.
그 외의 모든 것은 내장 동작을 유지합니다: 드래그 앤 드롭, 크기 조정, 그것들이 촉발하는 반복 범위 대화상자, 그리고 터치 기기에서 편집·삭제·크기 조정 동작을 갖춘 이벤트 툴바 — 여기서 콜백은 사용자가 툴바의 Edit 동작을 탭하여 대화상자가 열리기 직전에 발생합니다. :::
읽기 전용
readOnly prop을 사용하여 모든 편집 상호작용(이벤트 생성, 드래그 앤 드롭, 크기 조정, 팝오버 편집)을 비활성화합니다:
<EventTimelinePremium readOnly />
import * as React from 'react';
import { SchedulerEvent } from '@mui/x-scheduler/models';
import { EventTimelinePremium } from '@mui/x-scheduler-premium/event-timeline-premium';
import {
defaultVisibleDate,
initialEvents,
resources,
} from '../../datasets/company-roadmap';
export default function ReadOnly() {
const [events, setEvents] = React.useState<SchedulerEvent[]>(initialEvents);
return (
<div style={{ height: '500px', width: '100%', overflow: 'auto' }}>
<EventTimelinePremium
events={events}
resources={resources}
defaultVisibleDate={defaultVisibleDate}
onEventsChange={setEvents}
readOnly
defaultPreset="monthAndYear"
/>
</div>
);
}
일부 이벤트에만 설정
이벤트별
이벤트 모델에서 readOnly 속성을 사용하여 이벤트를 읽기 전용으로 표시합니다:
const event = {
// ...other properties
readOnly: true,
};
리소스별
리소스 모델에서 areEventsReadOnly 속성을 사용하여 리소스의 모든 이벤트를 읽기 전용으로 표시합니다:
const resource = {
// ...other properties
areEventsReadOnly: true,
};
우선순위 순서
읽기 전용 동작의 우선순위 순서는 다음과 같습니다:
- 이벤트에 할당된
readOnly속성
<EventTimelinePremium events={[{ id: '1', title: 'Event 1', readOnly: true }]} />
- 이벤트의 리소스에 할당된
areEventsReadOnly속성
<EventTimelinePremium
resources={[
{
id: '1',
title: 'Resource 1',
areEventsReadOnly: true,
},
]}
/>
:::success 리소스에 속성이 정의되어 있지 않으면, 그 속성이 정의된 가장 가까운 조상 리소스가 우선합니다. :::
- Event Timeline에 할당된
readOnlyprop
<EventTimelinePremium 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 <EventTimelinePremium resources={resources} events={events} />;
}
이벤트 복사 및 붙여넣기 🚧
:::warning 이 기능은 아직 사용할 수 없지만 계획되어 있습니다—이 GitHub 이슈에 👍 upvote하여 우선순위를 정하는 데 도움을 줄 수 있습니다. 특히 우리가 다뤄야 할 사용 사례가 있거나 현재 솔루션에서 특정한 문제점을 겪고 있다면, 주저하지 말고 댓글로 필요 사항을 남겨 주세요. :::
이 기능이 있으면 사용자가 타임라인 내에서 이벤트를 복사하고 붙여넣을 수 있게 됩니다.
실행 취소 및 다시 실행 🚧
:::warning 이 기능은 아직 사용할 수 없지만 계획되어 있습니다—이 GitHub 이슈에 👍 upvote하여 우선순위를 정하는 데 도움을 줄 수 있습니다. 특히 우리가 다뤄야 할 사용 사례가 있거나 현재 솔루션에서 특정한 문제점을 겪고 있다면, 주저하지 말고 댓글로 필요 사항을 남겨 주세요. :::
이 기능이 있으면 사용자가 이벤트에 가한 변경을 실행 취소하고 다시 실행할 수 있게 됩니다.