Skip to content

Latest commit

ย 

History

History
332 lines (253 loc) ยท 11.5 KB

getting-started.md

File metadata and controls

332 lines (253 loc) ยท 11.5 KB

์‹œ์ž‘ํ•˜๊ธฐ

๋ชฉ์ฐจ

์„ค์น˜ํ•˜๊ธฐ

TOAST UI ์ œํ’ˆ๋“ค์€ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๋ฅผ ์ด์šฉํ•˜๊ฑฐ๋‚˜, ์ง์ ‘ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋ฐ›์•„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ € ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•œ๋‹ค.

ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ € ์‚ฌ์šฉํ•˜๊ธฐ

TOAST UI ์ œํ’ˆ๋“ค์€ npm ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €์— ๋“ฑ๋ก๋˜์–ด ์žˆ๋‹ค. ๊ฐ ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ €๊ฐ€ ์ œ๊ณตํ•˜๋Š” CLI ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค. npm ์‚ฌ์šฉ์„ ์œ„ํ•ด์„  Node.js๋ฅผ ๋ฏธ๋ฆฌ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

npm

npm install @toast-ui/calendar # ์ตœ์‹  ๋ฒ„์ „
npm install @toast-ui/calendar@<version> # 2.0 ์ดํ›„ ํŠน์ • ๋ฒ„์ „
npm install tui-calendar@<version> # 1.x ํŠน์ • ๋ฒ„์ „

Contents Delivery Network (CDN) ์‚ฌ์šฉํ•˜๊ธฐ

TOAST UI Calendar๋Š” CDN์„ ํ†ตํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ์•„๋ž˜์˜ ์ฝ”๋“œ๋กœ CDN์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
<link rel="stylesheet" href="https://uicdn.toast.com/calendar/latest/toastui-calendar.min.css" />
<script src="https://uicdn.toast.com/calendar/latest/toastui-calendar.min.js"></script>

<!-- ๋ ˆ๊ฑฐ์‹œ ๋ธŒ๋ผ์šฐ์ €์šฉ ๋ฒˆ๋“ค ํŒŒ์ผ ๊ฐ€์ ธ์˜ค๊ธฐ -->
<!-- <script src="https://uicdn.toast.com/calendar/latest/toastui-calendar.ie11.min.js"></script> -->

<!-- ๋ชจ๋“ˆ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ -->
<!-- <script type="module" src="https://uicdn.toast.com/calendar/latest/toastui-calendar.mjs"></script> -->
  • CDN์€ ์•„๋ž˜์˜ ๋””๋ ‰ํ† ๋ฆฌ ๊ตฌ์กฐ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.
- uicdn.toast.com/
  โ”œโ”€ calendar/
  โ”‚  โ”œโ”€ latest
  โ”‚  โ”‚  โ”œโ”€ toastui-calendar.css
  โ”‚  โ”‚  โ”œโ”€ toastui-calendar.js
  โ”‚  โ”‚  โ”œโ”€ toastui-calendar.min.css
  โ”‚  โ”‚  โ”œโ”€ toastui-calendar.min.js
  โ”‚  โ”‚  โ”œโ”€ toastui-calendar.ie11.js
  โ”‚  โ”‚  โ”œโ”€ toastui-calendar.ie11.min.js
  โ”‚  โ”‚  โ”‚  toastui-calendar.mjs
  โ”‚  โ”œโ”€ v2.0.0/

์†Œ์Šค ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

์‚ฌ์šฉํ•˜๊ธฐ

HTML

TOAST UI Calendar๊ฐ€ ์ƒ์„ฑ๋  ์ปจํ…Œ์ด๋„ˆ ์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. ์ด ์š”์†Œ๋Š” ์ ์ ˆํ•œ ๋†’์ด์˜ height ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. (์ตœ์†Œ 600px ์ด์ƒ ๊ถŒ์žฅ)

<div id="calendar" style="height: 600px;"></div>

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

๋ถˆ๋Ÿฌ์˜ค๊ธฐ

TOAST UI Calendar๋Š” ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ์ƒ์„ฑ์ž ํ•จ์ˆ˜์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ™˜๊ฒฝ์— ๋”ฐ๋ผ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ์„ธ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์กด์žฌํ•œ๋‹ค.

