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

Sync ButtonToolbar class with the latest changes from the package. #208

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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: 9 additions & 14 deletions src/ButtonToolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Yiisoft\Html\Tag\Base\Tag;
use Yiisoft\Html\Tag\Div;

use function array_filter;
use function array_merge;
use function implode;

/**
Expand Down Expand Up @@ -56,7 +54,7 @@ final class ButtonToolbar extends \Yiisoft\Widget\Widget
private array $attributes = [];
/** @psalm-var ButtonGroup[]|Tag[] $buttonGroups */
private array $buttonGroups = [];
private array $cssClass = [];
private array $cssClasses = [];
private bool|string $id = true;

/**
Expand All @@ -69,7 +67,7 @@ final class ButtonToolbar extends \Yiisoft\Widget\Widget
public function addAttributes(array $values): self
{
$new = clone $this;
$new->attributes = array_merge($this->attributes, $values);
$new->attributes = [...$new->attributes, ...$values];

return $new;
}
Expand All @@ -80,7 +78,7 @@ public function addAttributes(array $values): self
* Multiple classes can be added by passing them as separate arguments. `null` values are filtered out
* automatically.
*
* @param string|null ...$value One or more CSS class names to add. Pass `null` to skip adding a class.
* @param string|null ...$values One or more CSS class names to add. Pass `null` to skip adding a class.
* For example:
*
* ```php
Expand All @@ -91,13 +89,10 @@ public function addAttributes(array $values): self
*
* @link https://html.spec.whatwg.org/#classes
*/
public function addClass(string|null ...$value): self
public function addClass(string|null ...$values): self
{
$new = clone $this;
$new->cssClass = array_merge(
$new->cssClass,
array_filter($value, static fn ($v) => $v !== null)
);
$new->cssClasses = [...$this->cssClasses, ...$values];

return $new;
}
Expand Down Expand Up @@ -157,7 +152,7 @@ public function buttonGroups(ButtonGroup|Tag ...$value): self
* Multiple classes can be added by passing them as separate arguments. `null` values are filtered out
* automatically.
*
* @param string|null ...$value One or more CSS class names to set. Pass `null` to skip setting a class.
* @param string|null ...$values One or more CSS class names to set. Pass `null` to skip setting a class.
* For example:
*
* ```php
Expand All @@ -166,10 +161,10 @@ public function buttonGroups(ButtonGroup|Tag ...$value): self
*
* @return self A new instance with the specified CSS classes set.
*/
public function class(string|null ...$value): self
public function class(string|null ...$values): self
{
$new = clone $this;
$new->cssClass = array_filter($value, static fn ($v) => $v !== null);
$new->cssClasses = $values;

return $new;
}
Expand Down Expand Up @@ -210,7 +205,7 @@ public function render(): string

unset($attributes['class'], $attributes['id']);

Html::addCssClass($attributes, [self::NAME, $classes, ...$this->cssClass]);
Html::addCssClass($attributes, [self::NAME, $classes, ...$this->cssClasses]);

$buttonGroup = implode("\n", $this->buttonGroups);
$buttonsGroups = $buttonGroup === '' ? '' : "\n" . $buttonGroup . "\n";
Expand Down
Loading