ILIAS  release_8 Revision v8.24
Button.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
25use ILIAS\UI\Implementation\Component\ComponentHelper;
28
32abstract class Button implements C\Button\Button
33{
34 use ComponentHelper;
36 use Triggerer;
37 use Engageable;
38
39 protected string $label;
40 protected ?string $action;
41 protected bool $active = true;
42 protected string $aria_label = '';
43 protected bool $aria_checked = false;
44
45
46 public function __construct(string $label, $action)
47 {
48 $this->checkStringOrSignalArg("action", $action);
49 $this->label = $label;
50 if (is_string($action)) {
51 $this->action = $action;
52 } else {
53 $this->action = null;
54 $this->setTriggeredSignal($action, "click");
55 }
56 }
57
61 public function getLabel(): string
62 {
63 return $this->label;
64 }
65
69 public function withLabel(string $label): C\Button\Button
70 {
71 $clone = clone $this;
72 $clone->label = $label;
73 return $clone;
74 }
75
79 public function getAction()
80 {
81 if ($this->action !== null) {
82 return $this->action;
83 }
84 return $this->getTriggeredSignalsFor("click");
85 }
86
90 public function isActive(): bool
91 {
92 return $this->active;
93 }
94
99 {
100 $clone = clone $this;
101 $clone->active = false;
102 return $clone;
103 }
104
108 public function withOnClick(Signal $signal): C\Button\Button
109 {
110 $this->action = null;
111 return $this->withTriggeredSignal($signal, 'click');
112 }
113
117 public function appendOnClick(Signal $signal): C\Clickable
118 {
119 return $this->appendTriggeredSignal($signal, 'click');
120 }
121
125 public function withOnHover(Signal $signal): C\Hoverable
126 {
127 // Note: The event 'hover' maps to 'mouseenter' in javascript. Although 'hover' is available in JQuery,
128 // it encodes the 'mouseenter' and 'mouseleave' events and thus expects two event handlers.
129 // In the context of this framework, the signal MUST only be triggered on the 'mouseenter' event.
130 // See also: https://api.jquery.com/hover/
131 return $this->withTriggeredSignal($signal, 'mouseenter');
132 }
133
137 public function appendOnHover(Signal $signal): C\Hoverable
138 {
139 return $this->appendTriggeredSignal($signal, 'mouseenter');
140 }
141
145 public function withAriaLabel(string $aria_label): C\Button\Button
146 {
147 $clone = clone $this;
148 $clone->aria_label = $aria_label;
149 return $clone;
150 }
151
155 public function getAriaLabel(): string
156 {
157 return $this->aria_label;
158 }
159}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
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
getTriggeredSignalsFor(string $event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:94
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
setTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:75