/* Node.js ํ™˜๊ฒฝ์—์„œ ES6 ๋ชจ๋“ˆ */
import Calendar from '@toast-ui/calendar';
/* Node.js ํ™˜๊ฒฝ์—์„œ CommonJS */
const Calendar = require('@toast-ui/calendar');
/* ๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์—์„œ namespace */
const Calendar = tui.Calendar;

๋ ˆ๊ฑฐ์‹œ ๋ธŒ๋ผ์šฐ์ €์šฉ ๋ฒˆ๋“ค ํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

TOAST UI Calendar๋Š” ๋ ˆ๊ฑฐ์‹œ ๋ธŒ๋ผ์šฐ์ €์šฉ ๋ฒˆ๋“ค ํŒŒ์ผ์„ ๋”ฐ๋กœ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋‹ค. ๊ธฐ๋ณธ ๋ฒˆ๋“ค์€ ๋ชจ๋˜ ๋ธŒ๋ผ์šฐ์ €์˜ ์ตœ์‹  2๊ฐœ ๋ฒ„์ „์„ ์•ˆ์ •์ ์œผ๋กœ ์ง€์›ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ๊ธฐ๋ณธ ๋ฒˆ๋“ค์€ IE11์„ ์œ„ํ•œ ํด๋ฆฌํ•„์ด ํฌํ•จ๋˜์–ด์žˆ์ง€ ์•Š์œผ๋ฏ€๋กœ IE11 ํ˜น์€ ์ผ์ • ์ˆ˜์ค€ ์ดํ•˜์˜ ๋ ˆ๊ฑฐ์‹œ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํด๋ฆฌํ•„์ด ํฌํ•จ๋œ IE11 ๋ฒˆ๋“ค์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค.

IE11์˜ ๋ฒˆ๋“ค ํฌ๊ธฐ๋Š” ๊ธฐ๋ณธ ๋ฒˆ๋“ค๋ณด๋‹ค 30%๊ฐ€๋Ÿ‰ ํฌ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ˜๋“œ์‹œ ์ง€์› ๋ฒ”์œ„๋ฅผ ์ž˜ ๊ณ ๋ คํ•˜์—ฌ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ๋ฒˆ๋“ค ์‚ฌ์ด์ฆˆ๋ฅผ ๋Š˜๋ฆฌ์ง€ ์•Š๋„๋ก ์œ ์˜ํ•ด์•ผ ํ•œ๋‹ค.

/* Node.js ํ™˜๊ฒฝ์—์„œ ES6 ๋ชจ๋“ˆ */
import Calendar from '@toast-ui/calendar/ie11';
/* Node.js ํ™˜๊ฒฝ์—์„œ CommonJS */
const Calendar = require('@toast-ui/calendar/ie11');
<!-- CDN๊ณผ ๋ธŒ๋ผ์šฐ์ € ํ™˜๊ฒฝ์—์„œ namespace -->
<script src="https://uicdn.toast.com/calendar/latest/toastui-calendar.ie11.min.js"></script>
<script>
  const Calendar = tui.Calendar;
</script>

CSS

Calendar๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” CSS ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค. import, require๋ฅผ ํ†ตํ•ด CSS ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๊ฑฐ๋‚˜, CDN์„ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

/* Node.js ํ™˜๊ฒฝ์—์„œ ES6 ๋ชจ๋“ˆ */
import '@toast-ui/calendar/dist/toastui-calendar.min.css'; // Calendar ์Šคํƒ€์ผ
/* Node.js ํ™˜๊ฒฝ์—์„œ CommonJS */
require('@toast-ui/calendar/dist/toastui-calendar.min.css');
<!-- CDN -->
<link rel="stylesheet" href="https://uicdn.toast.com/calendar/latest/toastui-calendar.min.css" />

์ธ์Šคํ„ด์Šค ๋งŒ๋“ค๊ธฐ

์ƒ์„ฑ์ž ํ•จ์ˆ˜๋Š” container, options ๋‘ ๊ฐœ๋ฅผ ์ธ์ž๋กœ ๊ฐ–๋Š”๋‹ค.

  • container: TOAST UI Calendar๋ฅผ ์ž์‹ ์š”์†Œ๋กœ ๊ฐ–๋Š” HTML ์š”์†Œ ๋˜๋Š” HTML ์š”์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•œ CSS ์„ ํƒ์ž ๋ฌธ์ž์—ด
  • options: ๊ธฐ๋ณธ ๋ทฐ ํƒ€์ž…, ํƒ€์ž„์กด, ํ…Œ๋งˆ, ํ…œํ”Œ๋ฆฟ ๋“ฑ TOAST UI Calendar๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•  ์ˆ˜ ์žˆ๋Š” ์˜ต์…˜ ๊ฐ์ฒด. ์ž์„ธํ•œ ์ •๋ณด๋Š” ์˜ต์…˜ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.
