Skip to content

chantouchsek/vue-calendar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TOAST UI Calendar for Vue

This is Vue component wrapping TOAST UI Calendar.

vue2 github version npm version license PRs welcome

🚩 Table of Contents

πŸ’Ύ Install

Using npm

npm install --save @chantouchsek/vue-calendar

Using yarn

yarn add @chantouchsek/vue-calendar

♻️ Usage with Nuxt.js

Create vue-calendar.client.[js,ts]

import VueCalendar from '@chantouchsek/vue-calendar'
import Vue from 'vue'
import 'tui-calendar/dist/tui-calendar.css'

Vue.use(VueCalendar)

Add vue-calendar.client to plugins section of nuxt.config.js

export default {
    plugins: ['~plugins/vue-calendar.client'],
}

πŸ“… Usage

Load

You can use Toast UI Calendar for Vue as moudule format or namespace. Also you can use Single File Component (SFC of Vue). When using module format and SFC, you should load tui-calendar.css in the script.

  • Using Ecmascript module

    import { VueCalendar } from '@chantouchsek/vue-calendar';
    import 'tui-calendar/dist/tui-calendar.css';
    
    // If you use the default popups, use this.
    import 'tui-date-picker/dist/tui-date-picker.css';
    import 'tui-time-picker/dist/tui-time-picker.css';
  • Using Commonjs module

    require('tui-calendar/dist/tui-calendar.css');
    
    // If you use the default popups, use this.
    require('tui-date-picker/dist/tui-date-picker.css');
    require('tui-time-picker/dist/tui-time-picker.css');
    
    var tuicalendar = require('@chantouchsek/vue-calendar');
    var VueCalendar = tuicalendar.VueCalendar;
  • Using Single File Component

    import 'tui-calendar/dist/tui-calendar.css'
    import VueCalendar from '@chantouchsek/vue-calendar/src/VueCalendar.vue'
    
    // If you use the default popups, use this.
    import 'tui-date-picker/dist/tui-date-picker.css';
    import 'tui-time-picker/dist/tui-time-picker.css';
  • Using namespace

    var VueCalendar = tuicalendar.VueCalendar;

Implement

  • Load calendar component and then add it to the components in your component or Vue instance.

    import 'tui-calendar/dist/tui-calendar.css'
    import { VueCalendar } from '@chantouchsek/vue-calendar'
    
    export default {
        name: 'YourComponent',
        components: {
            'calendar': VueCalendar
        }
    }

    or

    import 'tui-calendar/dist/tui-calendar.css'
    import { VueCalendar } from '@chantouchsek/vue-calendar'
    
    new Vue({
        el: '#app',
        components: {
            'calendar': VueCalendar
        }
    });
  • Insert <calendar> in the template or html. <calendar> element should have own height.

    <calendar height="800" />

Props

We provide props for Options of Toast UI Calendar. Each name of props is same options of Toast UI Calendar except view is for defaultView of option. Additionally you can set schedules using schedules of prop.

Name Type Default Reactive Description
tag String div O Tag of render element.
height String 800 O Set height of calendar.
events Array [] O Schedule list of calendar. If this prop is changed, Calendar is rendering.
calendars Array [] O Type list of calendars
view String 'week' O View of calendar. There are three views, day, week and month.
taskView Boolean, Array true O Show the milestone and task in weekly, daily view. If set true, the milestone and task show. If you want to show only the milestone or task, set array like this: ['mileston'] or ['task'].
scheduleView Boolean, Array true O Show the all day and time grid in weekly, daily view. If set true, the all day and time show. If you want to show only the all day or time, set array like this: ['allday'] or ['time'].
theme Object {} O Customize theme. For more infomation about theme, see ThemeConfig of Toast UI Calendar.
week Object {} O Set more for the week and day view. For more infomation about week, see WeekOptions of Toast UI Calendar.
month Object {} O Set more for the month view. For more infomation about month, see MonthOptions of Toast UI Calendar.
timezones Array [] O Set multiple time zones. For more information about timezones, see Timezone of Toast UI Calendar.
disableDblClick Boolean false O Disable double click to create a schedule.
disableClick Boolean false O Whether to use mouse click events as defaults to create schedules.
isReadOnly Boolean false O Set read only mode. If true, a user can't create and modify any schedule.
template Object {} X Customize renderer. For more information about template, see Template of Toast UI Calendar.
useCreationPopup Boolean true X Whether use default creation popup or not.
useDetailPopup Boolean true X Whether use default detail popup or not.
usageStatistics Boolean true X Whether send hostnames to Google Analytics or not.

Example

<template>
  <calendar
      height="800"
      :calendars="calendarList"
      :schedules="scheduleList"
      :view="view"
      :taskView="taskView"
      :scheduleView="scheduleView"
      :theme="theme"
      :week="week"
      :month="month"
      :timezones="timezones"
      :disableDblClick="disableDblClick"
      :isReadOnly="isReadOnly"
      :template="template"
      :useCreationPopup="useCreationPopup"
      :useDetailPopup="useDetailPopup"
  />
</template>
<script>
import 'tui-calendar/dist/tui-calendar.css'
import {VueCalendar} from '@chantouchsek/vue-calendar';

