Skip to content

Add linkClass() and addLinkClass() methods to pagination widgets #274

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

Merged
merged 1 commit into from
Apr 11, 2025
Merged
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
4 changes: 2 additions & 2 deletions config/widgets-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
'listAttributes()' => [['class' => 'pagination']],
'itemTag()' => ['li'],
'itemAttributes()' => [['class' => 'page-item']],
'linkAttributes()' => [['class' => 'page-link']],
'linkClass()' => ['page-link'],

Check warning on line 66 in config/widgets-themes.php

View check run for this annotation

Codecov / codecov/patch

config/widgets-themes.php#L66

Added line #L66 was not covered by tests
'currentItemClass()' => ['active'],
'disabledItemClass()' => ['disabled'],
],
Expand All @@ -72,7 +72,7 @@
'listAttributes()' => [['class' => 'pagination']],
'itemTag()' => ['li'],
'itemAttributes()' => [['class' => 'page-item']],
'linkAttributes()' => [['class' => 'page-link']],
'linkClass()' => ['page-link'],

Check warning on line 75 in config/widgets-themes.php

View check run for this annotation

Codecov / codecov/patch

config/widgets-themes.php#L75

Added line #L75 was not covered by tests
'disabledItemClass()' => ['disabled'],
],
InputPageSize::class => [
Expand Down
34 changes: 34 additions & 0 deletions src/Pagination/KeysetPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Yii\DataView\Pagination;

use BackedEnum;
use InvalidArgumentException;
use Stringable;
use Yiisoft\Data\Paginator\KeysetPaginator;
Expand Down Expand Up @@ -199,6 +200,39 @@
return $new;
}

/**
* Set new link classes.
*
* Multiple classes can be set by passing them as separate arguments. `null` values are filtered out
* automatically.
*
* @param BackedEnum|string|null ...$class One or more CSS class names to use. Pass `null` to skip a class.
* @return self
*/
public function linkClass(BackedEnum|string|null ...$class): self

Check warning on line 212 in src/Pagination/KeysetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/KeysetPagination.php#L212

Added line #L212 was not covered by tests
{
$new = clone $this;
$new->linkAttributes['class'] = [];
Html::addCssClass($new->linkAttributes, $class);
return $new;

Check warning on line 217 in src/Pagination/KeysetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/KeysetPagination.php#L214-L217

Added lines #L214 - L217 were not covered by tests
}

/**
* Adds one or more CSS classes to the existing link classes.
*
* Multiple classes can be added by passing them as separate arguments. `null` values are filtered out
* automatically.
*
* @param BackedEnum|string|null ...$class One or more CSS class names to add. Pass `null` to skip adding a class.
* @return self A new instance with the specified CSS classes added to existing ones.
*/
public function addLinkClass(BackedEnum|string|null ...$class): self

Check warning on line 229 in src/Pagination/KeysetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/KeysetPagination.php#L229

Added line #L229 was not covered by tests
{
$new = clone $this;
Html::addCssClass($new->linkAttributes, $class);
return $new;

Check warning on line 233 in src/Pagination/KeysetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/KeysetPagination.php#L231-L233

Added lines #L231 - L233 were not covered by tests
}

/**
* Sets the CSS class for disabled link elements.
*
Expand Down
34 changes: 34 additions & 0 deletions src/Pagination/OffsetPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Yii\DataView\Pagination;

use BackedEnum;
use InvalidArgumentException;
use Stringable;
use Yiisoft\Data\Paginator\PageToken;
Expand Down Expand Up @@ -138,6 +139,39 @@
return $new;
}

/**
* Set new link classes.
*
* Multiple classes can be set by passing them as separate arguments. `null` values are filtered out
* automatically.
*
* @param BackedEnum|string|null ...$class One or more CSS class names to use. Pass `null` to skip a class.
* @return self
*/
public function linkClass(BackedEnum|string|null ...$class): self

Check warning on line 151 in src/Pagination/OffsetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/OffsetPagination.php#L151

Added line #L151 was not covered by tests
{
$new = clone $this;
$new->linkAttributes['class'] = [];
Html::addCssClass($new->linkAttributes, $class);
return $new;

Check warning on line 156 in src/Pagination/OffsetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/OffsetPagination.php#L153-L156

Added lines #L153 - L156 were not covered by tests
}

/**
* Adds one or more CSS classes to the existing link classes.
*
* Multiple classes can be added by passing them as separate arguments. `null` values are filtered out
* automatically.
*
* @param BackedEnum|string|null ...$class One or more CSS class names to add. Pass `null` to skip adding a class.
* @return self A new instance with the specified CSS classes added to existing ones.
*/
public function addLinkClass(BackedEnum|string|null ...$class): self

Check warning on line 168 in src/Pagination/OffsetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/OffsetPagination.php#L168

Added line #L168 was not covered by tests
{
$new = clone $this;
Html::addCssClass($new->linkAttributes, $class);
return $new;

Check warning on line 172 in src/Pagination/OffsetPagination.php

View check run for this annotation

Codecov / codecov/patch

src/Pagination/OffsetPagination.php#L170-L172

Added lines #L170 - L172 were not covered by tests
}

public function currentLinkClass(?string $class): self
{
$new = clone $this;
Expand Down
Loading