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

Feature: Enable Scrolling and Strict Width to table #94

Closed
wants to merge 8 commits into from
Closed
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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ TableRepeater::make('social')
])
```

### Strict Width

Normally, setting a column width in a table adapts it to fit within the remaining
table space. If you want precise control and prevent stretching or shrinking,
use the `strictWidth()` method to enforce that specific width.

```php
TableRepeater::make('social')
->strictWidth() // accepts Closure
```

### Break Point

Below a specific break point the table will render as a set of panels to
Expand All @@ -126,6 +137,18 @@ TableRepeater::make('social')
->breakPoint('sm') // accepts Tailwind CSS screen sizes
```

### Scrolling

For tables exceeding available space, enable both scrolling and fixed column widths.
Use `scrollable()` to activate horizontal scrolling, and complement it with `strictWidth()`
to prevent unwanted stretching or shrinking of columns.

```php
TableRepeater::make('social')
->scrollable() // accepts Closure
->strictWidth() // accepts Closure
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
7 changes: 4 additions & 3 deletions resources/views/components/table-repeater.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
'xl' => 'break-point-xl',
'2xl' => 'break-point-2xl',
default => 'break-point-md',
}
},
'overflow-auto' => $shouldBeScrollable()
]) }}
>
@if (count($containers) || $emptyLabel !== false)
Expand Down Expand Up @@ -80,7 +81,7 @@
}
])
@if ($header['width'])
style="width: {{ $header['width'] }}"
style="{{$shouldStrictWidth()? 'min-width':'width'}}: {{ $header['width'] }}"
@endif
>
{{ $header['label'] }}
Expand Down Expand Up @@ -154,7 +155,7 @@ class="filament-table-repeater-row md:divide-x md:divide-gray-950/5 dark:md:divi
$columnWidths &&
isset($columnWidths[$cellKey])
)
style="width: {{ $columnWidths[$cellKey] }}"
style="{{$shouldStrictWidth()? 'min-width':'width'}}: {{ $columnWidths[$cellKey] }}"
@endif
>
{{ $cell }}
Expand Down
28 changes: 27 additions & 1 deletion src/Components/TableRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class TableRepeater extends Repeater
{
protected string $breakPoint = 'md';

protected bool $strictWidth = false;

protected bool $scrollable = false;

protected array|Closure $columnWidths = [];

protected null|bool|string|Closure $emptyLabel = null;
Expand All @@ -30,6 +34,20 @@ public function breakPoint(string $breakPoint = 'md'): static
return $this;
}

public function scrollable(bool|string|Closure $scrollable = true): static
{
$this->scrollable = $scrollable;

return $this;
}

public function strictWidth(bool|string|Closure $strictWidth = true): static
{
$this->strictWidth = $strictWidth;

return $this;
}

public function columnWidths(array|Closure $widths = []): static
{
$this->columnWidths = $widths;
Expand All @@ -50,11 +68,19 @@ public function alignHeaders(string|Closure $alignment = 'left'): static

return $this;
}

public function getBreakPoint(): string
{
return $this->breakPoint;
}
public function shouldStrictWidth(): bool
{
return $this->evaluate($this->strictWidth);
}

public function shouldBeScrollable(): bool
{
return $this->evaluate($this->scrollable);
}

public function getColumnWidths(): array
{
Expand Down