From de6651b54af73e7e1cc5c6ab44b04a17f82571e8 Mon Sep 17 00:00:00 2001 From: Tim Hemmes Date: Fri, 15 Mar 2024 13:14:02 +0100 Subject: [PATCH 1/8] Added support for Htmlable contents in BaseElement --- src/BaseElement.php | 18 ++++++++++-------- tests/Html/ButtonTest.php | 9 +++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/BaseElement.php b/src/BaseElement.php index 32973b5..aff2337 100644 --- a/src/BaseElement.php +++ b/src/BaseElement.php @@ -52,7 +52,7 @@ public function attribute($attribute, $value = null) { $element = clone $this; - $element->attributes->setAttribute($attribute, (string) $value); + $element->attributes->setAttribute($attribute, (string)$value); return $element; } @@ -325,7 +325,7 @@ public function if(bool $condition, \Closure $callback) */ public function unless(bool $condition, \Closure $callback) { - return $this->if(! $condition, $callback); + return $this->if(!$condition, $callback); } /** @@ -339,7 +339,7 @@ public function unless(bool $condition, \Closure $callback) */ public function ifNotNull($value, \Closure $callback) { - return ! is_null($value) ? $callback($this) : $this; + return !is_null($value) ? $callback($this) : $this; } /** @@ -405,8 +405,8 @@ public function isVoidElement(): bool * Dynamically handle calls to the class. * Check for methods finishing by If or fallback to Macroable. * - * @param string $name - * @param array $arguments + * @param string $name + * @param array $arguments * @return mixed * * @throws BadMethodCallException @@ -415,7 +415,7 @@ public function __call($name, $arguments) { if (Str::endsWith($name, $conditions = ['If', 'Unless', 'IfNotNull'])) { foreach ($conditions as $condition) { - if (! method_exists($this, $method = str_replace($condition, '', $name))) { + if (!method_exists($this, $method = str_replace($condition, '', $name))) { continue; } @@ -435,9 +435,9 @@ protected function callConditionalMethod($type, $method, array $arguments) switch ($type) { case 'If': - return $this->if((bool) $value, $callback); + return $this->if((bool)$value, $callback); case 'Unless': - return $this->unless((bool) $value, $callback); + return $this->unless((bool)$value, $callback); case 'IfNotNull': return $this->ifNotNull($value, $callback); default: @@ -465,6 +465,8 @@ protected function parseChildren($children, $mapper = null): Collection { if ($children instanceof HtmlElement) { $children = [$children]; + } elseif ($children instanceof Htmlable) { + $children = $children->toHtml(); } $children = Collection::make($children); diff --git a/tests/Html/ButtonTest.php b/tests/Html/ButtonTest.php index 5e36c93..427fed5 100644 --- a/tests/Html/ButtonTest.php +++ b/tests/Html/ButtonTest.php @@ -1,5 +1,7 @@ ', @@ -21,6 +23,13 @@ ); }); +it('can create a button with Htmlable contents', function () { + assertHtmlStringEqualsHtmlString( + '', + $this->html->button(new \Illuminate\View\ComponentSlot('Hi')) + ); +}); + it('can create a button with a type', function () { assertHtmlStringEqualsHtmlString( '', From 3d7aa3eac8a96888fbcfb466b94f84f62c60a0e1 Mon Sep 17 00:00:00 2001 From: Tim Hemmes Date: Mon, 18 Mar 2024 13:48:55 +0100 Subject: [PATCH 2/8] reverted styling changes --- src/BaseElement.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/BaseElement.php b/src/BaseElement.php index aff2337..5b95127 100644 --- a/src/BaseElement.php +++ b/src/BaseElement.php @@ -52,7 +52,7 @@ public function attribute($attribute, $value = null) { $element = clone $this; - $element->attributes->setAttribute($attribute, (string)$value); + $element->attributes->setAttribute($attribute, (string) $value); return $element; } @@ -325,7 +325,7 @@ public function if(bool $condition, \Closure $callback) */ public function unless(bool $condition, \Closure $callback) { - return $this->if(!$condition, $callback); + return $this->if(! $condition, $callback); } /** @@ -339,7 +339,7 @@ public function unless(bool $condition, \Closure $callback) */ public function ifNotNull($value, \Closure $callback) { - return !is_null($value) ? $callback($this) : $this; + return ! is_null($value) ? $callback($this) : $this; } /** @@ -405,8 +405,8 @@ public function isVoidElement(): bool * Dynamically handle calls to the class. * Check for methods finishing by If or fallback to Macroable. * - * @param string $name - * @param array $arguments + * @param string $name + * @param array $arguments * @return mixed * * @throws BadMethodCallException @@ -415,7 +415,7 @@ public function __call($name, $arguments) { if (Str::endsWith($name, $conditions = ['If', 'Unless', 'IfNotNull'])) { foreach ($conditions as $condition) { - if (!method_exists($this, $method = str_replace($condition, '', $name))) { + if (! method_exists($this, $method = str_replace($condition, '', $name))) { continue; } @@ -435,9 +435,9 @@ protected function callConditionalMethod($type, $method, array $arguments) switch ($type) { case 'If': - return $this->if((bool)$value, $callback); + return $this->if((bool) $value, $callback); case 'Unless': - return $this->unless((bool)$value, $callback); + return $this->unless((bool) $value, $callback); case 'IfNotNull': return $this->ifNotNull($value, $callback); default: From 63d82b96438b7971670049c765d8c3eee99e3185 Mon Sep 17 00:00:00 2001 From: Tim Hemmes Date: Mon, 18 Mar 2024 13:50:59 +0100 Subject: [PATCH 3/8] reverted whitespace removal --- src/BaseElement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BaseElement.php b/src/BaseElement.php index 5b95127..b50163e 100644 --- a/src/BaseElement.php +++ b/src/BaseElement.php @@ -405,8 +405,8 @@ public function isVoidElement(): bool * Dynamically handle calls to the class. * Check for methods finishing by If or fallback to Macroable. * - * @param string $name - * @param array $arguments + * @param string $name + * @param array $arguments * @return mixed * * @throws BadMethodCallException From 1287115a522d43e18ac5e5f62d967c97a5305980 Mon Sep 17 00:00:00 2001 From: Tim Hemmes Date: Mon, 18 Mar 2024 13:52:56 +0100 Subject: [PATCH 4/8] Removed unnecessary import --- tests/Html/ButtonTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Html/ButtonTest.php b/tests/Html/ButtonTest.php index 427fed5..ddf6225 100644 --- a/tests/Html/ButtonTest.php +++ b/tests/Html/ButtonTest.php @@ -1,7 +1,5 @@ ', From 1847be1dfeadbdc0cf47726e4a7329979f95a917 Mon Sep 17 00:00:00 2001 From: freekmurze Date: Sat, 23 Mar 2024 11:29:02 +0000 Subject: [PATCH 5/8] Update CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1ec4ad..a5475b3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to `laravel-html` will be documented in this file. +## 3.7.0 - 2024-03-23 + +### What's Changed + +* Fix return value in docs in element-methods.md by @raveren in https://github.com/spatie/laravel-html/pull/218 +* Add autocomplete attribute helper to input, select and textarea by @raveren in https://github.com/spatie/laravel-html/pull/219 +* Fix link with version in documentation by @fey in https://github.com/spatie/laravel-html/pull/217 + +### New Contributors + +* @raveren made their first contribution in https://github.com/spatie/laravel-html/pull/218 +* @fey made their first contribution in https://github.com/spatie/laravel-html/pull/217 + +**Full Changelog**: https://github.com/spatie/laravel-html/compare/3.6.0...3.7.0 + ## 3.6.0 - 2024-03-08 ### What's Changed From ad42d087a475b35f38d90f2f5d9f4d4eb79d8bf4 Mon Sep 17 00:00:00 2001 From: raveren Date: Thu, 18 Apr 2024 11:55:18 +0300 Subject: [PATCH 6/8] Add autocomplete attribute helper to the form element --- docs/general-usage/element-classes.md | 7 ++++--- src/Elements/Form.php | 2 ++ tests/Elements/FormTest.php | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/general-usage/element-classes.md b/docs/general-usage/element-classes.md index a7ec74f..6e037fc 100644 --- a/docs/general-usage/element-classes.md +++ b/docs/general-usage/element-classes.md @@ -52,6 +52,7 @@ echo Element::withTag('p')->text('This is the content!'); - `function acceptsFiles()` - `function action(?string $action)` +- `function autocomplete(bool|string $autocomplete = true)` - `function method(?string $method)` - `function novalidate($novalidate = true)` - `function target(string $target)` @@ -66,7 +67,7 @@ echo Element::withTag('p')->text('This is the content!'); ## `Input` -- `function autocomplete(?$autocomplete)` +- `function autocomplete(bool|string $autocomplete = true)` - `function autofocus(?$autofocus)` - `function checked($checked = true)` - `function disabled($disabled = true)` @@ -104,7 +105,7 @@ echo Element::withTag('p')->text('This is the content!'); ## `Select` -- `function autocomplete(?$autocomplete)` +- `function autocomplete(bool|string $autocomplete = true)` - `function autofocus(?$autofocus)` - `function disabled(?$disabled)` - `function isReadonly(?$readonly)` @@ -120,7 +121,7 @@ echo Element::withTag('p')->text('This is the content!'); ## `Textarea` -- `function autocomplete(?$autocomplete)` +- `function autocomplete(bool|string $autocomplete = true)` - `function autofocus()` - `function cols(int $cols)` - `function disabled(?$disabled)` diff --git a/src/Elements/Form.php b/src/Elements/Form.php index e26330e..9880d70 100644 --- a/src/Elements/Form.php +++ b/src/Elements/Form.php @@ -3,10 +3,12 @@ namespace Spatie\Html\Elements; use Spatie\Html\BaseElement; +use Spatie\Html\Elements\Attributes\Autocomplete; use Spatie\Html\Elements\Attributes\Target; class Form extends BaseElement { + use Autocomplete; use Target; protected $tag = 'form'; diff --git a/tests/Elements/FormTest.php b/tests/Elements/FormTest.php index 07a9173..00f4e56 100644 --- a/tests/Elements/FormTest.php +++ b/tests/Elements/FormTest.php @@ -26,6 +26,12 @@ Form::create()->acceptsFiles() ); +it('can create a form with a non-autocomplete attribute') + ->assertHtmlStringEqualsHtmlString( + '
', + Form::create()->autocomplete(false) + ); + it('can create a form with a novalidate attribute') ->assertHtmlStringEqualsHtmlString( '
', From 1b5bce9284ffe255ec4dd962c6e9d40c2ba99329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Kartal?= Date: Tue, 23 Apr 2024 20:40:20 +0000 Subject: [PATCH 7/8] Add name attribute to form element --- src/Elements/Form.php | 2 ++ tests/Elements/FormTest.php | 7 +++++++ tests/Html/FormTest.php | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/src/Elements/Form.php b/src/Elements/Form.php index 9880d70..e90ea46 100644 --- a/src/Elements/Form.php +++ b/src/Elements/Form.php @@ -4,11 +4,13 @@ use Spatie\Html\BaseElement; use Spatie\Html\Elements\Attributes\Autocomplete; +use Spatie\Html\Elements\Attributes\Name; use Spatie\Html\Elements\Attributes\Target; class Form extends BaseElement { use Autocomplete; + use Name; use Target; protected $tag = 'form'; diff --git a/tests/Elements/FormTest.php b/tests/Elements/FormTest.php index 00f4e56..a3e90d7 100644 --- a/tests/Elements/FormTest.php +++ b/tests/Elements/FormTest.php @@ -55,3 +55,10 @@ '
', Form::create()->target('_blank') ); + +it('can create a form with a name', function () { + assertHtmlStringEqualsHtmlString( + '
', + Form::create()->name('form-name') + ); +}); diff --git a/tests/Html/FormTest.php b/tests/Html/FormTest.php index be8f811..d2718a0 100644 --- a/tests/Html/FormTest.php +++ b/tests/Html/FormTest.php @@ -66,3 +66,10 @@ it('can return close model form') ->expect(fn () => (string) $this->html->closeModelForm()) ->toEqual(''); + +it('can create a form with a name', function () { + assertHtmlStringEqualsHtmlString( + '
', + $this->html->form('GET')->name('form-name') + ); +}); From c9e0eff141b43172b553f8b7cd23a37126ba0079 Mon Sep 17 00:00:00 2001 From: gqrdev Date: Tue, 23 Apr 2024 22:02:23 -0300 Subject: [PATCH 8/8] Register Service Provider in Laravel 11 --- docs/installation-setup.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/installation-setup.md b/docs/installation-setup.md index 3238e9a..b857db8 100644 --- a/docs/installation-setup.md +++ b/docs/installation-setup.md @@ -20,3 +20,13 @@ Next, you need to register the service provider: Spatie\Html\HtmlServiceProvider::class, ]; ``` + +If you're using Laravel 11: + +```php +// bootstrap/providers.php +return [ + ... + Spatie\Html\HtmlServiceProvider::class, +]; +```