-
-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added activeAccordion method to Accordion.php #2939
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
<div id="accordion-{{$templateSlug}}" class="accordion mb-3"> | ||
@foreach($manyForms as $name => $forms) | ||
<div class="accordion-heading @if ($loop->index) collapsed @endif" | ||
<div class="accordion-heading @if (!in_array($name, $open)) collapsed @endif" | ||
id="heading-{{\Illuminate\Support\Str::slug($name)}}" | ||
data-bs-toggle="collapse" | ||
data-bs-target="#collapse-{{\Illuminate\Support\Str::slug($name)}}" | ||
aria-expanded="true" | ||
aria-expanded="{{ in_array($name, $open) ? 'true' : 'false' }}" | ||
aria-controls="collapse-{{\Illuminate\Support\Str::slug($name)}}"> | ||
<h6 class="btn btn-link btn-group-justified pt-2 pb-2 mb-0 pe-0 ps-0 d-flex align-items-center"> | ||
<x-orchid-icon path="bs.chevron-right" class="small me-2"/> {!! $name !!} | ||
</h6> | ||
</div> | ||
|
||
<div id="collapse-{{\Illuminate\Support\Str::slug($name)}}" | ||
class="mt-2 collapse @if (!$loop->index) show @endif" | ||
class="mt-2 collapse @if (in_array($name, $open)) show @endif" | ||
aria-labelledby="heading-{{\Illuminate\Support\Str::slug($name)}}" | ||
@if (!$stayOpen) | ||
data-bs-parent="#accordion-{{$templateSlug}}" | ||
@endif | ||
@endif | ||
> | ||
@foreach($forms as $form) | ||
{!! $form !!} | ||
@endforeach | ||
@foreach($forms as $form) | ||
{!! $form !!} | ||
@endforeach | ||
</div> | ||
@endforeach | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
namespace Orchid\Screen\Layouts; | ||
|
||
use Illuminate\Support\Arr; | ||
use Orchid\Screen\Layout; | ||
use Orchid\Screen\Repository; | ||
|
||
|
@@ -17,11 +18,17 @@ abstract class Accordion extends Layout | |
*/ | ||
protected $template = 'platform::layouts.accordion'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $openSet = false; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $variables = [ | ||
'stayOpen' => false, | ||
'open' => [], | ||
]; | ||
|
||
/** | ||
|
@@ -32,6 +39,7 @@ abstract class Accordion extends Layout | |
public function __construct(array $layouts = []) | ||
{ | ||
$this->layouts = $layouts; | ||
$this->variables['open'] = [array_key_first($this->layouts)]; | ||
} | ||
|
||
/** | ||
|
@@ -55,4 +63,25 @@ public function stayOpen(bool $stayOpen = true): self | |
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set active accordion(s). | ||
* | ||
* @param string|array $activeAccordion | ||
* | ||
* @return $this | ||
*/ | ||
public function open(string|array $activeAccordion): self | ||
{ | ||
$activeAccordion = Arr::wrap($activeAccordion); | ||
|
||
$this->variables['open'] = $this->openSet | ||
? array_merge($this->variables['open'], $activeAccordion) | ||
: $activeAccordion; | ||
|
||
$this->openSet = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When creating a class, we set a standard key for the first tab in the constructor to preserve the standard previous behavior. A flag property is needed so that when the method is first called, it can be distinguished whether it was called earlier and, depending on this, merge the array or overwrite it. |
||
|
||
return $this; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should aim for more consistency with naming? Since we're calling the method
active*
, perhaps it would make sense to also use the key asactive
.