本文へ移動

カレンダーとボード

イベントカレンダー

会議室の予約を日・週・月・予定リスト表示で、部屋ごとの列や終日予定とともに表示します。移動、長さの変更、新規予約は提案として親が二重予約を確認して適用し、毎週の定例会議は1回分、以降すべて、シリーズ全体のいずれかで編集できます。

ライブデモGitHub で見る ↗

イベントカレンダー

部屋、終日予定、親が検証して適用する予約を、日・週・月・予定リストで表示します。

2026/11/09~2026/11/15
11月9日(月)
11月10日(火)
11月11日(水)
11月12日(木)
11月13日(金)
11月14日(土)
11月15日(日)
終日
上下の矢印キーで予定を移動し、Shift で終了を伸縮します。左右キーで別の日や資源へ移動します。Escape でドラッグを取り消します。左右の矢印キーで予定を1日ずつ移動し、Shift で終了を伸縮します。Escape でドラッグを取り消します。

予約をドラッグで移動し、下端をドラッグで伸縮します。空いている枠をドラッグすると部屋を予約できます。

読み込んだ範囲: 11月9日(月) – 11月15日(日)。フォーカスした予約は矢印キーで移動、Shift+矢印で伸縮し、日表示では左右キーで別の部屋へ移動します。予定リストでは上下キーで予約間を移動します。週次定例は毎週火曜日に繰り返し、「繰り返し予定の編集」で編集の対象を選びます。Escape で選択を解除します。読み取り専用では空いている所をクリックしても解除します。

デモの右下の角をドラッグすると高さを変えられます。

ソースコード

vue
<script setup lang="ts">
import { computed, ref, useTemplateRef } from 'vue'
import {
  EventCalendar, applyRecurringEdit, eventCalendarRange, expandRecurringEvents, intlTimeFormatter, useEditHistory, type CalendarEvent,
  type CalendarResource, type EventCalendarCreate, type EventCalendarEdit, type EventCalendarViewName, type RecurringEditScope, type TimeRange,
} from '../src'
import DemoPanel from './components/DemoPanel.vue'
import { download } from './download'
import StatusLine from './components/StatusLine.vue'
import { unusedNumber } from './ids'
import { useDemoLocale } from './i18n'

const { t, labels, intlLocale } = useDemoLocale()