export default {
  name: 'myCalendar',
  components: {
    'calendar': VueCalendar
  },
  data() {
    return {
      calendarList: [
        {
          id: '0',
          name: 'home'
        },
        {
          id: '1',
          name: 'office'
        }
      ],
      scheduleList: [
        {
          id: '1',
          calendarId: '1',
          title: 'my schedule',
          category: 'time',
          dueDateClass: '',
          start: '2018-10-18T22:30:00+09:00',
          end: '2018-10-19T02:30:00+09:00'
        },
        {
          id: '2',
          calendarId: '1',
          title: 'second schedule',
          category: 'time',
          dueDateClass: '',
          start: '2018-10-18T17:30:00+09:00',
          end: '2018-10-19T17:31:00+09:00'
        }
      ],
      view: 'day',
      taskView: false,
      scheduleView: ['time'],
      theme: {
        'month.dayname.height': '30px',
        'month.dayname.borderLeft': '1px solid #ff0000',
        'month.dayname.textAlign': 'center',
        'week.today.color': '#333',
        'week.daygridLeft.width': '100px',
        'week.timegridLeft.width': '100px'
      },
      week: {
        narrowWeekend: true,
        showTimezoneCollapseButton: true,
        timezonesCollapsed: false
      },
      month: {
        visibleWeeksCount: 6,
        startDayOfWeek: 1
      },
      timezones: [{
        timezoneOffset: 540,
        displayLabel: 'GMT+09:00',
        tooltip: 'Seoul'
      }, {
        timezoneOffset: -420,
        displayLabel: 'GMT-08:00',
        tooltip: 'Los Angeles'
      }],
      disableDblClick: true,
      isReadOnly: false,
      template: {
        milestone: function (schedule) {
          return `<span style="color:red;">${schedule.title}</span>`;
        },
        milestoneTitle: function () {
          return 'MILESTONE';
        },
      },
      useCreationPopup: true,
      useDetailPopup: false,
    }
  }
}
</script>

Event

  • afterRenderSchedule : Occurs when every single schedule after rendering whole calendar.
  • beforeCreateSchedule : Occurs when select time period in daily, weekly, monthly.
  • beforeDeleteSchedule : Occurs when delete a schedule.
  • beforeUpdateSchedule : Occurs when drag a schedule to change time in daily, weekly, monthly.
  • clickDayname : Occurs when click a day name in weekly.
  • clickSchedule : Occurs when click a schedule.
  • clickTimezonesCollapseBtn : Occurs when click timezones collapse button. This event works when timezone prop has multi timezones and week prop has { showTimezoneCollapseButton: true }.

For more information such as the parameters of each event, see Event of Toast UI Calendar.

Example

<template>
  <calendar
      height="800"
      @afterRenderSchedule="onAfterRenderSchedule"
      @beforeCreateSchedule="onBeforeCreateSchedule"
      @beforeDeleteSchedule="onBeforeDeleteSchedule"
      @beforeUpdateSchedule="onBeforeUpdateSchedule"
      @clickDayname="onClickDayname"
      @clickSchedule="onClickSchedule"
      @clickTimezonesCollapseBtn="onClickTimezonesCollapseBtn"
  />
</template>
<script>
import 'tui-calendar/dist/tui-calendar.css'
import {VueCalendar} from '@chantouchsek/vue-calendar';

export default {
  name: 'myCalendar',
  components: {
    'calendar': VueCalendar
  },
  methods: {
    onAfterRenderSchedule(e) {
      // implement your code
    },
    onBeforeCreateSchedule(e) {
      // implement your code
    },
    onBeforeDeleteSchedule(e) {
      // implement your code
    },
    onBeforeUpdateSchedule(e) {
      // implement your code
    },
    onClickDayname(e) {
      // implement your code
    },
    onClickSchedule(e) {
      // implement your code
    },
    onClickTimezonesCollapseBtn(e) {
      // implement your code
    }
  }
}
</script>

Method

For use method, first you need to assign ref attribute of element like this:

<calendar ref="calendar"/>

After then, you can use methods through this.$refs. We provide getRootElement and invoke methods.

  • getRootElement

    You can get root element of calendar using this method.

    this.$refs.calendar.getRootElement();
  • invoke

    If you want to more manipulate the Calendar, you can use invoke method to call the method of Toast UI Calendar. First argument of invoke is name of the method and second argument is parameters of the method. To find out what kind of methods are available, see method of Toast UI Calendar.

    this.$refs.calendar.invoke('today');

πŸ”§ Pull Request Steps

TOAST UI products are open source, so you can create a pull request(PR) after you fix issues. Run npm scripts and develop yourself with the following process.

Setup

Fork develop branch into your personal repository. Clone it to local computer. Install node modules. Before starting development, you should check to haveany errors.

$ git clone https://github.com/{your-personal-repo}/[[repo name]].git
$ cd [[repo name]]
$ npm install

Develop

Let's start development!

Pull Request

Before PR, check to test lastly and then check any errors. If it has no error, commit and then push it!

For more information on PR's step, please see links of Contributing section.

πŸ’¬ Contributing

πŸ“œ License

This software is licensed under the MIT Β© ChantouchSek