Skip to content

Commit fe69cae

Browse files
committed
add checkbox support for the conditional wrapper
1 parent 4375d47 commit fe69cae

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

resources/views/bootstrap-5/conditional-wrapper.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<div
22
{{ $attributes }}
33

4+
@if(! $enableCheckbox)
45
data-enable-elem="{{ $enableElem }}"
56
data-enable-section-value="{{ $jsonEncode ? json_encode($enableValue) : $enableValue }}"
7+
@else
8+
data-enable-section-checkbox="{{ $enableElem }}"
9+
@endif
610

711
@if($hideFields)
812
data-hide-fields="true"

resources/views/material-admin-26/conditional-wrapper.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div
22
{{ $attributes }}
33

4+
@if(! $enableCheckbox)
45
data-enable-elem="{{ $enableElem }}"
56
data-enable-section-value="{{ $jsonEncode ? json_encode($enableValue) : $enableValue }}"
6-
7-
@if($hideFields)
8-
data-hide-fields="true"
7+
@else
8+
data-enable-section-checkbox="{{ $enableElem }}"
99
@endif
1010

1111
@if($disable)

src/Views/Components/ConditionalWrapper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ public function __construct(
1717
public string $enableElem,
1818
public $enableValue,
1919
public bool $hideFields = false,
20-
public bool $disable = false,
21-
?bool $jsonEncode = null,
22-
string $framework = ''
23-
) {
20+
public bool $disable = false,
21+
public bool $enableCheckbox = false,
22+
?bool $jsonEncode = null,
23+
string $framework = ''
24+
)
25+
{
2426
parent::__construct($framework);
2527

2628
$this->jsonEncode = is_null($jsonEncode) ? is_array($this->enableValue) : $jsonEncode;

tests/Feature/ConditionalWrapperTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class ConditionalWrapperTest extends TestCase
88
{
99
/** @test */
10-
public function it_can_render_conditional_wrapper()
10+
public function it_can_render_conditional_wrapper_bs5()
1111
{
1212
$this->setFrameworkBootstrap5();
1313
$this->registerTestRoute('conditional-wrapper');
@@ -17,12 +17,32 @@ public function it_can_render_conditional_wrapper()
1717
}
1818

1919
/** @test */
20-
public function it_can_generate_material_admin_26_conditional_wrapper()
20+
public function it_can_render_conditional_wrapper_powered_by_checkbox_bs5()
21+
{
22+
$this->setFrameworkBootstrap5();
23+
$this->registerTestRoute('conditional-wrapper-checkbox');
24+
25+
$this->visit('/conditional-wrapper-checkbox')
26+
->seeElement('div[data-enable-section-checkbox="#input"]');
27+
}
28+
29+
/** @test */
30+
public function it_can_render_conditional_wrapper_material_26()
2131
{
2232
$this->setFrameworkMaterialAdmin26();
2333
$this->registerTestRoute('conditional-wrapper');
2434

2535
$this->visit('/conditional-wrapper')
2636
->seeElement('div[data-enable-elem="#input"]');
2737
}
38+
39+
/** @test */
40+
public function it_can_render_conditional_wrapper_powered_by_checkbox_material_26()
41+
{
42+
$this->setFrameworkMaterialAdmin26();
43+
$this->registerTestRoute('conditional-wrapper-checkbox');
44+
45+
$this->visit('/conditional-wrapper-checkbox')
46+
->seeElement('div[data-enable-section-checkbox="#input"]');
47+
}
2848
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<x-forms::conditional-wrapper
2+
enable-elem="#input"
3+
:enable-value="1"
4+
enable-checkbox
5+
>
6+
Javaabu
7+
</x-forms::conditional-wrapper>

0 commit comments

Comments
 (0)