// Room bookings in an event calendar: the parent owns the events and applies the proposals of the calendar (moves,
// resizes, room changes and new bookings) as undoable steps. A room can hold one booking at a time, so `validateEdit`
// and `validateCreate` reject double bookings. All times are UTC, so the demo never depends on the local zone. The weekly
// sync is a recurring series (`recurrence`): the calendar shows its occurrences from `expandRecurringEvents`, and an edit
// of one occurrence is applied with `applyRecurringEdit` to this event, this and following events, or all of them.
// The view switch also offers the opt-in agenda view (`views`), a list of the week's bookings by day.
const at = (date: string, time = '00:00') => Date.parse(`2026-11-${date}T${time}:00Z`)
const views: EventCalendarViewName[] = ['day', 'week', 'month', 'agenda']
const rooms: CalendarResource[] = [
  { id: 'atlas', label: 'Atlas', detail: t({ en: '12 seats', ja: '12 席' }) },
  { id: 'borealis', label: 'Borealis', detail: t({ en: '6 seats', ja: '6 席' }) },
  { id: 'lab', label: t({ en: 'Hardware lab', ja: 'ハードウェアラボ' }), detail: t({ en: 'Bench access', ja: '作業台あり' }) },
]
const roomLabel = (id?: string) => rooms.find(room => room.id === id)?.label
type Booking = CalendarEvent<{ owner: string }>
const initialEvents: Booking[] = [
  { id: 'standup', label: t({ en: 'Standup', ja: '朝会' }), start: at('09', '09:00'), end: at('09', '09:30'), resourceId: 'atlas', data: { owner: 'Platform' } },
  { id: 'review', label: t({ en: 'Design review', ja: 'デザインレビュー' }), start: at('11', '10:00'), end: at('11', '11:00'), resourceId: 'atlas', tone: 'violet', data: { owner: 'Design' } },
  { id: 'call', label: t({ en: 'Customer call', ja: '顧客との通話' }), start: at('11', '10:30'), end: at('11', '12:00'), resourceId: 'borealis', tone: 'teal', data: { owner: 'Sales' } },
  { id: 'safety', label: t({ en: 'Lab safety', ja: 'ラボの安全講習' }), start: at('11', '13:00'), end: at('11', '14:00'), resourceId: 'lab', tone: 'amber', data: { owner: 'Facilities' } },
  { id: 'demo', label: t({ en: 'Sprint demo', ja: 'スプリントデモ' }), start: at('12', '15:00'), end: at('12', '16:30'), resourceId: 'borealis', data: { owner: 'Platform' } },
  { id: 'migration', label: t({ en: 'Server migration', ja: 'サーバー移行' }), start: at('13', '18:00'), end: at('14', '09:00'), resourceId: 'lab', tone: 'amber', data: { owner: 'Platform' } },
  { id: 'retro', label: t({ en: 'Retrospective', ja: '振り返り' }), start: at('13', '11:00'), end: at('13', '12:00'), resourceId: 'atlas', tone: 'violet', data: { owner: 'Platform' } },
  { id: 'offsite', label: t({ en: 'Team offsite', ja: 'チーム合宿' }), start: at('17'), end: at('19'), allDay: true, tone: 'teal', data: { owner: 'All' } },
  { id: 'release', label: t({ en: 'Release day', ja: 'リリース日' }), start: at('13'), end: at('14'), allDay: true, color: '#c23b22', data: { owner: 'Platform' } },
  { id: 'audit', label: t({ en: 'Lab audit', ja: 'ラボ監査' }), start: at('10'), end: at('11'), allDay: true, resourceId: 'lab', tone: 'amber', editable: false, data: { owner: 'Facilities' } },
  {
    id: 'sync', label: t({ en: 'Weekly sync', ja: '週次定例' }), start: at('03', '16:00'), end: at('03', '16:30'), resourceId: 'borealis', tone: 'violet', data: { owner: 'Platform' },
    recurrence: { rule: 'FREQ=WEEKLY;BYDAY=TU;COUNT=8' },
  },
]
// The demo clock is fixed, so the now line and Today never depend on when the demo runs.
const now = at('11', '11:15')

const history = useEditHistory(initialEvents)
const events = history.state
const view = ref<EventCalendarViewName>('week')
const date = ref(now)
const selectedId = ref<string>()
const showRooms = ref(true)
const readonly = ref(false)
const rtl = ref(false)
const status = ref(t({ en: 'Drag a booking to move it, drag its bottom edge to resize it, or drag over an empty slot to book a room.', ja: '予約をドラッグで移動し、下端をドラッグで伸縮します。空いている枠をドラッグすると部屋を予約できます。' }))
const loaded = ref<TimeRange>(eventCalendarRange('week', now))
const scope = ref<RecurringEditScope>('occurrence')
const scopeNames: Record<RecurringEditScope, string> = t({
  en: { occurrence: 'this event', following: 'this and following events', series: 'all events' },
  ja: { occurrence: 'この予定', following: 'この予定以降', series: 'すべての予定' },
})
/** The bookings the calendar shows: plain events and the occurrences of the series in the loaded range. */
const shown = computed(() => expandRecurringEvents(events.value, loaded.value))

const formatDay = intlTimeFormatter({ locale: intlLocale.value, format: { weekday: 'short', month: 'short', day: 'numeric' } })
const formatTime = intlTimeFormatter({ locale: intlLocale.value })
const label = (id: string) => shown.value.find(event => event.id === id)?.label ?? id
function describe(range: TimeRange, allDay?: boolean) {
  return allDay ? formatDay(range.start) : `${formatDay(range.start)} ${formatTime(range.start)}–${formatTime(range.end)}`
}

