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

V3 - Develop to Master (3.1.3) #1561

Merged
merged 7 commits into from
Nov 19, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
v3 - Add option to hide Column Header (#1512)
* Add option to hide Column Header

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>
  • Loading branch information
lrljoe and lrljoe authored Nov 18, 2023
commit f6a69d6410444b9a204a13bf9ee3424d9bcf770e
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
## UNRELEASED
- Add capability to set a custom script path for the scripts/styles by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1557
- Added missing tailwind background colour class for when hovering over the clear button in dark mode by @slakbal in https://github.com/rappasoft/laravel-livewire-tables/pull/1553
- Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512


## [v3.1.3] - 2023-11-03
17 changes: 17 additions & 0 deletions docs/columns/available-methods.md
Original file line number Diff line number Diff line change
@@ -255,3 +255,20 @@ If you are using non-latin characters as the Column Title, you should set a lati
Column::make('地址', 'address.address')
->setCustomSlug('Address')
```

### Hiding Column Label

Labels are visible by default, but should you wish to hide the label from the table header, without impacting on wider table behaviour, you may implement the following method:
```php
Column::make('Name')
->setColumnLabelStatusDisabled()
```

### Displaying Column Label

Labels are visible by default, but should you wish to override a previous "hideColumnLabel()", you may implement the below method:

```php
Column::make('Name')
->setColumnLabelStatusEnabled()
```
94 changes: 49 additions & 45 deletions resources/views/components/table/th.blade.php
Original file line number Diff line number Diff line change
@@ -18,32 +18,34 @@
->except('default')
}}
>
@unless ($component->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback()))
{{ $column->getTitle() }}
@else
<button
wire:click="sortBy('{{ ($column->isSortable() ? $column->getColumnSelectName() : $column->getSlug()) }}')"
{{
$attributes->merge($customSortButtonAttributes)
->class(['flex items-center space-x-1 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400' => $customSortButtonAttributes['default'] ?? true])
->except(['default', 'wire:key'])
}}
>
<span>{{ $column->getTitle() }}</span>
@if($column->getColumnLabelStatus())
@unless ($component->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback()))
{{ $column->getTitle() }}
@else
<button
wire:click="sortBy('{{ ($column->isSortable() ? $column->getColumnSelectName() : $column->getSlug()) }}')"
{{
$attributes->merge($customSortButtonAttributes)
->class(['flex items-center space-x-1 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400' => $customSortButtonAttributes['default'] ?? true])
->except(['default', 'wire:key'])
}}
>
<span>{{ $column->getTitle() }}</span>

<span class="relative flex items-center">
@if ($direction === 'asc')
<x-heroicon-o-chevron-up class="w-3 h-3 group-hover:opacity-0" />
<x-heroicon-o-chevron-down class="w-3 h-3 opacity-0 group-hover:opacity-100 absolute"/>
@elseif ($direction === 'desc')
<x-heroicon-o-chevron-down class="w-3 h-3 group-hover:opacity-0" />
<x-heroicon-o-x-circle class="w-3 h-3 opacity-0 group-hover:opacity-100 absolute"/>
@else
<x-heroicon-o-chevron-up class="w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity duration-300" />
@endif
</span>
</button>
@endunless
<span class="relative flex items-center">
@if ($direction === 'asc')
<x-heroicon-o-chevron-up class="w-3 h-3 group-hover:opacity-0" />
<x-heroicon-o-chevron-down class="w-3 h-3 opacity-0 group-hover:opacity-100 absolute"/>
@elseif ($direction === 'desc')
<x-heroicon-o-chevron-down class="w-3 h-3 group-hover:opacity-0" />
<x-heroicon-o-x-circle class="w-3 h-3 opacity-0 group-hover:opacity-100 absolute"/>
@else
<x-heroicon-o-chevron-up class="w-3 h-3 opacity-0 group-hover:opacity-100 transition-opacity duration-300" />
@endif
</span>
</button>
@endunless
@endif
</th>
@elseif ($component->isBootstrap())
<th scope="col" {{
@@ -55,26 +57,28 @@
->except('default')
}}
>
@unless ($component->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback()))
{{ $column->getTitle() }}
@else
<div
class="d-flex align-items-center"
wire:click="sortBy('{{ ($column->isSortable() ? $column->getColumnSelectName() : $column->getSlug()) }}')"
style="cursor:pointer;"
>
<span>{{ $column->getTitle() }}</span>
@if($column->getColumnLabelStatus())
@unless ($component->sortingIsEnabled() && ($column->isSortable() || $column->getSortCallback()))
{{ $column->getTitle() }}
@else
<div
class="d-flex align-items-center"
wire:click="sortBy('{{ ($column->isSortable() ? $column->getColumnSelectName() : $column->getSlug()) }}')"
style="cursor:pointer;"
>
<span>{{ $column->getTitle() }}</span>

<span class="relative d-flex align-items-center">
@if ($direction === 'asc')
<x-heroicon-o-chevron-up class="ml-1" style="width:1em;height:1em;" />
@elseif ($direction === 'desc')
<x-heroicon-o-chevron-down class="ml-1" style="width:1em;height:1em;" />
@else
<x-heroicon-o-chevron-up-down class="ml-1" style="width:1em;height:1em;" />
@endif
</span>
</div>
@endunless
<span class="relative d-flex align-items-center">
@if ($direction === 'asc')
<x-heroicon-o-chevron-up class="ml-1" style="width:1em;height:1em;" />
@elseif ($direction === 'desc')
<x-heroicon-o-chevron-down class="ml-1" style="width:1em;height:1em;" />
@else
<x-heroicon-o-chevron-up-down class="ml-1" style="width:1em;height:1em;" />
@endif
</span>
</div>
@endunless
@endif
</th>
@endif
2 changes: 2 additions & 0 deletions src/Views/Column.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ class Column
{
use IsColumn;

protected bool $displayColumnLabel = true;

public function __construct(string $title, string $from = null)
{
$this->title = trim($title);
19 changes: 19 additions & 0 deletions src/Views/Traits/Configuration/ColumnConfiguration.php
Original file line number Diff line number Diff line change
@@ -163,4 +163,23 @@ public function setCustomSlug(string $customSlug): self

return $this;
}

public function setColumnLabelStatusDisabled(): self
{
$this->setColumnLabelStatus(false);

return $this;
}

public function setColumnLabelStatusEnabled(): self
{
$this->setColumnLabelStatus(true);

return $this;
}

public function setColumnLabelStatus(bool $status): void
{
$this->displayColumnLabel = $status;
}
}
5 changes: 5 additions & 0 deletions src/Views/Traits/Helpers/ColumnHelpers.php
Original file line number Diff line number Diff line change
@@ -449,4 +449,9 @@ public function hasCustomSlug(): bool
{
return $this->customSlug !== null;
}

public function getColumnLabelStatus(): bool
{
return $this->displayColumnLabel ?? true;
}
}
21 changes: 21 additions & 0 deletions tests/Traits/Helpers/ColumnHelpersTest.php
Original file line number Diff line number Diff line change
@@ -348,4 +348,25 @@ public function can_column_custom_slug_returns(): void

$this->assertSame(\Illuminate\Support\Str::slug('test123'), $column->getSlug());
}

/** @test */
public function can_check_if_column_label_should_be_shown(): void
{
$column = Column::make('ID', 'id');

$this->assertTrue($column->getColumnLabelStatus());

$column2 = Column::make('ID', 'id')
->setColumnLabelStatusDisabled()
->footer(fn ($rows) => 'Hi');

$this->assertFalse($column2->getColumnLabelStatus());

$column3 = Column::make('ID', 'id')
->setColumnLabelStatusEnabled()
->footer(fn ($rows) => 'Hi');

$this->assertTrue($column3->getColumnLabelStatus());
$this->assertFalse($column2->getColumnLabelStatus());
}
}
7 changes: 4 additions & 3 deletions tests/Traits/Visuals/SortingVisualsTest.php
Original file line number Diff line number Diff line change
@@ -33,9 +33,10 @@ public function testArraySetup(): array
public function th_headers_are_buttons_with_sorting_enabled(): void
{
Livewire::test(PetsTable::class)
->assertSeeHtml('<button
wire:click="sortBy(\'id\')"
class="flex items-center space-x-1 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400"');
->assertSeeHtmlInOrder([
'wire:click="sortBy(\'id\')"',
'class="flex items-center space-x-1 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400"',
]);
}

/** @test */