Skip to content

Commit

Permalink
Merge pull request #81 from monzer15/patch-1
Browse files Browse the repository at this point in the history
Ability to customize headers text alignment
  • Loading branch information
awcodes authored Dec 29, 2023
2 parents 7a30542 + fa3dfd6 commit aebf810
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ TableRepeater::make('social')
->headers(['Platform', 'Handle'])
```

To change the headers alignment use the `alignHeaders('center')` method.

```php
TableRepeater::make('social')
->alignHeaders('center')
```

### Labels

To automatically hide all the labels of the fields in the table use the `hideLabels()` method.
Expand Down
7 changes: 6 additions & 1 deletion resources/views/components/table-repeater.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@
@foreach ($headers as $key => $header)
<th
@class([
'filament-table-repeater-header-column px-3 py-2 font-medium text-left bg-gray-100 dark:text-gray-300 dark:bg-gray-900/60',
'filament-table-repeater-header-column px-3 py-2 font-medium bg-gray-100 dark:text-gray-300 dark:bg-gray-900/60',
'ltr:rounded-tl-xl rtl:rounded-tr-xl' => $loop->first,
'ltr:rounded-tr-xl rtl:rounded-tl-xl' => $loop->last && ! $hasActions,
match($getHeadersAlignment()) {
'center' => 'text-center',
'right' => 'text-right rtl:text-left',
default => 'text-left rtl:text-right'
}
])
@if ($header['width'])
style="width: {{ $header['width'] }}"
Expand Down
16 changes: 15 additions & 1 deletion src/Components/TableRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TableRepeater extends Repeater

protected bool|Closure $withoutHeader = false;

protected string|Closure|null $headersAlignment = null;

public function breakPoint(string $breakPoint = 'md'): static
{
$this->breakPoint = $breakPoint;
Expand All @@ -42,6 +44,13 @@ public function emptyLabel(bool|string|Closure $label = null): static
return $this;
}

public function alignHeaders(string|Closure $alignment = 'left'): static
{
$this->headersAlignment = $alignment;

return $this;
}

public function getBreakPoint(): string
{
return $this->breakPoint;
Expand Down Expand Up @@ -77,6 +86,11 @@ public function getEmptyLabel(): bool|string|null
return $this->evaluate($this->emptyLabel);
}

public function getHeadersAlignment(): string
{
return $this->evaluate($this->headersAlignment) ?? 'left';
}

public function getHeaders(): array
{
$mergedHeaders = [];
Expand All @@ -91,7 +105,7 @@ public function getHeaders(): array
$key = method_exists($field, 'getName') ? $field->getName() : $field->getId();

$isRequired = false;

if (property_exists($field, 'isRequired') && is_bool($field->isRequired())) {
$isRequired = $field->isRequired();

Expand Down

0 comments on commit aebf810

Please sign in to comment.