/** The room booking that `range` would double-book in `resourceId`, if any. */
function conflict(range: TimeRange, resourceId: string | undefined, ignoreId?: string) {
  if (resourceId === undefined) return undefined
  return shown.value.find(event => event.id !== ignoreId && event.resourceId === resourceId && event.start < range.end && range.start < event.end)
}
function validateEdit(change: EventCalendarEdit) {
  const event = shown.value.find(item => item.id === change.id)
  const resourceId = change.resource?.after ?? event?.resourceId
  const other = conflict(change.after, resourceId, change.id)
  if (other) return t({ en: `${roomLabel(resourceId)} is already booked for ${other.label}.`, ja: `${roomLabel(resourceId)} は ${other.label} で予約済みです。` })
}
function validateCreate(proposal: EventCalendarCreate) {
  const other = conflict(proposal, proposal.resourceId)
  if (other) return t({ en: `${roomLabel(proposal.resourceId)} is already booked for ${other.label}.`, ja: `${roomLabel(proposal.resourceId)} は ${other.label} で予約済みです。` })
}
function applyEdit(change: EventCalendarEdit) {
  if (change.occurrence) {
    // An occurrence of the weekly sync: the scope decides which occurrences change.
    const event = shown.value.find(item => item.id === change.id)!
    history.commit(applyRecurringEdit(events.value, change.occurrence, { ...change.after, ...(change.resource ? { resourceId: change.resource.after } : {}) }, scope.value))
    const room = change.resource ? t({ en: ` in ${roomLabel(change.resource.after)}`, ja: `、${roomLabel(change.resource.after)}` }) : ''
    status.value = t({ en: `${event.label} → ${describe(change.after, event.allDay)}${room} (${scopeNames[scope.value]}).`, ja: `${event.label} → ${describe(change.after, event.allDay)}${room}(${scopeNames[scope.value]})。` })
    return
  }
  history.commit(events.value.map(event => event.id === change.id
    ? { ...event, ...change.after, ...(change.resource ? { resourceId: change.resource.after } : {}) } : event))
  const event = events.value.find(item => item.id === change.id)!
  const room = change.resource ? t({ en: ` in ${roomLabel(change.resource.after)}`, ja: `、${roomLabel(change.resource.after)}` }) : ''
  status.value = t({ en: `${event.label} → ${describe(change.after, event.allDay)}${room}.`, ja: `${event.label} → ${describe(change.after, event.allDay)}${room}。` })
}
function create(proposal: EventCalendarCreate) {
  const number = unusedNumber(events.value, 'booking-')
  const resourceId = proposal.resourceId
  history.commit([...events.value, {
    id: 'booking-' + number, label: t({ en: 'New booking ', ja: '新しい予約 ' }) + number, start: proposal.start, end: proposal.end, allDay: proposal.allDay,
    tone: 'blue', ...(resourceId ? { resourceId } : {}), data: { owner: t({ en: 'You', ja: 'あなた' }) },
  }])
  status.value = t({
    en: `Booked New booking ${number}, ${describe(proposal, proposal.allDay)}${resourceId ? ' in ' + roomLabel(resourceId) : ''}.`,
    ja: `新しい予約 ${number} を登録しました(${describe(proposal, proposal.allDay)}${resourceId ? '、' + roomLabel(resourceId) : ''})。`,
  })
}
function rejected(change: EventCalendarEdit | EventCalendarCreate, reason: string) {
  status.value = t({ en: 'Rejected: ', ja: '却下: ' }) + reason
}
function activate(id: string) {
  const event = shown.value.find(item => item.id === id)
  if (event) {
    status.value = t({
      en: `Opened ${event.label} (${event.data?.owner ?? 'no owner'}), ${describe(event, event.allDay)}${event.resourceId ? ', ' + roomLabel(event.resourceId) : ''}.`,
      ja: `${event.label} を開きました(${event.data?.owner ?? '担当なし'})。${describe(event, event.allDay)}${event.resourceId ? '、' + roomLabel(event.resourceId) : ''}。`,
    })
  }
}
function select(id: string) {
  status.value = t({ en: 'Selected ' + label(id) + '.', ja: label(id) + ' を選択しました。' })
}
// The calendar's selection follows `selectedId`: a click on empty calendar space that books nothing (the calendar is
// creatable, so only in read-only mode) and Escape that did not cancel a drag (the calendar calls preventDefault for
// that one) clear it.
function clearSelection() {
  if (selectedId.value === undefined) return
  selectedId.value = undefined
  status.value = t({ en: 'Selection cleared.', ja: '選択を解除しました。' })
}
function escapeSelection(event: KeyboardEvent) {
  if (event.key === 'Escape' && !event.defaultPrevented) clearSelection()
}
function rangeChange(range: TimeRange, current: EventCalendarViewName) {
  // A real application would load the bookings that overlap this range here.
  loaded.value = range
  void current
}
const loadedText = computed(() => `${formatDay(loaded.value.start)} – ${formatDay(loaded.value.end - 1)}`)
function undo() {
  history.undo()
  status.value = t({ en: 'Undid the last booking change.', ja: '直前の予約の変更を元に戻しました。' })
}
function redo() {
  history.redo()
  status.value = t({ en: 'Redid the booking change.', ja: '予約の変更をやり直しました。' })
}
// The export draws the shown view, the agenda included, with the calendar's labels, time zone and direction.
const calendar = useTemplateRef('calendar')
function exportSvg() {
  const svg = calendar.value?.exportSvg({ title: t({ en: 'Room bookings', ja: '会議室の予約' }) })
  if (!svg) return
  download(svg, 'room-bookings.svg')
  status.value = t({ en: `Exported SVG (${svg.length} characters).`, ja: `SVG を出力しました(${svg.length} 文字)。` })
}
</script>

