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

Ability to customize headers text alignment #81

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
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
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 text alignment use the `headersTextAlignment('center')` method.

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

monzer15 marked this conversation as resolved.
Show resolved Hide resolved
### Labels

To automatically hide all the labels of the fields in the table use the `hideLabels()` method.
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/table-repeater.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

$emptyLabel = $getEmptyLabel();

$headersTextAlignment = $getHeadersTextAlignment();
monzer15 marked this conversation as resolved.
Show resolved Hide resolved

$hasActions = $reorderAction->isVisible() || $cloneAction->isVisible() || $deleteAction->isVisible() || $moveUpAction->isVisible() || $moveDownAction->isVisible();
@endphp

Expand Down Expand Up @@ -53,7 +55,7 @@
@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 text-{$headersTextAlignment} 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,
monzer15 marked this conversation as resolved.
Show resolved Hide resolved
])
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 $headersTextAlignment = "left";
monzer15 marked this conversation as resolved.
Show resolved Hide resolved

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 headersTextAlignment(string|Closure $alignment = 'left'): static
{
$this->headersTextAlignment = $alignment;

return $this;
}
monzer15 marked this conversation as resolved.
Show resolved Hide resolved

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 getHeadersTextAlignment(): string
{
return $this->evaluate($this->headersTextAlignment);
}
monzer15 marked this conversation as resolved.
Show resolved Hide resolved

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