Skip to content

Commit

Permalink
Merge pull request #234 from raveren/main
Browse files Browse the repository at this point in the history
Add Conditionable trait: now `->when()` helper is available on all elements
  • Loading branch information
freekmurze authored Jul 3, 2024
2 parents 65c02c7 + eb8f8f8 commit 74ea924
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use Spatie\Html\Exceptions\InvalidChild;
use Spatie\Html\Exceptions\InvalidHtml;
use Spatie\Html\Exceptions\MissingTag;

abstract class BaseElement implements Htmlable, HtmlElement
{
use Conditionable;

use Macroable {
__call as __macro_call;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/BaseElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,12 @@ class Div extends BaseElement
'<div aria-describedby="bar"></div>',
Div::create()->aria('describedby', 'bar')->render()
);


it('can make use of the conditionable helper')
->assertHtmlStringEqualsHtmlString(
'<div></div>',
Div::create()
->when(false, fn(BaseElement $element) => $element->data('foo', 'bar'))
->render()
);

0 comments on commit 74ea924

Please sign in to comment.