Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Apr 23, 2024
1 parent 1c3fca1 commit dc785e9
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 36 deletions.
43 changes: 26 additions & 17 deletions resources/views/actions/button.blade.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<button {{ $attributes
->cssClass([
'layer' => 'inline-flex shrink-0 cursor-pointer select-none items-center',
'disabled' => '!bg-gray-300 pointer-events-none opacity-50',
])
->classMerge([
'layer',
'disabled' => $attributes->has('disabled'),
])
->merge([
'type' => 'button',
])
}}>
{{ $label }}

{{ $slot }}
</button>
<a
@if ($navigate()) wire:navigate @endif
{{ $attributes
->cssClass([
'layer' => 'inline-flex shrink-0 cursor-pointer items-center hover:text-primary-400',
'active' => 'text-primary-400 hover:text-primary-300',
'inactive' => 'text-secondary',
])
->classMerge([
'layer',
'active' => $active(),
'inactive' => ! $active(),
])
->merge([
'href' => $url(),
'aria-label' => $action->getLabel(),
'title' => $action->getLabel(),
])
}}
>
@if ($slot->isEmpty())
{{ $action->getLabel() }}
@else
{{ $slot }}
@endif
</a>
6 changes: 3 additions & 3 deletions resources/views/actions/link.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
@if ($navigate()) wire:navigate @endif
{{ $attributes
->cssClass([
'layer' => 'inline-flex shrink-0 cursor-pointer items-center hover:text-primary-400',
'layer' => 'inline-flex shrink-0 cursor-pointer items-center',
'active' => 'text-primary-400 hover:text-primary-300',
'inactive' => 'text-secondary',
'inactive' => 'text-secondary hover:text-primary-400',
])
->classMerge([
'layer',
'active' => $active(),
'inactive' => ! $active(),
])
->merge([
'href' => $url(),
'href' => $attributes->has('wire:click') ? false : $url(),
'aria-label' => $action->getLabel(),
'title' => $action->getLabel(),
])
Expand Down
49 changes: 49 additions & 0 deletions resources/views/navigation/group.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<nav {{ $attributes
->cssClass([
'layer' => 'flex items-center px-3 gap-5 border-b border-secondary-800/80 overflow-x-auto',
'tab' => 'text-sm font-medium py-3',
'active' => 'text-white border-b border-white-600/80',
'inactive' => 'text-secondary-600',
])
->classMerge([
'layer',
])
->whereDoesntStartWith('wire:model')
}}>


@foreach ($navigation->items() as $item)
<x-wireuse::actions-link
:action="$item"
wire:click="$set('{{ $wireModel }}', '{{ $item->getName() }}')"
class="{{ $attributes->classFor('tab') }}"
class:active="{{ $attributes->classFor('active') }}"
class:inactive="{{ $attributes->classFor('inactive') }}"
/>



{{-- <input
type="radio"
value="{{ $item->getName() }}"
id="{{ $item->getName() }}"
class="hidden"
{{ $attributes->whereStartsWith('wire:model') }}
>
<label
{{ $attributes
->classOnly([
'tab',
'active' => $item->getName() === $this->{$wireModel()},
])
->merge([
'for' => $item->getName()
])
}}
>
{{ $item->getLabel() }}
</label> --}}
@endforeach
</nav>
24 changes: 19 additions & 5 deletions src/Actions/Components/Button.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
<?php

namespace Foxws\WireUi\Actions\Components;
namespace Foxws\WireUse\Actions\Components;

use Closure;
use Foxws\WireUse\Actions\Support\Action;
use Foxws\WireUse\Views\Support\Component;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\View\View;

class Button extends Component
{
public function __construct(
public string|Htmlable|null $label = '',
public Action $action,
) {
}

public function render(): View
public function render(): View|Closure|string
{
return view('wireui::actions.button');
return view('wireuse::actions.button');
}

public function active(): bool
{
return $this->action->isActive();
}

public function icon(): ?string
{
return $this->when($this->active(),
fn () => $this->action->getActiveIcon(),
fn () => $this->action->getIcon(),
);
}
}
5 changes: 4 additions & 1 deletion src/Actions/Components/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use Closure;
use Foxws\WireUse\Actions\Support\Action;
use Foxws\WireUse\Views\Concerns\WithLayout;
use Foxws\WireUse\Views\Support\Component;
use Illuminate\View\View;

class Link extends Component
{
use WithLayout;

public function __construct(
public Action $action,
) {
Expand All @@ -25,7 +28,7 @@ public function url(): ?string
return $this->action->getRoute();
}

return $this->action->getUrl() ?? '/';
return $this->action->getUrl() ?? '#';
}

public function active(): bool
Expand Down
17 changes: 17 additions & 0 deletions src/Actions/Concerns/HasComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Foxws\WireUse\Actions\Concerns;

use Closure;
use Illuminate\View\Component;
use Livewire\Component as Livewire;

trait HasComponent
{
public function component(Component|Livewire|Closure|string $component): static
{
$this->component = $component;

return $this;
}
}
16 changes: 16 additions & 0 deletions src/Actions/Concerns/HasView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Foxws\WireUse\Actions\Concerns;

use Closure;
use Illuminate\View\View;

trait HasView
{
public function view(View|Closure|string $view): static
{
$this->view = $view;

return $this;
}
}
4 changes: 4 additions & 0 deletions src/Actions/Support/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

namespace Foxws\WireUse\Actions\Support;

use Foxws\WireUse\Actions\Concerns\HasComponent;
use Foxws\WireUse\Actions\Concerns\HasIcon;
use Foxws\WireUse\Actions\Concerns\HasName;
use Foxws\WireUse\Actions\Concerns\HasRequest;
use Foxws\WireUse\Actions\Concerns\HasRoute;
use Foxws\WireUse\Actions\Concerns\HasState;
use Foxws\WireUse\Actions\Concerns\HasView;
use Foxws\WireUse\Support\Components\Component;

class Action extends Component
{
use HasComponent;
use HasIcon;
use HasName;
use HasRequest;
use HasRoute;
use HasState;
use HasView;

public static function make(): static
{
Expand Down
5 changes: 4 additions & 1 deletion src/Actions/Support/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@

class Group extends Collection
{
//
public function items(): array
{
return $this->all();
}
}
24 changes: 24 additions & 0 deletions src/Navigation/Components/Group.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\Navigation\Support\NavigationGroup;
use Foxws\WireUse\Views\Concerns\WithLayout;
use Foxws\WireUse\Views\Support\Component;
use Illuminate\View\View;

class Group extends Component
{
use WithLayout;

public function __construct(
public NavigationGroup $navigation,
) {
}

public function render(): View|Closure|string
{
return view('wireuse::navigation.group');
}
}
13 changes: 13 additions & 0 deletions src/Navigation/Concerns/WithNavigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Foxws\WireUse\Navigation\Concerns;

use Foxws\WireUse\Navigation\Support\NavigationGroup;

trait WithNavigation
{
public function navigation(): NavigationGroup
{
return NavigationGroup::make();
}
}
8 changes: 8 additions & 0 deletions src/Views/Concerns/WithLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Foxws\WireUse\Views\Concerns;

trait WithLayout
{
//
}
16 changes: 7 additions & 9 deletions src/WireUseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected function registerBladeMacros(): static

ComponentAttributeBag::macro('cssClass', function (array $values = []): ComponentAttributeBag {
/** @var ComponentAttributeBag $this */

foreach ($values as $key => $value) {
$key = app(Bladeable::class)::classKeys($key)->first();

Expand All @@ -69,6 +70,7 @@ protected function registerBladeMacros(): static

ComponentAttributeBag::macro('classMerge', function (?array $values = null): ComponentAttributeBag {
/** @var ComponentAttributeBag $this */

$classes = app(Bladeable::class)::classMerged($this, $values)
->merge($this->get('class'))
->join(' ');
Expand All @@ -82,6 +84,7 @@ protected function registerBladeMacros(): static

ComponentAttributeBag::macro('classOnly', function (array $values): ComponentAttributeBag {
/** @var ComponentAttributeBag $this */

$classes = app(Bladeable::class)::classMerged($this, $values)
->join(' ');

Expand All @@ -103,22 +106,17 @@ protected function registerBladeMacros(): static
return $this;
});

ComponentAttributeBag::macro('classWithout', function (): ComponentAttributeBag {
ComponentAttributeBag::macro('classFor', function (string $key, ?string $default = null): string {
/** @var ComponentAttributeBag $this */

return $this
->whereDoesntStartWith('class:');
return $this->get(app(Bladeable::class)::classKeys($key)->first(), $default ?? '');
});

ComponentAttributeBag::macro('classFor', function (string $key, ?string $default = null): ComponentAttributeBag {
ComponentAttributeBag::macro('classWithout', function (): ComponentAttributeBag {
/** @var ComponentAttributeBag $this */
$value = $this->get(app(Bladeable::class)::classKeys($key)->first(), $default ?? '');

$this->offsetSet('class', $value);

return $this
->classSort()
->classWithout();
->whereDoesntStartWith('class:');
});

return $this;
Expand Down

0 comments on commit dc785e9

Please sign in to comment.