items = json_decode(htmlspecialchars_decode($value), true); } public function render(): string { if ($this->items === []) { throw new Exception('Dropdown menu has no items'); } $menuItems = ''; foreach ($this->items as $item) { switch ($item['type']) { case 'link': $menuItems .= anchor($item['uri'], $item['title'], [ 'class' => 'px-4 py-1 hover:bg-highlight focus:ring-accent focus:ring-inset' . (array_key_exists('class', $item) ? ' ' . $item['class'] : ''), ]); break; case 'html': $menuItems .= htmlspecialchars_decode((string) $item['content']); break; case 'separator': $menuItems .= '
'; break; default: break; } } return <<{$menuItems} HTML; } }