|
@@ -6,7 +6,8 @@ from typing import Any, Dict, Literal
|
|
|
|
|
|
from reflex.components import Component
|
|
|
from reflex.components.tags import Tag
|
|
|
-from reflex.utils import imports
|
|
|
+from reflex.config import get_config
|
|
|
+from reflex.utils.imports import ImportVar
|
|
|
from reflex.vars import Var
|
|
|
|
|
|
LiteralAlign = Literal["start", "center", "end", "baseline", "stretch"]
|
|
@@ -208,18 +209,23 @@ class Theme(RadixThemesComponent):
|
|
|
children = [ThemePanel.create(), *children]
|
|
|
return super().create(*children, **props)
|
|
|
|
|
|
- def _get_imports(self) -> imports.ImportDict:
|
|
|
- return imports.merge_imports(
|
|
|
- super()._get_imports(),
|
|
|
- {
|
|
|
- "": [
|
|
|
- imports.ImportVar(tag="@radix-ui/themes/styles.css", install=False)
|
|
|
- ],
|
|
|
- "/utils/theme.js": [
|
|
|
- imports.ImportVar(tag="theme", is_default=True),
|
|
|
- ],
|
|
|
- },
|
|
|
- )
|
|
|
+ def add_imports(self) -> dict[str, list[ImportVar] | ImportVar]:
|
|
|
+ """Add imports for the Theme component.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ The import dict.
|
|
|
+ """
|
|
|
+ _imports: dict[str, list[ImportVar] | ImportVar] = {
|
|
|
+ "/utils/theme.js": [ImportVar(tag="theme", is_default=True)],
|
|
|
+ }
|
|
|
+ if get_config().tailwind is None:
|
|
|
+ # When tailwind is disabled, import the radix-ui styles directly because they will
|
|
|
+ # not be included in the tailwind.css file.
|
|
|
+ _imports[""] = ImportVar(
|
|
|
+ tag="@radix-ui/themes/styles.css",
|
|
|
+ install=False,
|
|
|
+ )
|
|
|
+ return _imports
|
|
|
|
|
|
def _render(self, props: dict[str, Any] | None = None) -> Tag:
|
|
|
tag = super()._render(props)
|
|
@@ -243,13 +249,13 @@ class ThemePanel(RadixThemesComponent):
|
|
|
# Whether the panel is open. Defaults to False.
|
|
|
default_open: Var[bool]
|
|
|
|
|
|
- def _get_imports(self) -> dict[str, list[imports.ImportVar]]:
|
|
|
- return imports.merge_imports(
|
|
|
- super()._get_imports(),
|
|
|
- {
|
|
|
- "react": [imports.ImportVar(tag="useEffect")],
|
|
|
- },
|
|
|
- )
|
|
|
+ def add_imports(self) -> dict[str, str]:
|
|
|
+ """Add imports for the ThemePanel component.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ The import dict.
|
|
|
+ """
|
|
|
+ return {"react": "useEffect"}
|
|
|
|
|
|
def _get_hooks(self) -> str | None:
|
|
|
# The panel freezes the tab if the user color preference differs from the
|