mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-28 04:53:53 +03:00
fix: regression on toast component (#2502)
This commit is contained in:
parent
48c109e149
commit
49f1ba676f
@ -1,17 +1,10 @@
|
||||
import type { ToastOptions } from '@affine/component';
|
||||
import { toast as basicToast } from '@affine/component';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
|
||||
const logger = new DebugLogger('toast');
|
||||
|
||||
export const toast = (message: string, options?: ToastOptions) => {
|
||||
const mainContainer = document.querySelector(
|
||||
'.main-container'
|
||||
) as HTMLElement;
|
||||
logger.debug(`toast with message: "${message}"`, options);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('affine-toast:emit', { detail: message })
|
||||
);
|
||||
return basicToast(message, {
|
||||
portal: mainContainer || document.body,
|
||||
...options,
|
||||
|
@ -1,7 +1,10 @@
|
||||
// Copyright: https://github.com/toeverything/blocksuite/commit/8032ef3ab97aefce01664b36502fc392c5db8b78#diff-bf5b41be21936f9165a8400c7f20e24d3dbc49644ba57b9258e0943f0dc1c464
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { TemplateResult } from 'lit';
|
||||
import { css, html } from 'lit';
|
||||
|
||||
const logger = new DebugLogger('toast');
|
||||
|
||||
export const sleep = (ms = 0) =>
|
||||
new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
||||
@ -18,7 +21,7 @@ const htmlToElement = <T extends ChildNode>(html: string | TemplateResult) => {
|
||||
template.innerHTML = html;
|
||||
} else {
|
||||
const { strings, values } = html;
|
||||
const v = [...values, '']; // + last emtpty part
|
||||
const v = [...values, '']; // + last empty part
|
||||
template.innerHTML = strings.reduce((acc, cur, i) => acc + cur + v[i], '');
|
||||
}
|
||||
return template.content.firstChild as T;
|
||||
@ -92,22 +95,32 @@ export const toast = (
|
||||
element.textContent = message;
|
||||
ToastContainer.appendChild(element);
|
||||
|
||||
logger.debug(`toast with message: "${message}"`);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('affine-toast:emit', { detail: message })
|
||||
);
|
||||
|
||||
const fadeIn = [
|
||||
{
|
||||
opacity: 0,
|
||||
},
|
||||
{ opacity: 1 },
|
||||
];
|
||||
|
||||
const options = {
|
||||
duration: 230,
|
||||
easing: 'cubic-bezier(0.21, 1.02, 0.73, 1)',
|
||||
fill: 'forwards' as const,
|
||||
}; // satisfies KeyframeAnimationOptions;
|
||||
} satisfies KeyframeAnimationOptions;
|
||||
|
||||
element.animate(fadeIn, options);
|
||||
|
||||
setTimeout(async () => {
|
||||
if (typeof element.animate !== 'function') return;
|
||||
const fadeOut = fadeIn.reverse();
|
||||
const animation = element.animate(fadeOut, options);
|
||||
const animation = element.animate(
|
||||
// fade out
|
||||
fadeIn.reverse(),
|
||||
options
|
||||
);
|
||||
await animation.finished;
|
||||
element.style.maxHeight = '0';
|
||||
element.style.margin = '0';
|
||||
|
Loading…
Reference in New Issue
Block a user