-
-
Notifications
You must be signed in to change notification settings - Fork 22
Add Html::colorInput() and Input::color()
#252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bd9a616
a573446
3aa8b53
aac385d
8ac68f5
c1e21c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| use Yiisoft\Html\Tag\Img; | ||
| use Yiisoft\Html\Tag\Input; | ||
| use Yiisoft\Html\Tag\Input\Checkbox; | ||
| use Yiisoft\Html\Tag\Input\Color; | ||
| use Yiisoft\Html\Tag\Input\File; | ||
| use Yiisoft\Html\Tag\Input\Radio; | ||
| use Yiisoft\Html\Tag\Input\Range; | ||
|
|
@@ -877,6 +878,24 @@ | |
| return $attributes === [] ? $tag : $tag->addAttributes($attributes); | ||
| } | ||
|
|
||
| /** | ||
| * Generates a color {@see Input} field. | ||
| * | ||
| * @see Input::color() | ||
| * | ||
| * @param string|null $name The name attribute. | ||
| * @param string|Stringable|null $value The value attribute. | ||
| * @param array $attributes The tag attributes in terms of name-value pairs. | ||
| */ | ||
| public static function color( | ||
| ?string $name = null, | ||
| string|Stringable|null $value = null, | ||
| array $attributes = [] | ||
| ): Color { | ||
| $tag = Input::color($name, $value); | ||
| return $attributes === [] ? $tag : $tag->addAttributes($attributes); | ||
| } | ||
|
|
||
| /** | ||
| * Generates a checkbox {@see Input}. | ||
| * | ||
|
|
@@ -1649,7 +1668,7 @@ | |
| */ | ||
| public static function renderTagAttributes(array $attributes): string | ||
| { | ||
| if (count($attributes) > 1) { | ||
|
Check warning on line 1671 in src/Html.php
|
||
| $sorted = []; | ||
| foreach (self::ATTRIBUTE_ORDER as $name) { | ||
| if (isset($attributes[$name])) { | ||
|
|
@@ -1673,11 +1692,11 @@ | |
| /** @psalm-var array<array-key, scalar[]|string|Stringable|null> $value */ | ||
| foreach ($value as $n => $v) { | ||
| if (!isset($v)) { | ||
| continue; | ||
|
Check warning on line 1695 in src/Html.php
|
||
| } | ||
| $fullName = "$name-$n"; | ||
| if (in_array($fullName, self::ATTRIBUTES_WITH_CONCATENATED_VALUES, true)) { | ||
| $html .= self::renderAttribute( | ||
|
Check warning on line 1699 in src/Html.php
|
||
| $fullName, | ||
| self::encodeAttribute( | ||
| is_array($v) ? implode(' ', $v) : $v, | ||
|
|
@@ -1803,7 +1822,7 @@ | |
| } | ||
| } else { | ||
| /** @var string[] */ | ||
| $classes = preg_split('/\s+/', (string) $options['class'], -1, PREG_SPLIT_NO_EMPTY); | ||
|
Check warning on line 1825 in src/Html.php
|
||
| $classes = array_diff($classes, (array) $class); | ||
| if (empty($classes)) { | ||
| unset($options['class']); | ||
|
|
@@ -1956,7 +1975,7 @@ | |
| public static function cssStyleToArray(string|Stringable $style): array | ||
| { | ||
| $result = []; | ||
| foreach (explode(';', (string) $style) as $property) { | ||
|
Check warning on line 1978 in src/Html.php
|
||
| $property = explode(':', $property); | ||
| if (count($property) > 1) { | ||
| $result[trim($property[0])] = trim($property[1]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Html\Tag\Input; | ||
|
|
||
| use Yiisoft\Html\Tag\Base\InputTag; | ||
|
|
||
| /** | ||
| * @link https://html.spec.whatwg.org/multipage/input.html#color-state-(type=color) | ||
| */ | ||
| final class Color extends InputTag | ||
razvbir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| protected function prepareAttributes(): void | ||
| { | ||
| $this->attributes['type'] = 'color'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Html\Tests\Tag\Input; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Yiisoft\Html\Tag\Input\Color; | ||
|
|
||
| final class ColorTest extends TestCase | ||
| { | ||
| public function testBase(): void | ||
| { | ||
| $this->assertSame( | ||
| '<input type="color" name="color" value="#ff0000">', | ||
| Color::tag() | ||
| ->name('color') | ||
| ->value('#ff0000') | ||
| ->render() | ||
| ); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.