Skip to content

Commit

Permalink
feat: added set option and refresh resources function
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <[email protected]>
  • Loading branch information
lukas-frey committed Aug 23, 2024
1 parent 62adb0c commit 337365b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,30 @@ Event::make()
->extendedProps(['baz' => 'qux', 'quux' => 'corge']);
```

## Available Methods

### Refresh events
If you need to trigger a refresh of the events in the calendar, you can call `refreshRecords()` on the widget.

```php
$this->refreshRecords();
```

### Refresh resources
If you need to trigger a refresh of the resources in the calendar, you can call `refreshResources()` on the widget.

```php
$this->refreshResources();
```

### Set Option
To change any calendar option during runtime, you can use the `setOption()` method on the widget.

For example to programmatically change the date, you can use:
```php
$this->setOption('date', today()->addDay()->toIso8601String());
```

## Custom Event Content
By default, we use the default view from the calendar package. However, you are able to use your own by overriding the `getEventContent` method on your calendar widget class.

Expand Down Expand Up @@ -252,6 +276,20 @@ public function getEventContent(): null|string|array
}
```

## Custom resource label content
By default, we use the default view from the calendar package. However, you are able to use your own by overriding the `getResourceLabelContent` method on your calendar widget class.

```php
public function getResourceLabelContent(): null|string|array
{
// return a blade view
return view('calendar.resource');

// return a HtmlString
return new HtmlString('<div>My resource</div>');
}
```

## Customize the form schema
When an event triggers an action (such as view or edit actions), a modal with a form is mounted.

Expand Down
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.

8 changes: 7 additions & 1 deletion resources/js/calendar-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,13 @@ export default function calendarWidget({
...options
});

window.addEventListener('calendar--refresh', () => this.ec.refetchEvents())
window.addEventListener('calendar--refresh', () => {
this.ec.refetchEvents();
});

this.$wire.on('calendar--set', (data) => {
this.ec.setOption(data.key, data.value);
});
},

getEventContent: function (info) {
Expand Down
18 changes: 17 additions & 1 deletion src/Widgets/CalendarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,24 @@ class CalendarWidget extends Widget implements HasActions, HasForms

protected int | string | array $columnSpan = 'full';

public function refreshRecords(): void
public function refreshRecords(): static
{
$this->dispatch('calendar--refresh');

return $this;
}

public function refreshResources(): static
{
$this->setOption('resources', $this->getResourcesJs());

return $this;
}

public function setOption(string $key, mixed $value): static
{
$this->dispatch('calendar--set', key: $key, value: $value);

return $this;
}
}

0 comments on commit 337365b

Please sign in to comment.