Skip to content

Commit a6d7de1

Browse files
committed
Doc Changes, Cleanup, View Attributes
1 parent f186f3e commit a6d7de1

File tree

28 files changed

+367
-76
lines changed

28 files changed

+367
-76
lines changed

docs/columns/styling.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ For example:
3232
Column::make('Name')
3333
->setLabelAttributes(['class' => 'text-2xl'])
3434
```
35-
By default, this replaces the default classes on the label, if you would like to keep them, set the default/default-styling/default-colors flags to true as appropriate.
35+
By default, this appends to the default classes on the label, if you would like to replace them, set the default/default-styling/default-colors flags to false as appropriate.
3636

3737
## Styling Table Elements
3838

@@ -303,16 +303,28 @@ public function configure(): void
303303

304304
### via Attributes Callback
305305

306+
You can create a callback to style an individual table cell, which can be simple, or complex, based on your needs. The callback receives the value, the full table row, and the rowIndex (for striping).
307+
308+
The below example would replace the default colours with "bg-blue-500" for "normal" and "bg-red-800" for "dark" themes, regardless of value. The default styles would still be applied:
309+
```php
310+
Column::make("Name", "name")
311+
->attributes(fn($value, $row, $rowIndex) => ['class' => 'bg-blue-500 dark:bg-red-800', 'default-colors' => false]),
312+
```
313+
306314
### Enabling/Disabling whitespace-wrap
307315

316+
By default, text does not wrap, unless the Column is an "html" column.
317+
318+
You can enable whitespace-wrap per-column as follows:
308319
```php
309320
Column::make("Name", "name")
310321
->wrapText(),
311322
```
312323

324+
313325
## Set Text Alignment
314326

315-
You may customise the alignment of the text within the Column td elements as follows. This will over-ride the value set by "setDefaultBodyTextAlignment" methods
327+
You may customise the alignment of the text within the Column td elements as follows. This will over-ride the value set by "setDefaultBodyTextAlignment" methods.
316328

317329
### Left
318330
```php

resources/views/components/table/td/td.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@aware(['isTailwind','isTailwind4','isBootstrap', 'collapsingColumnInfo', 'tableRowDetails'])
2-
@props(['colIndex', 'isHtml' => false, 'wrapText' => false, 'isClickable' => false, 'customAttributes' => ['default' => true, 'default-colors' => true, 'default-styling' => true], 'textAlign' => $this->getDefaultBodyTextAlign()])
1+
@aware(['isTailwind','isTailwind4','isBootstrap', 'collapsingColumnInfo', 'tableRowDetails','defaultBodyTextAlign'])
2+
@props(['colIndex', 'isHtml' => false, 'wrapText' => false, 'isClickable' => false, 'customAttributes' => ['default' => true, 'default-colors' => true, 'default-styling' => true], 'textAlign' => $defaultBodyTextAlign])
33

