generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
HasToggleButton::class
trait. (#178)
- Loading branch information
1 parent
728d15f
commit 2368ecf
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Attribute\Component; | ||
|
||
use PHPForge\Html\Helper\Encode; | ||
use PHPForge\Widget\ElementInterface; | ||
|
||
/** | ||
* Is used by widgets that implement the toggle button method. | ||
*/ | ||
trait HasToggleButton | ||
{ | ||
protected string $toggleButton = ''; | ||
|
||
/** | ||
* Set the button toogle for the toggle. | ||
* | ||
* @param ElementInterface|string ...$values The button content. | ||
* | ||
* @return static A new instance of the current class with the specified toggle button. | ||
*/ | ||
public function toggleButton(string|ElementInterface ...$values): static | ||
{ | ||
$new = clone $this; | ||
$new->toggleButton = Encode::santizeXSS(...$values); | ||
|
||
return $new; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPForge\Html\Tests\Attribute\Component; | ||
|
||
use PHPForge\Html\Attribute\Component\HasToggleButton; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class HasToggleButtonTest extends TestCase | ||
{ | ||
public function testImmutability(): void | ||
{ | ||
$instance = new class () { | ||
use HasToggleButton; | ||
}; | ||
|
||
$this->assertNotSame($instance, $instance->toggleButton('')); | ||
} | ||
} |