const container = document.getElementById('calendar');
const options = {
  defaultView: 'week',
  timezone: {
    zones: [
      {
        timezoneName: 'Asia/Seoul',
        displayLabel: 'Seoul',
      },
      {
        timezoneName: 'Europe/London',
        displayLabel: 'London',
      },
    ],
  },
  calendars: [
    {
      id: 'cal1',
      name: '๊ฐœ์ธ',
      backgroundColor: '#03bd9e',
    },
    {
      id: 'cal2',
      name: '์ง์žฅ',
      backgroundColor: '#00a9ff',
    },
  ],
};

const calendar = new Calendar(container, options);

image

๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

Google Analytics(GA)๋ฅผ ์œ„ํ•œ hostname ์ˆ˜์ง‘ ๊ฑฐ๋ถ€ํ•˜๊ธฐ

TOAST UI ์บ˜๋ฆฐ๋”๋Š” GA๋ฅผ ์ ์šฉํ•˜์—ฌ ์˜คํ”ˆ ์†Œ์Šค ์‚ฌ์šฉ์— ๋Œ€ํ•œ ํ†ต๊ณ„๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ ์ „ ์„ธ๊ณ„์—์„œ ์–ผ๋งˆ๋‚˜ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. ์ด๋Š” ํ”„๋กœ์ ํŠธ์˜ ํ–ฅํ›„ ์ง„ํ–‰์„ ๊ฒฐ์ •ํ•˜๋Š” ์ค‘์š”ํ•œ ์ง€ํ‘œ ์—ญํ• ์„ ํ•œ๋‹ค. location.hostname(์˜ˆ๋ฅผ ๋“ค์–ด "ui.toast.com")์„ ์ˆ˜์ง‘ํ•˜๋ฉฐ ์‚ฌ์šฉ๋Ÿ‰์— ๋Œ€ํ•œ ํ†ต๊ณ„๋ฅผ ์ธก์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋งŒ ์‚ฌ์šฉ๋œ๋‹ค.

๋งŒ์•ฝ ์ด๋ฅผ ๊ฑฐ๋ถ€ํ•˜๋ ค๋ฉด usageStatistics ์˜ต์…˜์„ false๋กœ ์„ค์ •ํ•œ๋‹ค.

const calendar = new Calendar('#calendar', {
  usageStatistics: false
});

์ผ์ • ์ƒ์„ฑํ•˜๊ธฐ

์ผ์ •์„ ์ƒ์„ฑํ•  ๋•Œ๋Š” Calendar ์ธ์Šคํ„ด์Šค์˜ createEvents ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

์ผ์ • ์ •๋ณด๋Š” EventObject ํ˜•ํƒœ๋กœ ๋„˜๊ธด๋‹ค.

calendar.createEvents([
  {
    id: 'event1',
    calendarId: 'cal2',
    title: '์ฃผ๊ฐ„ ํšŒ์˜',
    start: '2022-06-07T09:00:00',
    end: '2022-06-07T10:00:00',
  },
  {
    id: 'event2',
    calendarId: 'cal1',
    title: '์ ์‹ฌ ์•ฝ์†',
    start: '2022-06-08T12:00:00',
    end: '2022-06-08T13:00:00',
  },
  {
    id: 'event3',
    calendarId: 'cal2',
    title: 'ํœด๊ฐ€',
    start: '2022-06-08',
    end: '2022-06-10',
    isAllday: true,
    category: 'allday',
  },
]);

createEvents

ํŒ์—… ์‚ฌ์šฉํ•˜๊ธฐ

TOAST UI Calendar๋Š” ์ผ์ • ์ƒ์„ฑ ํŒ์—…๊ณผ ์ผ์ • ์ƒ์„ธ ํŒ์—…์„ ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•œ๋‹ค. ์ด๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด useFormPopup๊ณผ useDetailPopup ์˜ต์…˜์„ true๋กœ ์„ค์ •ํ•ด์•ผ ํ•œ๋‹ค. ์˜ต์…˜์€ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ ์„ค์ •ํ•˜๊ฑฐ๋‚˜, ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ํ›„ setOptions ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค.

