Skip to content

Commit

Permalink
added support for infolist components
Browse files Browse the repository at this point in the history
  • Loading branch information
tjodalv committed Jan 30, 2024
1 parent 4aa639d commit 089e9c1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
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>
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 089e9c1

Please sign in to comment.