Skip to content

Commit

Permalink
refactor: add classes() alias and use laravel class
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <[email protected]>
  • Loading branch information
lukas-frey committed Nov 6, 2024
1 parent dba7071 commit 352ff24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ This flexibility allows you to easily customize the appearance of events based o

#### Customizing Event Classes

Following the same pattern as with the styles property, it is possible to inject custom classes into the Event element using the classNames property.
Following the same pattern as with the styles property, it is possible to inject custom classes into the Event element using the `classNames` or `classes` property.

Here's how you can use it:

Expand Down
21 changes: 9 additions & 12 deletions src/ValueObjects/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Guava\Calendar\ValueObjects;

use Carbon\Carbon;
use Illuminate\Support\Str;
use Guava\Calendar\Contracts\Eventable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class Event implements Arrayable, Eventable
{
Expand Down Expand Up @@ -124,6 +125,10 @@ public function getTextColor(): ?string
return $this->textColor;
}

public function classes(array $classes): static
{
return $this->classNames($classes);
}

public function classNames(array $classNames): static
{
Expand All @@ -134,17 +139,9 @@ public function classNames(array $classNames): static

public function getClassNames(): string
{
$classes = [];

foreach ($this->classNames as $key => $value) {
if (is_int($key) || $value === true) {
$classes[] = is_int($key) ? $value : $key;
}
}

return implode(' ', $classes);
return Arr::toCssClasses($this->classNames);
}

public function styles(array $styles): static
{
$this->styles = $styles;
Expand Down

0 comments on commit 352ff24

Please sign in to comment.