์ผ์ • ์ƒ์„ฑ ํŒ์—…์„ ์‚ฌ์šฉํ•  ๋•Œ๋Š” tui-date-picker์™€ tui-time-picker์˜ css ํŒŒ์ผ์„ ๊ฐ€์ ธ์™€์•ผ ์Šคํƒ€์ผ์ด ์ œ๋Œ€๋กœ ์ ์šฉ๋œ๋‹ค.

npm install tui-date-picker tui-time-picker
// ์ผ์ • ์ƒ์„ฑ ํŒ์—…์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด tui-date-picker์™€ tui-time-picker์˜ css ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
import 'tui-date-picker/dist/tui-date-picker.css';
import 'tui-time-picker/dist/tui-time-picker.css';

calendar.setOptions({
  useFormPopup: true,
  useDetailPopup: true,
});
์ผ์ • ์ƒ์„ฑ ํŒ์—… ์ผ์ • ์ƒ์„ธ ํŒ์—…
useFormPopup useDetailPopup

ํ…Œ๋งˆ ์ ์šฉํ•˜๊ธฐ

์ƒ‰์ƒ, ๋ฐฐ๊ฒฝ์ƒ‰๊ณผ ๊ฐ™์€ ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š” ํ…Œ๋งˆ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ…Œ๋งˆ๋Š” ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ ์˜ต์…˜ ๊ฐ์ฒด์˜ theme ํ”„๋กœํผํ‹ฐ์— ๋ช…์‹œํ•˜๊ฑฐ๋‚˜, ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ํ›„ setTheme ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ์ ์šฉ ๊ฐ€๋Šฅํ•œ ํ…Œ๋งˆ๋Š” ํ…Œ๋งˆ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

calendar.setTheme({
  common: {
    gridSelection: {
      backgroundColor: 'rgba(81, 230, 92, 0.05)',
      border: '1px dotted #515ce6',
    },
  },
});

theme

ํ…œํ”Œ๋ฆฟ ์ ์šฉํ•˜๊ธฐ

ํ…œํ”Œ๋ฆฟ์€ ์ปค์Šคํ…€ ๋ Œ๋”๋ง์„ ์ง€์›ํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ ์˜ต์…˜ ๊ฐ์ฒด์˜ template ํ”„๋กœํผํ‹ฐ์— ๋ช…์‹œํ•˜๊ฑฐ๋‚˜, ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ํ›„ setOptions ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ์ ์šฉ ๊ฐ€๋Šฅํ•œ ํ…œํ”Œ๋ฆฟ์€ ํ…œํ”Œ๋ฆฟ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

function formatTime(time) {
  const hours = `${time.getHours()}`.padStart(2, '0');
  const minutes = `${time.getMinutes()}`.padStart(2, '0');

  return `${hours}:${minutes}`;
}

calendar.setOptions({
  template: {
    time(event) {
      const { start, end, title } = event;

      return `<span style="color: white;">${formatTime(start)}~${formatTime(end)} ${title}</span>`;
    },
    allday(event) {
      return `<span style="color: gray;">${event.title}</span>`;
    },
  },
});

template

์ธ์Šคํ„ด์Šค ์ด๋ฒคํŠธ ์ ์šฉํ•˜๊ธฐ

TOAST UI Calendar๋Š” ์ธ์Šคํ„ด์Šค ์ด๋ฒคํŠธ๋ฅผ ์ œ๊ณตํ•œ๋‹ค. ํ•„์š”์— ๋”ฐ๋ผ ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์‹ ํ•˜๋„๋ก ์„ค์ •ํ•˜์—ฌ ์›ํ•˜๋Š” ๋™์ž‘์„ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ ๋ณ„๋„๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์ž์‹ ๋งŒ์˜ ์ด๋ฒคํŠธ๋ฅผ ์„ค์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

on ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šค ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ธ์Šคํ„ด์Šค ์ด๋ฒคํŠธ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค.

calendar.on('clickEvent', ({ event }) => {
  const el = document.getElementById('clicked-event');
  el.innerText = event.title;
});

instance event