ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
Button.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
29 
33 abstract class Button implements C\Button\Button
34 {
35  use ComponentHelper;
37  use Triggerer;
38  use Engageable;
39  use HasHelpTopics;
40 
41  protected string $label;
42  protected ?string $action;
43  protected bool $active = true;
44  protected string $aria_label = '';
45  protected bool $aria_checked = false;
46 
47 
48  public function __construct(string $label, $action)
49  {
50  $this->checkStringOrSignalArg("action", $action);
51  $this->label = $label;
52  if (is_string($action)) {
53  $this->action = $action;
54  } else {
55  $this->action = null;
56  $this->setTriggeredSignal($action, "click");
57  }
58  }
59 
63  public function getLabel(): string
64  {
65  return $this->label;
66  }
67 
71  public function withLabel(string $label): C\Button\Button
72  {
73  $clone = clone $this;
74  $clone->label = $label;
75  return $clone;
76  }
77 
81  public function getAction()
82  {
83  if ($this->action !== null) {
84  return $this->action;
85  }
86  return $this->getTriggeredSignalsFor("click");
87  }
88 
92  public function isActive(): bool
93  {
94  return $this->active;
95  }
96 
100  public function withUnavailableAction(bool $flag = true): C\Button\Button
101  {
102  $clone = clone $this;
103  $clone->active = !$flag;
104  return $clone;
105  }
106 
110  public function withOnClick(Signal $signal): C\Button\Button
111  {
112  $this->action = null;
113  return $this->withTriggeredSignal($signal, 'click');
114  }
115 
119  public function appendOnClick(Signal $signal): C\Clickable
120  {
121  return $this->appendTriggeredSignal($signal, 'click');
122  }
123 
127  public function withOnHover(Signal $signal): C\Hoverable
128  {
129  // Note: The event 'hover' maps to 'mouseenter' in javascript. Although 'hover' is available in JQuery,
130  // it encodes the 'mouseenter' and 'mouseleave' events and thus expects two event handlers.
131  // In the context of this framework, the signal MUST only be triggered on the 'mouseenter' event.
132  // See also: https://api.jquery.com/hover/
133  return $this->withTriggeredSignal($signal, 'mouseenter');
134  }
135 
139  public function appendOnHover(Signal $signal): C\Hoverable
140  {
141  return $this->appendTriggeredSignal($signal, 'mouseenter');
142  }
143 
147  public function withAriaLabel(string $aria_label): C\Button\Button
148  {
149  $clone = clone $this;
150  $clone->aria_label = $aria_label;
151  return $clone;
152  }
153 
157  public function getAriaLabel(): string
158  {
159  return $this->aria_label;
160  }
161 }
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:62
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
getTriggeredSignalsFor(string $event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:94
trait Engageable
Trait Engageable.
Definition: Engageable.php:29
setTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:75
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21