Skip to content

Commit

Permalink
Merge pull request #53 from awcodes/feat/icons-and-label
Browse files Browse the repository at this point in the history
Feat: Hidden icons and label support
  • Loading branch information
awcodes authored May 29, 2024
2 parents c4f3dd2 + 00d02df commit 272b84e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public function panel(Panel $panel): Panel

### Appearance

#### Rounded

By default, the Quick Create button will be fully rounded if you would like to have a more square button you can disable the rounding with the `rounded()` method.

```php
Expand All @@ -135,6 +137,40 @@ public function panel(Panel $panel): Panel
}
```

#### Hiding Icons

If you prefer to not show icons for the items in the menu you can disable them with the `hiddenIcons()` method.

```php
use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
return $panel
->plugins([
QuickCreatePlugin::make()
->hiddenIcons(),
])
}
```

#### Settings label

If you prefer to show a label with the plus icon you can set it using the `label()` method and passing your label to it.

```php
use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
return $panel
->plugins([
QuickCreatePlugin::make()
->label('New'),
])
}
```

### Slide Overs

By default, Quick Create will render simple resources in a standard modal. If you would like to render them in a slide over instead you may use the `slideOver()` modifier to do so.
Expand Down
9 changes: 7 additions & 2 deletions resources/views/components/create-menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
<x-slot name="trigger">
<button
@class([
'flex flex-shrink-0 w-8 h-8 bg-gray-100 items-center justify-center text-primary-500 hover:text-primary-900 dark:bg-gray-800 hover:bg-primary-500 dark:hover:bg-primary-500',
'flex flex-shrink-0 bg-gray-100 items-center justify-center text-primary-500 hover:text-primary-900 dark:bg-gray-800 hover:bg-primary-500 dark:hover:bg-primary-500',
'rounded-full' => $rounded,
'rounded-md' => ! $rounded,
'w-8 h-8' => ! $label,
'py-1 ps-3 pe-4 gap-1' => $label,
])
aria-label="{{ __('filament-quick-create::quick-create.button_label') }}"
>
Expand All @@ -15,12 +17,15 @@
icon="heroicon-o-plus"
class="w-5 h-5"
/>
@if ($label)
<span class="">{{ $label }}</span>
@endif
</button>
</x-slot>
<x-filament::dropdown.list>
@foreach($resources as $resource)
<x-filament::dropdown.list.item
:icon="$resource['icon']"
:icon="$hiddenIcons ? null : $resource['icon']"
:wire:click="$resource['action']"
:href="$resource['url']"
:tag="$resource['url'] ? 'a' : 'button'"
Expand Down
6 changes: 6 additions & 0 deletions src/Components/QuickCreateMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ class QuickCreateMenu extends Component implements HasForms, HasActions

public ?bool $rounded = null;

public bool $hiddenIcons = false;

public ?string $label = null;

/**
* @throws Exception
*/
public function mount(): void
{
$this->resources = QuickCreatePlugin::get()->getResources();
$this->rounded = QuickCreatePlugin::get()->isRounded();
$this->hiddenIcons = QuickCreatePlugin::get()->shouldHideIcons();
$this->label = QuickCreatePlugin::get()->getLabel();
}

/**
Expand Down
28 changes: 28 additions & 0 deletions src/QuickCreatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class QuickCreatePlugin implements Plugin

protected string | Closure | null $renderUsingHook = null;

protected bool | Closure | null $hiddenIcons = null;

protected string | Closure | null $label = null;

public function boot(Panel $panel): void
{
Livewire::component('quick-create-menu', Components\QuickCreateMenu::class);
Expand Down Expand Up @@ -207,4 +211,28 @@ public function getRenderHook(): string
{
return $this->evaluate($this->renderUsingHook) ?? PanelsRenderHook::USER_MENU_BEFORE;
}

public function hiddenIcons(bool | Closure $condition = true): static
{
$this->hiddenIcons = $condition;

return $this;
}

public function shouldHideIcons(): bool
{
return $this->evaluate($this->hiddenIcons) ?? false;
}

public function label(string | Closure $label): static
{
$this->label = $label;

return $this;
}

public function getLabel(): ?string
{
return $this->evaluate($this->label) ?? null;
}
}

0 comments on commit 272b84e

Please sign in to comment.