Skip to content

Commit

Permalink
Merge pull request #20 from awcodes/feat/simple-resources
Browse files Browse the repository at this point in the history
Feat: Support simple resources
  • Loading branch information
awcodes authored Nov 4, 2022
2 parents 41b249e + d21bff3 commit 62a8d62
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 83 deletions.
17 changes: 9 additions & 8 deletions .idea/blade.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/laravel-idea-personal.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/laravel-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 76 additions & 39 deletions resources/views/components/create-menu.blade.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,84 @@
@if ($items)
<div
x-data
class="relative"
>
<button
x-on:click="$refs.quickCreatePanel.toggle"
style="margin-inline-start: 1rem;"
@class([
'flex flex-shrink-0 w-10 h-10 rounded-full bg-gray-200 items-center justify-center',
'dark:bg-gray-900' => config('filament.dark_mode'),
])
>
@svg('heroicon-o-plus', 'w-4 h-4')
</button>

<div
x-ref="quickCreatePanel"
x-float.placement.bottom-end.flip
x-transition:enter="transition"
x-transition:enter-start="-translate-y-1 opacity-0"
x-transition:enter-end="translate-y-0 opacity-100"
x-transition:leave="transition"
x-transition:leave-start="translate-y-0 opacity-100"
x-transition:leave-end="-translate-y-1 opacity-0"
x-cloak
class="absolute hidden z-10 mt-2 overflow-y-auto shadow-xl rounded-xl top-full"
style="max-height: 15rem; min-width: 208px;"
>
<ul @class([
'py-1 space-y-1 overflow-hidden bg-white shadow rounded-xl',
'dark:border-gray-600 dark:bg-gray-700' => config('filament.dark_mode'),
])>
@foreach ($items as $resource)
<div>
@if ($resources)
<x-filament::dropdown placement="bottom-end">
<x-slot name="trigger" class="ml-4">
<button @class([
'flex flex-shrink-0 w-10 h-10 rounded-full bg-gray-200 items-center justify-center',
'dark:bg-gray-900' => config('filament.dark_mode'),
]) aria-label="{{ __('filament::layout.buttons.user_menu.label') }}">
@svg('heroicon-o-plus', 'w-4 h-4')
</button>
</x-slot>
<x-filament::dropdown.list>
@foreach($resources as $resource)
<x-filament::dropdown.item
:color="'secondary'"
:href="$resource['url']"
:icon="$resource['icon']"
tag="a"
:wire:click="$resource['action']"
:href="$resource['url']"
:tag="$resource['url'] ? 'a' : 'button'"
>
{{ $resource['label'] }}
</x-filament::dropdown.item>
@endforeach
</ul>
</div>
</div>
</x-filament::dropdown.list>
</x-filament::dropdown>

<form wire:submit.prevent="callMountedAction">
@php
$action = $this->getMountedAction();
@endphp

<x-filament::modal
id="quick-create-action"
:wire:key="$action ? $this->id . '.actions.' . $action->getName() . '.modal' : null"
:visible="filled($action)"
:width="$action?->getModalWidth()"
:slide-over="$action?->isModalSlideOver()"
display-classes="block"
>
@if ($action)
@if ($action->isModalCentered())
<x-slot name="heading">
{{ $action->getModalHeading() }}
</x-slot>

@if ($subheading = $action->getModalSubheading())
<x-slot name="subheading">
{{ $subheading }}
</x-slot>
@endif
@else
<x-slot name="header">
<x-filament::modal.heading>
{{ $action->getModalHeading() }}
</x-filament::modal.heading>

@if ($subheading = $action->getModalSubheading())
<x-filament::modal.subheading>
{{ $subheading }}
</x-filament::modal.subheading>
@endif
</x-slot>
@endif

{{ $action->getModalContent() }}

@if ($action->hasFormSchema())
{{ $this->getMountedActionForm() }}
@endif

@if (count($action->getModalActions()))
<x-slot name="footer">
<x-filament::modal.actions :full-width="$action->isModalCentered()">
@foreach ($action->getModalActions() as $modalAction)
{{ $modalAction }}
@endforeach
</x-filament::modal.actions>
</x-slot>
@endif
@endif
</x-filament::modal>
</form>
@endif
</div>
44 changes: 8 additions & 36 deletions src/FilamentQuickCreateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

use Filament\Facades\Filament;
use Filament\PluginServiceProvider;
use FilamentQuickCreate\Facades\QuickCreate as Facade;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Illuminate\View\View;
use FilamentQuickCreate\Facades\QuickCreate as QuickCreateFacade;
use Illuminate\Support\Facades\Blade;
use Livewire\Livewire;
use Spatie\LaravelPackageTools\Package;

class FilamentQuickCreateServiceProvider extends PluginServiceProvider
Expand All @@ -23,7 +21,7 @@ public function configurePackage(Package $package): void

public function packageRegistered(): void
{
$this->app->scoped(Facade::class, function () {
$this->app->scoped(QuickCreateFacade::class, function () {
return new QuickCreate();
});

Expand All @@ -32,39 +30,13 @@ public function packageRegistered(): void

public function boot()
{
Livewire::component('quick-create-menu', Http\Livewire\QuickCreateMenu::class);

Filament::registerRenderHook(
'global-search.end',
fn (): View => view('filament-quick-create::components.create-menu', [
'items' => $this->getFilamentResources(),
]),
'user-menu.start',
fn (): string => Blade::render('@livewire(\'quick-create-menu\')'),
);

parent::boot();
}

public function getFilamentResources(): array
{
$resources = collect(Facade::getResources())
->filter(function ($resource) {
return ! in_array($resource, config('filament-quick-create.exclude'));
})
->map(function ($resource) {
$resource = App::make($resource);
$route = $resource->getRouteBaseName().'.create';
if ($resource->canCreate() && Route::has($route)) {
return [
'label' => Str::ucfirst($resource->getModelLabel()),
'icon' => invade($resource)->getNavigationIcon(),
'url' => route($route),
];
}

return null;
})
->when(Facade::sortingEnabled(), fn ($collection) => $collection->sortBy('label'))
->values()
->toArray();

return array_filter($resources);
}
}
Loading

0 comments on commit 62a8d62

Please sign in to comment.