Skip to content

Commit

Permalink
BaseItemList: Emit events before and after adding the list item to th…
Browse files Browse the repository at this point in the history
…e list (#217)

It would be helpful if lists could perform additional tasks before and
after a list item is added to it. Hence the events `BEFORE_ITEM_ADD` and
`ON_ITEM_ADD` would be desirable.
  • Loading branch information
nilmerg authored May 28, 2024
2 parents 0747a58 + dc51003 commit 0721dd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions asset/css/list/list-item.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
&:hover {
color: @list-item-title-hover-color;
text-decoration: none;

.subject {
color: @list-item-title-hover-color;
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Common/BaseItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ abstract class BaseItemList extends BaseHtmlElement
{
use BaseFilter;

/** @var string Emitted while assembling the list after adding each list item */
public const ON_ITEM_ADD = 'item-added';

/** @var string Emitted while assembling the list before adding each list item */
public const BEFORE_ITEM_ADD = 'before-item-add';

/** @var array<string, mixed> */
protected $baseAttributes = [
'class' => ['item-list', 'default-layout'],
Expand Down Expand Up @@ -62,7 +68,9 @@ protected function assemble(): void
foreach ($this->data as $data) {
/** @var BaseListItem|BaseTableRowItem $item */
$item = new $itemClass($data, $this);
$this->emit(self::BEFORE_ITEM_ADD, [$item, $data]);
$this->addHtml($item);
$this->emit(self::ON_ITEM_ADD, [$item, $data]);
}

if ($this->isEmpty()) {
Expand Down

0 comments on commit 0721dd0

Please sign in to comment.