44
<td {{
55
$attributes->merge($isClickable ? $tableRowDetails['tdAttribs'] : [])->merge($customAttributes)

resources/views/components/tbody/tbody.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@aware(['dataTableFingerprint', 'isTailwind', 'isTailwind4', 'isBootstrap', 'coreTableAttributes', 'currentlyReorderingStatus', 'showBulkActionsSections', 'showCollapsingColumnSections', 'selectedVisibleColumns', 'selectedVisibleColumns', 'hasDisplayLoadingPlaceholder', 'hasTdAttributes'])
1+
@aware(['dataTableFingerprint', 'isTailwind', 'isTailwind4', 'isBootstrap', 'coreTableAttributes', 'currentlyReorderingStatus', 'showBulkActionsSections', 'showCollapsingColumnSections', 'selectedVisibleColumns', 'selectedVisibleColumns', 'hasDisplayLoadingPlaceholder', 'hasTdAttributes', 'defaultBodyTextAlign'])
22
@props(['row','rowIndex','rowPk', 'tableRowDetails'])
33

44
<tbody {{ $attributes->merge($coreTableAttributes['tbody'])
@@ -8,19 +8,19 @@
88
] : [])
99
->merge($tableRowDetails['attributes'])
1010
->class([
11-
'text-left' => $this->getDefaultBodyTextAlign() == 'left' && $isTailwind,
12-
'text-center' => $this->getDefaultBodyTextAlign() == 'center' && $isTailwind,
13-
'text-right' => $this->getDefaultBodyTextAlign() == 'right' && $isTailwind,
11+
'text-left' => $defaultBodyTextAlign == 'left' && $isTailwind,
12+
'text-center' => $defaultBodyTextAlign == 'center' && $isTailwind,
13+
'text-right' => $defaultBodyTextAlign == 'right' && $isTailwind,
1414
'even:bg-white even:dark:bg-gray-700 odd:bg-gray-50 odd:dark:bg-gray-800 dark:text-white' => $isTailwind,
1515
'divide-gray-200 dark:divide-none' => $isTailwind && ($coreTableAttributes['tbody']['default-colors'] ?? ($coreTableAttributes['tbody']['default'] ?? true)),
1616
'divide-y' => $isTailwind && ($coreTableAttributes['tbody']['default-styling'] ?? ($coreTableAttributes['tbody']['default'] ?? true)),
1717
1818
'tw4ph even:bg-white even:dark:bg-gray-700 odd:bg-gray-50 odd:dark:bg-gray-800 dark:text-white' => $isTailwind4,
1919
'tw4ph divide-gray-200 dark:divide-none' => $isTailwind4 && ($coreTableAttributes['tbody']['default-colors'] ?? ($coreTableAttributes['tbody']['default'] ?? true)),
2020
'tw4ph divide-y' => $isTailwind4 && ($coreTableAttributes['tbody']['default-styling'] ?? ($coreTableAttributes['tbody']['default'] ?? true)),
21-
'tw4ph text-left' => $this->getDefaultBodyTextAlign() == 'left' && $isTailwind4,
22-
'tw4ph text-center' => $this->getDefaultBodyTextAlign() == 'center' && $isTailwind4,
23-
'tw4ph text-right' => $this->getDefaultBodyTextAlign() == 'right' && $isTailwind4,
21+
'tw4ph text-left' => $defaultBodyTextAlign == 'left' && $isTailwind4,
22+
'tw4ph text-center' => $defaultBodyTextAlign == 'center' && $isTailwind4,
23+
'tw4ph text-right' => $defaultBodyTextAlign == 'right' && $isTailwind4,
2424
2525
])
2626
->except(['default','default-styling','default-colors'])

resources/views/components/tools/toolbar/toolbar.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@aware([ 'dataTableFingerprint','isTailwind','isTailwind4','isBootstrap'])
22
@props(['filterMenuResetButtonAttributes'])
3-
3+
@php($toolbarAttributes = $this->getToolBarAttributes())
44
<div {{
5-
$attributes->merge($this->getToolBarAttributes)
5+
$attributes->merge($toolbarAttributes)
66
->class([
7-
'md:flex md:justify-between mb-2 px-4 md:p-0' => ($isTailwind && ($this->getToolBarAttributes['default-styling'] ?? true)),
8-
'd-md-flex justify-content-between mb-3' => ($isBootstrap && ($this->getToolBarAttributes['default-styling'] ?? true)),
7+
'md:flex md:justify-between mb-2 px-4 md:p-0' => ($isTailwind && ($toolbarAttributes['default-styling'] ?? true)),
8+
'd-md-flex justify-content-between mb-3' => ($isBootstrap && ($toolbarAttributes['default-styling'] ?? true)),
99
])
1010
->except(['default','default-styling','default-colors'])
1111
}}
@@ -15,7 +15,7 @@
1515
'w-full mb-2 md:mb-0 md:w-2/4 md:flex space-y-4 md:space-y-0 md:space-x-2' => $isTailwind,
1616
])
1717
>
18-
@foreach($this->getLeftToolbarItems as $index => $toolbarItem)
18+
@foreach($this->getLeftToolbarItems() as $index => $toolbarItem)
1919
@include($toolbarItem['view'], array_merge(['wire:key' => $dataTableFingerprint.'-toolbarItem-left-'.$index], $toolbarItem['attributes']))
2020
@endforeach
2121
</div>
@@ -27,7 +27,7 @@
2727
])
2828
>
2929

