Skip to content

Commit

Permalink
Add ValueInterface to AbstractSelect, AbstractChoiceList, AbstractHid…
Browse files Browse the repository at this point in the history
…den, AbstractInput, and AbstractInputChoice. (#224)
  • Loading branch information
terabytesoftw committed Jan 11, 2024
1 parent 504fc64 commit a1bf3b7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Base/AbstractSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace PHPForge\Html\Base;

use InvalidArgumentException;
use PHPForge\Html\Input\Contract\{InputInterface, RequiredInterface};
use PHPForge\Html\Input\Contract\{InputInterface, RequiredInterface, ValueInterface};
use PHPForge\Html\{Attribute, Label, Tag};
use PHPForge\Widget\Element;

Expand All @@ -22,7 +22,7 @@
/**
* Provides a foundation for creating HTML `select` elements with various attributes and content.
*/
abstract class AbstractSelect extends Element implements InputInterface, RequiredInterface
abstract class AbstractSelect extends Element implements InputInterface, RequiredInterface, ValueInterface
{
use Attribute\Aria\HasAriaLabel;
use Attribute\CanBeAutofocus;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Base/AbstractChoiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ abstract class AbstractChoiceList extends Element implements
Contract\CheckedValueInterface,
Contract\InputInterface,
Contract\LabelInterface,
Contract\RequiredInterface
Contract\RequiredInterface,
Contract\ValueInterface
{
use Attribute\Aria\HasAriaDescribedBy;
use Attribute\Aria\HasAriaLabel;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Base/AbstractHidden.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace PHPForge\Html\Input\Base;

use PHPForge\Html\Input\Contract\ValueInterface;
use PHPForge\Html\{Attribute, Tag};
use PHPForge\Widget\Element;

abstract class AbstractHidden extends Element
abstract class AbstractHidden extends Element implements ValueInterface
{
use Attribute\Custom\HasAttributes;
use Attribute\Custom\HasPrefixAndSuffix;
Expand Down
4 changes: 2 additions & 2 deletions src/Input/Base/AbstractInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace PHPForge\Html\Input\Base;

use PHPForge\Html\Input\Contract;
use PHPForge\Html\Input\Contract\{AriaDescribedByInterface, InputInterface, ValueInterface};
use PHPForge\Html\{Attribute, Tag};
use PHPForge\Widget\Element;

/**
* Provides a foundation for creating HTML `input` custom elements with various attributes and content.
*/
abstract class AbstractInput extends Element implements Contract\AriaDescribedByInterface, Contract\InputInterface
abstract class AbstractInput extends Element implements AriaDescribedByInterface, InputInterface, ValueInterface
{
use Attribute\Aria\HasAriaDescribedBy;
use Attribute\Aria\HasAriaLabel;
Expand Down
3 changes: 2 additions & 1 deletion src/Input/Base/AbstractInputChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ abstract class AbstractInputChoice extends Element implements
Contract\CheckedValueInterface,
Contract\InputInterface,
Contract\LabelInterface,
Contract\RequiredInterface
Contract\RequiredInterface,
Contract\ValueInterface
{
use Attribute\Aria\HasAriaDescribedBy;
use Attribute\Aria\HasAriaLabel;
Expand Down
11 changes: 0 additions & 11 deletions src/Input/Contract/InputInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,4 @@ public function attributes(array $values): static;
* @link https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute
*/
public function id(string|null $value): static;

/**
* set the value content attribute gives the default value of the field.
*
* @param mixed $value The value of the widget.
*
* @return static A new instance of the current class with the specified value.
*
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-value
*/
public function value(mixed $value): static;
}
22 changes: 22 additions & 0 deletions src/Input/Contract/ValueInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PHPForge\Html\Input\Contract;

/**
* Provide methods for handling HTML value-related attributes and properties.
*/
interface ValueInterface
{
/**
* set the value content attribute gives the default value of the field.
*
* @param mixed $value The value of the widget.
*
* @return static A new instance of the current class with the specified value.
*
* @link https://html.spec.whatwg.org/multipage/input.html#attr-input-value
*/
public function value(mixed $value): static;
}

0 comments on commit a1bf3b7

Please sign in to comment.