定制 da-sie/livewire-calendar 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

da-sie/livewire-calendar

Composer 安装命令:

composer require da-sie/livewire-calendar

包简介

Laravel Livewire calendar component with month/week/day views, drag-and-drop, multi-day events, and accessibility

README 文档

README

A Laravel Livewire calendar component with month, week, and day views. Supports multi-day events, drag-and-drop, keyboard navigation, and full accessibility (ARIA).

Fork of asantibanez/livewire-calendar, modernized for Livewire 4, Laravel 11-13, and PHP 8.2+.

Requirements

  • PHP 8.2+
  • Laravel 11, 12, or 13
  • Livewire 4
  • TailwindCSS (for default styling)

Installation

composer require da-sie/livewire-calendar

Quick Start

Create a Livewire component that extends LivewireCalendar:

php artisan make:livewire AppointmentsCalendar
use Asantibanez\LivewireCalendar\LivewireCalendar;
use Illuminate\Support\Collection;
use Carbon\Carbon;

class AppointmentsCalendar extends LivewireCalendar
{
    public function events(): Collection
    {
        return collect([
            [
                'id' => 1,
                'title' => 'Breakfast',
                'description' => 'Pancakes!',
                'date' => Carbon::today(),
            ],
            [
                'id' => 2,
                'title' => 'Meeting',
                'description' => 'Work stuff',
                'date' => Carbon::tomorrow(),
            ],
        ]);
    }
}

Include in a Blade view:

<livewire:appointments-calendar />

Add the drag-and-drop scripts after Livewire's scripts:

@livewireCalendarScripts

Event Format

Events are keyed arrays with these fields:

Key Type Required Description
id mixed yes Unique identifier
title string yes Display title
description string no Description text
date Carbon/string yes Start date
date_end Carbon/string no End date (inclusive) for multi-day events

Multi-Day Events

Add date_end to make an event span multiple days:

[
    'id' => 1,
    'title' => 'Conference',
    'description' => 'Annual tech conference',
    'date' => '2026-04-08',
    'date_end' => '2026-04-10',
]

Multi-day events display across all days in their range. The title shows on the start day; continuation days show a compact indicator. Events without date_end behave as single-day events.

Loading multi-day events: If your events can start before the visible grid, use an overlap query:

public function events(): Collection
{
    return Event::query()
        ->whereDate('date', '<=', $this->gridEndsAt)
        ->where(function ($q) {
            $q->whereDate('date_end', '>=', $this->gridStartsAt)
              ->orWhereNull('date_end');
        })
        ->get()
        ->map(fn (Event $e) => [
            'id' => $e->id,
            'title' => $e->title,
            'description' => $e->notes,
            'date' => $e->date,
            'date_end' => $e->date_end,
        ]);
}

View Modes

The calendar supports three view modes: month (default), week, and day.

<livewire:appointments-calendar view-mode="week" />

Switching Views

Call setViewMode() from your component or a custom view:

$this->setViewMode('week');  // 'month', 'week', 'day'

Or from Blade via wire:click:

<button wire:click="setViewMode('month')">Month</button>
<button wire:click="setViewMode('week')">Week</button>
<button wire:click="setViewMode('day')">Day</button>

Navigation

Method Description
goToPreviousMonth Navigate to previous month
goToNextMonth Navigate to next month
goToCurrentMonth Navigate to current month
goToPreviousWeek Navigate to previous week
goToNextWeek Navigate to next week
goToPreviousDay Navigate to previous day
goToNextDay Navigate to next day

Use before-calendar-view or after-calendar-view to add navigation controls.

Filtering Properties

Use these properties in events() to filter your data:

Property Description
$this->startsAt Start of the visible period
$this->endsAt End of the visible period
$this->gridStartsAt Start of the grid (may include adjacent days)
$this->gridEndsAt End of the grid

In day mode, gridStartsAt and gridEndsAt match the single visible day. In week mode, they match the visible week.

Customization

Component Props

<livewire:appointments-calendar
    year="2026"
    month="4"
    view-mode="month"
    week-starts-at="1"
    event-view="custom.event"
    day-view="custom.day"
    day-of-week-view="custom.day-of-week"
    calendar-view="custom.calendar"
    before-calendar-view="custom.header"
    after-calendar-view="custom.footer"
    drag-and-drop-classes="border border-blue-400 border-4"
    :day-click-enabled="true"
    :event-click-enabled="true"
    :drag-and-drop-enabled="true"
    poll-millis="5000"
    poll-action="refreshEvents"
/>

Publishing Views

php artisan vendor:publish --tag=livewire-calendar

Published views receive these variables:

day view: $componentId, $day, $dayInMonth, $isToday, $events, $viewMode

event view: $event, $isStart, $isEnd, $eventClickEnabled, $dragAndDropEnabled

Publishing Assets

To use the JS file directly (instead of @livewireCalendarScripts):

php artisan vendor:publish --tag=livewire-calendar-assets

Then include manually:

<script src="{{ asset('vendor/livewire-calendar/calendar.js') }}" defer></script>

Interactions

Override these methods in your component:

public function onDayClick($year, $month, $day)
{
    // Triggered when a day cell is clicked
}

public function onEventClick($eventId)
{
    // Triggered when an event is clicked
}

public function onEventDropped($eventId, $year, $month, $day)
{
    // Triggered when an event is dragged and dropped to another day
    // $year/$month/$day = target day
}

Multi-Day Drag Source

For multi-day events, you may need to know which day segment was dragged. Listen for the calendar-event-dropped Livewire event:

use Livewire\Attributes\On;

#[On('calendar-event-dropped')]
public function handleEventDrop($eventId, $targetYear, $targetMonth, $targetDay, $sourceYear, $sourceMonth, $sourceDay)
{
    $event = Event::find($eventId);

    // Calculate how many days the event was moved
    $source = Carbon::create($sourceYear, $sourceMonth, $sourceDay);
    $target = Carbon::create($targetYear, $targetMonth, $targetDay);
    $diff = $source->diffInDays($target, false);

    // Shift both start and end dates by the same offset
    $event->update([
        'date' => Carbon::parse($event->date)->addDays($diff),
        'date_end' => $event->date_end ? Carbon::parse($event->date_end)->addDays($diff) : null,
    ]);
}

Accessibility

The calendar includes full ARIA support:

  • role="grid" on the calendar, role="gridcell" on day cells, role="columnheader" on day-of-week headers
  • aria-label on days (e.g. "April 8, 2026") and events
  • Keyboard navigation: Arrow keys move between day cells, Enter/Space triggers day click
  • Event keyboard: Enter/Space triggers event click when enabled
  • aria-live="polite" region for screen reader announcements
  • role="button" and tabindex="0" on clickable events only

Testing

composer test

Credits

License

MIT. See LICENSE.md.

da-sie/livewire-calendar 适用场景与选型建议

da-sie/livewire-calendar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「calendar」 「livewire」 「livewire-calendar」 「da-sie」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 da-sie/livewire-calendar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 da-sie/livewire-calendar 我们能提供哪些服务?
定制开发 / 二次开发

基于 da-sie/livewire-calendar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 34
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 231
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-08