-
Hi! I've been working on an addon that brings Naive UI components to Slidev, a slide-as-code tool based on Vue. I managed to introduce the components by using The issue is, the components in the slideshow do not respond to the dark theme. Since this is a plugin, I have no control on the definition of Are there any alternative ways to provide theme to all components? Here's the npm package I'm buildin: https://github.com/sghuang19/slidev-addon-naive And here's a screenshot: ![]() Here's how I configure the import naive, { darkTheme } from "naive-ui";
import { defineAppSetup } from "@slidev/types";
import { shallowRef, h } from "vue";
export default defineAppSetup(({ app }) => {
// Set up naive-ui
app.use(naive);
// Inject Naive UI styles into <head> element
if (typeof window !== "undefined") {
const head = document.head || document.getElementsByTagName("head")[0];
["naive-ui-style", "vueuc-style"].forEach((name) => {
const meta = document.createElement("meta");
meta.name = name;
head.appendChild(meta);
});
}
// Set dark mode
const naiveTheme = shallowRef(null);
const updateTheme = () => {
// console.log("Color scheme changed, updating Naive theme...");
naiveTheme.value = document.documentElement.classList.contains("dark")
? darkTheme
: null;
};
updateTheme();
// Watch for changes to <html> class and update theme
const observer = new MutationObserver(updateTheme);
observer.observe(document.documentElement, {
attributes: true,
attributeFilter: ["class"],
});
// TODO: provide updated theme
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Finally came up with a solution by injecting the |
Beta Was this translation helpful? Give feedback.
Finally came up with a solution by injecting the
n-config-provider
context manually:sghuang19/slidev-addon-naive#9