From fccb73ee70105efa056e878091cdd0dfb8fe31bc Mon Sep 17 00:00:00 2001 From: invrainbow <77120437+invrainbow@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:25:31 -0800 Subject: [PATCH] Fix rx.progress to support `max` prop (#2601) --- reflex/components/radix/primitives/progress.py | 9 +++++++-- reflex/components/radix/primitives/progress.pyi | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/reflex/components/radix/primitives/progress.py b/reflex/components/radix/primitives/progress.py index 5854c9e54..8679a55f0 100644 --- a/reflex/components/radix/primitives/progress.py +++ b/reflex/components/radix/primitives/progress.py @@ -55,6 +55,9 @@ class ProgressIndicator(ProgressComponent): # The current progress value. value: Var[Optional[int]] + # The maximum progress value. + max: Var[Optional[int]] + def _apply_theme(self, theme: Component): self.style = Style( { @@ -65,7 +68,7 @@ class ProgressIndicator(ProgressComponent): "&[data_state='loading']": { "transition": f"transform {DEFAULT_ANIMATION_DURATION}ms linear", }, - "transform": f"translateX(calc(-100% + {self.value}%))", # type: ignore + "transform": f"translateX(calc(-100% + ({self.value} / {self.max} * 100%)))", # type: ignore "boxShadow": "inset 0 0 0 1px var(--gray-a5)", } ) @@ -92,7 +95,9 @@ class Progress(SimpleNamespace): style.update({"width": width}) return ProgressRoot.create( - ProgressIndicator.create(value=props.get("value")), + ProgressIndicator.create( + value=props.get("value"), max=props.get("max", 100) + ), **props, ) diff --git a/reflex/components/radix/primitives/progress.pyi b/reflex/components/radix/primitives/progress.pyi index 70e19be44..0fadf594f 100644 --- a/reflex/components/radix/primitives/progress.pyi +++ b/reflex/components/radix/primitives/progress.pyi @@ -188,6 +188,7 @@ class ProgressIndicator(ProgressComponent): cls, *children, value: Optional[Union[Var[Optional[int]], Optional[int]]] = None, + max: Optional[Union[Var[Optional[int]], Optional[int]]] = None, as_child: Optional[Union[Var[bool], bool]] = None, style: Optional[Style] = None, key: Optional[Any] = None, @@ -247,6 +248,7 @@ class ProgressIndicator(ProgressComponent): Args: *children: The children of the component. value: The current progress value. + max: The maximum progress value. as_child: Change the default rendered element for the one passed as a child. style: The style of the component. key: A unique key for the component.