feat: refactor the usage of toast (#1699)

This commit is contained in:
Qi
2023-03-27 13:24:14 +08:00
committed by GitHub
parent 66dec34209
commit 449ffbc73f
14 changed files with 60 additions and 44 deletions

View File

@@ -1,20 +1,5 @@
export function stringToColour(str: string) {
str = str || 'affine';
let colour = '#';
let hash = 0;
// str to hash
for (
let i = 0;
i < str.length;
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
);
// int/hash to hex
for (
let i = 0;
i < 3;
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
);
return colour;
}
export * from './blocksuite';
export * from './create-emotion-cache';
export * from './is-valid-ip-address';
export * from './string2color';
export * from './toast';

View File

@@ -0,0 +1,20 @@
export function stringToColour(str: string) {
str = str || 'affine';
let colour = '#';
let hash = 0;
// str to hash
for (
let i = 0;
i < str.length;
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
);
// int/hash to hex
for (
let i = 0;
i < 3;
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
);
return colour;
}

View File

@@ -0,0 +1,12 @@
import type { ToastOptions } from '@affine/component';
import { toast as basicToast } from '@affine/component';
export const toast = (message: string, options?: ToastOptions) => {
const mainContainer = document.querySelector(
'.main-container'
) as HTMLElement;
return basicToast(message, {
portal: mainContainer || document.body,
...options,
});
};