Skip to content

Commit 7111e3f

Browse files
committed
feat: add conditional display wrapper component
1 parent ff73786 commit 7111e3f

File tree

5 files changed

+146
-0
lines changed

5 files changed

+146
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@props([
2+
'reference' => '#',
3+
'json' => false,
4+
'values' => [],
5+
'withWrapper' => true,
6+
'hideFields' => true,
7+
'reverse' => false,
8+
])
9+
10+
@php
11+
if ($json) {
12+
$values = json_encode($values);
13+
} else {
14+
15+
if (! is_array($values)) {
16+
$values = [$values];
17+
}
18+
19+
$values = "[" . implode(',', $values) . "]";
20+
}
21+
@endphp
22+
23+
<div
24+
{{ $attributes }}
25+
@if ($withWrapper) class="row" @endif
26+
data-enable-elem="{{ $reference }}"
27+
data-enable-section-value="{{ $values }}"
28+
data-hide-fields="{{ $hideFields ? 'true' : 'false' }}"
29+
data-disable="{{ $reverse ? 'true' : 'false' }}"
30+
>
31+
@if ($withWrapper)
32+
<div class="col"> @endif
33+
{{ $slot }}
34+
@if ($withWrapper) </div>
35+
@endif
36+
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@props([
2+
'reference' => '#',
3+
'json' => false,
4+
'values' => [],
5+
'withWrapper' => true,
6+
'hideFields' => true,
7+
'reverse' => false,
8+
])
9+
10+
@php
11+
if ($json) {
12+
$values = json_encode($values);
13+
} else {
14+
15+
if (! is_array($values)) {
16+
$values = [$values];
17+
}
18+
19+
$values = "[" . implode(',', $values) . "]";
20+
}
21+
@endphp
22+
23+
<div
24+
{{ $attributes }}
25+
@if ($withWrapper) class="row" @endif
26+
data-enable-elem="{{ $reference }}"
27+
data-enable-section-value="{{ $values }}"
28+
data-hide-fields="{{ $hideFields ? 'true' : 'false' }}"
29+
data-disable="{{ $reverse ? 'true' : 'false' }}"
30+
>
31+
@if ($withWrapper)
32+
<div class="col"> @endif
33+
{{ $slot }}
34+
@if ($withWrapper) </div>
35+
@endif
36+
</div>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Javaabu\Forms\Views\Components;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Javaabu\Forms\Support\FormatsValues;
7+
use Javaabu\Forms\Support\HandlesBoundValues;
8+
9+
class ConditionalWrapper extends Component
10+
{
11+
protected string $view = 'conditional-wrapper';
12+
public string $reference;
13+
public array $values;
14+
public bool $json;
15+
public bool $withWrapper;
16+
public bool $hideFields;
17+
public bool $reverse;
18+
19+
/**
20+
* Create a new component instance.
21+
*
22+
* @return void
23+
*/
24+
public function __construct(
25+
string $reference = '#',
26+
array $values = [],
27+
bool $json = false,
28+
bool $withWrapper = true,
29+
bool $hideFields = true,
30+
bool $reverse = false,
31+
string $framework = ''
32+
)
33+
{
34+
parent::__construct($framework);
35+
36+
$this->reference = $reference;
37+
$this->values = $values;
38+
$this->json = $json;
39+
$this->withWrapper = $withWrapper;
40+
$this->hideFields = $hideFields;
41+
$this->reverse = $reverse;
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Javaabu\Forms\Tests\Feature;
4+
5+
use Javaabu\Forms\Tests\TestCase;
6+
7+
class ConditionalWrapperTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_can_render_conditional_wrapper()
11+
{
12+
$this->setFrameworkBootstrap5();
13+
$this->registerTestRoute('conditional-wrapper');
14+
15+
$this->visit('/conditional-wrapper')
16+
->seeElement('div[data-enable-elem="#"]');
17+
}
18+
19+
/** @test */
20+
public function it_can_generate_material_admin_26_conditional_wrapper()
21+
{
22+
$this->setFrameworkMaterialAdmin26();
23+
$this->registerTestRoute('conditional-wrapper');
24+
25+
$this->visit('/conditional-wrapper')
26+
->seeElement('div[data-enable-elem="#"]');
27+
}
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<x-forms::conditional-wrapper>
2+
Javaabu
3+
</x-forms::conditional-wrapper>

0 commit comments

Comments
 (0)