Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typehinting in blade components #2081

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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
12 changes: 6 additions & 6 deletions resources/views/components/includes/actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
->class(['' => $this->isTailwind && $this->getActionWrapperAttributes['default-colors'] ?? true])
->class(['d-flex flex-cols py-2 space-x-2' => $this->isBootstrap && $this->getActionWrapperAttributes['default-styling'] ?? true])
->class(['' => $this->isBootstrap && $this->getActionWrapperAttributes['default-colors'] ?? true])
->class(['justify-start' => $this->getActionsPosition == 'left'])
->class(['justify-center' => $this->getActionsPosition == 'center'])
->class(['justify-end' => $this->getActionsPosition == 'right'])
->class(['pl-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'left'])
->class(['pr-2' => $this->showActionsInToolbar && $this->getActionsPosition == 'right'])
->class(['justify-start' => $this->getActionsPosition === 'left'])
->class(['justify-center' => $this->getActionsPosition === 'center'])
->class(['justify-end' => $this->getActionsPosition === 'right'])
->class(['pl-2' => $this->showActionsInToolbar && $this->getActionsPosition === 'left'])
->class(['pr-2' => $this->showActionsInToolbar && $this->getActionsPosition === 'right'])
->except(['default','default-styling','default-colors'])
}} >
@foreach($this->getActions as $action)
{{ $action->render() }}
@endforeach
</div>
</div>
9 changes: 4 additions & 5 deletions resources/views/components/includes/loading.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
@props(['colCount' => 1])

@php
$loaderRow = $this->getLoadingPlaceHolderRowAttributes();
$loaderCell = $this->getLoadingPlaceHolderCellAttributes();
$loaderIcon = $this->getLoadingPlaceHolderIconAttributes();
$loaderRow = $this->getLoadingPlaceHolderRowAttributes();
$loaderCell = $this->getLoadingPlaceHolderCellAttributes();
$loaderIcon = $this->getLoadingPlaceHolderIconAttributes();
@endphp

<tr wire:key="{{ $tableName }}-loader" wire:loading.class.remove="hidden d-none" {{
Expand All @@ -27,11 +27,10 @@
$attributes->merge($loaderIcon)
->class(['lds-hourglass' => $this->isTailwind && ($loaderIcon['default'] ?? true)])
->class(['lds-hourglass' => $this->isBootstrap && ($loaderIcon['default'] ?? true)])
->except(['default','default-styling','default-colors']);
->except(['default','default-styling','default-colors'])
}}></div>
<div>{!! $this->getLoadingPlaceholderContent() !!}</div>
</div>
@endif
</td>
</tr>

10 changes: 5 additions & 5 deletions resources/views/components/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{{ $attributes->merge($customAttributes['table'])
->class(['min-w-full divide-y divide-gray-200 dark:divide-none' => $customAttributes['table']['default'] ?? true])
->except(['default','default-styling','default-colors']) }}

