Skip to content

Commit

Permalink
fix(overlay): Fix SVG icons not showing properly in the overflow menu (
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Nov 30, 2023
1 parent 60cfa49 commit 9c2342c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-impalas-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix SVG icons not showing properly in the extended dropdown menu of the dev overlay
16 changes: 4 additions & 12 deletions packages/astro/src/runtime/client/dev-overlay/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { DevOverlayPlugin as DevOverlayPluginDefinition } from '../../../@t
import { type AstroDevOverlay, type DevOverlayPlugin } from './overlay.js';

import { settings } from './settings.js';
import type { Icon } from './ui-library/icons.js';

let overlay: AstroDevOverlay;

Expand All @@ -13,7 +12,7 @@ document.addEventListener('DOMContentLoaded', async () => {
{ default: astroAuditPlugin },
{ default: astroXrayPlugin },
{ default: astroSettingsPlugin },
{ AstroDevOverlay, DevOverlayCanvas },
{ AstroDevOverlay, DevOverlayCanvas, getPluginIcon },
{
DevOverlayCard,
DevOverlayHighlight,
Expand Down Expand Up @@ -188,8 +187,9 @@ document.addEventListener('DOMContentLoaded', async () => {
button.setAttribute('data-plugin-id', plugin.id);

const iconContainer = document.createElement('div');
const iconElement = getPluginIcon(plugin.icon);
iconContainer.append(iconElement);
const iconElement = document.createElement('template');
iconElement.innerHTML = getPluginIcon(plugin.icon);
iconContainer.append(iconElement.content.cloneNode(true));

const notification = document.createElement('div');
notification.classList.add('notification');
Expand Down Expand Up @@ -224,14 +224,6 @@ document.addEventListener('DOMContentLoaded', async () => {
}

canvas.append(dropdown);

function getPluginIcon(icon: Icon) {
if (isDefinedIcon(icon)) {
return getIconElement(icon)!;
}

return icon;
}
}
},
} satisfies DevOverlayPluginDefinition;
Expand Down
18 changes: 9 additions & 9 deletions packages/astro/src/runtime/client/dev-overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,11 @@ export class AstroDevOverlay extends HTMLElement {

getPluginTemplate(plugin: DevOverlayPlugin) {
return `<button class="item" data-plugin-id="${plugin.id}">
<div class="icon">${this.getPluginIcon(plugin.icon)}<div class="notification"></div></div>
<div class="icon">${getPluginIcon(plugin.icon)}<div class="notification"></div></div>
<span class="item-tooltip">${plugin.name}</span>
</button>`;
}

getPluginIcon(icon: Icon) {
if (isDefinedIcon(icon)) {
return getIconElement(icon)?.outerHTML;
}

return icon;
}

getPluginById(id: string) {
return this.plugins.find((plugin) => plugin.id === id);
}
Expand Down Expand Up @@ -525,3 +517,11 @@ export class DevOverlayCanvas extends HTMLElement {
</style>`;
}
}

export function getPluginIcon(icon: Icon) {
if (isDefinedIcon(icon)) {
return getIconElement(icon).outerHTML;
}

return icon;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export function isDefinedIcon(icon: Icon): icon is DefinedIcon {
return icon in icons;
}

export function getIconElement(name: DefinedIcon): SVGElement;
export function getIconElement(name: string & NonNullable<unknown>): undefined;
export function getIconElement(
name: keyof typeof icons | (string & NonNullable<unknown>)
name: DefinedIcon | (string & NonNullable<unknown>)
): SVGElement | undefined {
const icon = icons[name as keyof typeof icons];
const icon = icons[name as DefinedIcon];

if (!icon) {
return undefined;
Expand Down

0 comments on commit 9c2342c

Please sign in to comment.