Skip to content

Commit

Permalink
Merge pull request #7 from tjodalv/feature/infolists-support-and-badg…
Browse files Browse the repository at this point in the history
…e-fix

added support for filament infolist components and correctly implement accordion item badge
  • Loading branch information
atmonshi authored Jan 30, 2024
2 parents 7ceb300 + 089e9c1 commit c5cad58
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 7 deletions.
8 changes: 8 additions & 0 deletions resources/views/components/accordion/item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
'isIsolated' => false,
'icon' => null,
'label' => '',
'badge' => null,
'badgeColor' => null,
])
<div
x-data="{
Expand Down Expand Up @@ -34,6 +36,12 @@ class="fi-accordion-item-icon h-6 w-6 shrink-0 transition duration-75"
/>
@endif
{{ $label }}

@if (filled($badge))
<x-filament::badge :color="$badgeColor" size="sm" class="w-max">
{{ $badge }}
</x-filament::badge>
@endif
</span>
<span :class="{ 'rotate-180': activeAccordion == id }">
@svg('heroicon-m-chevron-down','w-4 h-4 duration-200 ease-out')
Expand Down
2 changes: 2 additions & 0 deletions resources/views/forms/accordions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<x-zeus-accordion::accordion.item
:label="$accordion->getLabel()"
:icon="$accordion->getIcon()"
:badge="$accordion->getBadge()"
:badge-color="$accordion->getBadgeColor()"
:isIsolated="$isIsolated"
:activeAccordion="$getActiveAccordion">
{{ $accordion }}
Expand Down
3 changes: 3 additions & 0 deletions resources/views/infolists/accordion.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
{{ $getChildComponentContainer() }}
</div>
36 changes: 36 additions & 0 deletions resources/views/infolists/accordions.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div
wire:ignore.self
x-cloak
{{
$attributes
->merge([
'id' => $getId(),
'wire:key' => "{$this->getId()}.{$getStatePath()}." . Accordions::class . '.container',
], escape: false)
->merge($getExtraAttributes(), escape: false)
->merge($getExtraAlpineAttributes(), escape: false)
->class([
'rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10',
])
}}
>

@php
$isIsolated = $isIsolated();
$getActiveAccordion = $getActiveAccordion();
@endphp

<x-zeus-accordion::accordion :activeAccordion="$getActiveAccordion">
@foreach ($getChildComponentContainer()->getComponents() as $accordion)
<x-zeus-accordion::accordion.item
:label="$accordion->getLabel()"
:icon="$accordion->getIcon()"
:badge="$accordion->getBadge()"
:badge-color="$accordion->getBadgeColor()"
:isIsolated="$isIsolated"
:activeAccordion="$getActiveAccordion">
{{ $accordion }}
</x-zeus-accordion::accordion.item>
@endforeach
</x-zeus-accordion::accordion>
</div>
9 changes: 2 additions & 7 deletions src/Forms/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use Closure;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Contracts\CanConcealComponents;
use Filament\Support\Concerns\HasBadge;
use Filament\Support\Concerns\HasIcon;
use Illuminate\Support\Str;

class Accordion extends Component implements CanConcealComponents
{
use HasIcon;
use HasBadge;

protected string $view = 'zeus-accordion::forms.accordion';

Expand Down Expand Up @@ -42,11 +44,4 @@ public static function make(string | Closure | null $label = null): static

return $static;
}

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

return $this;
}
}
41 changes: 41 additions & 0 deletions src/Infolists/Accordion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace LaraZeus\Accordion\Infolists;

use Closure;
use Filament\Infolists\Components\Component;
use Filament\Support\Concerns\HasBadge;
use Filament\Support\Concerns\HasIcon;
use Illuminate\Support\Str;

class Accordion extends Component
{
use HasIcon;
use HasBadge;

protected string $view = 'zeus-accordion::infolists.accordion';

final public function __construct(string $label)
{
$this->label($label);
$this->id(Str::slug($label));
}

public function getId(): string
{
return $this->getContainer()->getParentComponent()->getId() . '-' . parent::getId() . '-accordion';
}

public function getColumnsConfig(): array
{
return $this->columns ?? $this->getContainer()->getColumnsConfig();
}

public static function make(string | Closure | null $label = null): static
{
$static = app(static::class, ['label' => $label]);
$static->configure();

return $static;
}
}
50 changes: 50 additions & 0 deletions src/Infolists/Accordions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace LaraZeus\Accordion\Infolists;

use Closure;
use Filament\Infolists\Components\Component;
use Filament\Support\Concerns;
use LaraZeus\Accordion\Concerns\CanBeIsolated;

class Accordions extends Component
{
use CanBeIsolated;
use Concerns\HasExtraAlpineAttributes;

protected string $view = 'zeus-accordion::infolists.accordions';

protected int | Closure $activeAccordion = 1;

final public function __construct(?string $label = null)
{
$this->label($label);
}

public static function make(?string $label = null): static
{
$static = app(static::class, ['label' => $label]);
$static->configure();

return $static;
}

public function activeAccordion(int | Closure $activeAccordion): static
{
$this->activeAccordion = $activeAccordion;

return $this;
}

public function getActiveAccordion(): int
{
return $this->evaluate($this->activeAccordion);
}

public function accordions(array | Closure $accordions): static
{
$this->childComponents($accordions);

return $this;
}
}

0 comments on commit c5cad58

Please sign in to comment.