Skip to content

Commit 7372933

Browse files
committed
refactor: use popover for notifications
1 parent a57bb05 commit 7372933

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

scripts/app.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ export const List = defineComponent({
8181

8282
const { run: runLoad, isLoading, hasError } = useAsyncTask(load);
8383

84-
onMounted(() => runLoad());
84+
onMounted(async () => {
85+
notificationEl.value?.showPopover();
86+
const [, error] = await runLoad();
87+
if (!error) {
88+
notificationEl.value?.hidePopover();
89+
}
90+
});
91+
92+
const notificationEl = useTemplateRef("notificationEl");
8593

8694
/* -------------------------------------------------- *
8795
* Searching *
@@ -223,23 +231,16 @@ export const List = defineComponent({
223231
</div>
224232
</main>
225233
226-
<!-- Status notification -->
227-
<div class="status-layout">
228-
<Transition name="slide">
229-
<div
230-
v-if="isLoading || hasError"
231-
aria-busy="true"
232-
class="status"
233-
data-color-scheme="inverted"
234-
>
235-
<small class="status-label">
236-
<template v-if="!hasError">Fetching your stuff ...</template>
237-
<template v-else>🚨 Couldn&rsquo;t fetch your stars!</template>
238-
</small>
239-
</div>
240-
</Transition>
241-
</div>
242-
</div>`,
234+
<div
235+
:aria-busy="isLoading"
236+
class="notification"
237+
data-color-scheme="inverted"
238+
popover="manual"
239+
ref="notificationEl"
240+
>
241+
<template v-if="!hasError">Fetching your stuff ...</template>
242+
<template v-else>🚨 Couldn&rsquo;t fetch your stars!</template>
243+
</div>`,
243244
});
244245

245246
/* -------------------------------------------------- *

styles/styles.css

+23-27
Original file line numberDiff line numberDiff line change
@@ -160,37 +160,33 @@ layer(theme);
160160
* Fetch status *
161161
* -------------------------------------------------- */
162162

163-
.status-layout {
164-
bottom: var(--body-padding-y);
165-
display: flex;
166-
justify-content: center;
167-
left: 0;
168-
pointer-events: none;
169-
position: fixed;
170-
right: 0;
171-
}
172-
173-
.status {
163+
.notification {
174164
background: var(--c-surface-bg);
175165
border-radius: 9999px;
176-
color: var(--primary);
177-
padding: 0.75rem 1.125rem;
178-
pointer-events: auto;
179-
}
180-
181-
.status-label {
166+
border: none;
182167
color: var(--c-surface-fg);
168+
font-size: var(--font-size-small);
183169
font-weight: var(--font-weight-medium);
184-
}
170+
inset-block: auto var(--body-padding-y);
171+
opacity: 0;
172+
padding: 0.75rem 1.125rem;
173+
position: fixed;
174+
transition: all var(--transition) allow-discrete;
175+
translate: 0 1rem;
185176

186-
.slide-enter-active,
187-
.slide-leave-active {
188-
transition: 0.1s ease;
189-
transition-property: transform, opacity;
190-
}
177+
&:popover-open {
178+
opacity: 1;
179+
translate: 0 0;
180+
}
191181

192-
.slide-enter-from,
193-
.slide-leave-to {
194-
transform: scale(0.8);
195-
opacity: 0;
182+
@starting-style {
183+
&:popover-open {
184+
opacity: 0;
185+
translate: 0 1rem;
186+
}
187+
}
188+
189+
&[aria-busy]::before {
190+
color: var(--primary);
191+
}
196192
}

0 commit comments

Comments
 (0)