30-
@foreach($this->getRightToolbarItems as $index => $toolbarItem)
30+
@foreach($this->getRightToolbarItems() as $index => $toolbarItem)
3131
@include($toolbarItem['view'], array_merge(['wire:key' => $dataTableFingerprint.'-toolbarItem-right-'.$index], $toolbarItem['attributes']))
3232
@endforeach
3333

resources/views/components/wrapper.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@props(['component', 'isTailwind' => false, 'isTailwind4' => false, 'isBootstrap' => false,'isBootstrap4' => false, 'isBootstrap5' => false, 'tableName', 'primaryKey', 'collapsingColumnDetails', 'tdAttributes', 'tdCheckboxAttributes', 'collapsingColumnButtonExpandAttributes', 'collapsingColumnButtonCollapseAttributes', 'hasCollapsingColumns', 'currentlyReorderingStatus', 'hasDisplayLoadingPlaceholder', 'coreTableAttributes', 'selectedVisibleColumns', 'showBulkActionsSections', 'showCollapsingColumnSections', 'hasTrAttributes', 'collapsingColumnInfo', 'filterGenericData', 'hasTdAttributes', 'dataTableFingerprint'])
1+
@props(['component', 'isTailwind' => false, 'isTailwind4' => false, 'isBootstrap' => false,'isBootstrap4' => false, 'isBootstrap5' => false, 'tableName', 'primaryKey', 'collapsingColumnDetails', 'tdAttributes', 'tdCheckboxAttributes', 'collapsingColumnButtonExpandAttributes', 'collapsingColumnButtonCollapseAttributes', 'hasCollapsingColumns', 'currentlyReorderingStatus', 'hasDisplayLoadingPlaceholder', 'coreTableAttributes', 'selectedVisibleColumns', 'showBulkActionsSections', 'showCollapsingColumnSections', 'hasTrAttributes', 'collapsingColumnInfo', 'filterGenericData', 'hasTdAttributes', 'dataTableFingerprint', 'defaultBodyTextAlign'])
22
<div {{ $attributes->merge($this->getComponentWrapperAttributes()) }}>
33
@includeWhen($this->debugIsEnabled(),'livewire-tables::includes.debug')
44
@includeWhen($this->offlineIndicatorIsEnabled(),'livewire-tables::includes.offline')

resources/views/datatable.blade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
@php($currentlyReorderingStatus = $this->getCurrentlyReorderingStatus())
2-
@php($hasTdAttributes = $this->hasTdAttributes())
31
<div x-data="{ currentlyReorderingStatus: false }">
42
<div {{ $this->getTopLevelAttributes() }}>
3+
54
@includeWhen(
65
$this->hasConfigurableAreaFor('before-wrapper'),
76
$this->getConfigurableAreaFor('before-wrapper'),
87
$this->getParametersForConfigurableArea('before-wrapper')
98
)
109

11-
<x-livewire-tables::wrapper :$tableName :$dataTableFingerprint :$primaryKey :$isTailwind :$isTailwind4 :$isBootstrap :$isBootstrap4 :$isBootstrap5 :$localisationPath :$collapsingColumnDetails :$collapsingColumnButtonExpandAttributes :$collapsingColumnButtonCollapseAttributes :$hasCollapsingColumns :$currentlyReorderingStatus :$hasDisplayLoadingPlaceholder :$coreTableAttributes :$selectedVisibleColumns :$showBulkActionsSections :$showCollapsingColumnSections :$hasTrAttributes :$collapsingColumnInfo :$filterGenericData :$hasTdAttributes >
10+
<x-livewire-tables::wrapper :$tableName :$dataTableFingerprint :$primaryKey :$isTailwind :$isTailwind4 :$isBootstrap :$isBootstrap4 :$isBootstrap5 :$localisationPath :$collapsingColumnDetails :$collapsingColumnButtonExpandAttributes :$collapsingColumnButtonCollapseAttributes :$hasCollapsingColumns :$currentlyReorderingStatus :$hasDisplayLoadingPlaceholder :$coreTableAttributes :$selectedVisibleColumns :$showBulkActionsSections :$showCollapsingColumnSections :$hasTrAttributes :$collapsingColumnInfo :$filterGenericData :$hasTdAttributes :$defaultBodyTextAlign>
1211

