Skip to content

Commit

Permalink
appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Feb 20, 2024
1 parent 1c80830 commit 488d146
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/widgets-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'sortableHeaderAscPrepend()' => ['<div class="float-end fw-bold">⭡</div>'],
'sortableHeaderDescPrepend()' => ['<div class="float-end fw-bold">⭣</div>'],
'filterCellAttributes()' => [['class' => 'align-top']],
'filterCellInvalidClass()' => ['bg-danger bg-opacity-10'],
'filterErrorsContainerAttributes()' => [['class' => 'text-danger mt-1']],
'addColumnRendererConfigs()' => [
[
ActionColumnRenderer::class => [
Expand Down
5 changes: 2 additions & 3 deletions src/Column/Base/FilterContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ final class FilterContext
{
private readonly UrlQueryReader $urlQueryReader;

/**
* @param string[] $errors
*/
public function __construct(
public readonly string $formId,
public readonly Result $validationResult,
public readonly ?string $cellInvalidClass,
public readonly array $errorsContainerAttributes,
) {
$this->urlQueryReader = new UrlQueryReader();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Column/DataColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public function renderFilter(ColumnInterface $column, Cell $cell, FilterContext

$errors = $context->validationResult->getAttributeErrorMessages($column->queryProperty);
if (!empty($errors)) {
$content[] = Html::div()->content(...array_map(static fn(string $error) => Html::div($error), $errors));
$cell = $cell->addClass($context->cellInvalidClass);
$content[] = Html::div(attributes: $context->errorsContainerAttributes)
->content(...array_map(static fn(string $error) => Html::div($error), $errors));
}

return $cell->content(...$content)->encode(false);
Expand Down
18 changes: 18 additions & 0 deletions src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ final class GridView extends BaseListView
private ?string $sortableLinkDescClass = null;

private array $filterCellAttributes = [];
private ?string $filterCellInvalidClass = null;
private array $filterErrorsContainerAttributes = [];

private RendererContainer $columnRendererContainer;

Expand Down Expand Up @@ -116,6 +118,20 @@ public function filterCellAttributes(array $attributes): self
return $new;
}

public function filterCellInvalidClass(?string $class): self
{
$new = clone $this;
$new->filterCellInvalidClass = $class;
return $new;
}

public function filterErrorsContainerAttributes(array $attributes): self
{
$new = clone $this;
$new->filterErrorsContainerAttributes = $attributes;
return $new;
}

public function enableMultiSort(bool $value = true): self
{
$new = clone $this;
Expand Down Expand Up @@ -457,6 +473,8 @@ protected function renderItems(array $items, ValidationResult $filterValidationR
$filterContext = new FilterContext(
formId: Html::generateId(),
validationResult: $filterValidationResult,
cellInvalidClass: $this->filterCellInvalidClass,
errorsContainerAttributes: $this->filterErrorsContainerAttributes,
);
foreach ($columns as $i => $column) {
$cell = $renderers[$i] instanceof FilterableColumnRendererInterface
Expand Down

0 comments on commit 488d146

Please sign in to comment.