From 392c5b5a690e6c2ef76f908c5474d3fe0cd9b0f3 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Fri, 17 Jan 2025 16:21:53 -0800 Subject: [PATCH] who likes cond --- reflex/components/radix/themes/color_mode.py | 43 +++++++--------- reflex/components/radix/themes/color_mode.pyi | 49 ++----------------- 2 files changed, 24 insertions(+), 68 deletions(-) diff --git a/reflex/components/radix/themes/color_mode.py b/reflex/components/radix/themes/color_mode.py index e93a26ef6..2f46bf72d 100644 --- a/reflex/components/radix/themes/color_mode.py +++ b/reflex/components/radix/themes/color_mode.py @@ -20,7 +20,7 @@ from __future__ import annotations from typing import Dict, List, Literal, Optional, Union, get_args from reflex.components.component import BaseComponent -from reflex.components.core.cond import Cond, color_mode_cond, cond +from reflex.components.core.cond import color_mode_cond, cond from reflex.components.lucide.icon import Icon from reflex.components.radix.themes.components.dropdown_menu import dropdown_menu from reflex.components.radix.themes.components.switch import Switch @@ -40,28 +40,23 @@ DEFAULT_LIGHT_ICON: Icon = Icon.create(tag="sun") DEFAULT_DARK_ICON: Icon = Icon.create(tag="moon") -class ColorModeIcon(Cond): - """Displays the current color mode as an icon.""" +def icon( + light_component: BaseComponent | None = None, + dark_component: BaseComponent | None = None, +): + """Create a color mode icon component. - @classmethod - def create( - cls, - light_component: BaseComponent | None = None, - dark_component: BaseComponent | None = None, - ): - """Create an icon component based on color_mode. + Args: + light_component: The component to render in light mode. + dark_component: The component to render in dark mode. - Args: - light_component: the component to display when color mode is default - dark_component: the component to display when color mode is dark (non-default) - - Returns: - The conditionally rendered component - """ - return color_mode_cond( - light=light_component or DEFAULT_LIGHT_ICON, - dark=dark_component or DEFAULT_DARK_ICON, - ) + Returns: + The color mode icon component. + """ + return color_mode_cond( + light=light_component or DEFAULT_LIGHT_ICON, + dark=dark_component or DEFAULT_DARK_ICON, + ) LiteralPosition = Literal["top-left", "top-right", "bottom-left", "bottom-right"] @@ -150,7 +145,7 @@ class ColorModeIconButton(IconButton): return dropdown_menu.root( dropdown_menu.trigger( super().create( - ColorModeIcon.create(), + icon(), ), **props, ), @@ -161,7 +156,7 @@ class ColorModeIconButton(IconButton): ), ) return IconButton.create( - ColorModeIcon.create(), + icon(), on_click=toggle_color_mode, **props, ) @@ -195,7 +190,7 @@ class ColorModeSwitch(Switch): class ColorModeNamespace(Var): """Namespace for color mode components.""" - icon = staticmethod(ColorModeIcon.create) + icon = icon button = staticmethod(ColorModeIconButton.create) switch = staticmethod(ColorModeSwitch.create) diff --git a/reflex/components/radix/themes/color_mode.pyi b/reflex/components/radix/themes/color_mode.pyi index 3a9347017..43a7e5004 100644 --- a/reflex/components/radix/themes/color_mode.pyi +++ b/reflex/components/radix/themes/color_mode.pyi @@ -7,7 +7,6 @@ from typing import Any, Dict, List, Literal, Optional, Union, overload from reflex.components.component import BaseComponent from reflex.components.core.breakpoints import Breakpoints -from reflex.components.core.cond import Cond from reflex.components.lucide.icon import Icon from reflex.components.radix.themes.components.switch import Switch from reflex.event import BASE_STATE, EventType @@ -19,48 +18,10 @@ from .components.icon_button import IconButton DEFAULT_LIGHT_ICON: Icon DEFAULT_DARK_ICON: Icon -class ColorModeIcon(Cond): - @overload - @classmethod - def create( # type: ignore - cls, - *children, - cond: Optional[Union[Any, Var[Any]]] = None, - comp1: Optional[BaseComponent] = None, - comp2: Optional[BaseComponent] = None, - style: Optional[Style] = None, - key: Optional[Any] = None, - id: Optional[Any] = None, - class_name: Optional[Any] = None, - autofocus: Optional[bool] = None, - custom_attrs: Optional[Dict[str, Union[Var, Any]]] = None, - on_blur: Optional[EventType[[], BASE_STATE]] = None, - on_click: Optional[EventType[[], BASE_STATE]] = None, - on_context_menu: Optional[EventType[[], BASE_STATE]] = None, - on_double_click: Optional[EventType[[], BASE_STATE]] = None, - on_focus: Optional[EventType[[], BASE_STATE]] = None, - on_mount: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_down: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_enter: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_leave: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_move: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_out: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_over: Optional[EventType[[], BASE_STATE]] = None, - on_mouse_up: Optional[EventType[[], BASE_STATE]] = None, - on_scroll: Optional[EventType[[], BASE_STATE]] = None, - on_unmount: Optional[EventType[[], BASE_STATE]] = None, - **props, - ) -> "ColorModeIcon": - """Create an icon component based on color_mode. - - Args: - light_component: the component to display when color mode is default - dark_component: the component to display when color mode is dark (non-default) - - Returns: - The conditionally rendered component - """ - ... +def icon( + light_component: BaseComponent | None = None, + dark_component: BaseComponent | None = None, +): ... LiteralPosition = Literal["top-left", "top-right", "bottom-left", "bottom-right"] position_values: List[str] @@ -442,7 +403,7 @@ class ColorModeSwitch(Switch): ... class ColorModeNamespace(Var): - icon = staticmethod(ColorModeIcon.create) + icon = icon button = staticmethod(ColorModeIconButton.create) switch = staticmethod(ColorModeSwitch.create)