1312
@if($this->shouldShowTools())
1413

resources/views/includes/toolbar/items/column-select/legacy.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@aware([ 'dataTableFingerprint','isTailwind','isTailwind4','isBootstrap','isBootstrap4','isBootstrap5', 'localisationPath', 'dataTableFingerprint'])
22
@php($columnSelectButtonAttributes = $this->getColumnSelectButtonAttributes())
3-
@php($columnSelectMenuOptionCheckboxAttributes = $this->getColumnSelectMenuOptionCheckboxAttributes)
3+
@php($columnSelectMenuOptionCheckboxAttributes = $this->getColumnSelectMenuOptionCheckboxAttributes())
44
@php($selectableSelectedColumnCount = $this->getSelectableSelectedColumns()->count())
55

66
@if ($isTailwind)

resources/views/includes/toolbar/items/saving-state.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<select wire:model.live="savedState" class="h-min rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-none rounded-l-md focus:ring-0 focus:border-gray-300 border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-600 focus:border-gray-300 block w-full">
33
<option value=''>{{ __('savingtablestate::core.select_one') }}</option>
44
<option value='saveNew'>{{ __('savingtablestate::core.save_new') }}</option>
5-
@foreach($this->getAvailableTableStates as $id => $name)
5+
@foreach($this->getAvailableTableStates() as $id => $name)
66
<option value='{{ $id }}' wire:key="test-{{ $id }}">{{ $name}}</option>
77
@endforeach
88
</select>

src/DataTableComponent.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use Livewire\Attributes\{On, Renderless};
66
use Livewire\Component;
77
use Rappasoft\LaravelLivewireTables\Traits\{ComponentUtilities, WithCustomisations, WithData, WithDebugging, WithEvents, WithQuery, WithQueryString, WithRefresh, WithTableHooks};
8-
use Rappasoft\LaravelLivewireTables\Traits\Core\{HasCustomAttributes, HasLocalisations};
8+
use Rappasoft\LaravelLivewireTables\Traits\Core\{HasLocalisations};
99
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasTheme;
1010
use Rappasoft\LaravelLivewireTables\Traits\Styling\{HasCoreStyling};
11+
use Rappasoft\LaravelLivewireTables\Features\Core\HandlesCoreAttributes;
1112
use Rappasoft\LaravelLivewireTables\Features\Actions\Core\WithActions;
1213
use Rappasoft\LaravelLivewireTables\Features\BulkActions\Core\WithBulkActions;
1314
use Rappasoft\LaravelLivewireTables\Features\Columns\Core\WithColumns;
@@ -30,7 +31,8 @@
3031
abstract class DataTableComponent extends Component
3132
{
3233

33-
use WithFeatureDetection,
34+
use HandlesCoreAttributes,
35+
WithFeatureDetection,
3436
ComponentUtilities,
3537
WithQueryString,
3638
WithTableHooks,
@@ -49,7 +51,6 @@ abstract class DataTableComponent extends Component
4951
WithSorting,
5052
WithPagination,
5153
WithBulkActions,
52-
HasCustomAttributes,
5354
WithConfigurableAreas,
5455
WithCustomisations,
5556
WithDebugging,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Exceptions;
4+
5+
class AttributePropertyException extends \Exception {}

0 commit comments

Comments
 (0)