import { root } from "@lynx-js/react";
import { useState } from "react";
import "./index.scss";
export default function App() {
const [isDark, setIsDark] = useState(false);
const [useJS, setUseJS] = useState(false);
const [showError, setShowError] = useState(false);
const themeClass = isDark ? "theme-dark" : "theme-light";
const toggleTheme = () => {
if (useJS) {
setShowError(true);
setTimeout(() => setShowError(false), 3000);
return;
}
setIsDark(prev => !prev);
};
const toggleThemeByJS = () => {
setUseJS(true);
const rootElement = lynx.getElementById("root");
const newTheme = isDark ? "light" : "dark";
if (rootElement) {
if (isDark) {
rootElement.setProperty({
"--bg-primary": "#ffffff",
"--bg-secondary": "#f5f5f5",
"--text-primary": "#1a1a1a",
"--text-secondary": "#666666",
"--shadow": "rgba(0, 0, 0, 0.1)",
});
} else {
rootElement.setProperty({
"--bg-primary": "#2d2d2d",
"--bg-secondary": "#1a1a1a",
"--text-primary": "#ffffff",
"--text-secondary": "#cccccc",
"--shadow": "rgba(0, 0, 0, 0.3)",
});
}
setIsDark(prev => !prev);
}
};
return (
{isDark ? "🌙" : "☀️"}
{isDark ? "Dark Mode" : "Light Mode"}
Tap to switch theme by className
{isDark ? "🌙" : "☀️"}
{isDark ? "Dark Mode" : "Light Mode"}
Tap to switch theme through JS
Card Sample 1
This is a demo card showing theme switching effects.
Card Sample 2
This is a demo card showing theme switching effects.
Card Sample 3
This is a demo card showing theme switching effects.
Card Sample 4
This is a demo card showing theme switching effects.
{showError && (
Cannot change variables through the class after modifying them in JS!
)}
);
}
root.render();
if (import.meta.webpackHot) {
import.meta.webpackHot.accept();
}