Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Enh #48: Add `InputEmail` class for HTML `<input type="email">` element with attributes and rendering capabilities (@terabytesoftw)
- Enh #49: Add `InputDateTimeLocal` class for HTML `<input type="datetime-local">` element with attributes and rendering capabilities (@terabytesoftw)
- Bug #50: Standardize `tests` for clarity and consistency across all test cases (@terabytesoftw)
- Enh #51: Add `InputDate` class for HTML `<input type="date">` element with attributes and rendering capabilities (@terabytesoftw)

## 0.3.0 March 31, 2024

Expand Down
96 changes: 96 additions & 0 deletions src/Form/InputDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace UIAwesome\Html\Form;

use UIAwesome\Html\Attribute\Form\{
CanBeReadonly,
CanBeRequired,
HasAutocomplete,
HasForm,
HasList,
HasMax,
HasMin,
HasStep,
};
use UIAwesome\Html\Attribute\Global\{CanBeAutofocus, HasTabindex};
use UIAwesome\Html\Attribute\HasValue;
use UIAwesome\Html\Attribute\Values\Type;
use UIAwesome\Html\Core\Element\BaseInput;
use UIAwesome\Html\Interop\{VoidInterface, Voids};

/**
* Renders the HTML `<input type="date">` element.
*
* The value uses the `yyyy-mm-dd` format (for example, `2017-06-01`).
*
* Usage example:
* ```php
* echo \UIAwesome\Html\Form\InputDate::tag()
* ->name('birthday')
* ->render();
* echo InputDate::tag()
* ->max('2017-04-30')
* ->min('2017-04-01')
* ->name('party-date')
* ->required(true)
* ->render();
* echo InputDate::tag()
* ->name('appointment')
* ->readonly(true)
* ->value('2017-06-01')
* ->render();
* ```
*
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/date
*
* @copyright Copyright (C) 2026 Terabytesoftw.
* @license https://opensource.org/license/bsd-3-clause BSD 3-Clause License.
*/
final class InputDate extends BaseInput
{
use CanBeAutofocus;
use CanBeReadonly;
use CanBeRequired;
use HasAutocomplete;
use HasForm;
use HasList;
use HasMax;
use HasMin;
use HasStep;
use HasTabindex;
use HasValue;

/**
* Returns the tag enumeration for the `<input>` element.
*
* @return VoidInterface Tag enumeration instance for `<input>`.
*/
protected function getTag(): VoidInterface
{
return Voids::INPUT;
}

/**
* Returns the default configuration for the input element.
*
* @return array Default configuration array with method calls as keys.
*
* @phpstan-return array<string, mixed>
*/
protected function loadDefault(): array
{
return parent::loadDefault() + ['type' => [Type::DATE]];
}

/**
* Renders the `<input>` element with its attributes.
*
* @return string Rendered HTML for the `<input>` element.
*/
protected function run(): string
{
return $this->buildElement();
}
}
Loading
Loading