import { useRegisterActions } from "../../../src/useRegisterActions";
import toast from "react-hot-toast";
import * as React from "react";
function Toast({ title, action, buttonText }) {
return (
{title}
{buttonText}
);
}
export default function useThemeActions() {
useRegisterActions([
{
id: "theme",
name: "Change themeā¦",
keywords: "interface color dark light",
section: "Preferences",
},
{
id: "darkTheme",
name: "Dark",
keywords: "dark theme",
section: "",
perform: (actionImpl) => {
const attribute = "data-theme-dark";
const doc = document.documentElement;
doc.setAttribute(attribute, "");
toast(
{
actionImpl.command.history.undo();
toast.dismiss("dark");
toast(
{
actionImpl.command.history.redo();
toast.dismiss("dark-undo");
}}
/>,
{
id: "dark-undo",
}
);
}}
/>
,
{
id: "dark",
}
);
return () => {
doc.removeAttribute(attribute);
};
},
parent: "theme",
},
{
id: "lightTheme",
name: "Light",
keywords: "light theme",
section: "",
perform: (actionImpl) => {
const attribute = "data-theme-dark";
const doc = document.documentElement;
const isDark = doc.getAttribute(attribute) !== null;
document.documentElement.removeAttribute(attribute);
toast(
{
actionImpl.command.history.undo();
toast.dismiss("light");
toast(
{
actionImpl.command.history.redo();
toast.dismiss("light-undo");
}}
/>,
{
id: "light-undo",
}
);
}}
/>
,
{
id: "light",
}
);
return () => {
if (isDark) doc.setAttribute(attribute, "");
};
},
parent: "theme",
},
]);
}