Forráskód Böngészése

Fix rx.progress to support `max` prop (#2601)

invrainbow 1 éve
szülő
commit
fccb73ee70

+ 7 - 2
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,
         )
 

+ 2 - 0
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.