summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/web/src/Widget/Dropdown.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:38:04 +0000
commit1ff5c35de5dbd70a782875a91dd2232fd01b002b (patch)
tree77d9ce5e1bf78b3e6ef79f8f6e7861e2ced3c09b /vendor/ipl/web/src/Widget/Dropdown.php
parentInitial commit. (diff)
downloadicinga-php-library-upstream.tar.xz
icinga-php-library-upstream.zip
Adding upstream version 0.10.1.upstream/0.10.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ipl/web/src/Widget/Dropdown.php')
-rw-r--r--vendor/ipl/web/src/Widget/Dropdown.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/ipl/web/src/Widget/Dropdown.php b/vendor/ipl/web/src/Widget/Dropdown.php
new file mode 100644
index 0000000..b6eb20d
--- /dev/null
+++ b/vendor/ipl/web/src/Widget/Dropdown.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace ipl\Web\Widget;
+
+use ipl\Html\Attributes;
+use ipl\Html\BaseHtmlElement;
+use ipl\Html\Html;
+use ipl\Web\Url;
+
+/**
+ * Toggleable overlay dropdown element for displaying a list of links
+ */
+class Dropdown extends BaseHtmlElement
+{
+ /** @var array */
+ protected $links = [];
+
+ protected $defaultAttributes = ['class' => 'dropdown'];
+
+ protected $tag = 'div';
+
+ /**
+ * Create a dropdown element
+ *
+ * @param mixed $content
+ * @param Attributes|array $attributes
+ */
+ public function __construct($content, $attributes = null)
+ {
+ $toggle = new ActionLink($content, '#', null, [
+ 'aria-expanded' => false,
+ 'aria-haspopup' => true,
+ 'class' => 'dropdown-toggle',
+ 'role' => 'button'
+ ]);
+
+ $this
+ ->setContent($toggle)
+ ->getAttributes()
+ ->add($attributes);
+ }
+
+ /**
+ * Add a link to the dropdown
+ *
+ * @param mixed $content
+ * @param Url|string $url
+ * @param string $icon
+ *
+ * @return $this
+ */
+ public function addLink($content, $url, $icon = null)
+ {
+ $this->links[] = new ActionLink($content, $url, $icon, ['class' => 'dropdown-item']);
+
+ return $this;
+ }
+
+ protected function assemble()
+ {
+ $this->add(Html::tag('div', ['class' => 'dropdown-menu'], $this->links));
+ }
+}