Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions resources/views/components/forms/checkbox.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@aware(['tableName','primaryKey', 'isTailwind', 'isBootstrap', 'isBootstrap4', 'isBootstrap5'])
@props(['checkboxAttributes'])
@props(['checkboxAttributes',
//'row'
])
<input x-cloak
{{
$attributes->merge($checkboxAttributes)->class([
Expand All @@ -8,4 +10,5 @@
'form-check-input' => ($isBootstrap5) && ($checkboxAttributes['default'] ?? true),
])->except(['default','default-styling','default-colors'])
}}
/>
{{-- aria-label="select row number {{$row->id}}"--}}
/>
6 changes: 4 additions & 2 deletions resources/views/components/table/td/bulk-actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@php
$tdAttributes = $this->getBulkActionsTdAttributes;
// $tdCheckboxAttributes = $this->getBulkActionsTdCheckboxAttributes($row, $rowIndex);
$tdCheckboxAttributes = $this->getBulkActionsTdCheckboxAttributes;
@endphp

Expand All @@ -12,9 +13,10 @@
'inline-flex rounded-md shadow-sm' => $isTailwind,
'form-check' => $isBootstrap5,
])>
<x-livewire-tables::forms.checkbox
wire:key="{{ $tableName . 'selectedItems-'.$row->{$primaryKey} }}"
<x-livewire-tables::forms.checkbox
wire:key="{{ $tableName . 'selectedItems-'.$row->{$primaryKey} }}"
value="{{ $row->{$primaryKey} }}"
{{-- :$row--}}
:checkboxAttributes=$tdCheckboxAttributes
/>
</div>
Expand Down
41 changes: 27 additions & 14 deletions src/Traits/Styling/HasBulkActionsStyling.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Rappasoft\LaravelLivewireTables\Traits\Styling;

use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\View\ComponentAttributeBag;
use Livewire\Attributes\Computed;

Expand All @@ -15,7 +17,7 @@ trait HasBulkActionsStyling

protected array $bulkActionsTdAttributes = ['default' => null, 'default-colors' => null, 'default-styling' => null];

protected array $bulkActionsTdCheckboxAttributes = ['default' => null, 'default-colors' => null, 'default-styling' => null];
protected array|Closure $bulkActionsTdCheckboxAttributes = ['default' => null, 'default-colors' => null, 'default-styling' => null];

protected array $bulkActionsButtonAttributes = ['default-colors' => true, 'default-styling' => true];

Expand Down Expand Up @@ -105,22 +107,32 @@ public function getBulkActionsTdAttributes(): array
}

/**
* Used to get attributes for the Bulk Actions TD
* Used to get attributes for the Bulk Actions TD.
* The parameters are nullable so that the method can be called without any arguments. (Backward compatibility)
*
* @return array<mixed>
*/
#[Computed]
public function getBulkActionsTdCheckboxAttributes(): array
public function getBulkActionsTdCheckboxAttributes(Model $row = null, int $index = null): array
{
return array_merge(
[
'x-show' => '!currentlyReorderingStatus',
'x-model' => 'selectedItems',
'wire:loading.attr.delay' => 'disabled',
'type' => 'checkbox',
],
$this->getCustomAttributesNew('bulkActionsTdCheckboxAttributes', true, true)
);
$defaultAttributes = [
'x-show' => '!currentlyReorderingStatus',
'x-model' => 'selectedItems',
'wire:loading.attr.delay' => 'disabled',
'type' => 'checkbox',
];

if (is_callable($this->bulkActionsTdCheckboxAttributes)) {
$customAttributes = ($this->bulkActionsTdCheckboxAttributes)($row, $index);
return array_merge($defaultAttributes, $customAttributes ?: []);
}

if (is_array($this->bulkActionsTdCheckboxAttributes)) {
return array_merge($defaultAttributes,
$this->getCustomAttributesNew('bulkActionsTdCheckboxAttributes', true, true));
}

return $defaultAttributes;
}

/**
Expand Down Expand Up @@ -177,9 +189,10 @@ public function setBulkActionsTdAttributes(array $bulkActionsTdAttributes): self
/**
* Used to set attributes for the Bulk Actions Checkbox in the Row
*/
public function setBulkActionsTdCheckboxAttributes(array $bulkActionsTdCheckboxAttributes): self
public function setBulkActionsTdCheckboxAttributes(array|Closure $bulkActionsTdCheckboxAttributes): self
{
return $this->setCustomAttributesDefaults('bulkActionsTdCheckboxAttributes', $bulkActionsTdCheckboxAttributes);
$this->bulkActionsTdCheckboxAttributes = $bulkActionsTdCheckboxAttributes;
return $this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public function test_bulk_actions_td_checkbox_attributes_returns_additional_data
$this->assertSame($defaultAttributeBag->getAttributes(), $returnedAttributeBag->getAttributes());

$this->basicTable->setBulkActionsTdCheckboxAttributes([
'default' => false,
'default-colors' => true,
'default-styling' => false,
'class' => 'w-12',
]);

Expand Down