Skip to content

Commit

Permalink
[6.x] Add column customContent (#1708)
Browse files Browse the repository at this point in the history
* Add column customContent

* Add column customContent

* Pint fix
  • Loading branch information
luanfreitasdev authored Sep 30, 2024
1 parent 0a80362 commit 9e8681b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
98 changes: 51 additions & 47 deletions resources/views/components/row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
])

@includeWhen(isset($setUp['responsive']), data_get($theme, 'root') . '.toggle-detail-responsive', [
'view' => data_get($setUp, 'detail.viewIcon') ?? null,
])
'view' => data_get($setUp, 'detail.viewIcon') ?? null,
])

@php
$defaultCollapseIcon = data_get($theme, 'root') . '.toggle-detail';
Expand Down Expand Up @@ -62,57 +62,61 @@
])
wire:key="row-{{ substr($rowId, 0, 6) }}-{{ $field }}-{{ $childIndex ?? 0 }}"
>
@if (empty(data_get($row, 'actions')) && data_get($column, 'isAction'))
<div class="pg-actions">
@if (method_exists($this, 'actionsFromView') && ($actionsFromView = $this->actionsFromView($row)))
<div wire:key="actions-view-{{ data_get($row, $this->realPrimaryKey) }}">
{!! $actionsFromView !!}
</div>
@endif

<div wire:replace.self>
@if (data_get($column, 'isAction'))
<div
x-data="pgRenderActions({ rowId: @js(data_get($row, $this->realPrimaryKey)), parentId: @js($parentId) })"
class="{{ theme_style($theme, 'table.body.tdActionsContainer') }}"
x-html="toHtml"
>
@if (count(data_get($column, 'customContent')) > 0)
@include(data_get($column, 'customContent.view'), data_get($column, 'customContent.params'))
@else
@if (empty(data_get($row, 'actions')) && data_get($column, 'isAction'))
<div class="pg-actions">
@if (method_exists($this, 'actionsFromView') && ($actionsFromView = $this->actionsFromView($row)))
<div wire:key="actions-view-{{ data_get($row, $this->realPrimaryKey) }}">
{!! $actionsFromView !!}
</div>
@endif
</div>
</div>
@endif

@php
$showEditOnClick = $this->shouldShowEditOnClick($column, $row);
@endphp
<div wire:replace.self>
@if (data_get($column, 'isAction'))
<div
x-data="pgRenderActions({ rowId: @js(data_get($row, $this->realPrimaryKey)), parentId: @js($parentId) })"
class="{{ theme_style($theme, 'table.body.tdActionsContainer') }}"
x-html="toHtml"
>
</div>
@endif
</div>
</div>
@endif

@if ($showEditOnClick === true)
<span @class([$contentClassField, $contentClass])>
@include(theme_style($theme, 'editable.view') ?? null, [
'editable' => data_get($column, 'editable'),
])
</span>
@elseif(count(data_get($column, 'toggleable')) > 0)
@php
$showToggleable = $this->shouldShowToggleable($column, $row);
$showEditOnClick = $this->shouldShowEditOnClick($column, $row);
@endphp
@includeWhen($showToggleable, theme_style($theme, 'toggleable.view'), ['tableName' => $tableName])
@else
<span @class([$contentClassField, $contentClass])>
@if (filled($templateContent))
<div
x-data="pgRenderRowTemplate({
parentId: @js($parentId),
templateContent: @js($templateContent)
})"
x-html="rendered"
>
</div>
@else
<div>{!! data_get($column, 'index') ? $rowIndex : $content !!}</div>
@endif
</span>

@if ($showEditOnClick === true)
<span @class([$contentClassField, $contentClass])>
@include(theme_style($theme, 'editable.view') ?? null, [
'editable' => data_get($column, 'editable'),
])
</span>
@elseif(count(data_get($column, 'toggleable')) > 0)
@php
$showToggleable = $this->shouldShowToggleable($column, $row);
@endphp
@include(theme_style($theme, 'toggleable.view'), ['tableName' => $tableName])
@else
<span @class([$contentClassField, $contentClass])>
@if (filled($templateContent))
<div
x-data="pgRenderRowTemplate({
parentId: @js($parentId),
templateContent: @js($templateContent)
})"
x-html="rendered"
>
</div>
@else
<div>{!! data_get($column, 'index') ? $rowIndex : $content !!}</div>
@endif
</span>
@endif
@endif
</td>
@endforeach
4 changes: 3 additions & 1 deletion src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ final class Column implements \Livewire\Wireable

public mixed $filters = null;

public array $customContent = [];

/**
* Adds a new Column
*
Expand Down Expand Up @@ -259,7 +261,7 @@ public function editOnClick(
public function toggleable(
bool $hasPermission = true,
string $trueLabel = 'Yes',
string $falseLabel = 'No'
string $falseLabel = 'No',
): Column {
$this->editable = [];
$this->toggleable = [
Expand Down

0 comments on commit 9e8681b

Please sign in to comment.