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 1744d66 commit 00610d8
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"illuminate/view": "^10.0|^11.0",
"laravel/scout": "^10.0|^11.0",
"livewire/livewire": "^3.4",
"spatie/laravel-html": "^3.10",
"spatie/laravel-package-tools": "^1.16.3",
"spatie/php-structure-discoverer": "^2.1"
},
Expand Down
16 changes: 0 additions & 16 deletions resources/views/components/layout/container.blade.php

This file was deleted.

File renamed without changes.
17 changes: 17 additions & 0 deletions resources/views/forms/form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<form {{ $attributes
->cssClass([
'layer' => 'grid grid-flow-row auto-rows-min gap-3',
'actions' => 'flex flex-nowrap items-center gap-x-3 overflow-x-auto'
])
->classMerge([
'layer',
])
}}>
{{ $slot }}

@if ($actions)
<div {{ $attributes->classFor('actions') }}>
{{ $actions }}
</div>
@endif
</form>
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions resources/views/layout/container.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ html()
->div($slot)
->class([
'container',
'w-full max-w-4xl xl:max-w-5xl' => ! $fluid,
])
}}
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions src/Forms/Components/Input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Foxws\WireUse\Navigation\Components;

use Closure;
use Foxws\WireUse\Views\Support\Component;
use Illuminate\View\View;
use Spatie\Html\Html;

class Input extends Component
{
public function __construct(
public ?Html $prepend = null,
public ?Html $append = null,
public ?Html $label = null,
public ?Html $hint = null,
) {
}

public function render(): View|Closure|string
{
return view('wireuse::forms.input');
}
}
20 changes: 20 additions & 0 deletions src/Layout/Components/Container.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Foxws\WireUse\Layout\Components;

use Closure;
use Foxws\WireUse\Views\Support\Component;
use Illuminate\View\View;

class Container extends Component
{
public function __construct(
public bool $fluid = false,
) {
}

public function render(): View|Closure|string
{
return view('wireuse::layout.container');
}
}
20 changes: 20 additions & 0 deletions src/Layout/Components/Join.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Foxws\WireUse\Layout\Components;

use Closure;
use Foxws\WireUse\Views\Support\Component;
use Illuminate\View\View;

class Join extends Component
{
public function __construct(
public bool $fluid = false,
) {
}

public function render(): View|Closure|string
{
return view('wireuse::layout.join');
}
}
29 changes: 29 additions & 0 deletions src/Support/Html/Elements/Attributes/Livewire.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Foxws\WireUse\Support\Elements\Attributes;

use Illuminate\Support\Stringable;

trait Livewire
{
public function wireKey(string $value): static
{
return $this->attribute('wire:key', $value);
}

public function wireIgnore(bool $self = false): static
{
return $self
? $this->attribute('wire:ignore.self')
: $this->attribute('wire:ignore');
}

public function wireModel(string $key, ?string $modifiers = null): static
{
$directive = str('wire:model')
->when($modifiers, fn (Stringable $str) => $str->append(".{$modifiers}"))
->squish();

return $this->attribute($directive->value(), $key);
}
}
15 changes: 15 additions & 0 deletions src/Support/Html/Elements/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Foxws\WireUse\Support\Html\Elements;

use Spatie\Html\Elements\Form as FormElement;

class Form extends FormElement
{
public function wireSubmit(?string $action = null): static
{
$this->attributeIfNotNull($action, 'wire:submit', $action);

Check failure on line 11 in src/Support/Html/Elements/Form.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Foxws\WireUse\Support\Html\Elements\Form::attributeIfNotNull().

return $this;
}
}
22 changes: 22 additions & 0 deletions src/Support/Html/HtmlExtended.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Foxws\WireUse\Support\Html;

use Foxws\WireUse\Support\Html\Elements\Form as FormElement;
use Livewire\Form;
use Spatie\Html\Html;

class HtmlExtended extends Html
{
protected ?Form $form = null;

public function wireForm(Form $value, ?string $action = null): FormElement
{
$this->form = $value;

$form = FormElement::create();

return $form
->wireSubmit($action);
}
}
42 changes: 42 additions & 0 deletions src/Support/Html/Mixins/BaseElementMixin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Foxws\WireUse\Support\Html\Mixins;

use Illuminate\Support\Stringable;
use Spatie\Html\BaseElement;

class BaseElementMixin
{
public function wireKey()
{
return function (string $value) {
/** @var BaseElement $this */

return $this->attribute('wire:key', $value);
};
}

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

return $self
? $this->attribute('wire:ignore.self')
: $this->attribute('wire:ignore');
};
}

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

$directive = str('wire:model')
->when($modifiers, fn (Stringable $str) => $str->append(".{$modifiers}"))
->squish();

return $this->attribute($directive->value(), $key);
};
}
}
1 change: 1 addition & 0 deletions src/WireUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function registerComponents(
collect($scout)
->each(function (DiscoveredStructure $class) use ($namespace, $prefix) {
$name = static::componentName($class, $namespace, $prefix);
logger($name);

Blade::component($class->getFcqn(), $name->value());
});
Expand Down
16 changes: 15 additions & 1 deletion src/WireUseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace Foxws\WireUse;

use Foxws\WireUse\Support\Blade\Bladeable;
use Foxws\WireUse\Support\Html\Mixins\BaseElementMixin;
use Foxws\WireUse\Support\Html\HtmlExtended;
use Illuminate\Support\Facades\Blade;
use Illuminate\View\ComponentAttributeBag;
use Spatie\Html\BaseElement;
use Spatie\Html\Html;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -35,7 +39,8 @@ public function bootingPackage(): void
->registerBladeMacros()
->registerAnonymousComponent()
->registerComponents()
->registerLivewire();
->registerLivewire()
->registerHtml();
}

protected function registerFeatures(): static
Expand Down Expand Up @@ -165,4 +170,13 @@ protected function registerLivewire(): static

return $this;
}

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

BaseElement::mixin(new BaseElementMixin);

return $this;
}
}

0 comments on commit 00610d8

Please sign in to comment.