Skip to content

Commit

Permalink
Merge pull request #32 from agencetwogether/main
Browse files Browse the repository at this point in the history
Add possibility to animate icon
  • Loading branch information
199ocero authored Dec 7, 2024
2 parents 8828520 + 3c4a5fe commit 2f9052a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ content: [
This plugin is already accessible within the Infolists builder and now supports both the `->state([])` and `->record()` methods.

```php
use JaOcero\ActivityTimeline\Enums\IconAnimation;

public function activityTimelineInfolist(Infolist $infolist): Infolist
{
return $infolist
Expand Down Expand Up @@ -95,6 +97,11 @@ public function activityTimelineInfolist(Infolist $infolist): Infolist
'published' => 'heroicon-m-rocket-launch',
default => null,
})
/*
You can animate icon with ->animation() method.
Possible values : IconAnimation::Ping, IconAnimation::Pulse, IconAnimation::Bounce, IconAnimation::Spin or a Closure
*/
->animation(IconAnimation::Ping)
->color(fn (string | null $state): string | null => match ($state) {
'ideation' => 'purple',
'drafting' => 'info',
Expand Down
15 changes: 14 additions & 1 deletion resources/views/infolists/components/activity-icon.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
@php
use JaOcero\ActivityTimeline\Enums\IconAnimation;
@endphp
@if ($icon = $getIcon($getState()))
@php
$color = $getColor($getState()) ?? 'gray';
$animation = $getAnimation($getState());
@endphp

<div class="relative flex items-center justify-center w-8 h-8">
<div @class([
'relative flex items-center justify-center w-8 h-8',
match ($animation) {
IconAnimation::Spin, 'spin' => 'animate-spin',
IconAnimation::Ping, 'ping' => 'animate-ping',
IconAnimation::Pulse, 'pulse' => 'animate-pulse',
IconAnimation::Bounce, 'bounce' => 'animate-bounce',
default => $animation,
},
])>
<span @class([
'flex flex-shrink-0 p-[5px] w-8 h-8 justify-center items-center dark:border rounded-full dark:bg-gray-800 dark:border-gray-700',
match ($color) {
Expand Down
18 changes: 18 additions & 0 deletions src/Components/ActivityIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

namespace JaOcero\ActivityTimeline\Components;

use Closure;
use Filament\Infolists\Components\IconEntry;
use JaOcero\ActivityTimeline\Enums\IconAnimation;

class ActivityIcon extends IconEntry
{
protected string $viewIdentifier = 'activityIcon';

protected IconAnimation|string|Closure|null $animation = null;

protected string $view = 'activity-timeline::infolists.components.activity-icon';

public function animation(IconAnimation|string|Closure|null $animation): static
{
$this->animation = $animation;

return $this;
}

public function getAnimation(mixed $state): IconAnimation|string|null
{
return $this->evaluate($this->animation, [
'state' => $state,
]);
}

public function getViewIdentifier(): string
{
return $this->viewIdentifier;
Expand Down
14 changes: 14 additions & 0 deletions src/Enums/IconAnimation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace JaOcero\ActivityTimeline\Enums;

enum IconAnimation: string
{
case Spin = 'spin';

case Ping = 'ping';

case Pulse = 'pulse';

case Bounce = 'bounce';
}

0 comments on commit 2f9052a

Please sign in to comment.