React Gantt - Valtio 튜토리얼
이 튜토리얼은 React TypeScript 애플리케이션을 만들고, DHTMLX React Gantt 컴포넌트를 통합하며, Valtio로 상태를 관리하는 방법을 안내합니다.
사전 지식
- React, TypeScript, Vite, 및 Valtio에 대한 기본 지식
- 권장 사항: Basics를 읽어 데이터 바인딩 모드와 이 튜토리얼이 기반으로 하는
data.save콜백을 이해하세요.
빠른 설정 - 프로젝트 생성
시작하기 전에 Node.js를 설치하세요. https://nodejs.org/en/
다음과 같이 Vite React + TypeScript 프로젝트를 만듭니다:
npm create vite@latest react-gantt-valtio-demo -- --template react-ts
cd react-gantt-valtio-demo
다음으로 필요한 의존성을 설치합니다.
- npm용:
npm install valtio @mui/material @mui/icons-material @emotion/react @emotion/styled
- yarn용:
yarn add valtio @mui/material @mui/icons-material @emotion/react @emotion/styled
그다음 React Gantt 패키지를 설치합니다.
React Gantt 설치
React Gantt 설치 방법은 React Gantt 설치 가이드를 참고하세요.
이 튜토리얼에서는 평가판 패키지를 사용합니다:
npm install @dhtmlx/trial-react-gantt
또는
yarn add @dhtmlx/trial-react-gantt
Professional 패키지를 이미 사용 중이라면 명령어와 import에서 @dhtmlx/trial-react-gantt를 @dhx/react-gantt로 교체하세요.
이제 개발 서버를 시작할 수 있습니다:
npm run dev
이제 (http://localhost:5173) 에서 React 프로젝트가 실행 중이어야 합니다.
노트
Gantt가 바디 전체 공간을 차지하도록 만들려면 src 폴더에 있는 App.css의 기본 스타일을 제거하고 다음 스타일을 추가해야 합니다:
#root {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
샘플 데이터 및 설정 구성하기
Gantt 차트용 샘플 데이터를 src/seed/Seed.ts에 생성합니다. 이 파일에는 초기 데이터가 들어 있습니다:
import type { SerializedTask, Link, GanttConfig } from '@dhtmlx/trial-react-gantt';
export type ZoomLevel = 'day' | 'month' | 'year';
export const defaultZoomLevels: NonNullable<GanttConfig['zoom']> = {
current: 'day',
levels: [
{ name: 'day', scale_height: 27, min_column_width: 80, scales: [{ unit: 'day', step: 1, format: '%d %M' }] },
{ name: 'month', scale_height: 50, min_column_width: 120, scales: [{ unit: 'month', format: '%F, %Y' }, { unit: 'week', format: 'Week #%W' }] },
{ name: 'year', scale_height: 50, min_column_width: 30, scales: [{ unit: 'year', step: 1, format: '%Y' }] },
],
};
export const seedTasks: SerializedTask[] = [
{ id: 1, text: 'Office itinerancy', type: 'project', start_date: new Date(2025, 3, 2).toISOString(), duration: 17, progress: 0.4, parent: 0, open: true },
{ id: 2, text: 'Office facing', type: 'project', start_date: new Date(2025, 3, 2).toISOString(), duration: 8, progress: 0.6, parent: 1, open: true },
{ id: 3, text: 'Furniture installation', type: 'project', start_date: new Date(2025, 3, 11).toISOString(), duration: 8, progress: 0.6, parent: 1, open: true },
{ id: 4, text: 'The employee relocation', type: 'project', start_date: new Date(2025, 3, 13).toISOString(), duration: 5, progress: 0.5, parent: 1, priority: 3, open: true },
{ id: 5, text: 'Interior office', type: 'task', start_date: new Date(2025, 3, 3).toISOString(), duration: 7, progress: 0.6, parent: 2, priority: 1 },
{ id: 6, text: 'Air conditioners check', type: 'task', start_date: new Date(2025, 3, 3).toISOString(), duration: 7, progress: 0.6, parent: 2, priority: 2 },
{ id: 7, text: 'Workplaces preparation', type: 'task', start_date: new Date(2025, 3, 12).toISOString(), duration: 8, progress: 0.6, parent: 3 },
{ id: 8, text: 'Preparing workplaces', type: 'task', start_date: new Date(2025, 3, 14).toISOString(), duration: 5, progress: 0.5, parent: 4, priority: 1 },
{ id: 9, text: 'Workplaces importation', type: 'task', start_date: new Date(2025, 3, 21).toISOString(), duration: 4, progress: 0.5, parent: 4 },
{ id: 10, text: 'Workplaces exportation', type: 'task', start_date: new Date(2025, 3, 27).toISOString(), duration: 3, progress: 0.5, parent: 4, priority: 2 }
];
export const seedLinks: Link[] = [
{ id: 2, source: 2, target: 3, type: '0' },
{ id: 3, source: 3, target: 4, type: '0' },
{ id: 7, source: 8, target: 9, type: '0' }
];