mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Improve actions
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<x-filament-actions::action
|
||||
:action="$action"
|
||||
dynamic-component="filament::button"
|
||||
:outlined="$isOutlined()"
|
||||
:labeled-from="$getLabeledFromBreakpoint()"
|
||||
:icon-position="$getIconPosition()"
|
||||
:icon-size="$getIconSize()"
|
||||
:labeled-from="$getLabeledFromBreakpoint()"
|
||||
:outlined="$isOutlined()"
|
||||
:size="$getSize()"
|
||||
class="fi-ac-btn-action"
|
||||
>
|
||||
{{ $getLabel() }}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<x-filament-actions::group
|
||||
:group="$group"
|
||||
dynamic-component="filament::button"
|
||||
:outlined="$isOutlined()"
|
||||
:labeled-from="$getLabeledFromBreakpoint()"
|
||||
:group="$group"
|
||||
:icon-position="$getIconPosition()"
|
||||
:icon-size="$getIconSize()"
|
||||
:labeled-from="$getLabeledFromBreakpoint()"
|
||||
:outlined="$isOutlined()"
|
||||
:size="$getSize()"
|
||||
class="fi-ac-btn-group"
|
||||
>
|
||||
{{ $getLabel() }}
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
:tooltip="$action->getTooltip()"
|
||||
:disabled="$isDisabled"
|
||||
:icon="$icon ?? $action->getIcon()"
|
||||
:icon-size="$action->getIconSize()"
|
||||
:size="$action->getSize()"
|
||||
:label-sr-only="$action->isLabelHidden()"
|
||||
:attributes="\Filament\Support\prepare_inherited_attributes($attributes)->merge($action->getExtraAttributes(), escape: false)"
|
||||
>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
'dynamicComponent' => null,
|
||||
'group' => null,
|
||||
'icon' => null,
|
||||
'iconPosition' => null,
|
||||
'iconSize' => null,
|
||||
'iconButton' => false,
|
||||
'label' => null,
|
||||
'link' => false,
|
||||
@@ -24,6 +26,8 @@
|
||||
->color($color)
|
||||
->dropdownPlacement($dropdownPlacement)
|
||||
->icon($icon)
|
||||
->iconPosition($iconPosition)
|
||||
->iconSize($iconSize)
|
||||
->label($label)
|
||||
->size($size)
|
||||
->tooltip($tooltip)
|
||||
@@ -89,12 +93,11 @@
|
||||
<x-dynamic-component
|
||||
:badge="$group->getBadge()"
|
||||
:badge-color="$group->getBadgeColor()"
|
||||
:component="$dynamicComponent"
|
||||
:color="$group->getColor()"
|
||||
:tooltip="$group->getTooltip()"
|
||||
:component="$dynamicComponent"
|
||||
:icon="$group->getIcon()"
|
||||
:size="$group->getSize()"
|
||||
:label-sr-only="$group->isLabelHidden()"
|
||||
:tooltip="$group->getTooltip()"
|
||||
:attributes="\Filament\Support\prepare_inherited_attributes($attributes)->merge($group->getExtraAttributes(), escape: false)"
|
||||
>
|
||||
{{ $slot }}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<x-filament-actions::action
|
||||
:action="$action"
|
||||
:label="$getLabel()"
|
||||
dynamic-component="filament::icon-button"
|
||||
:icon-size="$getIconSize()"
|
||||
:label="$getLabel()"
|
||||
:size="$getSize()"
|
||||
class="fi-ac-icon-btn-action"
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<x-filament-actions::group
|
||||
:group="$group"
|
||||
:label="$getLabel()"
|
||||
dynamic-component="filament::icon-button"
|
||||
:group="$group"
|
||||
:icon-size="$getIconSize()"
|
||||
:label="$getLabel()"
|
||||
:size="$getSize()"
|
||||
class="fi-ac-icon-btn-group"
|
||||
/>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
dynamic-component="filament::link"
|
||||
:icon-position="$getIconPosition()"
|
||||
:icon-size="$getIconSize()"
|
||||
:size="$getSize()"
|
||||
class="fi-ac-link-action"
|
||||
>
|
||||
{{ $getLabel() }}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<x-filament-actions::group
|
||||
:group="$group"
|
||||
dynamic-component="filament::link"
|
||||
:group="$group"
|
||||
:icon-position="$getIconPosition()"
|
||||
:icon-size="$getIconSize()"
|
||||
:size="$getSize()"
|
||||
tag="button"
|
||||
class="fi-ac-link-group"
|
||||
>
|
||||
|
||||
@@ -6,8 +6,6 @@ use Closure;
|
||||
use Filament\Actions\Contracts\Groupable;
|
||||
use Filament\Actions\StaticAction;
|
||||
use Filament\Support\Enums\ActionSize;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -56,17 +54,8 @@ class Action extends StaticAction implements Arrayable, Groupable
|
||||
'dispatchToComponent' => $this->getDispatchToComponent(),
|
||||
'extraAttributes' => $this->getExtraAttributes(),
|
||||
'icon' => $this->getIcon(),
|
||||
'iconPosition' => match ($iconPosition = $this->getIconPosition()) {
|
||||
IconPosition::After => 'after',
|
||||
IconPosition::Before => 'before',
|
||||
default => $iconPosition,
|
||||
},
|
||||
'iconSize' => match ($iconSize = $this->getIconSize()) {
|
||||
IconSize::Small => 'sm',
|
||||
IconSize::Medium => 'md',
|
||||
IconSize::Large => 'lg',
|
||||
default => $iconSize,
|
||||
},
|
||||
'iconPosition' => $this->getIconPosition(),
|
||||
'iconSize' => $this->getIconSize(),
|
||||
'isOutlined' => $this->isOutlined(),
|
||||
'isDisabled' => $this->isDisabled(),
|
||||
'label' => $this->getLabel(),
|
||||
@@ -74,14 +63,8 @@ class Action extends StaticAction implements Arrayable, Groupable
|
||||
'shouldMarkAsRead' => $this->shouldMarkAsRead(),
|
||||
'shouldMarkAsUnread' => $this->shouldMarkAsUnread(),
|
||||
'shouldOpenUrlInNewTab' => $this->shouldOpenUrlInNewTab(),
|
||||
'size' => match ($size = $this->getSize()) {
|
||||
ActionSize::ExtraSmall => 'xs',
|
||||
ActionSize::Small => 'sm',
|
||||
ActionSize::Medium => 'md',
|
||||
ActionSize::Large => 'lg',
|
||||
ActionSize::ExtraLarge => 'xl',
|
||||
default => $size,
|
||||
},
|
||||
'size' => $this->getSize(),
|
||||
'tooltip' => $this->getTooltip(),
|
||||
'url' => $this->getUrl(),
|
||||
'view' => $this->getView(),
|
||||
];
|
||||
@@ -123,6 +106,7 @@ class Action extends StaticAction implements Arrayable, Groupable
|
||||
$static->markAsUnread($data['shouldMarkAsUnread'] ?? false);
|
||||
$static->outlined($data['isOutlined'] ?? false);
|
||||
$static->url($data['url'] ?? null, $data['shouldOpenUrlInNewTab'] ?? false);
|
||||
$static->tooltip($data['tooltip'] ?? null);
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
namespace Filament\Notifications\Actions;
|
||||
|
||||
use Filament\Actions\ActionGroup as BaseActionGroup;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property array<Action> $actions
|
||||
@@ -20,20 +19,19 @@ class ActionGroup extends BaseActionGroup implements Arrayable
|
||||
return [
|
||||
'actions' => collect($this->getActions())->toArray(),
|
||||
'color' => $this->getColor(),
|
||||
'dropdownMaxHeight' => $this->getDropdownMaxHeight(),
|
||||
'dropdownPlacement' => $this->getDropdownPlacement(),
|
||||
'dropdownWidth' => $this->getDropdownWidth(),
|
||||
'extraAttributes' => $this->getExtraAttributes(),
|
||||
'hasDropdown' => $this->hasDropdown(),
|
||||
'icon' => $this->getIcon(),
|
||||
'iconPosition' => match ($iconPosition = $this->getIconPosition()) {
|
||||
IconPosition::After => 'after',
|
||||
IconPosition::Before => 'before',
|
||||
default => $iconPosition,
|
||||
},
|
||||
'iconSize' => match ($iconSize = $this->getIconSize()) {
|
||||
IconSize::Small => 'sm',
|
||||
IconSize::Medium => 'md',
|
||||
IconSize::Large => 'large',
|
||||
default => $iconSize,
|
||||
},
|
||||
'iconPosition' => $this->getIconPosition(),
|
||||
'iconSize' => $this->getIconSize(),
|
||||
'isOutlined' => $this->isOutlined(),
|
||||
'label' => $this->getLabel(),
|
||||
'size' => $this->getSize(),
|
||||
'tooltip' => $this->getTooltip(),
|
||||
'view' => $this->getView(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -44,18 +42,45 @@ class ActionGroup extends BaseActionGroup implements Arrayable
|
||||
{
|
||||
$static = static::make(
|
||||
array_map(
|
||||
fn (array $action): Action => Action::fromArray($action),
|
||||
fn (array $action): Action | ActionGroup => match (array_key_exists('actions', $action)) {
|
||||
true => ActionGroup::fromArray($action),
|
||||
false => Action::fromArray($action),
|
||||
},
|
||||
$data['actions'] ?? [],
|
||||
),
|
||||
);
|
||||
|
||||
$view = $data['view'] ?? null;
|
||||
|
||||
if (filled($view) && ($static->getView() !== $view) && static::isViewSafe($view)) {
|
||||
$static->view($view);
|
||||
}
|
||||
|
||||
if (filled($size = $data['size'] ?? null)) {
|
||||
$static->size($size);
|
||||
}
|
||||
|
||||
$static->color($data['color'] ?? null);
|
||||
$static->dropdown($data['hasDropdown'] ?? false);
|
||||
$static->dropdownMaxHeight($data['dropdownMaxHeight'] ?? null);
|
||||
$static->dropdownPlacement($data['dropdownPlacement'] ?? null);
|
||||
$static->dropdownWidth($data['dropdownWidth'] ?? null);
|
||||
$static->extraAttributes($data['extraAttributes'] ?? []);
|
||||
$static->icon($data['icon'] ?? null);
|
||||
$static->iconPosition($data['iconPosition'] ?? null);
|
||||
$static->iconSize($data['iconSize'] ?? null);
|
||||
$static->label($data['label'] ?? null);
|
||||
$static->outlined($data['isOutlined'] ?? null);
|
||||
$static->tooltip($data['tooltip'] ?? null);
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param view-string $view
|
||||
*/
|
||||
protected static function isViewSafe(string $view): bool
|
||||
{
|
||||
return Str::startsWith($view, 'filament-actions::');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Filament\Support\Enums;
|
||||
|
||||
enum IconPosition
|
||||
enum IconPosition: string
|
||||
{
|
||||
case Before;
|
||||
case Before = 'before';
|
||||
|
||||
case After;
|
||||
case After = 'after';
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace Filament\Support\Enums;
|
||||
|
||||
enum IconSize
|
||||
enum IconSize: string
|
||||
{
|
||||
case Small;
|
||||
case Small = 'sm';
|
||||
|
||||
case Medium;
|
||||
case Medium = 'md';
|
||||
|
||||
case Large;
|
||||
case Large = 'lg';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user