Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new levels of notification for dev toolbar apps #10252

Merged
merged 11 commits into from
Mar 8, 2024
Next Next commit
Add new levels of notification
  • Loading branch information
Princesseuh committed Feb 22, 2024
commit d597770edb256008a18b20d11c7391ac53b69750
16 changes: 16 additions & 0 deletions packages/astro/src/runtime/client/dev-toolbar/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,27 @@ document.addEventListener('DOMContentLoaded', async () => {
if (!(evt instanceof CustomEvent)) return;

notification.toggleAttribute('data-active', evt.detail.state ?? true);
notification.toggleAttribute('data-level', evt.detail.level ?? 'error');

eventTarget.dispatchEvent(
new CustomEvent('toggle-notification', {
detail: {
state: hiddenApps.some((p) => p.notification.state === true),
// Find the highest level of notification
level: hiddenApps.reduce((acc, p) => {
if (p.notification.state) {
if (p.notification.level === 'error') {
return 'error';
}
if (p.notification.level === 'warning' && acc !== 'error') {
return 'warning';
}
if (p.notification.level === 'info' && acc !== 'error' && acc !== 'warning') {
return 'info';
}
}
return acc;
}),
},
})
);
Expand Down
11 changes: 10 additions & 1 deletion packages/astro/src/runtime/client/dev-toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type DevToolbarApp = DevToolbarAppDefinition & {
status: 'ready' | 'loading' | 'error';
notification: {
state: boolean;
level: 'error' | 'warn' | 'info';
};
eventTarget: EventTarget;
};
Expand Down Expand Up @@ -187,10 +188,18 @@ export class AstroDevToolbar extends HTMLElement {
}
}

#dev-bar #bar-container .item.active .notification {
#dev-bar #bar-container .item.active .notification-error {
border-color: rgba(71, 78, 94, 1);
}

#dev-bar #bar-container .item.active .notification-warn {
border-color: #FFC107;
}

#dev-bar #bar-container .item.active .notification-info {
border-color: #007BFF;
}

#dev-bar .item .icon {
position: relative;
max-width: 20px;
Expand Down