tutu/src/utils.tsx

27 lines
560 B
TypeScript
Raw Normal View History

2024-07-14 12:28:44 +00:00
import { createRenderEffect, createSignal, onCleanup } from "solid-js";
export function useDocumentTitle(newTitle?: string) {
2024-08-05 07:33:00 +00:00
const capturedTitle = document.title;
const [title, setTitle] = createSignal(newTitle ?? capturedTitle);
2024-07-14 12:28:44 +00:00
createRenderEffect(() => {
2024-08-05 07:33:00 +00:00
document.title = title();
});
2024-07-14 12:28:44 +00:00
onCleanup(() => {
2024-08-05 07:33:00 +00:00
document.title = capturedTitle;
});
2024-07-14 12:28:44 +00:00
2024-08-05 07:33:00 +00:00
return setTitle;
2024-07-14 12:28:44 +00:00
}
export function mergeClass(c1: string | undefined, c2: string | undefined) {
if (!c1) {
2024-08-05 07:33:00 +00:00
return c2;
2024-07-14 12:28:44 +00:00
}
if (!c2) {
2024-08-05 07:33:00 +00:00
return c1;
2024-07-14 12:28:44 +00:00
}
2024-08-05 07:33:00 +00:00
return [c1, c2].join(" ");
2024-07-14 12:28:44 +00:00
}