generated from yii-tools/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f2759d
commit 582b870
Showing
6 changed files
with
115 additions
and
38 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
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UIAwesome\Html\Field\Concern; | ||
|
||
/** | ||
* Provides methods for configuring enclosing field by label. | ||
*/ | ||
trait CanBeEnclosedByLabel | ||
{ | ||
protected bool $enclosedByLabel = false; | ||
|
||
/** | ||
* Set the current instance as being enclosed by a label. | ||
* | ||
* @return self A new instance of of the current class with the specified enclosed by label property. | ||
*/ | ||
public function enclosedByLabel(): self | ||
{ | ||
$new = clone $this; | ||
$new->enclosedByLabel = true; | ||
|
||
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UIAwesome\Html\Field\Concern; | ||
|
||
/** | ||
* Provides methods for configuring field input class. | ||
*/ | ||
trait HasClass | ||
{ | ||
protected string $class = ''; | ||
protected bool $classOverride = false; | ||
|
||
/** | ||
* Set the `CSS` `HTML` field class attribute. | ||
* | ||
* @param string $value The `CSS` attribute of the widget. | ||
* @param bool $override If `true` the value will be overridden. | ||
* | ||
* @return static A new instance of the current class with the specified class value. | ||
* | ||
* @link https://html.spec.whatwg.org/#classes | ||
*/ | ||
public function class(string $value, bool $override = false): static | ||
{ | ||
$new = clone $this; | ||
$new->class = $value; | ||
$new->classOverride = $override; | ||
|
||
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UIAwesome\Html\Field\Tests\Concern; | ||
|
||
use UIAwesome\Html\Field\Concern\CanBeEnclosedByLabel; | ||
|
||
final class CanBeEnclosedByLabelTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testImmutability(): void | ||
{ | ||
$instance = new class () { | ||
use CanBeEnclosedByLabel; | ||
}; | ||
|
||
$this->assertNotSame($instance, $instance->enclosedByLabel()); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UIAwesome\Html\Field\Tests\Concern; | ||
|
||
use UIAwesome\Html\Field\Concern\HasClass; | ||
|
||
final class HasClassTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testImmutability(): void | ||
{ | ||
$instance = new class () { | ||
use HasClass; | ||
}; | ||
|
||
$this->assertNotSame($instance, $instance->class('')); | ||
} | ||
} |
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