Skip to content

Commit

Permalink
add table action button component
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Nov 26, 2023
1 parent 1d18f84 commit 20035ef
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
41 changes: 41 additions & 0 deletions resources/views/components/table-action.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@if($type === 'link')
<x-splade-link {{ $attributes->class([
'text-left w-full px-4 py-2 text-sm font-normal',
'text-danger-700 dark:text-white dark:hover:bg-danger-600 hover:bg-gray-50 hover:text-danger-900' => $danger,
'text-warning-700 dark:text-white dark:hover:bg-warning-600 hover:bg-gray-50 hover:text-warning-900' => $warning,
'text-primary-700 dark:text-white dark:hover:bg-primary-600 hover:bg-gray-50 hover:text-primary-900' => $primary,
'text-success-700 dark:text-white dark:hover:bg-success-600 hover:bg-gray-50 hover:text-success-900' => $success,
'text-gray-700 dark:text-white dark:hover:bg-gray-600 hover:bg-gray-50 hover:text-gray-900' => $secondary,
]) }} :method="$method">
<div class="flex justify-start gap-2">
@if($icon)
<div class="flex flex-col justify-center items-center">
<i class="{{$icon}}"></i>
</div>
@endif
<div>
{{$label ?: $slot}}
</div>
</div>
</x-splade-link>
@else
<button {{ $attributes->class([
'text-left w-full px-4 py-2 text-sm font-normal',
'text-danger-700 dark:text-white dark:hover:bg-danger-600 hover:bg-gray-50 hover:text-danger-900' => $danger,
'text-warning-700 dark:text-white dark:hover:bg-warning-600 hover:bg-gray-50 hover:text-warning-900' => $warning,
'text-primary-700 dark:text-white dark:hover:bg-primary-600 hover:bg-gray-50 hover:text-primary-900' => $primary,
'text-success-700 dark:text-white dark:hover:bg-success-600 hover:bg-gray-50 hover:text-success-900' => $success,
'text-gray-700 dark:text-white dark:hover:bg-gray-600 hover:bg-gray-50 hover:text-gray-900' => $secondary,
]) }}>
<div class="flex justify-start gap-2">
@if($icon)
<div class="flex flex-col justify-center items-center">
<i class="{{$icon}}"></i>
</div>
@endif
<div>
{{$label ?: $slot}}
</div>
</div>
</button>
@endif
2 changes: 2 additions & 0 deletions src/TomatoAdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use TomatoPHP\TomatoAdmin\Views\RelationsGroup;
use TomatoPHP\TomatoAdmin\Views\Slider;
use TomatoPHP\TomatoAdmin\Views\SubmitButtons;
use TomatoPHP\TomatoAdmin\Views\TableAction;
use TomatoPHP\TomatoAdmin\Views\Tooltip;
use TomatoPHP\TomatoAdmin\Views\Widget;
use TomatoPHP\TomatoAdmin\Http\Middleware\LanguageSwitcher;
Expand Down Expand Up @@ -149,6 +150,7 @@ public function boot(): void
Dropdown::class,
DropdownItem::class,
Slider::class,
TableAction::class
]);
}
}
34 changes: 34 additions & 0 deletions src/Views/TableAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace TomatoPHP\TomatoAdmin\Views;

use Illuminate\View\Component;

class TableAction extends Component
{
public ?bool $primary =false;

public function __construct(
public string $type='link',
public ?string $label=null,
public ?string $method="get",
public ?string$icon=null,
public ?bool $warning =false,
public ?bool $secondary =false,
public ?bool $danger =false,
public ?bool $success =false,
)
{
$this->primary = !$this->warning && !$this->danger && !$this->success && !$this->secondary;
}

/**
* Get the view / contents that represents the component.
*
* @return \Illuminate\View\View
*/
public function render()
{
return view('tomato-admin::components.table-action');
}
}

0 comments on commit 20035ef

Please sign in to comment.