Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Jul 7, 2024
1 parent f9eeb41 commit 6a14e77
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
24 changes: 0 additions & 24 deletions src/Support/Html/HtmlExtended.php

This file was deleted.

16 changes: 11 additions & 5 deletions src/Support/Html/Mixins/BaseElementMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class BaseElementMixin
{
public function wireKey(): mixed
{
return function (?string $value = null) {
return function (?string $value = null): BaseElement
{
/** @var BaseElement $this */

return $this->attribute('wire:key', $value);
Expand All @@ -18,7 +19,8 @@ public function wireKey(): mixed

public function wireIgnore(): mixed
{
return function (?bool $self = false) {
return function (?bool $self = false): BaseElement
{
/** @var BaseElement $this */

return $self
Expand All @@ -29,7 +31,8 @@ public function wireIgnore(): mixed

public function wireNavigate(): mixed
{
return function () {
return function (): BaseElement
{
/** @var BaseElement $this */

return $this->attribute('wire:navigate');
Expand All @@ -38,7 +41,8 @@ public function wireNavigate(): mixed

public function wireSubmit(): mixed
{
return function (?string $action = null) {
return function (?string $action = null): BaseElement
{
/** @var BaseElement $this */

return $this->attribute('wire:submit', $action);
Expand All @@ -47,8 +51,10 @@ public function wireSubmit(): mixed

public function wireModel(): mixed
{
return function (string $key, ?string $modifiers = null) {
return function (string $key, ?string $modifiers = null): BaseElement
{
/** @var BaseElement $this */

$directive = str('wire:model')
->when($modifiers, fn (Stringable $str) => $str->append(".{$modifiers}"))
->squish();
Expand Down
31 changes: 31 additions & 0 deletions src/Support/Html/Mixins/HtmlExtendedMixin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Foxws\WireUse\Support\Html\Mixins;

use Livewire\Form;
use Spatie\Html\Elements\Div;

class HtmlExtendedMixin
{
protected ?Form $form = null;

public function wireForm(): mixed
{
return function (?Form $value = null): static
{
$this->form = $value;

return $this;
};
}

public function icon(): mixed
{
return function (string $name, ?string $class = null, ?array $attributes = []): Div
{
/** @var Div $this */

return $this->div(svg($name, $class, $attributes));

Check failure on line 28 in src/Support/Html/Mixins/HtmlExtendedMixin.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Spatie\Html\Elements\Div::div().

Check failure on line 28 in src/Support/Html/Mixins/HtmlExtendedMixin.php

View workflow job for this annotation

GitHub Actions / phpstan

Function svg not found.
};
}
}
5 changes: 2 additions & 3 deletions src/WireUseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Foxws\WireUse;

use Foxws\WireUse\Support\Blade\Bladeable;
use Foxws\WireUse\Support\Html\HtmlExtended;
use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin;
use Foxws\WireUse\Support\Html\Mixins\HtmlExtendedMixin;
use Foxws\WireUse\Support\Html\Mixins\LinkElementMixin;
use Illuminate\Support\Facades\Blade;
use Illuminate\View\ComponentAttributeBag;
Expand Down Expand Up @@ -175,8 +175,7 @@ protected function registerLivewire(): static

protected function registerHtml(): static
{
$this->app->singleton(Html::class, HtmlExtended::class);

Html::mixin(new HtmlExtendedMixin);
BaseElement::mixin(new BaseElementMixin);
A::mixin(new LinkElementMixin);

Expand Down

0 comments on commit 6a14e77

Please sign in to comment.