>
<thead wire:key="{{ $tableName }}-thead"
{{ $attributes->merge($customAttributes['thead'])
Expand All @@ -43,11 +43,11 @@
{{ $slot }}
</tbody>

@if (isset($tfoot))
@isset($tfoot)
<tfoot wire:key="{{ $tableName }}-tfoot">
{{ $tfoot }}
</tfoot>
@endif
@endisset
</table>
</div>
@elseif ($isBootstrap)
Expand Down Expand Up @@ -84,11 +84,11 @@
{{ $slot }}
</tbody>

@if (isset($tfoot))
@isset($tfoot)
<tfoot wire:key="{{ $tableName }}-tfoot">
{{ $tfoot }}
</tfoot>
@endif
@endisset
</table>
</div>
@endif
5 changes: 3 additions & 2 deletions resources/views/components/table/collapsed-columns.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@
colspan="{{ $colspan }}"
>
<div>
@php /** @var \Rappasoft\LaravelLivewireTables\Views\Column $column */ @endphp
@foreach($columns as $colIndex => $column)
@continue($column->isHidden())
@continue($this->columnSelectIsEnabled() && ! $this->columnSelectIsEnabledForColumn($column))

<p wire:key="{{ $tableName }}-row-{{ $row->{$primaryKey} }}-collapsed-contents-{{ $colIndex }}"

@class([
'block mb-2' => $isTailwind && $column->shouldCollapseAlways(),
'block mb-2 sm:hidden' => $isTailwind && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && !$column->shouldCollapseOnMobile(),
'block mb-2 md:hidden' => $isTailwind && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && $column->shouldCollapseOnMobile(),
'block mb-2 lg:hidden' => $isTailwind && !$column->shouldCollapseAlways() && ($column->shouldCollapseOnTablet() || $column->shouldCollapseOnMobile()),

'd-block mb-2' => $isBootstrap && $column->shouldCollapseAlways(),
'd-block mb-2 d-sm-none' => $isBootstrap && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && !$column->shouldCollapseOnMobile(),
'd-block mb-2 d-md-none' => $isBootstrap && !$column->shouldCollapseAlways() && !$column->shouldCollapseOnTablet() && $column->shouldCollapseOnMobile(),
Expand Down
3 changes: 2 additions & 1 deletion resources/views/components/table/td.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
@props(['column', 'colIndex'])

@php
/** @var \Rappasoft\LaravelLivewireTables\Views\Column $column */
$customAttributes = $this->getTdAttributes($column, $row, $colIndex, $rowIndex)
@endphp

<td wire:key="{{ $tableName . '-table-td-'.$row->{$primaryKey}.'-'.$column->getSlug() }}"
@if ($column->isClickable())
@if($this->getTableRowUrlTarget($row) === "navigate") wire:navigate href="{{ $this->getTableRowUrl($row) }}"
@if($this->getTableRowUrlTarget($row) === 'navigate') wire:navigate href="{{ $this->getTableRowUrl($row) }}"
@else onclick="window.open('{{ $this->getTableRowUrl($row) }}', '{{ $this->getTableRowUrlTarget($row) ?? '_self' }}')"
@endif
@endif
Expand Down
2 changes: 2 additions & 0 deletions resources/views/components/table/td/plain.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@aware(['component', 'rowIndex', 'rowID','isTailwind','isBootstrap'])
@props(['column' => null, 'customAttributes' => [], 'displayMinimisedOnReorder' => false, 'hideUntilReorder' => false])

@php /** @var \Rappasoft\LaravelLivewireTables\Views\Column|null $column */ @endphp

@if ($isTailwind)
<td x-cloak {{ $attributes
->merge($customAttributes)
Expand Down
3 changes: 2 additions & 1 deletion resources/views/components/table/th.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@props(['column', 'index'])

@php
/** @var \Rappasoft\LaravelLivewireTables\Views\Column $column */
$attributes = $attributes->merge(['wire:key' => $tableName . '-header-col-'.$column->getSlug()]);
$allThAttributes = $this->getAllThAttributes($column);

Expand Down Expand Up @@ -41,7 +42,7 @@
}}
>
<span {{ $customLabelAttributes->except(['default', 'default-colors', 'default-styling']) }}>{{ $column->getTitle() }}</span>
<x-livewire-tables::table.th.sort-icons :$direction
<x-livewire-tables::table.th.sort-icons :$direction
{{
$attributes->merge($customSortIconAttributes)
->except(['default', 'default-colors', 'default-styling', 'wire:key'])
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/tools.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@aware(['component','isTailwind','isBootstrap'])
@php($toolsAttributes = $this->getToolsAttributesBag())

<div {{
<div {{
$toolsAttributes->merge()
->class(['flex-col' => $isTailwind && ($toolsAttributes['default-styling'] ?? true)])
->class(['d-flex flex-column' => $isBootstrap && ($toolsAttributes['default-styling'] ?? true)])
->except(['default','default-styling','default-colors'])
->except(['default','default-styling','default-colors'])
}}
>
{{ $slot }}
Expand Down
8 changes: 4 additions & 4 deletions resources/views/components/tools/filter-label.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
@props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false, 'for' => null])

@php
/** @var \Rappasoft\LaravelLivewireTables\Views\Filter $filter */
$filterLabelAttributes = $filter->getFilterLabelAttributes();
$customLabelAttributes = $filter->getLabelAttributes();

@endphp

@if($filter->hasCustomFilterLabel() && !$filter->hasCustomPosition())
@include($filter->getCustomFilterLabel(),['filter' => $filter, 'filterLayout' => $filterLayout, 'tableName' => $tableName, 'isTailwind' => $isTailwind, 'isBootstrap' => $isBootstrap, 'isBootstrap4' => $isBootstrap4, 'isBootstrap5' => $isBootstrap5, 'customLabelAttributes' => $customLabelAttributes])
@elseif(!$filter->hasCustomPosition())
Expand All @@ -14,13 +15,12 @@
{{
$attributes->merge($customLabelAttributes)->merge($filterLabelAttributes)
->class(['block text-sm font-medium leading-5 text-gray-700 dark:text-white' => $isTailwind && ($filterLabelAttributes['default'] ?? true)])
->class(['d-block' => $isBootstrap && $filterLayout == 'slide-down' && ($filterLabelAttributes['default'] ?? true)])
->class(['mb-2' => $isBootstrap && $filterLayout == 'popover' && ($filterLabelAttributes['default'] ?? true)])
->class(['d-block' => $isBootstrap && $filterLayout === 'slide-down' && ($filterLabelAttributes['default'] ?? true)])
->class(['mb-2' => $isBootstrap && $filterLayout === 'popover' && ($filterLabelAttributes['default'] ?? true)])
->except(['default', 'default-colors', 'default-styling'])
}}

>
{{ $filter->getName() }}
</label>

@endif
2 changes: 1 addition & 1 deletion resources/views/components/tools/filter-pills.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</small>

@foreach($this->getAppliedFiltersWithValues() as $filterSelectName => $value)
@php /** @var \Rappasoft\LaravelLivewireTables\Views\Filter $filter */ @endphp
@php($filter = $this->getFilterByKey($filterSelectName))
@continue(is_null($filter) || $filter->isHiddenFromPills())
@php( $filterPillTitle = $filter->getFilterPillTitle())
Expand All @@ -31,4 +32,3 @@
</div>
</div>
@endif

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<button
wire:click.prevent="setFilterDefaults"
@class([
"focus:outline-none active:outline-none"
'focus:outline-none active:outline-none'
])>
<span @class([
"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",
"bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900"
'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium',
'bg-gray-100 text-gray-800 dark:bg-gray-200 dark:text-gray-900'
])>
{{ __($this->getLocalisationPath.'Clear') }}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
wire:click="resetFilter('{{ $filterKey }}')"
type="button"
@class([
"flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none",
"text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white",
'flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center focus:outline-none',
'text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white',
])
>
<span class="sr-only">{{ __($this->getLocalisationPath.'Remove filter option') }}</span>
Expand Down
19 changes: 11 additions & 8 deletions resources/views/components/tools/filters/boolean.blade.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
@php($defaultValue = ($filter->hasFilterDefaultValue() ? (bool) $filter->getFilterDefaultValue() : false))
<div class="flex flex-cols"
@php
/** @var \Rappasoft\LaravelLivewireTables\Views\Filters\BooleanFilter $filter */
$defaultValue = ($filter->hasFilterDefaultValue() ? (bool) $filter->getFilterDefaultValue() : false)
@endphp
<div class="flex flex-cols"
x-data="newBooleanFilter('{{ $filter->getKey() }}', '{{ $tableName }}', '{{ $defaultValue }}')"
>
>
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
<input id="thisId" type="checkbox" name="switch" class="hidden" :checked="value" />

<button id="{{ $tableName }}-filter-{{ $filter->getKey() }}"
x-ref="switchButton"
type="button"
type="button"
@click="toggleStatusWithUpdate"
:class="(value == 1 || value == true) ? 'bg-blue-600' : 'bg-neutral-200'"
:class="(value == 1 || value == true) ? 'bg-blue-600' : 'bg-neutral-200'"
class="relative inline-flex h-6 py-0.5 ml-4 focus:outline-none rounded-full w-10"
x-cloak>
<span :class="(value == 1 || value == true) ? 'translate-x-[18px]' : 'translate-x-0.5'" class="w-5 h-5 duration-200 ease-in-out bg-white rounded-full shadow-md"></span>
</button>
<template x-if="(value == 1 || value == true)">
<button @click="toggleStatusWithReset" type="button"
class="flex-shrink-0 ml-1 h-6 w-6 rounded-full inline-flex items-center justify-center text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:outline-none focus:bg-indigo-500 focus:text-white"
>
>

<span class="sr-only">{{ __($localisationPath.'Remove filter option') }}</span>
<x-heroicon-m-x-mark class="h-6 w-6" />
</button>
</template>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@php
/** @var \Rappasoft\LaravelLivewireTables\Views\Filters\DateRangeFilter $filter */
$filterKey = $filter->getKey();
@endphp

Expand All @@ -23,6 +24,6 @@
'd-inline-block w-100 form-control' => $isBootstrap,
])
@if($filter->hasConfig('placeholder')) placeholder="{{ $filter->getConfig('placeholder') }}" @endif
/>
/>
</div>
</div>
13 changes: 7 additions & 6 deletions resources/views/components/tools/filters/date.blade.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
@php /** @var \Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter $filter */ @endphp
<div>
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
<div @class([
"rounded-md shadow-sm" => $isTailwind,
"mb-3 mb-md-0 input-group" => $isBootstrap,
'rounded-md shadow-sm' => $isTailwind,
'mb-3 mb-md-0 input-group' => $isBootstrap,
])>
<input {{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
<input {{ $filter->getWireMethod('filterComponents.'.$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'date') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
type="date"
@if($filter->hasConfig('min')) min="{{ $filter->getConfig('min') }}" @endif
@if($filter->hasConfig('max')) max="{{ $filter->getConfig('max') }}" @endif
@if($filter->hasConfig('placeholder')) placeholder="{{ $filter->getConfig('placeholder') }}" @endif
@class([
"block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600" => $isTailwind,
"form-control" => $isBootstrap,
'block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600' => $isTailwind,
'form-control' => $isBootstrap,
])
/>
</div>
</div>
</div>
13 changes: 7 additions & 6 deletions resources/views/components/tools/filters/datetime.blade.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
@php /** @var \Rappasoft\LaravelLivewireTables\Views\Filters\DateTimeFilter $filter */ @endphp
<div>
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />

<div @class([
"rounded-md shadow-sm" => $isTailwind,
"mb-3 mb-md-0 input-group" => $isBootstrap,
'rounded-md shadow-sm' => $isTailwind,
'mb-3 mb-md-0 input-group' => $isBootstrap,
])>
<input {{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
<input {{ $filter->getWireMethod('filterComponents.'.$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'datetime') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
type="datetime-local"
@if($filter->hasConfig('min')) min="{{ $filter->getConfig('min') }}" @endif
@if($filter->hasConfig('max')) max="{{ $filter->getConfig('max') }}" @endif
@if($filter->hasConfig('placeholder')) placeholder="{{ $filter->getConfig('placeholder') }}" @endif
@class([
"block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600" => $isTailwind,
"form-control" => $isBootstrap,
'block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600' => $isTailwind,
'form-control' => $isBootstrap,
])
/>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@php /** @var \Rappasoft\LaravelLivewireTables\Views\Filters\LivewireComponentArrayFilter $filter */ @endphp

<div wire:key="filterComponents.{{ $filter->getKey() }}-wrapper">
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
<livewire:dynamic-component :is="$livewireComponent" :tableComponent="get_class($this)" :filterKey="$filter->getKey()" :$tableName :key="'filterComponents-'.$filter->getKey()" wire:model="filterComponents.{{ $filter->getKey() }}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@php /** @var \Rappasoft\LaravelLivewireTables\Views\Filters\LivewireComponentFilter $filter */ @endphp

<div wire:key="filterComponents.{{ $filter->getKey() }}-wrapper">
<x-livewire-tables::tools.filter-label :$filter :$filterLayout :$tableName :$isTailwind :$isBootstrap4 :$isBootstrap5 :$isBootstrap />
<livewire:dynamic-component :is="$livewireComponent" :tableComponent="get_class($this)" :filterKey="$filter->getKey()" :$tableName :key="'filterComponents-'.$filter->getKey()" wire:model.live="filterComponents.{{ $filter->getKey() }}" />
Expand Down
Loading
Loading