Skip to content

Commit

Permalink
feat: add slot label and day header format options
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <[email protected]>
  • Loading branch information
lukas-frey committed Oct 10, 2024
1 parent bca113d commit fb806f6
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/js/calendar-widget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion resources/js/calendar-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function calendarWidget({
dateSelectEnabled = false,
dateClickEnabled = false,
viewDidMountEnabled = false,
eventAllUpdatedEnabled = false,
dayMaxEvents = false,
moreLinkContent = null,
resources = [],
Expand All @@ -21,6 +22,8 @@ export default function calendarWidget({
hasEventClickContextMenu = false,
hasNoEventsClickContextMenu = false,
options = {},
dayHeaderFormat = null,
slotLabelFormat = null,
}) {
return {

Expand All @@ -47,6 +50,14 @@ export default function calendarWidget({
eventDurationEditable: eventResizeEnabled,
};

if (dayHeaderFormat) {
settings.dayHeaderFormat = dayHeaderFormat;
}

if (slotLabelFormat) {
settings.slotLabelFormat = slotLabelFormat;
}

if (dateClickEnabled) {
settings.dateClick = (info) => {
if (hasDateClickContextMenu) {
Expand Down Expand Up @@ -245,6 +256,14 @@ export default function calendarWidget({
};
}

if (eventAllUpdatedEnabled) {
settings.eventAllUpdated = (info) => {
this.$wire.onEventAllUpdated({
info: info,
});
};
}

this.ec = new EventCalendar(this.$el.querySelector('div'), {
...settings,
...options
Expand Down Expand Up @@ -278,7 +297,7 @@ export default function calendarWidget({
return undefined;
},

getResourceLabelContent: function(info) {
getResourceLabelContent: function (info) {
if (typeof resourceLabelContent === 'string') {
return this.wrapContent(resourceLabelContent, info);
}
Expand Down
7 changes: 7 additions & 0 deletions resources/views/widgets/calendar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
$dateClickEnabled = $this->isDateClickEnabled();
$dateSelectEnabled = $this->isDateSelectEnabled();
$viewDidMountEnabled = $this->isViewDidMountEnabled();
$eventAllUpdatedEnabled = $this->isEventAllUpdatedEnabled();
$onEventResizeStart = method_exists($this, 'onEventResizeStart');
$onEventResizeStop = method_exists($this, 'onEventResizeStop');
$hasDateClickContextMenu = !empty($this->getCachedDateClickContextMenuActions());
$hasDateSelectContextMenu = !empty($this->getCachedDateSelectContextMenuActions());
$hasEventClickContextMenu = !empty($this->getCachedEventClickContextMenuActions());
$hasNoEventsClickContextMenu = !empty($this->getCachedNoEventsClickContextMenuActions());
$dayHeaderFormatJs = $this->getDayHeaderFormatJs();
$slotLabelFormatJs = $this->getSlotLabelFormatJs();
@endphp

<x-filament-widgets::widget>
Expand Down Expand Up @@ -76,6 +80,7 @@
dateClickEnabled: @js($dateClickEnabled),
dateSelectEnabled: @js($dateSelectEnabled),
viewDidMountEnabled: @js($viewDidMountEnabled),
eventAllUpdatedEnabled: @js($eventAllUpdatedEnabled),
onEventResizeStart: @js($onEventResizeStart),
onEventResizeStop: @js($onEventResizeStop),
dayMaxEvents: @js($this->dayMaxEvents()),
Expand All @@ -86,6 +91,8 @@
hasEventClickContextMenu: @js($hasEventClickContextMenu),
hasNoEventsClickContextMenu: @js($hasNoEventsClickContextMenu),
options: @js($this->getOptions()),
dayHeaderFormat: {{$dayHeaderFormatJs}},
slotLabelFormat: {{$slotLabelFormatJs}},
})"
>
<div id="calendar"></div>
Expand Down
22 changes: 22 additions & 0 deletions src/Concerns/HandlesEventAllUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Guava\Calendar\Concerns;

trait HandlesEventAllUpdated
{
protected bool $eventAllUpdatedEnabled = false;

public function onEventAllUpdated(array $info = []): void {}

public function eventAllUpdated(bool $enabled = true): static
{
$this->eventAllUpdatedEnabled = $enabled;

return $this;
}

public function isEventAllUpdatedEnabled(): bool
{
return $this->eventAllUpdatedEnabled;
}
}
16 changes: 16 additions & 0 deletions src/Concerns/HasDayHeaderFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Guava\Calendar\Concerns;

use Livewire\Attributes\Js;

trait HasDayHeaderFormat
{
#[Js]
public function getDayHeaderFormatJs(): ?string
{
return <<<'JS'
null
JS;
}
}
16 changes: 16 additions & 0 deletions src/Concerns/HasSlotLabelFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Guava\Calendar\Concerns;

use Livewire\Attributes\Js;

trait HasSlotLabelFormat
{
#[Js]
public function getSlotLabelFormatJs(): ?string
{
return <<<'JS'
null
JS;
}
}
6 changes: 6 additions & 0 deletions src/Widgets/CalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
use Filament\Widgets\Widget;
use Guava\Calendar\Concerns\HandlesDateClick;
use Guava\Calendar\Concerns\HandlesDateSelect;
use Guava\Calendar\Concerns\HandlesEventAllUpdated;
use Guava\Calendar\Concerns\HandlesEventClick;
use Guava\Calendar\Concerns\HandlesEventDragAndDrop;
use Guava\Calendar\Concerns\HandlesEventResize;
use Guava\Calendar\Concerns\HandlesNoEventsClick;
use Guava\Calendar\Concerns\HandlesViewMount;
use Guava\Calendar\Concerns\HasCalendarView;
use Guava\Calendar\Concerns\HasContextMenuActions;
use Guava\Calendar\Concerns\HasDayHeaderFormat;
use Guava\Calendar\Concerns\HasDayMaxEvents;
use Guava\Calendar\Concerns\HasDefaultActions;
use Guava\Calendar\Concerns\HasEventContent;
Expand All @@ -31,6 +33,7 @@
use Guava\Calendar\Concerns\HasResourceLabelContent;
use Guava\Calendar\Concerns\HasResources;
use Guava\Calendar\Concerns\HasSchema;
use Guava\Calendar\Concerns\HasSlotLabelFormat;
use Guava\Calendar\Concerns\InteractsWithEventRecord;

class CalendarWidget extends Widget implements HasActions, HasForms
Expand All @@ -43,6 +46,7 @@ class CalendarWidget extends Widget implements HasActions, HasForms
use HandlesEventResize;
use HandlesNoEventsClick;
use HandlesViewMount;
use HandlesEventAllUpdated;
use HasCalendarView;
use HasContextMenuActions;
use HasDayMaxEvents;
Expand All @@ -62,6 +66,8 @@ class CalendarWidget extends Widget implements HasActions, HasForms
use InteractsWithActions;
use InteractsWithEventRecord;
use InteractsWithForms;
use HasDayHeaderFormat;
use HasSlotLabelFormat;

protected static string $view = 'guava-calendar::widgets.calendar';

Expand Down

0 comments on commit fb806f6

Please sign in to comment.