2024-10-14 12:05:08 +00:00
|
|
|
import {
|
|
|
|
createRenderEffect,
|
|
|
|
onCleanup,
|
|
|
|
type Accessor,
|
|
|
|
} from "solid-js";
|
2024-07-14 12:28:44 +00:00
|
|
|
|
2024-10-14 12:05:08 +00:00
|
|
|
export function useDocumentTitle(newTitle?: string | Accessor<string>) {
|
2024-08-05 07:33:00 +00:00
|
|
|
const capturedTitle = document.title;
|
2024-07-14 12:28:44 +00:00
|
|
|
|
|
|
|
createRenderEffect(() => {
|
2024-10-14 12:05:08 +00:00
|
|
|
if (newTitle)
|
|
|
|
document.title = typeof newTitle === "string" ? newTitle : newTitle();
|
2024-08-05 07:33:00 +00:00
|
|
|
});
|
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-10-14 12:05:08 +00:00
|
|
|
return (x: ((x: string) => string) | string) =>
|
|
|
|
(document.title = typeof x === "string" ? x : x(document.title));
|
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
|
|
|
}
|