<template>
  <DemoPanel title-id="event-calendar-title" :title="t({ en: 'Event calendar', ja: 'イベントカレンダー' })" :subtitle="t({ en: 'Day, week, month and agenda views with rooms, all-day events and bookings the parent validates and applies.', ja: '部屋、終日予定、親が検証して適用する予約を、日・週・月・予定リストで表示します。' })">
    <template #options>
      <label><input v-model="showRooms" type="checkbox"> {{ t({ en: 'Rooms in day view', ja: '日表示で部屋ごとに表示' }) }}</label>
      <label><input v-model="readonly" type="checkbox"> {{ t({ en: 'Read-only', ja: '読み取り専用' }) }}</label>
      <label><input v-model="rtl" type="checkbox"> {{ t({ en: 'Right to left', ja: '右から左' }) }}</label>
      <label>{{ t({ en: 'Recurring edits', ja: '繰り返し予定の編集' }) }} <select v-model="scope"><option value="occurrence">{{ t({ en: 'This event', ja: 'この予定' }) }}</option><option value="following">{{ t({ en: 'This and following', ja: 'この予定以降' }) }}</option><option value="series">{{ t({ en: 'All events', ja: 'すべての予定' }) }}</option></select></label>
      <button type="button" :disabled="!history.canUndo.value" @click="undo">{{ t({ en: 'Undo', ja: '元に戻す' }) }}</button>
      <button type="button" :disabled="!history.canRedo.value" @click="redo">{{ t({ en: 'Redo', ja: 'やり直す' }) }}</button>
      <button type="button" @click="exportSvg">{{ t({ en: 'Export SVG', ja: 'SVG で出力' }) }}</button>
    </template>
    <EventCalendar
      ref="calendar" v-model:view="view" v-model:date="date" v-model:selected-id="selectedId" :views="views"
      :events="shown" :resources="showRooms ? rooms : undefined" :now="now" :day-start="7" :day-end="20" :height="440"
      :readonly="readonly" creatable :labels="{ ...labels.eventCalendar, region: t({ en: 'Room bookings', ja: '会議室の予約' }) }" :locale="intlLocale" :dir="rtl ? 'rtl' : 'ltr'" :validate-edit="validateEdit" :validate-create="validateCreate"
      @edit="applyEdit" @edit-rejected="rejected" @create="create" @create-rejected="rejected" @select="select"
      @event-activate="activate" @range-change="rangeChange" @edit-cancel="status = 'Drag cancelled.'"
      @background-click="clearSelection" @keydown="escapeSelection"
    />
    <StatusLine :label="t({ en: 'Calendar status', ja: 'カレンダーの状態' })">{{ status }}</StatusLine>
    <p class="hint">{{ t({
      en: `Loaded range: ${loadedText}. Arrow keys move a focused booking, Shift+arrows resize it, and in the day view Left and Right move it to another room; in the agenda, Up and Down move between bookings. The weekly sync repeats every Tuesday; "Recurring edits" chooses which of its occurrences an edit changes. Escape clears the selection, and so does a click on empty space in read-only mode.`,
      ja: `読み込んだ範囲: ${loadedText}。フォーカスした予約は矢印キーで移動、Shift+矢印で伸縮し、日表示では左右キーで別の部屋へ移動します。予定リストでは上下キーで予約間を移動します。週次定例は毎週火曜日に繰り返し、「繰り返し予定の編集」で編集の対象を選びます。Escape で選択を解除します。読み取り専用では空いている所をクリックしても解除します。`,
    }) }}</p>
  </DemoPanel>
</template>

MIT ライセンスで公開しています。